diff options
213 files changed, 4106 insertions, 8646 deletions
diff --git a/.ci/gcc.sh b/.ci/gcc.sh index 3e4ed505da..5879fe4b20 100644 --- a/.ci/gcc.sh +++ b/.ci/gcc.sh @@ -11,6 +11,7 @@ fi setup_deps x64 CMAKE_EXTRA_FLAGS="-DTRAVIS_CI_BUILD=ON \ + -DUSE_JEMALLOC=OFF \ -DUSE_GCOV=ON \ -DBUSTED_OUTPUT_TYPE=plainTerminal" diff --git a/.travis.yml b/.travis.yml index f557daa9f4..6a5a33cc49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: c os: - linux +branches: + except: + - nightly env: global: - CI_SCRIPTS=$TRAVIS_BUILD_DIR/.ci diff --git a/CMakeLists.txt b/CMakeLists.txt index 4219c69b62..3ab7062019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,29 @@ option(LIBVTERM_USE_STATIC "Use static libvterm" ON) find_package(LibVterm REQUIRED) include_directories(SYSTEM ${LIBVTERM_INCLUDE_DIRS}) +option(SANITIZE "Enable Clang sanitizers for nvim binary" OFF) +if(SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang") + message(WARNING "SANITIZE is only supported for Clang ... disabling") + set(SANITIZE OFF) +endif() + +if(SANITIZE) + option(USE_JEMALLOC "Use jemalloc" OFF) +else() + option(USE_JEMALLOC "Use jemalloc" ON) +endif() + +if(USE_JEMALLOC) + option(JEMALLOC_USE_STATIC "Use static jemalloc" ON) + find_package(JeMalloc) + if(JEMALLOC_FOUND) + message(STATUS "Using jemalloc instead of libc allocator") + include_directories(SYSTEM ${JEMALLOC_INCLUDE_DIRS}) + else() + set(USE_JEMALLOC OFF) + endif() +endif() + find_package(LibIntl) if(LibIntl_FOUND) include_directories(SYSTEM ${LibIntl_INCLUDE_DIRS}) @@ -1,11 +1,11 @@  [Website](http://neovim.org) | +[Community](http://neovim.org/community/) | [Wiki](https://github.com/neovim/neovim/wiki) | [Documentation](http://neovim.org/doc) | [Mailing List](https://groups.google.com/forum/#!forum/neovim) | [Twitter](http://twitter.com/Neovim) | -[Reddit](http://www.reddit.com/r/neovim) | [Bountysource](https://www.bountysource.com/teams/neovim) [](https://travis-ci.org/neovim/neovim) @@ -46,10 +46,6 @@ For lots more details, see There is a formula for OSX/homebrew, a PKGBUILD for Arch Linux, RPM, deb, and more. See [the wiki](https://github.com/neovim/neovim/wiki/Installing-Neovim)! -### Community - -Join the community on IRC in #neovim on Freenode or the [mailing list](https://groups.google.com/forum/#!forum/neovim) - ### Contributing ...would be awesome! See [the wiki](https://github.com/neovim/neovim/wiki/Contributing) for more details. @@ -63,7 +59,7 @@ parts that were contributed under the Vim license. not sign the Contributor License Agreement (CLA) remain under the Vim license. - Contributions committed after [b17d96][license-commit] are licensed under - Apache 2.0 unless those contributions were copied from Vim (identified in + Apache 2.0 unless those contributions were copied from Vim (identified in the commit logs by the `vim-patch` token). See `LICENSE` for details. @@ -1274,6 +1274,39 @@ def CheckPosixThreading(filename, clean_lines, linenum, error): ' see os_localtime_r for an example.') +memory_functions = ( + ('malloc(', 'xmalloc('), + ('calloc(', 'xcalloc('), + ('realloc(', 'xrealloc('), + ('strdup(', 'xstrdup('), + ('free(', 'xfree('), +) +memory_ignore_pattern = re.compile(r'src/nvim/memory.c$') + + +def CheckMemoryFunctions(filename, clean_lines, linenum, error): + """Checks for calls to invalid functions. + + Args: + filename: The name of the current file. + clean_lines: A CleansedLines instance containing the file. + linenum: The number of the line to check. + error: The function to call with any errors found. + """ + if memory_ignore_pattern.search(filename): + return + line = clean_lines.elided[linenum] + for function, suggested_function in memory_functions: + ix = line.find(function) + # Comparisons made explicit for clarity -- pylint: + # disable=g-explicit-bool-comparison + if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and + line[ix - 1] not in ('_', '.', '>'))): + error(filename, linenum, 'runtime/memory_fn', 2, + 'Use ' + suggested_function + + '...) instead of ' + function + '...).') + + # Matches invalid increment: *count++, which moves pointer instead of # incrementing a value. _RE_PATTERN_INVALID_INCREMENT = re.compile( @@ -2925,6 +2958,7 @@ def ProcessLine(filename, file_extension, clean_lines, line, CheckForNonStandardConstructs(filename, clean_lines, line, nesting_state, error) CheckPosixThreading(filename, clean_lines, line, error) + CheckMemoryFunctions(filename, clean_lines, line, error) for check_fn in extra_check_functions: check_fn(filename, clean_lines, line, error) diff --git a/cmake/FindJeMalloc.cmake b/cmake/FindJeMalloc.cmake new file mode 100644 index 0000000000..fd20a456fb --- /dev/null +++ b/cmake/FindJeMalloc.cmake @@ -0,0 +1,48 @@ +# - Try to find jemalloc +# Once done this will define +# JEMALLOC_FOUND - System has jemalloc +# JEMALLOC_INCLUDE_DIRS - The jemalloc include directories +# JEMALLOC_LIBRARIES - The libraries needed to use jemalloc + +find_package(PkgConfig) +if(NOT JEMALLOC_USE_BUNDLED) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(PC_JEMALLOC QUIET jemalloc) + endif() +else() + set(PC_JEMALLOC_INCLUDEDIR) + set(PC_JEMALLOC_INCLUDE_DIRS) + set(PC_JEMALLOC_LIBDIR) + set(PC_JEMALLOC_LIBRARY_DIRS) + set(LIMIT_SEARCH NO_DEFAULT_PATH) +endif() + +set(JEMALLOC_DEFINITIONS ${PC_JEMALLOC_CFLAGS_OTHER}) + +find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h + PATHS ${PC_JEMALLOC_INCLUDEDIR} ${PC_JEMALLOC_INCLUDE_DIRS} + ${LIMIT_SEARCH}) + +# If we're asked to use static linkage, add libjemalloc.a as a preferred library name. +if(JEMALLOC_USE_STATIC) + list(APPEND JEMALLOC_NAMES + "${CMAKE_STATIC_LIBRARY_PREFIX}jemalloc${CMAKE_STATIC_LIBRARY_SUFFIX}") +endif() + +list(APPEND JEMALLOC_NAMES jemalloc) + +find_library(JEMALLOC_LIBRARY NAMES ${JEMALLOC_NAMES} + HINTS ${PC_JEMALLOC_LIBDIR} ${PC_JEMALLOC_LIBRARY_DIRS} + ${LIMIT_SEARCH}) + +set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY}) +set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(JeMalloc DEFAULT_MSG + JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR) + +mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY) diff --git a/cmake/GenerateHelptags.cmake b/cmake/GenerateHelptags.cmake index 658f4ab9cc..d4f4518b9b 100644 --- a/cmake/GenerateHelptags.cmake +++ b/cmake/GenerateHelptags.cmake @@ -9,6 +9,12 @@ else() endif() message(STATUS "Generating helptags in ${HELPTAGS_WORKING_DIRECTORY}.") +if(EXISTS "${HELPTAGS_WORKING_DIRECTORY}/") + message(STATUS "${HELPTAGS_WORKING_DIRECTORY} already exists") + # if the doc directory already exists, helptags could fail due to duplicate + # tags. Tell the user to remove the directory and try again. + set(TROUBLESHOOTING "\nRemove \"${HELPTAGS_WORKING_DIRECTORY}\" and try again") +endif() execute_process( COMMAND "${CMAKE_CURRENT_BINARY_DIR}/bin/nvim" @@ -22,5 +28,5 @@ execute_process( RESULT_VARIABLE res) if(NOT res EQUAL 0) - message(FATAL_ERROR "Generating helptags failed: ${err} - ${res}") + message(FATAL_ERROR "Generating helptags failed: ${err} - ${res}${TROUBLESHOOTING}") endif() diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index 0d3ef62297..ed1f422070 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -58,6 +58,7 @@ check_function_exists(setenv HAVE_SETENV) if(NOT HAVE_SETENV) message(SEND_ERROR "setenv() function not found on your system.") endif() +check_function_exists(unsetenv HAVE_UNSETENV) check_function_exists(setpgid HAVE_SETPGID) check_function_exists(setsid HAVE_SETSID) check_function_exists(sigaction HAVE_SIGACTION) diff --git a/config/config.h.in b/config/config.h.in index 382b5c653d..9b2abfa19d 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -37,6 +37,7 @@ // TODO: add proper cmake check // #define HAVE_SELINUX 1 #cmakedefine HAVE_SETENV +#cmakedefine HAVE_UNSETENV #cmakedefine HAVE_SETPGID #cmakedefine HAVE_SETSID #cmakedefine HAVE_SIGACTION @@ -65,5 +66,6 @@ #define FEAT_BROWSE #define FEAT_CSCOPE #define FEAT_MOUSE +#cmakedefine USE_JEMALLOC #endif // AUTO_CONFIG_H diff --git a/config/pathdef.c.in b/config/pathdef.c.in index b30bcfd3f1..faf4267ce8 100644 --- a/config/pathdef.c.in +++ b/config/pathdef.c.in @@ -1,5 +1,5 @@ #include "${PROJECT_SOURCE_DIR}/src/nvim/vim.h" -char_u *default_vim_dir = (char_u *)"${CMAKE_INSTALL_PREFIX}/share/nvim"; -char_u *default_vimruntime_dir = (char_u *)""; +char *default_vim_dir = "${CMAKE_INSTALL_PREFIX}/share/nvim"; +char *default_vimruntime_dir = ""; char_u *compiled_user = (char_u *)"${USERNAME}"; char_u *compiled_sys = (char_u *)"${HOSTNAME}"; diff --git a/runtime/autoload/remote/host.vim b/runtime/autoload/remote/host.vim index b07593f39b..ebbd85b6e6 100644 --- a/runtime/autoload/remote/host.vim +++ b/runtime/autoload/remote/host.vim @@ -133,6 +133,11 @@ function! s:RegistrationCommands(host) let lines = [] for path in paths let specs = rpcrequest(channel, 'specs', path) + if type(specs) != type([]) + " host didn't return a spec list, indicates a failure while loading a + " plugin + continue + endif call add(lines, "call remote#host#RegisterPlugin('".a:host \ ."', '".path."', [") for spec in specs @@ -244,9 +249,10 @@ function! s:RequirePythonHost(name) endif catch endtry - throw 'Failed to load python host.' . - \ " Try upgrading the Neovim python module with 'pip install --upgrade neovim'" . - \ " or see ':help nvim-python'." + throw 'Failed to load python host. You can try to see what happened ' . + \ 'by starting Neovim with $NVIM_PYTHON_PYTHON_LOG and opening '. + \ 'the generated log file. Also, the host stderr will be available '. + \ 'in Neovim log, so it may contain useful information.' endfunction call remote#host#Register('python', function('s:RequirePythonHost')) diff --git a/runtime/doc/Makefile b/runtime/doc/Makefile index 4bced03d7e..e0d6e48cb9 100644 --- a/runtime/doc/Makefile +++ b/runtime/doc/Makefile @@ -34,12 +34,7 @@ DOCS = \ helphelp.txt \ howto.txt \ if_cscop.txt \ - if_lua.txt \ - if_mzsch.txt \ - if_perl.txt \ if_pyth.txt \ - if_ruby.txt \ - if_tcl.txt \ indent.txt \ index.txt \ insert.txt \ @@ -156,12 +151,7 @@ HTMLS = \ helphelp.html \ howto.html \ if_cscop.html \ - if_lua.html \ - if_mzsch.html \ - if_perl.html \ if_pyth.html \ - if_ruby.html \ - if_tcl.html \ indent.html \ index.html \ insert.html \ diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 1393131ab7..f771c225f4 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -791,7 +791,7 @@ ShellCmdPost After executing a shell command with |:!cmd|, |:make| and |:grep|. Can be used to check for any changed files. For non-blocking shell commands, see - |JobActivity|. + |job-control|. *ShellFilterPost* ShellFilterPost After executing a shell command with ":{range}!cmd", ":w !cmd" or ":r !cmd". diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index b426799239..da101e2dd1 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -522,8 +522,6 @@ followed by another Vim command: :lcscope :make :normal - :perl - :perldo :promptfind :promptrepl :pyfile @@ -532,9 +530,6 @@ followed by another Vim command: :read ! :scscope :sign - :tcl - :tcldo - :tclfile :vglobal :windo :write ! diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 710793fb04..a9ed4acb19 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1879,7 +1879,6 @@ lispindent( {lnum}) Number Lisp indent for line {lnum} localtime() Number current time log( {expr}) Float natural logarithm (base e) of {expr} log10( {expr}) Float logarithm of Float {expr} to base 10 -luaeval( {expr}[, {expr}]) any evaluate |Lua| expression map( {expr}, {string}) List/Dict change each item in {expr} to {expr} maparg( {name}[, {mode} [, {abbr} [, {dict}]]]) String or Dict @@ -1905,7 +1904,6 @@ min( {list}) Number minimum value of items in {list} mkdir( {name} [, {path} [, {prot}]]) Number create directory {name} mode( [expr]) String current editing mode -mzeval( {expr}) any evaluate |MzScheme| expression nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum} nr2char( {expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr} or( {expr}, {expr}) Number bitwise OR @@ -4061,9 +4059,9 @@ jobstop({job}) {Nvim} *jobstop()* Stop a job created with |jobstart()| by sending a `SIGTERM` to the corresponding process. If the process doesn't exit cleanly soon, a `SIGKILL` will be sent. When the job is - finally closed, a |JobActivity| event will trigger with - `v:job_data[0]` set to `exited`. See |job-control| for more - information. + finally closed, the exit handler provided to |jobstart()| or + |termopen()| will be run. + See |job-control| for more information. jobwait({ids}[, {timeout}]) {Nvim} *jobwait()* Wait for a set of jobs to finish. The {ids} argument is a list @@ -4239,19 +4237,6 @@ log10({expr}) *log10()* < -2.0 -luaeval({expr}[, {expr}]) *luaeval()* - Evaluate Lua expression {expr} and return its result converted - to Vim data structures. Second {expr} may hold additional - argument accessible as _A inside first {expr}. - Strings are returned as they are. - Boolean objects are converted to numbers. - Numbers are converted to |Float| values. - Dictionaries and lists obtained by vim.eval() are returned - as-is. - Other objects are returned as zero without any errors. - See |lua-luaeval| for more details. - {only available when compiled with the |+lua| feature} - map({expr}, {string}) *map()* {expr} must be a |List| or a |Dictionary|. Replace each item in {expr} with the result of evaluating @@ -4615,23 +4600,6 @@ mode([expr]) Return a string that indicates the current mode. "c" or "n". Also see |visualmode()|. -mzeval({expr}) *mzeval()* - Evaluate MzScheme expression {expr} and return its result - converted to Vim data structures. - Numbers and strings are returned as they are. - Pairs (including lists and improper lists) and vectors are - returned as Vim |Lists|. - Hash tables are represented as Vim |Dictionary| type with keys - converted to strings. - All other types are converted to string with display function. - Examples: > - :mz (define l (list 1 2 3)) - :mz (define h (make-hash)) (hash-set! h "list" l) - :echo mzeval("l") - :echo mzeval("h") -< - {only available when compiled with the |+mzscheme| feature} - nextnonblank({lnum}) *nextnonblank()* Return the line number of the first line at or below {lnum} that is not blank. Example: > @@ -5405,13 +5373,25 @@ server2client( {clientid}, {string}) *server2client()* :echo server2client(expand("<client>"), "HELLO") < serverlist() *serverlist()* - Return a list of available server names, one per line. - When there are no servers or the information is not available - an empty string is returned. See also |clientserver|. - {only available when compiled with the |+clientserver| feature} + Returns a list of available server names in a list. + When there are no servers an empty string is returned. Example: > :echo serverlist() < +serverlisten([{address}]) *serverlisten()* + Opens a Unix or TCP socket at {address} for clients to connect + to and returns {address}. If no address is given, it is + equivalent to > + :call serverlisten(tempname()) +< If |$NVIM_LISTEN_ADDRESS| is not set, it will be set to + {address}. + +serverstop({address}) *serverstop()* + Closes the Unix or TCP socket at {address}. Does nothing if + {address} is empty, or does not refer to a server. If + {address} equals |$NVIM_LISTEN_ADDRESS|, the listen address + will be unset. + setbufvar({expr}, {varname}, {val}) *setbufvar()* Set option or local variable {varname} in buffer {expr} to {val}. @@ -6773,7 +6753,6 @@ lispindent Compiled with support for lisp indenting. listcmds Compiled with commands for the buffer list |:files| and the argument list |arglist|. localmap Compiled with local mappings and abbr. |:map-local| -lua Compiled with Lua interface |Lua|. mac Macintosh version of Vim. macunix Macintosh version of Vim, using Unix files (OS-X). menu Compiled with support for |:menu|. @@ -6792,10 +6771,8 @@ multi_byte Compiled with support for 'encoding' multi_byte_encoding 'encoding' is set to a multi-byte encoding. multi_byte_ime Compiled with support for IME input method. multi_lang Compiled with support for multiple languages. -mzscheme Compiled with MzScheme interface |mzscheme|. ole Compiled with OLE automation support for Win32. path_extra Compiled with up/downwards search in 'path' and 'tags' -perl Compiled with Perl interface. persistent_undo Compiled with support for persistent undo history. postscript Compiled with PostScript file printing. printer Compiled with |:hardcopy| support. @@ -6805,12 +6782,10 @@ python3 Compiled with Python 3.x interface. |has-python| quickfix Compiled with |quickfix| support. reltime Compiled with |reltime()| support. rightleft Compiled with 'rightleft' support. -ruby Compiled with Ruby interface |ruby|. scrollbind Compiled with 'scrollbind' support. showcmd Compiled with 'showcmd' support. signs Compiled with |:sign| support. smartindent Compiled with 'smartindent' support. -sniff Compiled with SNiFF interface support. spell Compiled with spell checking support |spell|. startuptime Compiled with |--startuptime| support. statusline Compiled with support for 'statusline', 'rulerformat' @@ -6825,7 +6800,6 @@ tag_old_static Compiled with support for old static tags |tag-old-static|. tag_any_white Compiled with support for any white characters in tags files |tag-any-white|. -tcl Compiled with Tcl interface. terminfo Compiled with terminfo instead of termcap. termresponse Compiled with support for |t_RV| and |v:termresponse|. textobjects Compiled with support for |text-objects|. diff --git a/runtime/doc/help.txt b/runtime/doc/help.txt index 34ca6d0d12..347c1310ff 100644 --- a/runtime/doc/help.txt +++ b/runtime/doc/help.txt @@ -156,12 +156,7 @@ GUI ~ Interfaces ~ |if_cscop.txt| using Cscope with Vim -|if_lua.txt| Lua interface -|if_mzsch.txt| MzScheme interface -|if_perl.txt| Perl interface |if_pyth.txt| Python interface -|if_tcl.txt| Tcl interface -|if_ruby.txt| Ruby interface |debugger.txt| Interface with a debugger |sign.txt| debugging signs diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt deleted file mode 100644 index 2b322ddbae..0000000000 --- a/runtime/doc/if_lua.txt +++ /dev/null @@ -1,403 +0,0 @@ -*if_lua.txt* For Vim version 7.4. Last change: 2013 Sep 04 - - - VIM REFERENCE MANUAL by Luis Carvalho - - -The Lua Interface to Vim *lua* *Lua* - -1. Commands |lua-commands| -2. The vim module |lua-vim| -3. List userdata |lua-list| -4. Dict userdata |lua-dict| -5. Funcref userdata |lua-funcref| -6. Buffer userdata |lua-buffer| -7. Window userdata |lua-window| -8. The luaeval function |lua-luaeval| - -{Vi does not have any of these commands} - -The Lua interface is available only when Vim was compiled with the -|+lua| feature. - -============================================================================== -1. Commands *lua-commands* - - *:lua* -:[range]lua {chunk} - Execute Lua chunk {chunk}. {not in Vi} - -Examples: -> - :lua print("Hello, Vim!") - :lua local curbuf = vim.buffer() curbuf[7] = "line #7" -< - -:[range]lua << {endmarker} -{script} -{endmarker} - Execute Lua script {script}. {not in Vi} - Note: This command doesn't work when the Lua - feature wasn't compiled in. To avoid errors, see - |script-here|. - -{endmarker} must NOT be preceded by any white space. If {endmarker} is -omitted from after the "<<", a dot '.' must be used after {script}, like -for the |:append| and |:insert| commands. -This form of the |:lua| command is mainly useful for including Lua code -in Vim scripts. - -Example: -> - function! CurrentLineInfo() - lua << EOF - local linenr = vim.window().line - local curline = vim.buffer()[linenr] - print(string.format("Current line [%d] has %d chars", - linenr, #curline)) - EOF - endfunction -< - - *:luado* -:[range]luado {body} Execute Lua function "function (line, linenr) {body} - end" for each line in the [range], with the function - argument being set to the text of each line in turn, - without a trailing <EOL>, and the current line number. - If the value returned by the function is a string it - becomes the text of the line in the current turn. The - default for [range] is the whole file: "1,$". - {not in Vi} - -Examples: -> - :luado return string.format("%s\t%d", line:reverse(), #line) - - :lua require"lpeg" - :lua -- balanced parenthesis grammar: - :lua bp = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" } - :luado if bp:match(line) then return "-->\t" .. line end -< - - *:luafile* -:[range]luafile {file} - Execute Lua script in {file}. {not in Vi} - The whole argument is used as a single file name. - -Examples: -> - :luafile script.lua - :luafile % -< - -All these commands execute a Lua chunk from either the command line (:lua and -:luado) or a file (:luafile) with the given line [range]. Similarly to the Lua -interpreter, each chunk has its own scope and so only global variables are -shared between command calls. All Lua default libraries are available. In -addition, Lua "print" function has its output redirected to the Vim message -area, with arguments separated by a white space instead of a tab. - -Lua uses the "vim" module (see |lua-vim|) to issue commands to Vim -and manage buffers (|lua-buffer|) and windows (|lua-window|). However, -procedures that alter buffer content, open new buffers, and change cursor -position are restricted when the command is executed in the |sandbox|. - - -============================================================================== -2. The vim module *lua-vim* - -Lua interfaces Vim through the "vim" module. The first and last line of the -input range are stored in "vim.firstline" and "vim.lastline" respectively. The -module also includes routines for buffer, window, and current line queries, -Vim evaluation and command execution, and others. - - vim.list([arg]) Returns an empty list or, if "arg" is a Lua - table with numeric keys 1, ..., n (a - "sequence"), returns a list l such that l[i] = - arg[i] for i = 1, ..., n (see |List|). - Non-numeric keys are not used to initialize - the list. See also |lua-eval| for conversion - rules. Example: > - :lua t = {math.pi, false, say = 'hi'} - :echo luaeval('vim.list(t)') - :" [3.141593, 0], 'say' is ignored -< - vim.dict([arg]) Returns an empty dictionary or, if "arg" is a - Lua table, returns a dict d such that d[k] = - arg[k] for all string keys k in "arg" (see - |Dictionary|). Number keys are converted to - strings. Keys that are not strings are not - used to initialize the dictionary. See also - |lua-eval| for conversion rules. Example: > - :lua t = {math.pi, false, say = 'hi'} - :echo luaeval('vim.dict(t)') - :" {'say': 'hi'}, numeric keys ignored -< - vim.funcref({name}) Returns a Funcref to function {name} (see - |Funcref|). It is equivalent to Vim's - "function". NOT IMPLEMENTED YET - - vim.buffer([arg]) If "arg" is a number, returns buffer with - number "arg" in the buffer list or, if "arg" - is a string, returns buffer whose full or short - name is "arg". In both cases, returns 'nil' - (nil value, not string) if the buffer is not - found. Otherwise, if "toboolean(arg)" is - 'true' returns the first buffer in the buffer - list or else the current buffer. - - vim.window([arg]) If "arg" is a number, returns window with - number "arg" or 'nil' (nil value, not string) - if not found. Otherwise, if "toboolean(arg)" - is 'true' returns the first window or else the - current window. - - vim.type({arg}) Returns the type of {arg}. It is equivalent to - Lua's "type" function, but returns "list", - "dict", "funcref", "buffer", or "window" if - {arg} is a list, dictionary, funcref, buffer, - or window, respectively. Examples: > - :lua l = vim.list() - :lua print(type(l), vim.type(l)) - :" userdata list -< - vim.command({cmd}) Executes the vim (ex-mode) command {cmd}. - Examples: > - :lua vim.command"set tw=60" - :lua vim.command"normal ddp" -< - vim.eval({expr}) Evaluates expression {expr} (see |expression|), - converts the result to Lua, and returns it. - Vim strings and numbers are directly converted - to Lua strings and numbers respectively. Vim - lists and dictionaries are converted to Lua - userdata (see |lua-list| and |lua-dict|). - Examples: > - :lua tw = vim.eval"&tw" - :lua print(vim.eval"{'a': 'one'}".a) -< - vim.line() Returns the current line (without the trailing - <EOL>), a Lua string. - - vim.beep() Beeps. - - vim.open({fname}) Opens a new buffer for file {fname} and - returns it. Note that the buffer is not set as - current. - - -============================================================================== -3. List userdata *lua-list* - -List userdata represent vim lists, and the interface tries to follow closely -Vim's syntax for lists. Since lists are objects, changes in list references in -Lua are reflected in Vim and vice-versa. A list "l" has the following -properties and methods: - -Properties ----------- - o "#l" is the number of items in list "l", equivalent to "len(l)" - in Vim. - o "l[k]" returns the k-th item in "l"; "l" is zero-indexed, as in Vim. - To modify the k-th item, simply do "l[k] = newitem"; in - particular, "l[k] = nil" removes the k-th item from "l". - o "l()" returns an iterator for "l". - -Methods -------- - o "l:add(item)" appends "item" to the end of "l". - o "l:insert(item[, pos])" inserts "item" at (optional) - position "pos" in the list. The default value for "pos" is 0. - -Examples: -> - :let l = [1, 'item'] - :lua l = vim.eval('l') -- same 'l' - :lua l:add(vim.list()) - :lua l[0] = math.pi - :echo l[0] " 3.141593 - :lua l[0] = nil -- remove first item - :lua l:insert(true, 1) - :lua print(l, #l, l[0], l[1], l[-1]) - :lua for item in l() do print(item) end -< - -============================================================================== -4. Dict userdata *lua-dict* - -Similarly to list userdata, dict userdata represent vim dictionaries; since -dictionaries are also objects, references are kept between Lua and Vim. A dict -"d" has the following properties: - -Properties ----------- - o "#d" is the number of items in dict "d", equivalent to "len(d)" - in Vim. - o "d.key" or "d['key']" returns the value at entry "key" in "d". - To modify the entry at this key, simply do "d.key = newvalue"; in - particular, "d.key = nil" removes the entry from "d". - o "d()" returns an iterator for "d" and is equivalent to "items(d)" in - Vim. - -Examples: -> - :let d = {'n':10} - :lua d = vim.eval('d') -- same 'd' - :lua print(d, d.n, #d) - :let d.self = d - :lua for k, v in d() do print(d, k, v) end - :lua d.x = math.pi - :lua d.self = nil -- remove entry - :echo d -< - -============================================================================== -5. Funcref userdata *lua-funcref* - -Funcref userdata represent funcref variables in Vim. Funcrefs that were -defined with a "dict" attribute need to be obtained as a dictionary key -in order to have "self" properly assigned to the dictionary (see examples -below.) A funcref "f" has the following properties: - -Properties ----------- - o "#f" is the name of the function referenced by "f" - o "f(...)" calls the function referenced by "f" (with arguments) - -Examples: -> - :function I(x) - : return a:x - : endfunction - :let R = function('I') - :lua i1 = vim.funcref('I') - :lua i2 = vim.eval('R') - :lua print(#i1, #i2) -- both 'I' - :lua print(i1, i2, #i2(i1) == #i1(i2)) - :function Mylen() dict - : return len(self.data) - : endfunction - :let mydict = {'data': [0, 1, 2, 3]} - :lua d = vim.eval('mydict'); d.len = vim.funcref('Mylen') - :echo mydict.len() - :lua l = d.len -- assign d as 'self' - :lua print(l()) -< - -============================================================================== -6. Buffer userdata *lua-buffer* - -Buffer userdata represent vim buffers. A buffer userdata "b" has the following -properties and methods: - -Properties ----------- - o "b()" sets "b" as the current buffer. - o "#b" is the number of lines in buffer "b". - o "b[k]" represents line number k: "b[k] = newline" replaces line k - with string "newline" and "b[k] = nil" deletes line k. - o "b.name" contains the short name of buffer "b" (read-only). - o "b.fname" contains the full name of buffer "b" (read-only). - o "b.number" contains the position of buffer "b" in the buffer list - (read-only). - -Methods -------- - o "b:insert(newline[, pos])" inserts string "newline" at (optional) - position "pos" in the buffer. The default value for "pos" is - "#b + 1". If "pos == 0" then "newline" becomes the first line in - the buffer. - o "b:next()" returns the buffer next to "b" in the buffer list. - o "b:previous()" returns the buffer previous to "b" in the buffer - list. - o "b:isvalid()" returns 'true' (boolean) if buffer "b" corresponds to - a "real" (not freed from memory) Vim buffer. - -Examples: -> - :lua b = vim.buffer() -- current buffer - :lua print(b.name, b.number) - :lua b[1] = "first line" - :lua b:insert("FIRST!", 0) - :lua b[1] = nil -- delete top line - :lua for i=1,3 do b:insert(math.random()) end - :3,4lua for i=vim.lastline,vim.firstline,-1 do b[i] = nil end - :lua vim.open"myfile"() -- open buffer and set it as current - - function! ListBuffers() - lua << EOF - local b = vim.buffer(true) -- first buffer in list - while b ~= nil do - print(b.number, b.name, #b) - b = b:next() - end - vim.beep() - EOF - endfunction -< - -============================================================================== -7. Window userdata *lua-window* - -Window objects represent vim windows. A window userdata "w" has the following -properties and methods: - -Properties ----------- - o "w()" sets "w" as the current window. - o "w.buffer" contains the buffer of window "w" (read-only). - o "w.line" represents the cursor line position in window "w". - o "w.col" represents the cursor column position in window "w". - o "w.width" represents the width of window "w". - o "w.height" represents the height of window "w". - -Methods -------- - o "w:next()" returns the window next to "w". - o "w:previous()" returns the window previous to "w". - o "w:isvalid()" returns 'true' (boolean) if window "w" corresponds to - a "real" (not freed from memory) Vim window. - -Examples: -> - :lua w = vim.window() -- current window - :lua print(w.buffer.name, w.line, w.col) - :lua w.width = w.width + math.random(10) - :lua w.height = 2 * math.random() * w.height - :lua n,w = 0,vim.window(true) while w~=nil do n,w = n + 1,w:next() end - :lua print("There are " .. n .. " windows") -< - -============================================================================== -8. The luaeval function *lua-luaeval* *lua-eval* - -The (dual) equivalent of "vim.eval" for passing Lua values to Vim is -"luaeval". "luaeval" takes an expression string and an optional argument and -returns the result of the expression. It is semantically equivalent in Lua to: -> - local chunkheader = "local _A = select(1, ...) return " - function luaeval (expstr, arg) - local chunk = assert(loadstring(chunkheader .. expstr, "luaeval")) - return chunk(arg) -- return typval - end -< -Note that "_A" receives the argument to "luaeval". Lua numbers, strings, and -list, dict, and funcref userdata are converted to their Vim respective types, -while Lua booleans are converted to numbers. An error is thrown if conversion -of any of the remaining Lua types, including userdata other than lists, dicts, -and funcrefs, is attempted. - -Examples: > - - :echo luaeval('math.pi') - :lua a = vim.list():add('newlist') - :let a = luaeval('a') - :echo a[0] " 'newlist' - :function Rand(x,y) " random uniform between x and y - : return luaeval('(_A.y-_A.x)*math.random()+_A.x', {'x':a:x,'y':a:y}) - : endfunction - :echo Rand(1,10) - - -============================================================================== - vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/if_mzsch.txt b/runtime/doc/if_mzsch.txt deleted file mode 100644 index b42570a75a..0000000000 --- a/runtime/doc/if_mzsch.txt +++ /dev/null @@ -1,286 +0,0 @@ -*if_mzsch.txt* For Vim version 7.4. Last change: 2012 Dec 17 - - - VIM REFERENCE MANUAL by Sergey Khorev - - -The MzScheme Interface to Vim *mzscheme* *MzScheme* - -1. Commands |mzscheme-commands| -2. Examples |mzscheme-examples| -3. Threads |mzscheme-threads| -4. Vim access from MzScheme |mzscheme-vim| -5. mzeval() Vim function |mzscheme-mzeval| -6. Using Function references |mzscheme-funcref| -7. Dynamic loading |mzscheme-dynamic| - -{Vi does not have any of these commands} - -The MzScheme interface is available only if Vim was compiled with the -|+mzscheme| feature. - -Based on the work of Brent Fulgham. -Dynamic loading added by Sergey Khorev - -MzScheme and PLT Scheme names have been rebranded as Racket. For more -information please check http://racket-lang.org - -Futures and places of Racket version 5.x up to and including 5.3.1 do not -work correctly with processes created by Vim. -The simplest solution is to build Racket on your own with these features -disabled: > - ./configure --disable-futures --disable-places --prefix=your-install-prefix - -To speed up the process, you might also want to use --disable-gracket and ---disable-docs - -============================================================================== -1. Commands *mzscheme-commands* - - *:mzscheme* *:mz* -:[range]mz[scheme] {stmt} - Execute MzScheme statement {stmt}. {not in Vi} - -:[range]mz[scheme] << {endmarker} -{script} -{endmarker} - Execute inlined MzScheme script {script}. - Note: This command doesn't work if the MzScheme - feature wasn't compiled in. To avoid errors, see - |script-here|. - - *:mzfile* *:mzf* -:[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi} - -All of these commands do essentially the same thing - they execute a piece of -MzScheme code, with the "current range" set to the given line -range. - -In the case of :mzscheme, the code to execute is in the command-line. -In the case of :mzfile, the code to execute is the contents of the given file. - -MzScheme interface defines exception exn:vim, derived from exn. -It is raised for various Vim errors. - -During compilation, the MzScheme interface will remember the current MzScheme -collection path. If you want to specify additional paths use the -'current-library-collection-paths' parameter. E.g., to cons the user-local -MzScheme collection path: > - :mz << EOF - (current-library-collection-paths - (cons - (build-path (find-system-path 'addon-dir) (version) "collects") - (current-library-collection-paths))) - EOF -< - -All functionality is provided through module vimext. - -The exn:vim is available without explicit import. - -To avoid clashes with MzScheme, consider using prefix when requiring module, -e.g.: > - :mzscheme (require (prefix vim- vimext)) -< -All the examples below assume this naming scheme. - - *mzscheme-sandbox* -When executed in the |sandbox|, access to some filesystem and Vim interface -procedures is restricted. - -============================================================================== -2. Examples *mzscheme-examples* -> - :mzscheme (display "Hello") - :mz (display (string-append "Using MzScheme version " (version))) - :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x - :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x - :mzscheme (vim-set-buff-line 10 "This is line #10") -< -Inline script usage: > - function! <SID>SetFirstLine() - :mz << EOF - (display "!!!") - (require (prefix vim- vimext)) - ; for newer versions (require (prefix-in vim- 'vimext)) - (vim-set-buff-line 1 "This is line #1") - (vim-beep) - EOF - endfunction - - nmap <F9> :call <SID>SetFirstLine() <CR> -< -File execution: > - :mzfile supascript.scm -< -Vim exception handling: > - :mz << EOF - (require (prefix vim- vimext)) - ; for newer versions (require (prefix-in vim- 'vimext)) - (with-handlers - ([exn:vim? (lambda (e) (display (exn-message e)))]) - (vim-eval "nonsense-string")) - EOF -< -Auto-instantiation of vimext module (can be placed in your |vimrc|): > - function! MzRequire() - :redir => l:mzversion - :mz (version) - :redir END - if strpart(l:mzversion, 1, 1) < "4" - " MzScheme versions < 4.x: - :mz (require (prefix vim- vimext)) - else - " newer versions: - :mz (require (prefix-in vim- 'vimext)) - endif - endfunction - - if has("mzscheme") - silent call MzRequire() - endif -< -============================================================================== -3. Threads *mzscheme-threads* - -The MzScheme interface supports threads. They are independent from OS threads, -thus scheduling is required. The option 'mzquantum' determines how often -Vim should poll for available MzScheme threads. -NOTE -Thread scheduling in the console version of Vim is less reliable than in the -GUI version. - -============================================================================== -4. Vim access from MzScheme *mzscheme-vim* - - *mzscheme-vimext* -The 'vimext' module provides access to procedures defined in the MzScheme -interface. - -Common ------- - (command {command-string}) Perform the vim ":Ex" style command. - (eval {expr-string}) Evaluate the vim expression into - respective MzScheme object: |Lists| are - represented as Scheme lists, - |Dictionaries| as hash tables, - |Funcref|s as functions (see also - |mzscheme-funcref|) - NOTE the name clashes with MzScheme eval, - use module qualifiers to overcome this. - (range-start) Start/End of the range passed with - (range-end) the Scheme command. - (beep) beep - (get-option {option-name} [buffer-or-window]) Get Vim option value (either - local or global, see set-option). - (set-option {string} [buffer-or-window]) - Set a Vim option. String must have option - setting form (like optname=optval, or - optname+=optval, etc.) When called with - {buffer} or {window} the local option will - be set. The symbol 'global can be passed - as {buffer-or-window}. Then |:setglobal| - will be used. - -Buffers *mzscheme-buffer* -------- - (buff? {object}) Is object a buffer? - (buff-valid? {object}) Is object a valid buffer? (i.e. - corresponds to the real Vim buffer) - (get-buff-line {linenr} [buffer]) - Get line from a buffer. - (set-buff-line {linenr} {string} [buffer]) - Set a line in a buffer. If {string} is #f, - the line gets deleted. The [buffer] - argument is optional. If omitted, the - current buffer will be used. - (get-buff-line-list {start} {end} [buffer]) - Get a list of lines in a buffer. {Start} - and {end} are 1-based and inclusive. - (set-buff-line-list {start} {end} {string-list} [buffer]) - Set a list of lines in a buffer. If - string-list is #f or null, the lines get - deleted. If a list is shorter than - {end}-{start} the remaining lines will - be deleted. - (get-buff-name [buffer]) Get a buffer's text name. - (get-buff-num [buffer]) Get a buffer's number. - (get-buff-size [buffer]) Get buffer line count. - (insert-buff-line-list {linenr} {string/string-list} [buffer]) - Insert a list of lines into a buffer after - {linenr}. If {linenr} is 0, lines will be - inserted at start. - (curr-buff) Get the current buffer. Use other MzScheme - interface procedures to change it. - (buff-count) Get count of total buffers in the editor. - (get-next-buff [buffer]) Get next buffer. - (get-prev-buff [buffer]) Get previous buffer. Return #f when there - are no more buffers. - (open-buff {filename}) Open a new buffer (for file "name") - (get-buff-by-name {buffername}) Get a buffer by its filename or #f - if there is no such buffer. - (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if - there is no buffer with this number). - -Windows *mzscheme-window* ------- - (win? {object}) Is object a window? - (win-valid? {object}) Is object a valid window (i.e. corresponds - to the real Vim window)? - (curr-win) Get the current window. - (win-count) Get count of windows. - (get-win-num [window]) Get window number. - (get-win-by-num {windownum}) Get window by its number. - (get-win-buffer [window]) Get the buffer for a given window. - (get-win-height [window]) - (set-win-height {height} [window]) Get/Set height of window. - (get-win-width [window]) - (set-win-width {width} [window])Get/Set width of window. - (get-win-list [buffer]) Get list of windows for a buffer. - (get-cursor [window]) Get cursor position in a window as - a pair (linenr . column). - (set-cursor (line . col) [window]) Set cursor position. - -============================================================================== -5. mzeval() Vim function *mzscheme-mzeval* - -To facilitate bi-directional interface, you can use |mzeval()| function to -evaluate MzScheme expressions and pass their values to VimL. - -============================================================================== -6. Using Function references *mzscheme-funcref* - -MzScheme interface allows use of |Funcref|s so you can call Vim functions -directly from Scheme. For instance: > - function! MyAdd2(arg) - return a:arg + 2 - endfunction - mz (define f2 (vim-eval "function(\"MyAdd2\")")) - mz (f2 7) -< or : > - :mz (define indent (vim-eval "function('indent')")) - " return Vim indent for line 12 - :mz (indent 12) -< - -============================================================================== -7. Dynamic loading *mzscheme-dynamic* *E815* - -On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version| -output then includes |+mzscheme/dyn|. - -This means that Vim will search for the MzScheme DLL files only when needed. -When you don't use the MzScheme interface you don't need them, thus you can -use Vim without these DLL files. - -To use the MzScheme interface the MzScheme DLLs must be in your search path. -In a console window type "path" to see what directories are used. - -The names of the DLLs must match the MzScheme version Vim was compiled with. -For MzScheme version 209 they will be "libmzsch209_000.dll" and -"libmzgc209_000.dll". To know for sure look at the output of the ":version" -command, look for -DDYNAMIC_MZSCH_DLL="something" and --DDYNAMIC_MZGC_DLL="something" in the "Compilation" info. - -====================================================================== - vim:tw=78:ts=8:sts=4:ft=help:norl: diff --git a/runtime/doc/if_perl.txt b/runtime/doc/if_perl.txt deleted file mode 100644 index 7be5f06f68..0000000000 --- a/runtime/doc/if_perl.txt +++ /dev/null @@ -1,294 +0,0 @@ -*if_perl.txt* For Vim version 7.4. Last change: 2013 Oct 05 - - - VIM REFERENCE MANUAL by Sven Verdoolaege - and Matt Gerassimof - -Perl and Vim *perl* *Perl* - -1. Editing Perl files |perl-editing| -2. Compiling VIM with Perl interface |perl-compiling| -3. Using the Perl interface |perl-using| -4. Dynamic loading |perl-dynamic| - -{Vi does not have any of these commands} - -The Perl interface only works when Vim was compiled with the |+perl| feature. - -============================================================================== -1. Editing Perl files *perl-editing* - -Vim syntax highlighting supports Perl and POD files. Vim assumes a file is -Perl code if the filename has a .pl or .pm suffix. Vim also examines the first -line of a file, regardless of the filename suffix, to check if a file is a -Perl script (see scripts.vim in Vim's syntax directory). Vim assumes a file -is POD text if the filename has a .POD suffix. - -To use tags with Perl, you need a recent version of Exuberant ctags. Look -here: - http://ctags.sourceforge.net - -Alternatively, you can use the Perl script pltags.pl, which is shipped with -Vim in the $VIMRUNTIME/tools directory. This script has currently more -features than Exuberant ctags' Perl support. - -============================================================================== -2. Compiling VIM with Perl interface *perl-compiling* - -To compile Vim with Perl interface, you need Perl 5.004 (or later). Perl must -be installed before you compile Vim. Vim's Perl interface does NOT work with -the 5.003 version that has been officially released! It will probably work -with Perl 5.003_05 and later. - -The Perl patches for Vim were made by: - Sven Verdoolaege <skimo@breughel.ufsia.ac.be> - Matt Gerassimof - -Perl for MS-Windows can be found at: http://www.perl.com/ -The ActiveState one should work. - -============================================================================== -3. Using the Perl interface *perl-using* - - *:perl* *:pe* -:pe[rl] {cmd} Execute Perl command {cmd}. The current package - is "main". Simple example to test if `:perl` is - working: > - :perl VIM::Msg("Hello") - -:pe[rl] << {endpattern} -{script} -{endpattern} - Execute Perl script {script}. - {endpattern} must NOT be preceded by any white space. - If {endpattern} is omitted, it defaults to a dot '.' - like for the |:append| and |:insert| commands. Using - '.' helps when inside a function, because "$i;" looks - like the start of an |:insert| command to Vim. - This form of the |:perl| command is mainly useful for - including perl code in vim scripts. - Note: This command doesn't work when the Perl feature - wasn't compiled in. To avoid errors, see - |script-here|. - - -Example vim script: > - - function! WhitePearl() - perl << EOF - VIM::Msg("pearls are nice for necklaces"); - VIM::Msg("rubys for rings"); - VIM::Msg("pythons for bags"); - VIM::Msg("tcls????"); - EOF - endfunction -< - - *:perldo* *:perld* -:[range]perld[o] {cmd} Execute Perl command {cmd} for each line in the - [range], with $_ being set to the text of each line in - turn, without a trailing <EOL>. Setting $_ will change - the text, but note that it is not possible to add or - delete lines using this command. - The default for [range] is the whole file: "1,$". - -Here are some things you can try: > - - :perl $a=1 - :perldo $_ = reverse($_);1 - :perl VIM::Msg("hello") - :perl $line = $curbuf->Get(42) -< - *E299* -Executing Perl commands in the |sandbox| is limited. ":perldo" will not be -possible at all. ":perl" will be evaluated in the Safe environment, if -possible. - - - *perl-overview* -Here is an overview of the functions that are available to Perl: > - - :perl VIM::Msg("Text") # displays a message - :perl VIM::Msg("Error", "ErrorMsg") # displays an error message - :perl VIM::Msg("remark", "Comment") # displays a highlighted message - :perl VIM::SetOption("ai") # sets a vim option - :perl $nbuf = VIM::Buffers() # returns the number of buffers - :perl @buflist = VIM::Buffers() # returns array of all buffers - :perl $mybuf = (VIM::Buffers('qq.c'))[0] # returns buffer object for 'qq.c' - :perl @winlist = VIM::Windows() # returns array of all windows - :perl $nwin = VIM::Windows() # returns the number of windows - :perl ($success, $v) = VIM::Eval('&path') # $v: option 'path', $success: 1 - :perl ($success, $v) = VIM::Eval('&xyz') # $v: '' and $success: 0 - :perl $v = VIM::Eval('expand("<cfile>")') # expands <cfile> - :perl $curwin->SetHeight(10) # sets the window height - :perl @pos = $curwin->Cursor() # returns (row, col) array - :perl @pos = (10, 10) - :perl $curwin->Cursor(@pos) # sets cursor to @pos - :perl $curwin->Cursor(10,10) # sets cursor to row 10 col 10 - :perl $mybuf = $curwin->Buffer() # returns the buffer object for window - :perl $curbuf->Name() # returns buffer name - :perl $curbuf->Number() # returns buffer number - :perl $curbuf->Count() # returns the number of lines - :perl $l = $curbuf->Get(10) # returns line 10 - :perl @l = $curbuf->Get(1 .. 5) # returns lines 1 through 5 - :perl $curbuf->Delete(10) # deletes line 10 - :perl $curbuf->Delete(10, 20) # delete lines 10 through 20 - :perl $curbuf->Append(10, "Line") # appends a line - :perl $curbuf->Append(10, "Line1", "Line2", "Line3") # appends 3 lines - :perl @l = ("L1", "L2", "L3") - :perl $curbuf->Append(10, @l) # appends L1, L2 and L3 - :perl $curbuf->Set(10, "Line") # replaces line 10 - :perl $curbuf->Set(10, "Line1", "Line2") # replaces lines 10 and 11 - :perl $curbuf->Set(10, @l) # replaces 3 lines -< - *perl-Msg* -VIM::Msg({msg}, {group}?) - Displays the message {msg}. The optional {group} - argument specifies a highlight group for Vim to use - for the message. - - *perl-SetOption* -VIM::SetOption({arg}) Sets a vim option. {arg} can be any argument that the - ":set" command accepts. Note that this means that no - spaces are allowed in the argument! See |:set|. - - *perl-Buffers* -VIM::Buffers([{bn}...]) With no arguments, returns a list of all the buffers - in an array context or returns the number of buffers - in a scalar context. For a list of buffer names or - numbers {bn}, returns a list of the buffers matching - {bn}, using the same rules as Vim's internal - |bufname()| function. - WARNING: the list becomes invalid when |:bwipe| is - used. Using it anyway may crash Vim. - - *perl-Windows* -VIM::Windows([{wn}...]) With no arguments, returns a list of all the windows - in an array context or returns the number of windows - in a scalar context. For a list of window numbers - {wn}, returns a list of the windows with those - numbers. - WARNING: the list becomes invalid when a window is - closed. Using it anyway may crash Vim. - - *perl-DoCommand* -VIM::DoCommand({cmd}) Executes Ex command {cmd}. - - *perl-Eval* -VIM::Eval({expr}) Evaluates {expr} and returns (success, value) in list - context or just value in scalar context. - success=1 indicates that val contains the value of - {expr}; success=0 indicates a failure to evaluate - the expression. '@x' returns the contents of register - x, '&x' returns the value of option x, 'x' returns the - value of internal |variables| x, and '$x' is equivalent - to perl's $ENV{x}. All |functions| accessible from - the command-line are valid for {expr}. - A |List| is turned into a string by joining the items - and inserting line breaks. - - *perl-SetHeight* -Window->SetHeight({height}) - Sets the Window height to {height}, within screen - limits. - - *perl-GetCursor* -Window->Cursor({row}?, {col}?) - With no arguments, returns a (row, col) array for the - current cursor position in the Window. With {row} and - {col} arguments, sets the Window's cursor position to - {row} and {col}. Note that {col} is numbered from 0, - Perl-fashion, and thus is one less than the value in - Vim's ruler. - -Window->Buffer() *perl-Buffer* - Returns the Buffer object corresponding to the given - Window. - - *perl-Name* -Buffer->Name() Returns the filename for the Buffer. - - *perl-Number* -Buffer->Number() Returns the number of the Buffer. - - *perl-Count* -Buffer->Count() Returns the number of lines in the Buffer. - - *perl-Get* -Buffer->Get({lnum}, {lnum}?, ...) - Returns a text string of line {lnum} in the Buffer - for each {lnum} specified. An array can be passed - with a list of {lnum}'s specified. - - *perl-Delete* -Buffer->Delete({lnum}, {lnum}?) - Deletes line {lnum} in the Buffer. With the second - {lnum}, deletes the range of lines from the first - {lnum} to the second {lnum}. - - *perl-Append* -Buffer->Append({lnum}, {line}, {line}?, ...) - Appends each {line} string after Buffer line {lnum}. - The list of {line}s can be an array. - - *perl-Set* -Buffer->Set({lnum}, {line}, {line}?, ...) - Replaces one or more Buffer lines with specified - {lines}s, starting at Buffer line {lnum}. The list of - {line}s can be an array. If the arguments are - invalid, replacement does not occur. - -$main::curwin - The current window object. - -$main::curbuf - The current buffer object. - - - *script-here* -When using a script language in-line, you might want to skip this when the -language isn't supported. But this mechanism doesn't work: > - if has('perl') - perl << EOF - this will NOT work! - EOF - endif -Instead, put the Perl/Python/Ruby/etc. command in a function and call that -function: > - if has('perl') - function DefPerl() - perl << EOF - this works - EOF - endfunction - call DefPerl() - endif -Note that "EOF" must be at the start of the line. - -============================================================================== -4. Dynamic loading *perl-dynamic* - -On MS-Windows and Unix the Perl library can be loaded dynamically. The -|:version| output then includes |+perl/dyn|. - -This means that Vim will search for the Perl DLL or shared library file only -when needed. When you don't use the Perl interface you don't need it, thus -you can use Vim without this file. - - -MS-Windows ~ - -You can download Perl from http://www.perl.org. The one from ActiveState was -used for building Vim. - -To use the Perl interface the Perl DLL must be in your search path. -If Vim reports it cannot find the perl512.dll, make sure your $PATH includes -the directory where it is located. The Perl installer normally does that. -In a console window type "path" to see what directories are used. - -The name of the DLL must match the Perl version Vim was compiled with. -Currently the name is "perl512.dll". That is for Perl 5.12. To know for -sure edit "gvim.exe" and search for "perl\d*.dll\c". - -============================================================================== - vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt index 4ed8eac742..c2d169283f 100644 --- a/runtime/doc/if_pyth.txt +++ b/runtime/doc/if_pyth.txt @@ -107,6 +107,29 @@ Here are some examples *python-examples* > (Note that changes - like the imports - persist from one command to the next, just like in the Python interpreter.) + *script-here* +When using a script language in-line, you might want to skip this when the +language isn't supported. Note that this mechanism doesn't work: +> + if has('python') + python << EOF + this will NOT work! + EOF + endif + +Instead, put the Python command in a function and call that function: +> + if has('python') + function DefPython() + python << EOF + this works + EOF + endfunction + call DefPython() + endif + +Note that "EOF" must be at the start of the line. + ============================================================================== 2. The vim module *python-vim* diff --git a/runtime/doc/if_ruby.txt b/runtime/doc/if_ruby.txt deleted file mode 100644 index 0a32d87851..0000000000 --- a/runtime/doc/if_ruby.txt +++ /dev/null @@ -1,216 +0,0 @@ -*if_ruby.txt* For Vim version 7.4. Last change: 2012 Aug 02 - - - VIM REFERENCE MANUAL by Shugo Maeda - -The Ruby Interface to Vim *ruby* *Ruby* - - -1. Commands |ruby-commands| -2. The VIM module |ruby-vim| -3. VIM::Buffer objects |ruby-buffer| -4. VIM::Window objects |ruby-window| -5. Global variables |ruby-globals| -6. Dynamic loading |ruby-dynamic| - -{Vi does not have any of these commands} - *E266* *E267* *E268* *E269* *E270* *E271* *E272* *E273* - -The Ruby interface only works when Vim was compiled with the |+ruby| feature. - -The home page for ruby is http://www.ruby-lang.org/. You can find links for -downloading Ruby there. - -============================================================================== -1. Commands *ruby-commands* - - *:ruby* *:rub* -:rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: > - :ruby print "Hello" - -:rub[y] << {endpattern} -{script} -{endpattern} - Execute Ruby script {script}. - {endpattern} must NOT be preceded by any white space. - If {endpattern} is omitted, it defaults to a dot '.' - like for the |:append| and |:insert| commands. This - form of the |:ruby| command is mainly useful for - including ruby code in vim scripts. - Note: This command doesn't work when the Ruby feature - wasn't compiled in. To avoid errors, see - |script-here|. - -Example Vim script: > - - function! RedGem() - ruby << EOF - class Garnet - def initialize(s) - @buffer = VIM::Buffer.current - vimputs(s) - end - def vimputs(s) - @buffer.append(@buffer.count,s) - end - end - gem = Garnet.new("pretty") - EOF - endfunction -< - - *:rubydo* *:rubyd* *E265* -:[range]rubyd[o] {cmd} Evaluate Ruby command {cmd} for each line in the - [range], with $_ being set to the text of each line in - turn, without a trailing <EOL>. Setting $_ will change - the text, but note that it is not possible to add or - delete lines using this command. - The default for [range] is the whole file: "1,$". - - *:rubyfile* *:rubyf* -:rubyf[ile] {file} Execute the Ruby script in {file}. This is the same as - ":ruby load 'file'", but allows file name completion. - -Executing Ruby commands is not possible in the |sandbox|. - -============================================================================== -2. The VIM module *ruby-vim* - -Ruby code gets all of its access to vim via the "VIM" module. - -Overview > - print "Hello" # displays a message - VIM.command(cmd) # execute an Ex command - num = VIM::Window.count # gets the number of windows - w = VIM::Window[n] # gets window "n" - cw = VIM::Window.current # gets the current window - num = VIM::Buffer.count # gets the number of buffers - b = VIM::Buffer[n] # gets buffer "n" - cb = VIM::Buffer.current # gets the current buffer - w.height = lines # sets the window height - w.cursor = [row, col] # sets the window cursor position - pos = w.cursor # gets an array [row, col] - name = b.name # gets the buffer file name - line = b[n] # gets a line from the buffer - num = b.count # gets the number of lines - b[n] = str # sets a line in the buffer - b.delete(n) # deletes a line - b.append(n, str) # appends a line after n - line = VIM::Buffer.current.line # gets the current line - num = VIM::Buffer.current.line_number # gets the current line number - VIM::Buffer.current.line = "test" # sets the current line number -< - -Module Functions: - - *ruby-message* -VIM::message({msg}) - Displays the message {msg}. - - *ruby-set_option* -VIM::set_option({arg}) - Sets a vim option. {arg} can be any argument that the ":set" command - accepts. Note that this means that no spaces are allowed in the - argument! See |:set|. - - *ruby-command* -VIM::command({cmd}) - Executes Ex command {cmd}. - - *ruby-evaluate* -VIM::evaluate({expr}) - Evaluates {expr} using the vim internal expression evaluator (see - |expression|). Returns the expression result as a string. - A |List| is turned into a string by joining the items and inserting - line breaks. - -============================================================================== -3. VIM::Buffer objects *ruby-buffer* - -VIM::Buffer objects represent vim buffers. - -Class Methods: - -current Returns the current buffer object. -count Returns the number of buffers. -self[{n}] Returns the buffer object for the number {n}. The first number - is 0. - -Methods: - -name Returns the name of the buffer. -number Returns the number of the buffer. -count Returns the number of lines. -length Returns the number of lines. -self[{n}] Returns a line from the buffer. {n} is the line number. -self[{n}] = {str} - Sets a line in the buffer. {n} is the line number. -delete({n}) Deletes a line from the buffer. {n} is the line number. -append({n}, {str}) - Appends a line after the line {n}. -line Returns the current line of the buffer if the buffer is - active. -line = {str} Sets the current line of the buffer if the buffer is active. -line_number Returns the number of the current line if the buffer is - active. - -============================================================================== -4. VIM::Window objects *ruby-window* - -VIM::Window objects represent vim windows. - -Class Methods: - -current Returns the current window object. -count Returns the number of windows. -self[{n}] Returns the window object for the number {n}. The first number - is 0. - -Methods: - -buffer Returns the buffer displayed in the window. -height Returns the height of the window. -height = {n} Sets the window height to {n}. -width Returns the width of the window. -width = {n} Sets the window width to {n}. -cursor Returns a [row, col] array for the cursor position. -cursor = [{row}, {col}] - Sets the cursor position to {row} and {col}. - -============================================================================== -5. Global variables *ruby-globals* - -There are two global variables. - -$curwin The current window object. -$curbuf The current buffer object. - -============================================================================== -6. Dynamic loading *ruby-dynamic* - -On MS-Windows and Unix the Ruby library can be loaded dynamically. The -|:version| output then includes |+ruby/dyn|. - -This means that Vim will search for the Ruby DLL file or shared library only -when needed. When you don't use the Ruby interface you don't need it, thus -you can use Vim even though this library file is not on your system. - -You need to install the right version of Ruby for this to work. You can find -the package to download from: -http://www.garbagecollect.jp/ruby/mswin32/en/download/release.html -Currently that is ruby-1.9.1-p429-i386-mswin32.zip - -To use the Ruby interface the Ruby DLL must be in your search path. In a -console window type "path" to see what directories are used. - -The name of the DLL must match the Ruby version Vim was compiled with. -Currently the name is "msvcrt-ruby191.dll". That is for Ruby 1.9.1. To know -for sure edit "gvim.exe" and search for "ruby\d*.dll\c". - -If you want to build Vim with Ruby 1.9.1, you need to edit the config.h file -and comment-out the check for _MSC_VER. -You may also need to rename the include directory name to match the version, -strangely for Ruby 1.9.3 the directory is called 1.9.1. - -============================================================================== - vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/if_tcl.txt b/runtime/doc/if_tcl.txt deleted file mode 100644 index d6726a3546..0000000000 --- a/runtime/doc/if_tcl.txt +++ /dev/null @@ -1,533 +0,0 @@ -*if_tcl.txt* For Vim version 7.4. Last change: 2012 Aug 02 - - - VIM REFERENCE MANUAL by Ingo Wilken - - -The Tcl Interface to Vim *tcl* *Tcl* *TCL* - -1. Commands |tcl-ex-commands| -2. Tcl commands |tcl-commands| -3. Tcl variables |tcl-variables| -4. Tcl window commands |tcl-window-cmds| -5. Tcl buffer commands |tcl-buffer-cmds| -6. Miscellaneous; Output from Tcl |tcl-misc| |tcl-output| -7. Known bugs & problems |tcl-bugs| -8. Examples |tcl-examples| -9. Dynamic loading |tcl-dynamic| - -{Vi does not have any of these commands} *E280* *E281* - -The Tcl interface only works when Vim was compiled with the |+tcl| feature. - -WARNING: There are probably still some bugs. Please send bug reports, -comments, ideas etc to <Ingo.Wilken@informatik.uni-oldenburg.de> - -============================================================================== -1. Commands *tcl-ex-commands* *E571* *E572* - - *:tcl* *:tc* -:tc[l] {cmd} Execute Tcl command {cmd}. A simple check if `:tcl` - is working: > - :tcl puts "Hello" - -:[range]tc[l] << {endmarker} -{script} -{endmarker} - Execute Tcl script {script}. - Note: This command doesn't work when the Tcl feature - wasn't compiled in. To avoid errors, see - |script-here|. - -{endmarker} must NOT be preceded by any white space. If {endmarker} is -omitted from after the "<<", a dot '.' must be used after {script}, like for -the |:append| and |:insert| commands. -This form of the |:tcl| command is mainly useful for including tcl code in Vim -scripts. - -Example: > - function! DefineDate() - tcl << EOF - proc date {} { - return [clock format [clock seconds]] - } - EOF - endfunction -< - - *:tcldo* *:tcld* -:[range]tcld[o] {cmd} Execute Tcl command {cmd} for each line in [range] - with the variable "line" being set to the text of each - line in turn, and "lnum" to the line number. Setting - "line" will change the text, but note that it is not - possible to add or delete lines using this command. - If {cmd} returns an error, the command is interrupted. - The default for [range] is the whole file: "1,$". - See |tcl-var-line| and |tcl-var-lnum|. {not in Vi} - - *:tclfile* *:tclf* -:tclf[ile] {file} Execute the Tcl script in {file}. This is the same as - ":tcl source {file}", but allows file name completion. - {not in Vi} - - -Note that Tcl objects (like variables) persist from one command to the next, -just as in the Tcl shell. - -Executing Tcl commands is not possible in the |sandbox|. - -============================================================================== -2. Tcl commands *tcl-commands* - -Tcl code gets all of its access to vim via commands in the "::vim" namespace. -The following commands are implemented: > - - ::vim::beep # Guess. - ::vim::buffer {n} # Create Tcl command for one buffer. - ::vim::buffer list # Create Tcl commands for all buffers. - ::vim::command [-quiet] {cmd} # Execute an Ex command. - ::vim::expr {expr} # Use Vim's expression evaluator. - ::vim::option {opt} # Get vim option. - ::vim::option {opt} {val} # Set vim option. - ::vim::window list # Create Tcl commands for all windows. - -Commands: - ::vim::beep *tcl-beep* - Honk. Does not return a result. - - ::vim::buffer {n} *tcl-buffer* - ::vim::buffer exists {n} - ::vim::buffer list - Provides access to vim buffers. With an integer argument, creates a - buffer command (see |tcl-buffer-cmds|) for the buffer with that - number, and returns its name as the result. Invalid buffer numbers - result in a standard Tcl error. To test for valid buffer numbers, - vim's internal functions can be used: > - set nbufs [::vim::expr bufnr("$")] - set isvalid [::vim::expr "bufexists($n)"] -< The "list" option creates a buffer command for each valid buffer, and - returns a list of the command names as the result. - Example: > - set bufs [::vim::buffer list] - foreach b $bufs { $b append end "The End!" } -< The "exists" option checks if a buffer with the given number exists. - Example: > - if { [::vim::buffer exists $n] } { ::vim::command ":e #$n" } -< This command might be replaced by a variable in future versions. - See also |tcl-var-current| for the current buffer. - - ::vim::command {cmd} *tcl-command* - ::vim::command -quiet {cmd} - Execute the vim (ex-mode) command {cmd}. Any Ex command that affects - a buffer or window uses the current buffer/current window. Does not - return a result other than a standard Tcl error code. After this - command is completed, the "::vim::current" variable is updated. - The "-quiet" flag suppresses any error messages from vim. - Examples: > - ::vim::command "set ts=8" - ::vim::command "%s/foo/bar/g" -< To execute normal-mode commands, use "normal" (see |:normal|): > - set cmd "jj" - ::vim::command "normal $cmd" -< See also |tcl-window-command| and |tcl-buffer-command|. - - ::vim::expr {expr} *tcl-expr* - Evaluates the expression {expr} using vim's internal expression - evaluator (see |expression|). Any expression that queries a buffer - or window property uses the current buffer/current window. Returns - the result as a string. A |List| is turned into a string by joining - the items and inserting line breaks. - Examples: > - set perl_available [::vim::expr has("perl")] -< See also |tcl-window-expr| and |tcl-buffer-expr|. - - ::vim::option {opt} *tcl-option* - ::vim::option {opt} {value} - Without second argument, queries the value of a vim option. With this - argument, sets the vim option to {value}, and returns the previous - value as the result. Any options that are marked as 'local to buffer' - or 'local to window' affect the current buffer/current window. The - global value is not changed, use the ":set" command for that. For - boolean options, {value} should be "0" or "1", or any of the keywords - "on", "off" or "toggle". See |option-summary| for a list of options. - Example: > - ::vim::option ts 8 -< See also |tcl-window-option| and |tcl-buffer-option|. - - ::vim::window {option} *tcl-window* - Provides access to vim windows. Currently only the "list" option is - implemented. This creates a window command (see |tcl-window-cmds|) for - each window, and returns a list of the command names as the result. - Example: > - set wins [::vim::window list] - foreach w $wins { $w height 4 } -< This command might be replaced by a variable in future versions. - See also |tcl-var-current| for the current window. - -============================================================================== -3. Tcl variables *tcl-variables* - -The ::vim namespace contains a few variables. These are created when the Tcl -interpreter is called from vim and set to current values. > - - ::vim::current # array containing "current" objects - ::vim::lbase # number of first line - ::vim::range # array containing current range numbers - line # current line as a string (:tcldo only) - lnum # current line number (:tcldo only) - -Variables: - ::vim::current *tcl-var-current* - This is an array providing access to various "current" objects - available in vim. The contents of this array are updated after - "::vim::command" is called, as this might change vim's current - settings (e.g., by deleting the current buffer). - The "buffer" element contains the name of the buffer command for the - current buffer. This can be used directly to invoke buffer commands - (see |tcl-buffer-cmds|). This element is read-only. - Example: > - $::vim::current(buffer) insert begin "Hello world" -< The "window" element contains the name of the window command for the - current window. This can be used directly to invoke window commands - (see |tcl-window-cmds|). This element is read-only. - Example: > - $::vim::current(window) height 10 -< - ::vim::lbase *tcl-var-lbase* - This variable controls how Tcl treats line numbers. If it is set to - '1', then lines and columns start at 1. This way, line numbers from - Tcl commands and vim expressions are compatible. If this variable is - set to '0', then line numbers and columns start at 0 in Tcl. This is - useful if you want to treat a buffer as a Tcl list or a line as a Tcl - string and use standard Tcl commands that return an index ("lsort" or - "string first", for example). The default value is '1'. Currently, - any non-zero values is treated as '1', but your scripts should not - rely on this. See also |tcl-linenumbers|. - - ::vim::range *tcl-var-range* - This is an array with three elements, "start", "begin" and "end". It - contains the line numbers of the start and end row of the current - range. "begin" is the same as "start". This variable is read-only. - See |tcl-examples|. - - line *tcl-var-line* - lnum *tcl-var-lnum* - These global variables are only available if the ":tcldo" Ex command - is being executed. They contain the text and line number of the - current line. When the Tcl command invoked by ":tcldo" is completed, - the current line is set to the contents of the "line" variable, unless - the variable was unset by the Tcl command. The "lnum" variable is - read-only. These variables are not in the "::vim" namespace so they - can be used in ":tcldo" without much typing (this might be changed in - future versions). See also |tcl-linenumbers|. - -============================================================================== -4. Tcl window commands *tcl-window-cmds* - -Window commands represent vim windows. They are created by several commands: - ::vim::window list |tcl-window| - "windows" option of a buffer command |tcl-buffer-windows| -The ::vim::current(window) variable contains the name of the window command -for the current window. A window command is automatically deleted when the -corresponding vim window is closed. - -Let's assume the name of the window command is stored in the Tcl variable "win", -i.e. "$win" calls the command. The following options are available: > - - $win buffer # Create Tcl command for window's buffer. - $win command {cmd} # Execute Ex command in windows context. - $win cursor # Get current cursor position. - $win cursor {var} # Set cursor position from array variable. - $win cursor {row} {col} # Set cursor position. - $win delcmd {cmd} # Call Tcl command when window is closed. - $win expr {expr} # Evaluate vim expression in windows context. - $win height # Report the window's height. - $win height {n} # Set the window's height. - $win option {opt} [val] # Get/Set vim option in windows context. - -Options: - $win buffer *tcl-window-buffer* - Creates a Tcl command for the window's buffer, and returns its name as - the result. The name should be stored in a variable: > - set buf [$win buffer] -< $buf is now a valid Tcl command. See |tcl-buffer-cmds| for the - available options. - - $win cursor *tcl-window-cursor* - $win cursor {var} - $win cursor {row} {col} - Without argument, reports the current cursor position as a string. - This can be converted to a Tcl array variable: > - array set here [$win cursor] -< "here(row)" and "here(column)" now contain the cursor position. - With a single argument, the argument is interpreted as the name of a - Tcl array variable, which must contain two elements "row" and "column". - These are used to set the cursor to the new position: > - $win cursor here ;# not $here ! -< With two arguments, sets the cursor to the specified row and column: > - $win cursor $here(row) $here(column) -< Invalid positions result in a standard Tcl error, which can be caught - with "catch". The row and column values depend on the "::vim::lbase" - variable. See |tcl-var-lbase|. - - $win delcmd {cmd} *tcl-window-delcmd* - Registers the Tcl command {cmd} as a deletion callback for the window. - This command is executed (in the global scope) just before the window - is closed. Complex commands should be build with "list": > - $win delcmd [list puts vimerr "window deleted"] -< See also |tcl-buffer-delcmd|. - - $win height *tcl-window-height* - $win height {n} - Without argument, reports the window's current height. With an - argument, tries to set the window's height to {n}, then reports the - new height (which might be different from {n}). - - $win command [-quiet] {cmd} *tcl-window-command* - $win expr {expr} *tcl-window-expr* - $win option {opt} [val] *tcl-window-option* - These are similar to "::vim::command" etc., except that everything is - done in the context of the window represented by $win, instead of the - current window. For example, setting an option that is marked 'local - to window' affects the window $win. Anything that affects or queries - a buffer uses the buffer displayed in this window (i.e. the buffer - that is represented by "$win buffer"). See |tcl-command|, |tcl-expr| - and |tcl-option| for more information. - Example: > - $win option number on - -============================================================================== -5. Tcl buffer commands *tcl-buffer-cmds* - -Buffer commands represent vim buffers. They are created by several commands: - ::vim::buffer {N} |tcl-buffer| - ::vim::buffer list |tcl-buffer| - "buffer" option of a window command |tcl-window-buffer| -The ::vim::current(buffer) variable contains the name of the buffer command -for the current buffer. A buffer command is automatically deleted when the -corresponding vim buffer is destroyed. Whenever the buffer's contents are -changed, all marks in the buffer are automatically adjusted. Any changes to -the buffer's contents made by Tcl commands can be undone with the "undo" vim -command (see |undo|). - -Let's assume the name of the buffer command is stored in the Tcl variable "buf", -i.e. "$buf" calls the command. The following options are available: > - - $buf append {n} {str} # Append a line to buffer, after line {n}. - $buf command {cmd} # Execute Ex command in buffers context. - $buf count # Report number of lines in buffer. - $buf delcmd {cmd} # Call Tcl command when buffer is deleted. - $buf delete {n} # Delete a single line. - $buf delete {n} {m} # Delete several lines. - $buf expr {expr} # Evaluate vim expression in buffers context. - $buf get {n} # Get a single line as a string. - $buf get {n} {m} # Get several lines as a list. - $buf insert {n} {str} # Insert a line in buffer, as line {n}. - $buf last # Report line number of last line in buffer. - $buf mark {mark} # Report position of buffer mark. - $buf name # Report name of file in buffer. - $buf number # Report number of this buffer. - $buf option {opt} [val] # Get/Set vim option in buffers context. - $buf set {n} {text} # Replace a single line. - $buf set {n} {m} {list} # Replace several lines. - $buf windows # Create Tcl commands for buffer's windows. -< - *tcl-linenumbers* -Most buffer commands take line numbers as arguments. How Tcl treats these -numbers depends on the "::vim::lbase" variable (see |tcl-var-lbase|). Instead -of line numbers, several keywords can be also used: "top", "start", "begin", -"first", "bottom", "end" and "last". - -Options: - $buf append {n} {str} *tcl-buffer-append* - $buf insert {n} {str} *tcl-buffer-insert* - Add a line to the buffer. With the "insert" option, the string - becomes the new line {n}, with "append" it is inserted after line {n}. - Example: > - $buf insert top "This is the beginning." - $buf append end "This is the end." -< To add a list of lines to the buffer, use a loop: > - foreach line $list { $buf append $num $line ; incr num } -< - $buf count *tcl-buffer-count* - Reports the total number of lines in the buffer. - - $buf delcmd {cmd} *tcl-buffer-delcmd* - Registers the Tcl command {cmd} as a deletion callback for the buffer. - This command is executed (in the global scope) just before the buffer - is deleted. Complex commands should be build with "list": > - $buf delcmd [list puts vimerr "buffer [$buf number] gone"] -< See also |tcl-window-delcmd|. - - $buf delete {n} *tcl-buffer-delete* - $buf delete {n} {m} - Deletes line {n} or lines {n} through {m} from the buffer. - This example deletes everything except the last line: > - $buf delete first [expr [$buf last] - 1] -< - $buf get {n} *tcl-buffer-get* - $buf get {n} {m} - Gets one or more lines from the buffer. For a single line, the result - is a string; for several lines, a list of strings. - Example: > - set topline [$buf get top] -< - $buf last *tcl-buffer-last* - Reports the line number of the last line. This value depends on the - "::vim::lbase" variable. See |tcl-var-lbase|. - - $buf mark {mark} *tcl-buffer-mark* - Reports the position of the named mark as a string, similar to the - cursor position of the "cursor" option of a window command (see - |tcl-window-cursor|). This can be converted to a Tcl array variable: > - array set mpos [$buf mark "a"] -< "mpos(column)" and "mpos(row)" now contain the position of the mark. - If the mark is not set, a standard Tcl error results. - - $buf name - Reports the name of the file in the buffer. For a buffer without a - file, this is an empty string. - - $buf number - Reports the number of this buffer. See |:buffers|. - This example deletes a buffer from vim: > - ::vim::command "bdelete [$buf number]" -< - $buf set {n} {string} *tcl-buffer-set* - $buf set {n} {m} {list} - Replace one or several lines in the buffer. If the list contains more - elements than there are lines to replace, they are inserted into the - buffer. If the list contains fewer elements, any unreplaced line is - deleted from the buffer. - - $buf windows *tcl-buffer-windows* - Creates a window command for each window that displays this buffer, and - returns a list of the command names as the result. - Example: > - set winlist [$buf windows] - foreach win $winlist { $win height 4 } -< See |tcl-window-cmds| for the available options. - - $buf command [-quiet] {cmd} *tcl-buffer-command* - $buf expr {expr} *tcl-buffer-expr* - $buf option {opt} [val] *tcl-buffer-option* - These are similar to "::vim::command" etc., except that everything is - done in the context of the buffer represented by $buf, instead of the - current buffer. For example, setting an option that is marked 'local - to buffer' affects the buffer $buf. Anything that affects or queries - a window uses the first window in vim's window list that displays this - buffer (i.e. the first entry in the list returned by "$buf windows"). - See |tcl-command|, |tcl-expr| and |tcl-option| for more information. - Example: > - if { [$buf option modified] } { $buf command "w" } - -============================================================================== -6. Miscellaneous; Output from Tcl *tcl-misc* *tcl-output* - -The standard Tcl commands "exit" and "catch" are replaced by custom versions. -"exit" terminates the current Tcl script and returns to vim, which deletes the -Tcl interpreter. Another call to ":tcl" then creates a new Tcl interpreter. -"exit" does NOT terminate vim! "catch" works as before, except that it does -not prevent script termination from "exit". An exit code != 0 causes the ex -command that invoked the Tcl script to return an error. - -Two new I/O streams are available in Tcl, "vimout" and "vimerr". All output -directed to them is displayed in the vim message area, as information messages -and error messages, respectively. The standard Tcl output streams stdout and -stderr are mapped to vimout and vimerr, so that a normal "puts" command can be -used to display messages in vim. - -============================================================================== -7. Known bugs & problems *tcl-bugs* - -Calling one of the Tcl Ex commands from inside Tcl (via "::vim::command") may -have unexpected side effects. The command creates a new interpreter, which -has the same abilities as the standard interpreter - making "::vim::command" -available in a safe child interpreter therefore makes the child unsafe. (It -would be trivial to block nested :tcl* calls or ensure that such calls from a -safe interpreter create only new safe interpreters, but quite pointless - -depending on vim's configuration, "::vim::command" may execute arbitrary code -in any number of other scripting languages.) A call to "exit" within this new -interpreter does not affect the old interpreter; it only terminates the new -interpreter, then script processing continues normally in the old interpreter. - -Input from stdin is currently not supported. - -============================================================================== -8. Examples: *tcl-examples* - -Here are a few small (and maybe useful) Tcl scripts. - -This script sorts the lines of the entire buffer (assume it contains a list -of names or something similar): - set buf $::vim::current(buffer) - set lines [$buf get top bottom] - set lines [lsort -dictionary $lines] - $buf set top bottom $lines - -This script reverses the lines in the buffer. Note the use of "::vim::lbase" -and "$buf last" to work with any line number setting. - set buf $::vim::current(buffer) - set t $::vim::lbase - set b [$buf last] - while { $t < $b } { - set tl [$buf get $t] - set bl [$buf get $b] - $buf set $t $bl - $buf set $b $tl - incr t - incr b -1 - } - -This script adds a consecutive number to each line in the current range: - set buf $::vim::current(buffer) - set i $::vim::range(start) - set n 1 - while { $i <= $::vim::range(end) } { - set line [$buf get $i] - $buf set $i "$n\t$line" - incr i ; incr n - } - -The same can also be done quickly with two Ex commands, using ":tcldo": - :tcl set n 1 - :[range]tcldo set line "$n\t$line" ; incr n - -This procedure runs an Ex command on each buffer (idea stolen from Ron Aaron): - proc eachbuf { cmd } { - foreach b [::vim::buffer list] { - $b command $cmd - } - } -Use it like this: - :tcl eachbuf %s/foo/bar/g -Be careful with Tcl's string and backslash substitution, tough. If in doubt, -surround the Ex command with curly braces. - - -If you want to add some Tcl procedures permanently to vim, just place them in -a file (e.g. "~/.vimrc.tcl" on Unix machines), and add these lines to your -startup file (usually "~/.vimrc" on Unix): - if has("tcl") - tclfile ~/.vimrc.tcl - endif - -============================================================================== -9. Dynamic loading *tcl-dynamic* - -On MS-Windows the Tcl library can be loaded dynamically. The |:version| -output then includes |+tcl/dyn|. - -This means that Vim will search for the Tcl DLL file only when needed. When -you don't use the Tcl interface you don't need it, thus you can use Vim -without this DLL file. - -To use the Tcl interface the Tcl DLL must be in your search path. In a -console window type "path" to see what directories are used. - -The name of the DLL must match the Tcl version Vim was compiled with. -Currently the name is "tcl83.dll". That is for Tcl 8.3. To know for sure -edit "gvim.exe" and search for "tcl\d*.dll\c". - -============================================================================== - vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index 3eedb234f3..dfa4086488 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -1325,9 +1325,6 @@ tag command action ~ |:ltag| :lt[ag] jump to tag and add matching tags to the location list |:lunmap| :lu[nmap] like ":unmap!" but includes Lang-Arg mode -|:lua| :lua execute |Lua| command -|:luado| :luad[o] execute Lua command for each line -|:luafile| :luaf[ile] execute |Lua| script file |:lvimgrep| :lv[imgrep] search for pattern in files |:lvimgrepadd| :lvimgrepa[dd] like :vimgrep, but append to current list |:lwindow| :lw[indow] open or close location window @@ -1348,8 +1345,6 @@ tag command action ~ |:mkvimrc| :mkv[imrc] write current mappings and settings to a file |:mkview| :mkvie[w] write view of current window to a file |:mode| :mod[e] show or change the screen mode -|:mzscheme| :mz[scheme] execute MzScheme command -|:mzfile| :mzf[ile] execute MzScheme script file |:next| :n[ext] go to next file in the argument list |:new| :new create a new empty window |:nmap| :nm[ap] like ":map" but for Normal mode @@ -1382,13 +1377,11 @@ tag command action ~ |:ownsyntax| :ow[nsyntax] set new local syntax highlight for this window |:pclose| :pc[lose] close preview window |:pedit| :ped[it] edit file in the preview window -|:perl| :pe[rl] execute Perl command |:print| :p[rint] print lines |:profdel| :profd[el] stop profiling a function or script |:profile| :prof[ile] profiling functions and scripts |:promptfind| :pro[mptfind] open GUI dialog for searching |:promptrepl| :promptr[epl] open GUI dialog for search/replace -|:perldo| :perld[o] execute Perl command for each line |:pop| :po[p] jump to older entry in tag stack |:popup| :popu[p] popup a menu by name |:ppop| :pp[op] ":pop" in preview window @@ -1429,9 +1422,6 @@ tag command action ~ |:rewind| :rew[ind] go to the first file in the argument list |:right| :ri[ght] right align text |:rightbelow| :rightb[elow] make split window appear right or below -|:ruby| :rub[y] execute Ruby command -|:rubydo| :rubyd[o] execute Ruby command for each line -|:rubyfile| :rubyf[ile] execute Ruby script file |:rundo| :rund[o] read undo information from a file |:runtime| :ru[ntime] source vim scripts in 'runtimepath' |:rviminfo| :rv[iminfo] read from viminfo file @@ -1534,9 +1524,6 @@ tag command action ~ |:tab| :tab create new tab when opening new window |:tag| :ta[g] jump to tag |:tags| :tags show the contents of the tag stack -|:tcl| :tc[l] execute Tcl command -|:tcldo| :tcld[o] execute Tcl command for each line -|:tclfile| :tclf[ile] execute Tcl script file |:tearoff| :te[aroff] tear-off a menu |:tfirst| :tf[irst] jump to first matching tag |:throw| :th[row] throw an exception diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index c4c21f9175..e008fa12fe 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -1421,9 +1421,9 @@ automatically switch to HTML/CSS/JavaScript completion. Note: contrary to original HTML files completion of tags (and only tags) isn't context aware. -RUBY *ft-ruby-omni* +RUBY *ft-ruby-omni* {Nvim} -Completion of Ruby code requires that vim be built with |+ruby|. +NOTE: Completion for ruby code is not currently provided by Nvim. Ruby completion will parse your buffer on demand in order to provide a list of completions. These completions will be drawn from modules loaded by 'require' @@ -1444,7 +1444,7 @@ The completions provided by CTRL-X CTRL-O are sensitive to the context: Notes: - Vim will load/evaluate code in order to provide completions. This may - cause some code execution, which may be a concern. This is no longer + cause some code execution, which may be a concern. This is no longer enabled by default, to enable this feature add > let g:rubycomplete_buffer_loading = 1 <- In context 1 above, Vim can parse the entire buffer to add a list of diff --git a/runtime/doc/message.txt b/runtime/doc/message.txt index 70f20a155b..bd236536c0 100644 --- a/runtime/doc/message.txt +++ b/runtime/doc/message.txt @@ -315,10 +315,9 @@ generate this message. This could be caused by a |-m| commandline argument. You can switch the 'write' option on with ":set write". *E25* > - GUI cannot be used: Not enabled at compile time + Nvim does not have a built-in GUI -You are running a version of Vim that doesn't include the GUI code. Therefore -"gvim" and ":gui" don't work. +Neovim does not have a built in GUI, so |:gvim| and |:gui| don't work. *E49* > Invalid scroll size @@ -522,7 +521,7 @@ for about 14 levels. When more nesting is done, Vim assumes that there is a recursive loop somewhere and stops with this error message. *E319* > - Sorry, the command is not available in this version + The command is not available in this version You have used a command that is not present in the version of Vim you are using. When compiling Vim, many different features can be enabled or diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt index f3fcd069c4..b6142e2234 100644 --- a/runtime/doc/msgpack_rpc.txt +++ b/runtime/doc/msgpack_rpc.txt @@ -116,6 +116,12 @@ functions can be called interactively: >>> nvim = attach('socket', path='[address]') >>> nvim.command('echo "hello world!"') < +One can also spawn and connect to an embedded nvim instance via |rpcstart()| +> + let vim = rpcstart('nvim', ['--embed']) + echo rpcrequest(vim, 'vim_eval', '"Hello " . "world!"') + call rpcstop(vim) +< ============================================================================== 4. Implementing new clients *msgpack-rpc-clients* @@ -177,6 +183,10 @@ Buffer -> enum value kObjectTypeBuffer Window -> enum value kObjectTypeWindow Tabpage -> enum value kObjectTypeTabpage +An API method expecting one of these types may be passed an integer instead, +although they are not interchangeable. For example, a Buffer may be passed as +an integer, but not a Window or Tabpage. + The most reliable way of determining the type codes for the special nvim types is at runtime by inspecting the `types` key of metadata dictionary returned by `vim_get_api_info` method. Here's an example json representation of the @@ -216,7 +226,7 @@ that makes this task easier: - Methods that operate instances of Nvim's types are prefixed with the type name in lower case, e.g. `buffer_get_line` represents the `get_line` method of a Buffer instance. -- Global methods are prefixed with `vim`, e.g. `vim_list_buffers`. +- Global methods are prefixed with `vim`, e.g. `vim_get_buffers`. So, for an object-oriented language, a client library would have the classes that represent Nvim's types, and the methods of each class could be defined diff --git a/runtime/doc/nvim_python.txt b/runtime/doc/nvim_python.txt index 531036d567..bafcf047dd 100644 --- a/runtime/doc/nvim_python.txt +++ b/runtime/doc/nvim_python.txt @@ -35,7 +35,7 @@ Most Python plugins created for Vim 7.3 should work after these steps. *g:python_host_prog* -To point Nvim to a specific Python interpreter, set `g:python_host_prog`: +To point Nvim to a specific Python interpreter, set |g:python_host_prog|: > let g:python_host_prog='/path/to/python' < diff --git a/runtime/doc/nvim_terminal_emulator.txt b/runtime/doc/nvim_terminal_emulator.txt index 160242a7fa..850391200e 100644 --- a/runtime/doc/nvim_terminal_emulator.txt +++ b/runtime/doc/nvim_terminal_emulator.txt @@ -99,16 +99,13 @@ variables (set via the |TermOpen| autocmd): - `{g,b}:terminal_color_$NUM`: The terminal color palette, where `$NUM` is the color index, between 0 and 255 inclusive. This only affects UIs with RGB capabilities; for normal terminals the color index is simply forwarded. -- `{g,b}:terminal_focused_cursor_highlight`: Highlight group applied to the - cursor in a focused terminal. The default equivalent to having a group with - `cterm=reverse` `gui=reverse``. -- `{g,b}:terminal_unfocused_cursor_highlight`: Highlight group applied to the - cursor in an unfocused terminal. The default equivalent to having a group with - `ctermbg=11` `guibg=#fce94f``. The configuration variables are only processed when the terminal starts, which is why it needs to be done with the |TermOpen| autocmd or setting global variables before the terminal is started. +The terminal cursor can be highlighted via |hl-TermCursor| and +|hl-TermCursorNC|. + ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index c0f1888d84..6090dd6cb0 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -3651,17 +3651,19 @@ A jump table for the options with a short description can be found at |Q_op|. *'highlight'* *'hl'* 'highlight' 'hl' string (default (as a single string): - "8:SpecialKey,~:EndOfBuffer,@:NonText,i - d:Directory,e:ErrorMsg,i:IncSearch, - l:Search,m:MoreMsg,M:ModeMsg,n:LineNr, + "8:SpecialKey,~:EndOfBuffer,z:TermCursor, + Z:TermCursorNC,@:NonText,d:Directory, + e:ErrorMsg,i:IncSearch,l:Search, + m:MoreMsg,M:ModeMsg,n:LineNr, N:CursorLineNr,r:Question,s:StatusLine, S:StatusLineNC,c:VertSplit,t:Title, - v:Visual,w:WarningMsg,W:WildMenu,f:Folded, - F:FoldColumn,A:DiffAdd,C:DiffChange, - D:DiffDelete,T:DiffText,>:SignColumn, - B:SpellBad,P:SpellCap,R:SpellRare, - L:SpellLocal,-:Conceal,+:Pmenu,=:PmenuSel, - x:PmenuSbar,X:PmenuThumb") + v:Visual,w:WarningMsg,W:WildMenu, + f:Folded,F:FoldColumn,A:DiffAdd, + C:DiffChange,D:DiffDelete,T:DiffText, + >:SignColumn,B:SpellBad,P:SpellCap, + R:SpellRare,L:SpellLocal,-:Conceal, + +:Pmenu,=:PmenuSel,x:PmenuSbar, + X:PmenuThumb") global {not in Vi} This option can be used to set highlighting mode for various @@ -3670,6 +3672,8 @@ A jump table for the options with a short description can be found at |Q_op|. use for that occasion. The occasions are: |hl-SpecialKey| 8 Meta and special keys listed with ":map" |hl-EndOfBuffer| ~ lines after the last line in the buffer + |hl-TermCursor| z Cursor in a focused terminal + |hl-TermCursorNC| Z Cursor in an unfocused terminal |hl-NonText| @ '@' at the end of the window and characters from 'showbreak' |hl-Directory| d directories in CTRL-D listing and other special @@ -3681,7 +3685,7 @@ A jump table for the options with a short description can be found at |Q_op|. |hl-ModeMsg| M Mode (e.g., "-- INSERT --") |hl-LineNr| n line number for ":number" and ":#" commands, and when 'number' or 'relativenumber' option is set. - |hl-CursorLineNr| N like n for when 'cursorline' or 'relativenumber' is + |hl-CursorLineNr| N like n for when 'cursorline' or 'relativenumber' is set. |hl-Question| r |hit-enter| prompt and yes/no questions |hl-StatusLine| s status line of current window |status-line| @@ -4949,15 +4953,6 @@ A jump table for the options with a short description can be found at |Q_op|. time in msec between two mouse clicks for the second click to be recognized as a multi click. - *'mzquantum'* *'mzq'* -'mzquantum' 'mzq' number (default 100) - global - {not in Vi} - {not available when compiled without the |+mzscheme| - feature} - The number of milliseconds between polls for MzScheme threads. - Negative or zero value means no thread scheduling. - *'nrformats'* *'nf'* 'nrformats' 'nf' string (default "octal,hex") local to buffer diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index 1554b823eb..5e0aa8021f 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -793,7 +793,6 @@ Short explanation of each option: *option-list* 'mousemodel' 'mousem' changes meaning of mouse buttons 'mouseshape' 'mouses' shape of the mouse pointer in different modes 'mousetime' 'mouset' max time between mouse double-click -'mzquantum' 'mzq' the interval between polls for MzScheme threads 'nrformats' 'nf' number formats recognized for CTRL-A command 'number' 'nu' print the line number in front of each line 'numberwidth' 'nuw' number of columns used for the line number diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 19289dafec..6415b4203f 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -3221,16 +3221,10 @@ The g:vimsyn_embed option allows users to select what, if any, types of embedded script highlighting they wish to have. > g:vimsyn_embed == 0 : don't embed any scripts - g:vimsyn_embed =~ 'm' : support embedded mzscheme - g:vimsyn_embed =~ 'p' : support embedded perl g:vimsyn_embed =~ 'P' : support embedded python - g:vimsyn_embed =~ 'r' : support embedded ruby - g:vimsyn_embed =~ 't' : support embedded tcl < By default, g:vimsyn_embed is a string supporting interpreters that your vim -itself supports. Concatenate multiple characters to support multiple types -of embedded interpreters; ie. g:vimsyn_embed= "mp" supports embedded mzscheme -and embedded perl. +itself supports. *g:vimsyn_folding* Some folding is now supported with syntax/vim.vim: > @@ -3238,11 +3232,7 @@ Some folding is now supported with syntax/vim.vim: > g:vimsyn_folding == 0 or doesn't exist: no syntax-based folding g:vimsyn_folding =~ 'a' : augroups g:vimsyn_folding =~ 'f' : fold functions - g:vimsyn_folding =~ 'm' : fold mzscheme script - g:vimsyn_folding =~ 'p' : fold perl script g:vimsyn_folding =~ 'P' : fold python script - g:vimsyn_folding =~ 'r' : fold ruby script - g:vimsyn_folding =~ 't' : fold tcl script < *g:vimsyn_noerror* Not all error highlighting that syntax/vim.vim does may be correct; VimL is a @@ -4763,6 +4753,10 @@ DiffText diff mode: Changed text within a changed line |diff.txt| {Nvim} *hl-EndOfBuffer* EndOfBuffer filler lines (~) after the end of the buffer. By default, this is highlighted like |hl-NonText|. + {Nvim} *hl-TermCursor* +TermCursor cursor in a focused terminal + {Nvim} *hl-TermCursorNC* +TermCursorNC cursor in an unfocused terminal *hl-ErrorMsg* ErrorMsg error messages on the command line *hl-VertSplit* diff --git a/runtime/doc/tips.txt b/runtime/doc/tips.txt index 90aa20e8b4..e1d02da292 100644 --- a/runtime/doc/tips.txt +++ b/runtime/doc/tips.txt @@ -26,7 +26,6 @@ Change a name in multiple files |change-name| Speeding up external commands |speed-up| Useful mappings |useful-mappings| Compressing the help files |gzip-helpfile| -Executing shell commands in a window |shell-window| Hex editing |hex-editing| Using <> notation in autocommands |autocmd-<>| Highlighting matching parens |match-parens| @@ -406,20 +405,6 @@ when they are not in the same location as the compressed "doc" directory. See |$VIMRUNTIME|. ============================================================================== -Executing shell commands in a window *shell-window* - -There have been questions for the possibility to execute a shell in a window -inside Vim. The answer: you can't! Including this would add a lot of code to -Vim, which is a good reason not to do this. After all, Vim is an editor, it -is not supposed to do non-editing tasks. However, to get something like this, -you might try splitting your terminal screen or display window with the -"splitvt" program. You can probably find it on some ftp server. The person -that knows more about this is Sam Lantinga <slouken@cs.ucdavis.edu>. -An alternative is the "window" command, found on BSD Unix systems, which -supports multiple overlapped windows. Or the "screen" program, found at -www.uni-erlangen.de, which supports a stack of windows. - -============================================================================== Hex editing *hex-editing* *using-xxd* See section |23.4| of the user manual. diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index f66bc961f0..73dea6293d 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -849,8 +849,6 @@ Results in E670. (Tony Mechelynck, 2010 May 2) 'beval' option should be global-local. -Ruby: ":ruby print $buffer.number" returns zero. - setpos() does not restore cursor position after :normal. (Tyru, 2010 Aug 11) 7 The 'directory' option supports changing path separators to "%" to make @@ -1186,8 +1184,6 @@ still delete them. Also convert all buffer file names? Update src/testdir/main.aap. -"vim -c 'sniff connect'" hangs Vim. (Dominique Pelle, 2008 Dec 7) - Something wrong with session that has "cd" commands and "badd", in such a way that Vim doesn't find the edited file in the buffer list, causing the ATTENTION message? (Tony Mechelynck, 2008 Dec 1) @@ -1604,9 +1600,6 @@ error. without --remote-silent it works fine. (Ben Fritz, 2008 Jun 20) Gvim: dialog for closing Vim should check if Vim is busy writing a file. Then use a different dialog: "busy saving, really quit? yes / no". -Check other interfaces for changing curbuf in a wrong way. Patch like for -if_ruby.c. - ":helpgrep" should use the directory from 'helpfile'. The need_fileinfo flag is messy. Instead make the message right away and put @@ -2689,7 +2682,6 @@ Problems that will (probably) not be solved: XtOpenDisplay() prints this directly, there is no way to avoid it. - X windows: Setting 'guifontset' to an illegal value sometimes crashes Vim. This is caused by a fault in a X library function, can't be solved in Vim. -- Win32 tcl: has("tcl") hangs when the tcl84.dll is from cygwin. - Motif: When adding a menu item "Find this &Symbol", the "s" in "this" will be underlined, instead of in "Symbol". Motif doesn't let us specify which character gets the highlighting. diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index 4db0af07a5..90b4ba7a9d 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -914,8 +914,6 @@ Various: *various-functions* taglist() get list of matching tags tagfiles() get a list of tags files - luaeval() evaluate Lua expression - mzeval() evaluate |MzScheme| expression py3eval() evaluate Python expression (|+python3|) pyeval() evaluate Python expression (|+python|) diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index d138fcf456..fe3915a561 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -279,7 +279,6 @@ g8 Print the hex values of the bytes used in the < The screen is not redrawn then, thus you have to use CTRL-L or ":redraw!" if the command did display something. - Also see |shell-window|. *:!!* :!! Repeat last ":!{cmd}". @@ -364,8 +363,6 @@ N *+lispindent* |'lisp'| N *+listcmds* Vim commands for the list of buffers |buffer-hidden| and argument list |:argdelete| N *+localmap* Support for mappings local to a buffer |:map-local| -m *+lua* |Lua| interface -m *+lua/dyn* |Lua| interface |/dyn| N *+menu* |:menu| N *+mksession* |:mksession| N *+modify_fname* |filename-modifiers| @@ -381,11 +378,7 @@ N *+mouse_xterm* Unix only: xterm mouse handling |xterm-mouse| N *+multi_byte* 16 and 32 bit characters |multibyte| *+multi_byte_ime* Win32 input method for multibyte chars |multibyte-ime| N *+multi_lang* non-English language support |multi-lang| -m *+mzscheme* Mzscheme interface |mzscheme| -m *+mzscheme/dyn* Mzscheme interface |mzscheme-dynamic| |/dyn| N *+path_extra* Up/downwards search in 'path' and 'tags' -m *+perl* Perl interface |perl| -m *+perl/dyn* Perl interface |perl-dynamic| |/dyn| N *+persistent_undo* Persistent undo |undo-persistence| *+postscript* |:hardcopy| writes a PostScript file N *+printer* |:hardcopy| command @@ -398,8 +391,6 @@ N *+quickfix* |:make| and |quickfix| commands N *+reltime* |reltime()| function, 'hlsearch'/'incsearch' timeout, 'redrawtime' option B *+rightleft* Right to left typing |'rightleft'| -m *+ruby* Ruby interface |ruby| -m *+ruby/dyn* Ruby interface |ruby-dynamic| |/dyn| N *+scrollbind* |'scrollbind'| B *+signs* |:sign| N *+smartindent* |'smartindent'| @@ -411,8 +402,6 @@ N *+syntax* Syntax highlighting |syntax| N *+tag_binary* binary searching in tags file |tag-binary-search| N *+tag_old_static* old method for static tags |tag-old-static| m *+tag_any_white* any white space allowed in tags file |tag-any-white| -m *+tcl* Tcl interface |tcl| -m *+tcl/dyn* Tcl interface |tcl-dynamic| |/dyn| *+terminfo* uses |terminfo| instead of termcap N *+termresponse* support for |t_RV| and |v:termresponse| N *+textobjects* |text-objects| selection diff --git a/runtime/doc/vi_diff.txt b/runtime/doc/vi_diff.txt index 9b1657fd09..7661652ac3 100644 --- a/runtime/doc/vi_diff.txt +++ b/runtime/doc/vi_diff.txt @@ -401,8 +401,7 @@ Scripts and Expressions. |expression| |:try| Catch exceptions. etc., etc. See |eval|. Debugging and profiling are supported. |debug-scripts| |profile| - If this is not enough, an interface is provided to |Python|, |Ruby|, - |Tcl|, |Lua|, |Perl| and |MzScheme|. + If this is not enough, an interface is provided to |Python|. Viminfo. |viminfo-file| The command-line history, marks and registers can be stored in a file diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 328e1eda75..94514d7b03 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -68,6 +68,8 @@ Events: Highlight groups: - |hl-EndOfBuffer| +- |hl-TermCursor| +- |hl-TermCursorNC| ============================================================================== 5. Missing legacy features *nvim-features-missing* diff --git a/runtime/optwin.vim b/runtime/optwin.vim index 92ded381d0..395d6d9b46 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -1251,10 +1251,6 @@ call append("$", "\t(local to buffer)") call <SID>BinOptionL("bl") call append("$", "debug\tset to \"msg\" to see all error messages") call append("$", " \tset debug=" . &debug) -if has("mzscheme") - call append("$", "mzquantum\tinterval in milliseconds between polls for MzScheme threads") - call append("$", " \tset mzq=" . &mzq) -endif set cpo&vim diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index 8ad6b2819f..aadc3371f3 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -17,12 +17,12 @@ set cpo&vim syn cluster vimCommentGroup contains=vimTodo,@Spell " regular vim commands {{{2 -syn keyword vimCommand contained a arga[dd] ar[gs] bd[elete] bN[ext] breakd[el] bufdo cabc[lear] cat[ch] cex[pr] c[hange] cla[st] cnew[er] cNf[ile] con cp[revious] cuna[bbrev] del deletep delm[arks] diffp[atch] dig[raphs] do e echon endf endw[hile] f[ile] fin[d] folddoc[losed] fu[nction] gvim helpt[ags] iabc[lear] intro k l lan lc[d] lefta[bove] lg[etfile] lla[st] lnew[er] lNf[ile] lockv[ar] ls lvimgrepa[dd] mat[ch] mk[exrc] mo n n[ext] o ownsyntax perld[o] pre[serve] promptf[ind] ptl[ast] ptr[ewind] py3do qa[ll] r[ead] redr[aw] retu[rn] rub[y] rv[iminfo] sba[ll] sbN[ext] scripte[ncoding] setf[iletype] sh[ell] sim[alt] sm[ap] sni[ff] sor[t] spelli[nfo] spr[evious] start st[op] sunmenu syn ta tabf[ind] tabnew tabr[ewind] tcld[o] tj[ump] tN tr tu[nmenu] undoj[oin] uns[ilent] ve[rsion] vimgrepa[dd] vs[plit] winc[md] wN[ext] ws[verb] x[it] xnoremenu -syn keyword vimCommand contained ab argd[elete] argu[ment] bel[owright] bo[tright] breakl[ist] b[uffer] cad cb[uffer] cf[ile] changes cl[ist] cn[ext] col[der] conf[irm] cq[uit] cw[indow] delc[ommand] deletl delp diffpu[t] dir doau ea e[dit] endfo[r] ene[w] files fini[sh] foldd[oopen] g h hi if is[earch] keepa la lan[guage] lch[dir] lex[pr] lgr[ep] lli[st] lne[xt] lo lol[der] lt[ag] lw[indow] menut mks[ession] mod[e] nbc[lose] nmapc[lear] ol[dfiles] p po[p] prev[ious] promptr[epl] ptn pts[elect] pydo q[uit] rec[over] redraws[tatus] rew[ind] rubyd[o] sal[l] sbf[irst] sbp[revious] scrip[tnames] setg[lobal] si sl sme sno[magic] so[urce] spellr[epall] sre[wind] startg[replace] stopi[nsert] sus[pend] sync tab tabfir[st] tabn[ext] tabs tclf[ile] tl[ast] tn[ext] tr[ewind] u undol[ist] up[date] vert[ical] vi[sual] w windo wp[revious] wundo xmapc[lear] xunme -syn keyword vimCommand contained abc[lear] argdo as[cii] bf[irst] bp[revious] br[ewind] buffers caddb[uffer] cc cfir[st] chd[ir] clo[se] cN[ext] colo[rscheme] con[tinue] cr[ewind] d delel deletp dep diffs[plit] di[splay] dp earlier el[se] endfun ex filet fir[st] foldo[pen] go[to] ha[rdcopy] hid[e] ij[ump] isp[lit] keepalt lad la[st] lcl[ose] lf[ile] lgrepa[dd] lmak[e] lN[ext] loadk lop[en] lua ma menut[ranslate] mksp[ell] m[ove] nb[key] noa omapc[lear] pc[lose] popu p[rint] ps[earch] ptN pu[t] pyf[ile] quita[ll] red reg[isters] ri[ght] rubyf[ile] san[dbox] sbl[ast] sbr[ewind] scs setl[ocal] sig sla[st] smenu snoreme spe spellu[ndo] st star[tinsert] sts[elect] sv[iew] syncbind tabc[lose] tabl[ast] tabN[ext] ta[g] te[aroff] tm tN[ext] try un unh[ide] v vi viu[sage] wa[ll] winp[os] wq wv[iminfo] xme xunmenu -syn keyword vimCommand contained abo[veleft] arge[dit] au bl[ast] br bro[wse] bun[load] cad[dexpr] ccl[ose] cgetb[uffer] che[ckpath] cmapc[lear] cnf com cope[n] cs de delep delf di difft[his] dj[ump] dr[op] ec elsei[f] endf[unction] exi[t] filetype fix[del] for gr[ep] h[elp] his[tory] il[ist] iuna[bbrev] keepj[umps] laddb[uffer] lat lcs lfir[st] lh[elpgrep] lmapc[lear] lnf loadkeymap lpf[ile] luado mak[e] mes mkv mz nbs[tart] noautocmd on[ly] pe popu[p] pro pta[g] ptn[ext] pw[d] py[thon] r redi[r] res[ize] rightb[elow] rundo sa[rgument] sbm[odified] sb[uffer] scscope sf[ind] sign sl[eep] sn[ext] snoremenu spelld[ump] spellw[rong] sta[g] startr[eplace] sun[hide] sw[apname] syntime tabd[o] tabm[ove] tabo[nly] tags tf[irst] tm[enu] to[pleft] ts[elect] una[bbreviate] unl ve vie[w] vmapc[lear] wh[ile] win[size] wqa[ll] x xmenu xwininfo -syn keyword vimCommand contained al[l] argg[lobal] bad[d] bm[odified] brea[k] bu bw[ipeout] caddf[ile] cd cgete[xpr] checkt[ime] cn cNf comc[lear] co[py] cscope debug d[elete] delf[unction] diffg[et] diffu[pdate] dl ds[earch] echoe[rr] em[enu] en[dif] exu[sage] fin fo[ld] fu grepa[dd] helpf[ind] i imapc[lear] j[oin] kee[pmarks] lad[dexpr] later lcscope lgetb[uffer] l[ist] lN lNf lo[adview] lp[revious] luafile ma[rk] messages mkvie[w] mzf[ile] ne noh[lsearch] o[pen] ped[it] pp[op] profd[el] ptf[irst] ptN[ext] py python3 re red[o] ret[ab] ru ru[ntime] sav[eas] sbn[ext] scrip se[t] sfir[st] sil[ent] sm[agic] sN[ext] so spe[llgood] sp[lit] star stj[ump] sunme sy t tabe[dit] tabN tabp[revious] tc[l] th[row] tn tp[revious] tu u[ndo] unlo[ckvar] verb[ose] vim[grep] vne[w] win wn[ext] w[rite] xa[ll] xnoreme y[ank] -syn keyword vimCommand contained ar argl[ocal] ba[ll] bn[ext] breaka[dd] buf c cal[l] ce[nter] cg[etfile] cl cN cnf[ile] comp[iler] cpf[ile] cstag debugg[reedy] deletel dell diffo[ff] dig dli[st] dsp[lit] echom[sg] en endt[ry] f fina[lly] foldc[lose] fun gui helpg[rep] ia in ju[mps] keepp[atterns] laddf[ile] lb[uffer] le[ft] lgete[xpr] ll lne lnf[ile] loc[kmarks] lr[ewind] lv[imgrep] marks mk mkv[imrc] mz[scheme] new nu[mber] opt[ions] pe[rl] pr prof[ile] ptj[ump] ptp[revious] py3 q +syn keyword vimCommand contained a arga[dd] ar[gs] bd[elete] bN[ext] breakd[el] bufdo cabc[lear] cat[ch] cex[pr] c[hange] cla[st] cnew[er] cNf[ile] con cp[revious] cuna[bbrev] del deletep delm[arks] diffp[atch] dig[raphs] do e echon endf endw[hile] f[ile] fin[d] folddoc[losed] fu[nction] gvim helpt[ags] iabc[lear] intro k l lan lc[d] lefta[bove] lg[etfile] lla[st] lnew[er] lNf[ile] lockv[ar] ls lvimgrepa[dd] mat[ch] mk[exrc] mo n n[ext] o ownsyntax pre[serve] promptf[ind] ptl[ast] ptr[ewind] py3do qa[ll] r[ead] redr[aw] retu[rn] rub[y] rv[iminfo] sba[ll] sbN[ext] scripte[ncoding] setf[iletype] sh[ell] sim[alt] sm[ap] sni[ff] sor[t] spelli[nfo] spr[evious] start st[op] sunmenu syn ta tabf[ind] tabnew tabr[ewind] tj[ump] tN tr tu[nmenu] undoj[oin] uns[ilent] ve[rsion] vimgrepa[dd] vs[plit] winc[md] wN[ext] ws[verb] x[it] xnoremenu +syn keyword vimCommand contained ab argd[elete] argu[ment] bel[owright] bo[tright] breakl[ist] b[uffer] cad cb[uffer] cf[ile] changes cl[ist] cn[ext] col[der] conf[irm] cq[uit] cw[indow] delc[ommand] deletl delp diffpu[t] dir doau ea e[dit] endfo[r] ene[w] files fini[sh] foldd[oopen] g h hi if is[earch] keepa la lan[guage] lch[dir] lex[pr] lgr[ep] lli[st] lne[xt] lo lol[der] lt[ag] lw[indow] menut mks[ession] mod[e] nbc[lose] nmapc[lear] ol[dfiles] p po[p] prev[ious] promptr[epl] ptn pts[elect] pydo q[uit] rec[over] redraws[tatus] rew[ind] sal[l] sbf[irst] sbp[revious] scrip[tnames] setg[lobal] si sl sme sno[magic] so[urce] spellr[epall] sre[wind] startg[replace] stopi[nsert] sus[pend] sync tab tabfir[st] tabn[ext] tabs tl[ast] tn[ext] tr[ewind] u undol[ist] up[date] vert[ical] vi[sual] w windo wp[revious] wundo xmapc[lear] xunme +syn keyword vimCommand contained abc[lear] argdo as[cii] bf[irst] bp[revious] br[ewind] buffers caddb[uffer] cc cfir[st] chd[ir] clo[se] cN[ext] colo[rscheme] con[tinue] cr[ewind] d delel deletp dep diffs[plit] di[splay] dp earlier el[se] endfun ex filet fir[st] foldo[pen] go[to] ha[rdcopy] hid[e] ij[ump] isp[lit] keepalt lad la[st] lcl[ose] lf[ile] lgrepa[dd] lmak[e] lN[ext] loadk lop[en] ma menut[ranslate] mksp[ell] m[ove] nb[key] noa omapc[lear] pc[lose] popu p[rint] ps[earch] ptN pu[t] pyf[ile] quita[ll] red reg[isters] ri[ght] san[dbox] sbl[ast] sbr[ewind] scs setl[ocal] sig sla[st] smenu snoreme spe spellu[ndo] st star[tinsert] sts[elect] sv[iew] syncbind tabc[lose] tabl[ast] tabN[ext] ta[g] te[aroff] tm tN[ext] try un unh[ide] v vi viu[sage] wa[ll] winp[os] wq wv[iminfo] xme xunmenu +syn keyword vimCommand contained abo[veleft] arge[dit] au bl[ast] br bro[wse] bun[load] cad[dexpr] ccl[ose] cgetb[uffer] che[ckpath] cmapc[lear] cnf com cope[n] cs de delep delf di difft[his] dj[ump] dr[op] ec elsei[f] endf[unction] exi[t] filetype fix[del] for gr[ep] h[elp] his[tory] il[ist] iuna[bbrev] keepj[umps] laddb[uffer] lat lcs lfir[st] lh[elpgrep] lmapc[lear] lnf loadkeymap lpf[ile] mak[e] mes mkv nbs[tart] noautocmd on[ly] pe popu[p] pro pta[g] ptn[ext] pw[d] py[thon] r redi[r] res[ize] rightb[elow] rundo sa[rgument] sbm[odified] sb[uffer] scscope sf[ind] sign sl[eep] sn[ext] snoremenu spelld[ump] spellw[rong] sta[g] startr[eplace] sun[hide] sw[apname] syntime tabd[o] tabm[ove] tabo[nly] tags tf[irst] tm[enu] to[pleft] ts[elect] una[bbreviate] unl ve vie[w] vmapc[lear] wh[ile] win[size] wqa[ll] x xmenu xwininfo +syn keyword vimCommand contained al[l] argg[lobal] bad[d] bm[odified] brea[k] bu bw[ipeout] caddf[ile] cd cgete[xpr] checkt[ime] cn cNf comc[lear] co[py] cscope debug d[elete] delf[unction] diffg[et] diffu[pdate] dl ds[earch] echoe[rr] em[enu] en[dif] exu[sage] fin fo[ld] fu grepa[dd] helpf[ind] i imapc[lear] j[oin] kee[pmarks] lad[dexpr] later lcscope lgetb[uffer] l[ist] lN lNf lo[adview] lp[revious] ma[rk] messages mkvie[w] ne noh[lsearch] o[pen] ped[it] pp[op] profd[el] ptf[irst] ptN[ext] py python3 re red[o] ret[ab] ru ru[ntime] sav[eas] sbn[ext] scrip se[t] sfir[st] sil[ent] sm[agic] sN[ext] so spe[llgood] sp[lit] star stj[ump] sunme sy t tabe[dit] tabN tabp[revious] tc[l] th[row] tn tp[revious] tu u[ndo] unlo[ckvar] verb[ose] vim[grep] vne[w] win wn[ext] w[rite] xa[ll] xnoreme y[ank] +syn keyword vimCommand contained ar argl[ocal] ba[ll] bn[ext] breaka[dd] buf c cal[l] ce[nter] cg[etfile] cl cN cnf[ile] comp[iler] cpf[ile] cstag debugg[reedy] deletel dell diffo[ff] dig dli[st] dsp[lit] echom[sg] en endt[ry] f fina[lly] foldc[lose] fun gui helpg[rep] ia in ju[mps] keepp[atterns] laddf[ile] lb[uffer] le[ft] lgete[xpr] ll lne lnf[ile] loc[kmarks] lr[ewind] lv[imgrep] marks mk mkv[imrc] new nu[mber] opt[ions] pe[rl] pr prof[ile] ptj[ump] ptp[revious] py3 q syn match vimCommand contained "\<z[-+^.=]\=" syn keyword vimStdPlugin contained DiffOrig Man N[ext] P[rint] S TOhtml XMLent XMLns @@ -31,8 +31,8 @@ syn keyword vimOption contained acd ambiwidth arabicshape autowriteall backupdir syn keyword vimOption contained ai ambw ari aw backupext beval brk buflisted cdpath cin cinwords cocu compatible cpt cscopetag cst cursorline dex digraph ead ei equalalways eventignore fde fdt fic fillchars foldclose foldmarker formatlistpat gcr ghr guicursor guitablabel hi hkmapp icon imak ims incsearch infercase isk keymap langmenu linespace loadplugins macatsui maxcombine mef mls modelines mousehide mp nu omnifunc paragraphs penc pm printdevice printoptions quoteescape remap rl ruf sc scrollopt selectmode shellpipe shellxquote showcmd sidescroll smartindent sol spellsuggest sr stal sua swf syntax taglength tbidi terse tildeop tl tr tty tw undofile vb vi wa wd wi wildignorecase window winwidth wmw writeany syn keyword vimOption contained akm anti arshape awa backupskip bex browsedir buftype cedit cindent clipboard cole complete crb cscopetagorder csto cwh dg dip eadirection ek equalprg ex fdi fen fileencoding fk foldcolumn foldmethod formatoptions gd go guifont guitabtooltip hid hkp iconstring imc imsearch inde insertmode iskeyword keymodel laststatus lisp lpl magic maxfuncdepth menuitems mm modifiable mousem mps number opendevice paste pex pmbcs printencoding prompt rdt report rlc ruler scb scs sessionoptions shellquote shiftround showfulltag sidescrolloff smarttab sp spf srr startofline suffixes switchbuf ta tagrelative tbis textauto timeout tm ts tx undolevels vbs viewdir wak weirdinvert wic wildmenu winfixheight wiv wop writebackup syn keyword vimOption contained al antialias autochdir background balloondelay bexpr bk bs casemap cf cink cmdheight colorcolumn completefunc copyindent cscopeverbose csverb debug dict dir eb enc errorbells expandtab fdl fenc fileencodings fkmap foldenable foldminlines formatprg gdefault gp guifontset helpfile hidden hl ignorecase imcmdline imsf indentexpr is isp keywordprg lazyredraw lispwords ls makeef maxmapdepth mfd mmd modified mousemodel msm numberwidth operatorfunc pastetoggle pexpr pmbfn printexpr pt re restorescreen rnu rulerformat scr sect sft shellredir shiftwidth showmatch siso smc spc spl ss statusline suffixesadd sws tabline tags tbs textmode timeoutlen to tsl uc undoreload vdir viewoptions warn wfh wig wildmode winfixwidth wiw wrap writedelay -syn keyword vimOption contained aleph ar autoindent backspace ballooneval bg bkc bsdir cb cfu cinkeys cmdwinheight columns completeopt cot cscopepathcomp cspc cuc deco dictionary directory ed encoding errorfile exrc fdls fencs fileformat flp foldexpr foldnestmax fp gfm grepformat guifontwide helpheight highlight hlg im imd imstatusfunc indentkeys isf isprint km lbr list lsp makeprg maxmem mh mmp more mouses mzq nuw opfunc patchexpr pfn popt printfont pumheight readonly revins ro runtimepath scroll sections sh shellslash shm showmode sj smd spell splitbelow ssl stl sw sxe tabpagemax tagstack tenc textwidth title toolbar tsr ttym udf updatecount ve viminfo wb wfw wildchar wildoptions winheight wm wrapmargin ws -syn keyword vimOption contained allowrevins arab autoread backup balloonexpr bh bl bsk cc ch cino cmp com concealcursor cp cscopeprg csprg cul def diff display endofline errorformat fcl fdm fex fileformats fml foldignore foldopen fs gfn grepprg guiheadroom helplang history hls imactivatefunc imdisable inc indk isfname joinspaces kmp lcs listchars lw mat maxmempattern mis mmt mouse mouseshape mzquantum odev patchmode ph preserveindent printheader pvh redrawtime ri rs sb scrollbind secure shcf shelltemp shortmess showtabline slm spellcapcheck splitright ssop stmp swapfile sxq tabstop tal term titlelen toolbariconsize ttimeout ttymouse udir updatetime verbose virtualedit wc wh wildcharm wim winminheight wmh wrapscan ww +syn keyword vimOption contained aleph ar autoindent backspace ballooneval bg bkc bsdir cb cfu cinkeys cmdwinheight columns completeopt cot cscopepathcomp cspc cuc deco dictionary directory ed encoding errorfile exrc fdls fencs fileformat flp foldexpr foldnestmax fp gfm grepformat guifontwide helpheight highlight hlg im imd imstatusfunc indentkeys isf isprint km lbr list lsp makeprg maxmem mh mmp more mouses nuw opfunc patchexpr pfn popt printfont pumheight readonly revins ro runtimepath scroll sections sh shellslash shm showmode sj smd spell splitbelow ssl stl sw sxe tabpagemax tagstack tenc textwidth title toolbar tsr ttym udf updatecount ve viminfo wb wfw wildchar wildoptions winheight wm wrapmargin ws +syn keyword vimOption contained allowrevins arab autoread backup balloonexpr bh bl bsk cc ch cino cmp com concealcursor cp cscopeprg csprg cul def diff display endofline errorformat fcl fdm fex fileformats fml foldignore foldopen fs gfn grepprg guiheadroom helplang history hls imactivatefunc imdisable inc indk isfname joinspaces kmp lcs listchars lw mat maxmempattern mis mmt mouse mouseshape odev patchmode ph preserveindent printheader pvh redrawtime ri rs sb scrollbind secure shcf shelltemp shortmess showtabline slm spellcapcheck splitright ssop stmp swapfile sxq tabstop tal term titlelen toolbariconsize ttimeout ttymouse udir updatetime verbose virtualedit wc wh wildcharm wim winminheight wmh wrapscan ww syn keyword vimOption contained altkeymap arabic autowrite backupcopy bdir bin bomb bt ccv charconvert cinoptions cms comments conceallevel cpo cscopequickfix csqf cursorbind define diffexpr dy ef eol esckeys fcs fdn ff fileignorecase fmr foldlevel foldtext fsync gfs gtl guioptions hf hk hlsearch imactivatekey imi include inex isi js kp linebreak lm lz matchpairs maxmemtot mkspellmem mod mousef mouset nf pa path pheader previewheight printmbcharset pvw regexpengine rightleft rtp sbo scrolljump sel shell shq sm so spellfile spr st sts swapsync syn tag tb termbidi tgst titleold top ttimeoutlen ttyscroll ul ur unnamedclip unc verbosefile visualbell " vimOptions: These are the turn-off setting variants {{{2 @@ -62,18 +62,18 @@ syn keyword vimErrSetting contained hardtabs ht w1200 w300 w9600 " AutoCmd Events {{{2 syn case ignore -syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite BufWriteCmd BufWritePost BufWritePre Cmd-event CmdwinEnter CmdwinLeave ColorScheme CompleteDone CursorHold CursorHoldI CursorMoved CursorMovedI EncodingChanged FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileChangedShellPost FileEncoding FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter InsertLeave JobActivity MenuPopup QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SessionLoadPost ShellCmdPost ShellFilterPost SourceCmd SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabEnter TabLeave TabNew TabNewEntered TabClosed TermChanged TermResponse TextChanged TextChangedI User UserGettingBored VimEnter VimLeave VimLeavePre VimResized WinEnter WinLeave +syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite BufWriteCmd BufWritePost BufWritePre Cmd-event CmdwinEnter CmdwinLeave ColorScheme CompleteDone CursorHold CursorHoldI CursorMoved CursorMovedI EncodingChanged FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileChangedShellPost FileEncoding FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter InsertLeave MenuPopup QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SessionLoadPost ShellCmdPost ShellFilterPost SourceCmd SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabEnter TabLeave TabNew TabNewEntered TabClosed TermChanged TermResponse TextChanged TextChangedI User UserGettingBored VimEnter VimLeave VimLeavePre VimResized WinEnter WinLeave " Highlight commonly used Groupnames {{{2 syn keyword vimGroup contained Comment Constant String Character Number Boolean Float Identifier Function Statement Conditional Repeat Label Operator Keyword Exception PreProc Include Define Macro PreCondit Type StorageClass Structure Typedef Special SpecialChar Tag Delimiter SpecialComment Debug Underlined Ignore Error Todo " Default highlighting groups {{{2 -syn keyword vimHLGroup contained ColorColumn Cursor CursorColumn CursorIM CursorLine CursorLineNr DiffAdd DiffChange DiffDelete DiffText Directory EndOfBuffer ErrorMsg FoldColumn Folded IncSearch LineNr MatchParen Menu ModeMsg MoreMsg NonText Normal Pmenu PmenuSbar PmenuSel PmenuThumb Question Scrollbar Search SignColumn SpecialKey SpellBad SpellCap SpellLocal SpellRare StatusLine StatusLineNC TabLine TabLineFill TabLineSel Title Tooltip VertSplit Visual VisualNOS WarningMsg WildMenu +syn keyword vimHLGroup contained ColorColumn Cursor CursorColumn CursorIM CursorLine CursorLineNr DiffAdd DiffChange DiffDelete DiffText Directory EndOfBuffer ErrorMsg FoldColumn Folded IncSearch LineNr MatchParen Menu ModeMsg MoreMsg NonText Normal Pmenu PmenuSbar PmenuSel PmenuThumb Question Scrollbar Search SignColumn SpecialKey SpellBad SpellCap SpellLocal SpellRare StatusLine StatusLineNC TabLine TabLineFill TabLineSel TermCursor TermCursorNC Title Tooltip VertSplit Visual VisualNOS WarningMsg WildMenu syn match vimHLGroup contained "Conceal" syn case match " Function Names {{{2 -syn keyword vimFuncName contained abs and argidx atan browsedir bufloaded bufwinnr byteidxcomp changenr clearmatches complete_add copy count deepcopy diff_filler escape executable expand feedkeys filter float2nr fnameescape foldclosedend foldtextresult garbagecollect getbufvar getcmdline getcwd getfsize getline getpid getreg gettabwinvar getwinvar has hasmapto histget hlID indent inputdialog inputsave invert items len line localtime luaeval mapcheck matcharg matchlist min mzeval or prevnonblank py3eval readfile remote_expr remote_read rename reverse screenchar search searchpairpos serverlist setcmdpos setloclist setpos setreg settabwinvar sha256 shiftwidth sin sort spellbadword split str2float strchars strftime string strpart strtrans submatch synconcealed synIDattr synstack tabpagebuflist tabpagewinnr taglist tanh tolower tr type undotree virtcol wildmenumode wincol winline winrestcmd winsaveview writefile +syn keyword vimFuncName contained abs and argidx atan browsedir bufloaded bufwinnr byteidxcomp changenr clearmatches complete_add copy count deepcopy diff_filler escape executable expand feedkeys filter float2nr fnameescape foldclosedend foldtextresult garbagecollect getbufvar getcmdline getcwd getfsize getline getpid getreg gettabwinvar getwinvar has hasmapto histget hlID indent inputdialog inputsave invert items len line localtime mapcheck matcharg matchlist min or prevnonblank py3eval readfile remote_expr remote_read rename reverse screenchar search searchpairpos serverlist setcmdpos setloclist setpos setreg settabwinvar sha256 shiftwidth sin sort spellbadword split str2float strchars strftime string strpart strtrans submatch synconcealed synIDattr synstack tabpagebuflist tabpagewinnr taglist tanh tolower tr type undotree virtcol wildmenumode wincol winline winrestcmd winsaveview writefile syn keyword vimFuncName contained acos append argv atan2 bufexists bufname byte2line call char2nr col complete_check cos cscope_connection delete diff_hlID eval exists expr8 filereadable finddir floor fnamemodify foldlevel foreground get getchar getcmdpos getfontname getftime getloclist getpos getregtype getwinposx glob has_key histadd histnr hostname index inputlist inputsecret isdirectory join libcall line2byte log map match matchdelete matchstr mkdir nextnonblank pathshorten printf pyeval reltime remote_foreground remote_send repeat round screencol searchdecl searchpos setbufvar setline setmatches setqflist settabvar setwinvar shellescape simplify sinh soundfold spellsuggest sqrt str2nr strdisplaywidth stridx strlen strridx strwidth substitute synID synIDtrans system tabpagenr tagfiles tan tempname toupper trunc undofile values visualmode winbufnr winheight winnr winrestview winwidth xor syn keyword vimFuncName contained add argc asin browse buflisted bufnr byteidx ceil cindent complete confirm cosh cursor did_filetype empty eventhandler exp extend filewritable findfile fmod foldclosed foldtext function getbufline getcharmod getcmdtype getfperm getftype getmatches getqflist gettabvar getwinposy globpath haslocaldir histdel hlexists iconv input inputrestore insert islocked keys libcallnr lispindent log10 maparg matchadd matchend max mode nr2char pow pumvisible range reltimestr remote_peek remove resolve screenattr screenrow searchpair server2client jobsend jobstart jobstop rpcnotify rpcrequest rpcstart rpcstop @@ -550,14 +550,9 @@ syn region vimGlobal matchgroup=Statement start='\<v\%[global]!\=/' skip='\\.' e " Allows users to specify the type of embedded script highlighting " they want: (perl/python/ruby/tcl support) " g:vimsyn_embed == 0 : don't embed any scripts -" g:vimsyn_embed ~= 'l' : embed lua (but only if vim supports it) -" g:vimsyn_embed ~= 'm' : embed mzscheme (but only if vim supports it) -" g:vimsyn_embed ~= 'p' : embed perl (but only if vim supports it) " g:vimsyn_embed ~= 'P' : embed python (but only if vim supports it) -" g:vimsyn_embed ~= 'r' : embed ruby (but only if vim supports it) -" g:vimsyn_embed ~= 't' : embed tcl (but only if vim supports it) if !exists("g:vimsyn_embed") - let g:vimsyn_embed= "lmpPr" + let g:vimsyn_embed= "P" endif " [-- lua --] {{{3 @@ -570,21 +565,9 @@ if !filereadable(s:luapath) endif endfor endif -if (g:vimsyn_embed =~ 'l' && has("lua")) && filereadable(s:luapath) - unlet! b:current_syntax - exe "syn include @vimLuaScript ".s:luapath - if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'l' - syn region vimLuaRegion fold matchgroup=vimScriptDelim start=+lua\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimLuaScript - syn region vimLuaRegion fold matchgroup=vimScriptDelim start=+lua\s*<<\s*$+ end=+\.$+ contains=@vimLuaScript - else - syn region vimLuaRegion matchgroup=vimScriptDelim start=+lua\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimLuaScript - syn region vimLuaRegion matchgroup=vimScriptDelim start=+lua\s*<<\s*$+ end=+\.$+ contains=@vimLuaScript - endif - syn cluster vimFuncBodyList add=vimLuaRegion -else - syn region vimEmbedError start=+lua\s*<<\s*\z(.*\)$+ end=+^\z1$+ - syn region vimEmbedError start=+lua\s*<<\s*$+ end=+\.$+ -endif + +syn region vimEmbedError start=+lua\s*<<\s*\z(.*\)$+ end=+^\z1$+ +syn region vimEmbedError start=+lua\s*<<\s*$+ end=+\.$+ unlet s:luapath " [-- perl --] {{{3 @@ -597,21 +580,9 @@ if !filereadable(s:perlpath) endif endfor endif -if (g:vimsyn_embed =~ 'p' && has("perl")) && filereadable(s:perlpath) - unlet! b:current_syntax - exe "syn include @vimPerlScript ".s:perlpath - if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'p' - syn region vimPerlRegion fold matchgroup=vimScriptDelim start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript - syn region vimPerlRegion fold matchgroup=vimScriptDelim start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript - else - syn region vimPerlRegion matchgroup=vimScriptDelim start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript - syn region vimPerlRegion matchgroup=vimScriptDelim start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript - endif - syn cluster vimFuncBodyList add=vimPerlRegion -else - syn region vimEmbedError start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ - syn region vimEmbedError start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ -endif + +syn region vimEmbedError start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ +syn region vimEmbedError start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ unlet s:perlpath " [-- ruby --] {{{3 @@ -624,20 +595,9 @@ if !filereadable(s:rubypath) endif endfor endif -if (g:vimsyn_embed =~ 'r' && has("ruby")) && filereadable(s:rubypath) - unlet! b:current_syntax - exe "syn include @vimRubyScript ".s:rubypath - if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'r' - syn region vimRubyRegion fold matchgroup=vimScriptDelim start=+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimRubyScript - else - syn region vimRubyRegion matchgroup=vimScriptDelim start=+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimRubyScript - endif - syn region vimRubyRegion matchgroup=vimScriptDelim start=+rub[y]\s*<<\s*$+ end=+\.$+ contains=@vimRubyScript - syn cluster vimFuncBodyList add=vimRubyRegion -else - syn region vimEmbedError start=+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ - syn region vimEmbedError start=+rub[y]\s*<<\s*$+ end=+\.$+ -endif + +syn region vimEmbedError start=+rub[y]\s*<<\s*\z(.*\)$+ end=+^\z1$+ +syn region vimEmbedError start=+rub[y]\s*<<\s*$+ end=+\.$+ unlet s:rubypath " [-- python --] {{{3 @@ -684,22 +644,11 @@ if s:trytcl endif endfor endif - if (g:vimsyn_embed =~ 't' && has("tcl")) && filereadable(s:tclpath) - unlet! b:current_syntax - exe "syn include @vimTclScript ".s:tclpath - if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 't' - syn region vimTclRegion fold matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimTclScript - syn region vimTclRegion fold matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=@vimTclScript - else - syn region vimTclRegion matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimTclScript - syn region vimTclRegion matchgroup=vimScriptDelim start=+tc[l]\=\s*<<\s*$+ end=+\.$+ contains=@vimTclScript - endif - syn cluster vimFuncBodyList add=vimTclScript - else - syn region vimEmbedError start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ - syn region vimEmbedError start=+tc[l]\=\s*<<\s*$+ end=+\.$+ - endif + + syn region vimEmbedError start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ + syn region vimEmbedError start=+tc[l]\=\s*<<\s*$+ end=+\.$+ unlet s:tclpath + else syn region vimEmbedError start=+tc[l]\=\s*<<\s*\z(.*\)$+ end=+^\z1$+ syn region vimEmbedError start=+tc[l]\=\s*<<\s*$+ end=+\.$+ @@ -716,23 +665,9 @@ if !filereadable(s:mzschemepath) endif endfor endif -if (g:vimsyn_embed =~ 'm' && has("mzscheme")) && filereadable(s:mzschemepath) - unlet! b:current_syntax - let iskKeep= &isk - exe "syn include @vimMzSchemeScript ".s:mzschemepath - let &isk= iskKeep - if exists("g:vimsyn_folding") && g:vimsyn_folding =~ 'm' - syn region vimMzSchemeRegion fold matchgroup=vimScriptDelim start=+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimMzSchemeScript - syn region vimMzSchemeRegion fold matchgroup=vimScriptDelim start=+mz\%[scheme]\s*<<\s*$+ end=+\.$+ contains=@vimMzSchemeScript - else - syn region vimMzSchemeRegion matchgroup=vimScriptDelim start=+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimMzSchemeScript - syn region vimMzSchemeRegion matchgroup=vimScriptDelim start=+mz\%[scheme]\s*<<\s*$+ end=+\.$+ contains=@vimMzSchemeScript - endif - syn cluster vimFuncBodyList add=vimMzSchemeRegion -else - syn region vimEmbedError start=+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ - syn region vimEmbedError start=+mz\%[scheme]\s*<<\s*$+ end=+\.$+ -endif + +syn region vimEmbedError start=+mz\%[scheme]\s*<<\s*\z(.*\)$+ end=+^\z1$+ +syn region vimEmbedError start=+mz\%[scheme]\s*<<\s*$+ end=+\.$+ unlet s:mzschemepath " Synchronize (speed) {{{2 diff --git a/runtime/tools/README.txt b/runtime/tools/README.txt deleted file mode 100644 index 19976b325c..0000000000 --- a/runtime/tools/README.txt +++ /dev/null @@ -1,37 +0,0 @@ -Some tools that can be used with Vim: - -blink.c: C program to make the cursor blink in an xterm. - -ccfilter*: C program to filter the output of a few compilers to a common - QuickFix format. - -efm_filter.*: Perl script to filter compiler messages to QuickFix format. - -efm_perl.pl: Perl script to filter error messages from the Perl interpreter - for use with Vim quickfix mode. - -mve.* Awk script to filter error messages to QuickFix format. - -pltags.pl: Perl script to create a tags file from Perl scripts. - -ref: Shell script for the K command. - -shtags.*: Perl script to create a tags file from a shell script. - -vim132: Shell script to edit in 132 column mode on vt100 compatible - terminals. - -vimm: Shell script to start Vim on a DEC terminal with mouse - enabled. - -vimspell.*: Shell script for highlighting spelling mistakes. - -vim_vs_net.cmd: MS-Windows command file to use Vim with MS Visual Studio 7 and - later. - -xcmdsrv_client.c: Example for a client program that communicates with a Vim - server through the X-Windows interface. - -unicode.vim Vim script to generate tables for src/mbyte.c. - -[xxd can be found in the src directory] diff --git a/runtime/tools/blink.c b/runtime/tools/blink.c deleted file mode 100644 index 1ffd848edc..0000000000 --- a/runtime/tools/blink.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * An extremely simple program to make the cursor blink in an xterm. - * This is useful when the cursor is hard to spot in a highlighted file. - * Start in the background: "blink&" Stop by killing it. - * Bram Moolenaar 980109 (based on an idea from John Lange). - */ - -#include <stdio.h> - -main() -{ - while (1) - { - printf("\e[?25h"); - fflush(stdout); - usleep(400000); /* on time */ - printf("\e[?25l"); - fflush(stdout); - usleep(250000); /* off time */ - } -} diff --git a/runtime/tools/ccfilter.1 b/runtime/tools/ccfilter.1 deleted file mode 100644 index e3de38da1f..0000000000 --- a/runtime/tools/ccfilter.1 +++ /dev/null @@ -1,93 +0,0 @@ -.TH ccfilter 1 "01-Apr-97" -.SH NAME -ccfilter \- a compiler's output filter for vim quickfix -.SH SYNOPSIS -ccfilter [ -.B <options> -] -.SH DESCRIPTION -The ccfilter utility "filters" the output of several compilers -and makers (make/gmake) from several platforms (see NOTES below) -to a standardized format which easily fits in vim's quickfix -feature. For further details, see in vim ":help quickfix". -.PP -ccfilter reads -.B 'stdin' -and outputs to -.B 'stdout' -\. -.PP -The need for ccfilter is clear, as some compilers have irregular -and/or multiple line error messages (with the relevant information on -line 2), which makes it impossible for the errorformat to correctly -display them ! - -When working on different platforms, and with different compilers, -ccfilter eases the utilization of quickfix, due to it's standardized -output, allowing to have in .vimrc a plain -.br -.B \ \ \ \ :set\ errorformat=%f:%l:%c:%t:%m - -.SH USAGE -When using ccfilter, one would include the following lines in .vimrc: -.br -.B \ \ \ \ :set shellpipe=\\\\|&ccfilter\\\\> -.br -.B \ \ \ \ :set errorformat=%f:%l:%c:%t:%m - -.SH OPTIONS -.TP 16 --c -Decrement column by one. This may be needed, depending on -the compiler being used. -.TP --r -Decrement row by one. This may be needed, depending on -the compiler being used. -.TP --v -Verbose (Outputs also invalid lines). -This option makes ccfilter output also the lines that -couldn't be correctly parsed. This is used mostly for -ccfilter debugging. -.TP --o <COMPILER> -Treat input as <COMPILER>'s output. -Even when configuring ccfilter to assume a default -COMPILER, sometimes it's helpful to be able to specify -the COMPILER used to generate ccfilter's input. -For example, when cross-compiling on a network from a -single machine. -.TP --h -Shows a brief help, describing the configured default COMPILER -and the valid parameters for COMPILER. - -.SH NOTES -Currently, ccfilter accepts output from several compilers, as -described below: -.TP 10 -GCC -GCC compiler -.TP -AIX -AIX's C compiler -.TP -ATT -AT&T/NCR's High Performance C Compiler -.TP -IRIX -IRIX's MIPS/MIPSpro C compiler -.TP -SOLARIS -SOLARIS's SparcWorks C compiler -.TP -HPUX -HPUX's C compiler - -.SH AUTHOR -.B ccfilter -was developed by -.B Pablo Ariel Kohan -.BR -.B mailto:pablo@memco.co.il diff --git a/runtime/tools/ccfilter.c b/runtime/tools/ccfilter.c deleted file mode 100644 index 270333910f..0000000000 --- a/runtime/tools/ccfilter.c +++ /dev/null @@ -1,326 +0,0 @@ -/* ======================================================================= */ -/* Project : VIM */ -/* Module : ccfilter Version: 02.01.01 */ -/* File : ccfilter.c */ -/* Purpose : Filter gmake/cc output into a standardized form */ -/* ======================================================================= */ -/* Created On: 12-Sep-95 20:32 */ -/* Last modification: 03-Feb-98 */ -/* -e option added by Bernd Feige */ -/* ======================================================================= */ -/* Copyright : */ -/* This source file is copyright (c) to Pablo Ariel Kohan */ -/* ======================================================================= */ -#define __CCFILTER_C__ - -#include <ctype.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#define LINELENGTH 2048 - -/* Collector(s) */ -char Line[LINELENGTH]; -char Line2[LINELENGTH]; -/* Components */ -char FileName[1024]; -char BasePath[1024]; -char CWD[1024]; -unsigned long Row; -unsigned long Col; -char Severity; -char Reason[LINELENGTH]; - -#define COMPILER_UNKNOWN 0 -#define COMPILER_GCC 1 -#define COMPILER_AIX 2 -#define COMPILER_ATT 3 -#define COMPILER_IRIX 4 -#define COMPILER_SOLARIS 5 -#define COMPILER_HPUX 6 - -char *COMPILER_Names[][2] = - { - /* Name Description */ - { "N/A", "" }, - { "GCC", "GCC compiler" }, - { "AIX", "AIX's C compiler" }, - { "ATT", "AT&T/NCR's High Performance C Compiler" }, - { "IRIX", "IRIX's MIPS/MIPSpro C compiler" }, - { "SOLARIS", "SOLARIS's SparcWorks C compiler" }, - { "HPUX", "HPUX's C compiler" } - }; -#define COMPILER_QTY (sizeof(COMPILER_Names)/sizeof(COMPILER_Names[0])) - -#if defined(_GCC) -# define COMPILER_DEFAULT COMPILER_GCC -#elif defined(_AIX) -# define COMPILER_DEFAULT COMPILER_AIX -#elif defined(_ATT) -# define COMPILER_DEFAULT COMPILER_ATT -#elif defined(_IRIX) -# define COMPILER_DEFAULT COMPILER_IRIX -#elif defined(_SOLARIS) -# define COMPILER_DEFAULT COMPILER_SOLARIS -#elif defined(_HPUX) -# define COMPILER_DEFAULT COMPILER_HPUX -#else -# define COMPILER_DEFAULT COMPILER_UNKNOWN -#endif - -const char USAGE[] = -"ccfilter v2.1 (c)1994-1997 by Pablo Ariel Kohan\n" -"Filter Out compiler's output, and converts it to fit VIM\n\n" -"Usage:\n" -" ccfilter [<options>]\n" -"Where: <options> is one or more of:\n" -" -c Decrement column by one\n" -" -r Decrement row by one\n" -" -e Echo stdin to stderr\n" -" -v Verbose (Outputs also invalid lines)\n" -" -o <COMPILER> Treat input as <COMPILER>'s output\n" -" Note: COMPILER may be preceded by an _\n" -" -h This usage.\n"; - - -int ShowUsage( char *szError ) -{ int i; - - fprintf( stderr, USAGE ); - - fprintf( stderr, "Current default <COMPILER>: %s\n", - COMPILER_Names[COMPILER_DEFAULT][0] ); - - fprintf( stderr, "Acceptable parameters for <COMPILER> are:\n" ); - for (i=1; i < COMPILER_QTY; i++) - fprintf( stderr, " %-15.15s %s\n", - COMPILER_Names[i][0], - COMPILER_Names[i][1] ); - fprintf(stderr, szError); - return 0; -} - -char *echogets(char *s, int echo) { - char * const retval=fgets(s, LINELENGTH, stdin); - if (echo!=0 && retval!=NULL) { - fputs(retval, stderr); - } - return retval; -} - -int main( int argc, char *argv[] ) -{ int rv, i, j, ok; - int stay; - int prefetch; - char *p; - int dec_col = 0; /* Decrement column value by 1 */ - int dec_row = 0; /* Decrement row value by 1 */ - int echo = 0; /* Echo stdin to stderr */ - int verbose = 0; /* Include Bad Formatted Lines */ - int CWDlen; - int COMPILER = COMPILER_DEFAULT; - - getcwd( CWD, sizeof(CWD) ); - CWDlen = strlen(CWD); - - for (i=1; i<argc; i++) - { - if (argv[i][0] != '-') - return ShowUsage(""); - switch ( argv[i][1] ) - { - case 'c': - dec_col = 1; - break; - case 'r': - dec_row = 1; - break; - case 'e': - echo = 1; - break; - case 'v': - verbose = 1; - break; - case 'o': - { - if (i+1 >= argc) - return ShowUsage("Error: Missing parameter for -o\n"); - i++; - COMPILER = -1; - for (j=1; j<COMPILER_QTY; j++) - if ( (strcmp(argv[i], COMPILER_Names[j][0]) == 0) || - ( (argv[i][0] == '_') && - (strcmp(&argv[i][1], COMPILER_Names[j][0]) == 0) ) ) - COMPILER = j; - if (COMPILER == -1) - return ShowUsage("Error: Invalid COMPILER specified\n"); - } - break; - case 'h': - return ShowUsage(""); - default: - return ShowUsage("Error: Invalid option\n"); - } - } - if (COMPILER == 0) - return ShowUsage("Error: COMPILER must be specified in this system\n"); - - stay = ( echogets(Line, echo) != NULL ); - prefetch = 0; - - while( stay ) - { - *FileName = 0; - Row = 0; - Col = 0; - Severity = ' '; - *Reason = 0; - ok = 0; - switch (COMPILER) - { - case COMPILER_GCC: - Severity = 'e'; -#ifdef GOTO_FROM_WHERE_INCLUDED - rv = sscanf( Line, "In file included from %[^:]:%u:", - FileName, &Row ); - if ( rv == 2 ) - { - ok = (echogets(Reason, echo) != NULL); - } - else -#endif - { - if ((rv = sscanf( Line, "%[^:]:%u: warning: %[^\n]", - FileName, &Row, Reason ))==3) { - Severity = 'w'; - } else { - rv = sscanf( Line, "%[^:]:%u: %[^\n]", - FileName, &Row, Reason ); - } - ok = ( rv == 3 ); - } - Col = (dec_col ? 1 : 0 ); - break; - case COMPILER_AIX: - rv = sscanf( Line, "\"%[^\"]\", line %u.%u: %*s (%c) %[^\n]", - FileName, &Row, &Col, &Severity, Reason ); - ok = ( rv == 5 ); - break; - case COMPILER_HPUX: - rv = sscanf( Line, "cc: \"%[^\"]\", line %u: %c%*[^:]: %[^\n]", - FileName, &Row, &Severity, Reason ); - ok = ( rv == 4 ); - Col = (dec_col ? 1 : 0 ); - break; - case COMPILER_SOLARIS: - rv = sscanf( Line, "\"%[^\"]\", line %u: warning: %[^\n]", - FileName, &Row, Reason ); - Severity = 'w'; - ok = ( rv == 3 ); - if ( rv != 3 ) - { - rv = sscanf( Line, "\"%[^\"]\", line %u: %[^\n]", - FileName, &Row, Reason ); - Severity = 'e'; - ok = ( rv == 3 ); - } - Col = (dec_col ? 1 : 0 ); - break; - case COMPILER_ATT: - rv = sscanf( Line, "%c \"%[^\"]\",L%u/C%u%*[^:]:%[^\n]", - &Severity, FileName, &Row, &Col, Reason ); - ok = ( rv == 5 ); - - if (rv != 5) - { rv = sscanf( Line, "%c \"%[^\"]\",L%u/C%u: %[^\n]", - &Severity, FileName, &Row, &Col, Reason ); - ok = ( rv == 5 ); - } - - if (rv != 5) - { rv = sscanf( Line, "%c \"%[^\"]\",L%u: %[^\n]", - &Severity, FileName, &Row, Reason ); - ok = ( rv == 4 ); - Col = (dec_col ? 1 : 0 ); - } - - stay = (echogets(Line2, echo) != NULL); - while ( stay && (Line2[0] == '|') ) - { for (p=&Line2[2]; (*p) && (isspace(*p)); p++); - strcat( Reason, ": " ); - strcat( Reason, p ); - Line2[0] = 0; - stay = (echogets(Line2, echo) != NULL); - } - prefetch = 1; - strcpy( Line, Line2 ); - break; - case COMPILER_IRIX: - Col = 1; - prefetch = 0; - rv = 0; - ok = 0; - if ( !strncmp(Line, "cfe: ", 5) ) - { p = &Line[5]; - Severity = tolower(*p); - p = strchr( &Line[5], ':' ); - if (p == NULL) - { ok = 0; - } - else - { - rv = sscanf( p+2, "%[^:]: %u: %[^\n]", - FileName, &Row, Reason ); - if (rv != 3) - rv = sscanf( p+2, "%[^,], line %u: %[^\n]", - FileName, &Row, Reason ); - ok = ( rv == 3 ); - } - - if (ok) - { prefetch = 1; - stay = (echogets(Line, echo) != NULL); - if (Line[0] == ' ') - stay = (echogets(Line2, echo) != NULL); - if ( (Line2[0] == ' ') && - ( (Line2[1] == '-') || (Line2[1] == '^') ) ) - { Col = strlen(Line2)-1; - prefetch = 0; - } - else - { strcat( Line, "\n" ); - strcat( Line, Line2 ); - } - } - } - break; - } - if (dec_col) Col--; - if (dec_row) Row--; - if (!ok) - { - if ( Line[0] == 'g' ) - p = &Line[1]; - else - p = &Line[0]; - ok = sscanf( p, "make[%*d]: Entering directory `%[^']", - BasePath ); - if (verbose) - printf( "[%u]?%s\n", ok, Line ); - } - else - { - for (p=Reason; (*p) && (isspace(*p)); p++); - if ( BasePath[CWDlen] == 0 ) - printf( "%s:%u:%u:%c:%s\n", FileName, Row, Col, Severity, p ); - else - { - printf( "%s/%s:%u:%u:%c:%s\n", &BasePath[CWDlen+1], FileName, Row, Col, Severity, p ); - } - } - if (!prefetch) - stay = ( echogets(Line, echo) != NULL ); - } - return 0; -} diff --git a/runtime/tools/ccfilter_README.txt b/runtime/tools/ccfilter_README.txt deleted file mode 100644 index 3c12a8c89b..0000000000 --- a/runtime/tools/ccfilter_README.txt +++ /dev/null @@ -1,91 +0,0 @@ -COMPILING AND INSTALLING: -========================= - -To compile ccfilter, you can just do a plain: - cc ccfilter.c -o ccfilter -Though, it may be wise to have your default compiler defined, -so you would normally compile it with one of the following: - cc -D_GCC ccfilter.c -o ccfilter - cc -D_AIX ccfilter.c -o ccfilter - cc -D_ATT ccfilter.c -o ccfilter - cc -D_IRIX ccfilter.c -o ccfilter - cc -D_SOLARIS ccfilter.c -o ccfilter - cc -D_HPUX ccfilter.c -o ccfilter -You can then copy ccfilter to its target destination (i.e: /usr/local/bin). -The man page ccfilter.1 has to be copied to somewhere in your MANPATH, -under a man1 directory (i.e: /usr/local/man/man1). - - -SUPPORTED COMPILERS/PORTING NOTES: -================================== - -The supported formats for the different compilers are described below: -In this section, meta-names are used as place-holders in the line -formats: <FILE> <ROW> <COL> <SEVERITY> <REASON> <> -The <> denotes ignored text. -Line formats are delimited by the ^ (caret) symbol. - -0) Special case: "gmake directory change" lines: - Lines with a format like: - ^gmake[<NUM>]: Entering directory `<DIR>'^ - are used to follow the directory changes during the make process, - providing in the <FILE> part, a relative (if possible) directory - path to the erroneous file. - - -1) GCC: - Recognized lines are of the format: - - ^In file included from <FILE>:<ROW>:^ - Line following this one is used as <REASON> - <SEVERITY> is always 'e' (error) - <COL> is always '0' - - - ^<FILE>:<ROW>:<REASON>^ - <SEVERITY> is always 'e' (error) - <COL> is always '0' - - -2) AIX: - Recognized lines are of the format: - - ^"<FILE>", line <ROW>.<COL>: <> (<SEVERITY>) <REASON>", - - -3) HPUX: - Recognized lines are of the format: - - ^cc: "<FILE>", line <ROW>: <SEVERITY>: <REASON>^ - <COL> is always '0' - - -4) SOLARIS: - Recognized lines are of the format: - - ^"<FILE>", line <ROW>: warning: <REASON>^ - This assumes <SEVERITY> is "W" - <COL> is always '0' - - - ^"<FILE>", line <ROW>: <REASON>^ - This assumes <SEVERITY> is "E" - <COL> is always '0' - - -5) ATT / NCR: - Recognized lines are of the format: - - ^<SEVERITY> "<FILE>",L<ROW>/C<COL><>:<REASON>^ - or - - ^<SEVERITY> "<FILE>",L<ROW>/C<COL>:<REASON>^ - Following lines beginning with a pipe (|) are continuation - lines, and are therefore appended to the <REASON> - - - ^<SEVERITY> "<FILE>",L<ROW>:<REASON>^ - <COL> is '0' - Following lines beginning with a pipe (|) are continuation - lines, and are therefore appended to the <REASON> - - -6) SGI-IRIX: - Recognized lines are of the format: - - ^cfe: <SEVERITY>: <FILE>: <ROW>: <REASON>^ - or - ^cfe: <SEVERITY>: <FILE>, line <ROW>: <REASON>^ - Following lines beginning with a dash (-) are "column-bar" - that end with a caret in the column of the error. These lines - are analyzed to generate the <COL>. diff --git a/runtime/tools/efm_filter.pl b/runtime/tools/efm_filter.pl deleted file mode 100755 index 1d1a4f303b..0000000000 --- a/runtime/tools/efm_filter.pl +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env perl -# -# This program works as a filter that reads from stdin, copies to -# stdout *and* creates an error file that can be read by vim. -# -# This program has only been tested on SGI, Irix5.3. -# -# Written by Ives Aerts in 1996. This little program is not guaranteed -# to do (or not do) anything at all and can be freely used for -# whatever purpose you can think of. - -$args = @ARGV; - -unless ($args == 1) { - die("Usage: vimccparse <output filename>\n"); -} - -$filename = @ARGV[0]; -open (OUT, ">$filename") || die ("Can't open file: \"$filename\""); - -while (<STDIN>) { - print; - if ( (/"(.*)", line (\d+): (e)rror\((\d+)\):/) - || (/"(.*)", line (\d+): (w)arning\((\d+)\):/) ) { - $file=$1; - $line=$2; - $errortype="\u$3"; - $errornr=$4; - chop($errormsg=<STDIN>); - $errormsg =~ s/^\s*//; - $sourceline=<STDIN>; - $column=index(<STDIN>, "^") - 1; - - print OUT "$file>$line:$column:$errortype:$errornr:$errormsg\n"; - } -} - -close(OUT); -exit(0); diff --git a/runtime/tools/efm_filter.txt b/runtime/tools/efm_filter.txt deleted file mode 100644 index d3f97f45ad..0000000000 --- a/runtime/tools/efm_filter.txt +++ /dev/null @@ -1,31 +0,0 @@ -[adopted from a message that Ives posted in the Vim mailing list] - -Some compilers produce an error message that cannot be handled with -'errorformat' in Vim. Following is an example of a Perl script that -translates one error message into something that Vim understands. - - -The compiler that generates this kind of error messages (4 lines): - -"/tmp_mnt/cm/src/apertos/MoU/MetaCore/MetaCore/common/src/MetaCoreImp_M.cc", -line 50: error(3114): - identifier "PRIMITIVE_M" is undefined - return(ExecuteCore(PRIMITIVE_M, - -You can find a small perl program at the end. -The way I use it is: - -:set errorformat=%f>%l:%c:%t:%n:%m -:set makeprg=clearmake\ -C\ gnu -:set shellpipe=2>&1\|\ vimccparse - -If somebody thinks this is useful: feel free to do whatever you can think -of with this code. - --Ives -____________________________________________________________ -Ives Aerts (SW Developer) Sony Telecom Europe -ives@sonytel.be St.Stevens Woluwestr. 55 -`Death could create most things, B-1130 Brussels, Belgium - except for plumbing.' PHONE : +32 2 724 19 67 - (Soul Music - T.Pratchett) FAX : +32 2 726 26 86 diff --git a/runtime/tools/efm_perl.pl b/runtime/tools/efm_perl.pl deleted file mode 100755 index 1aab2d4ea0..0000000000 --- a/runtime/tools/efm_perl.pl +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/perl -w - -# vimparse.pl - Reformats the error messages of the Perl interpreter for use -# with the quickfix mode of Vim -# -# Copyright (c) 2001 by Joerg Ziefle <joerg.ziefle@gmx.de> -# You may use and distribute this software under the same terms as Perl itself. -# -# Usage: put one of the two configurations below in your ~/.vimrc (without the -# description and '# ') and enjoy (be sure to adjust the paths to vimparse.pl -# before): -# -# Program is run interactively with 'perl -w': -# -# set makeprg=$HOME/bin/vimparse.pl\ %\ $* -# set errorformat=%f:%l:%m -# -# Program is only compiled with 'perl -wc': -# -# set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $* -# set errorformat=%f:%l:%m -# -# Usage: -# vimparse.pl [-c] [-f <errorfile>] <programfile> [programargs] -# -# -c compile only, don't run (perl -wc) -# -f write errors to <errorfile> -# -# Example usages: -# * From the command line: -# vimparse.pl program.pl -# -# vimparse.pl -c -f errorfile program.pl -# Then run vim -q errorfile to edit the errors with Vim. -# -# * From Vim: -# Edit in Vim (and save, if you don't have autowrite on), then -# type ':mak' or ':mak args' (args being the program arguments) -# to error check. -# -# Version history: -# 0.2 (04/12/2001): -# * First public version (sent to Bram) -# * -c command line option for compiling only -# * grammatical fix: 'There was 1 error.' -# * bug fix for multiple arguments -# * more error checks -# * documentation (top of file, &usage) -# * minor code clean ups -# 0.1 (02/02/2001): -# * Initial version -# * Basic functionality -# -# Todo: -# * test on more systems -# * use portable way to determine the location of perl ('use Config') -# * include option that shows perldiag messages for each error -# * allow to pass in program by STDIN -# * more intuitive behaviour if no error is found (show message) -# -# Tested under SunOS 5.7 with Perl 5.6.0. Let me know if it's not working for -# you. - -use strict; -use Getopt::Std; - -use vars qw/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars' - -use constant VERSION => 0.2; - -getopts('cf:h'); - -&usage if $opt_h; # not necessarily needed, but good for further extension - -if (defined $opt_f) { - - open FILE, "> $opt_f" or do { - warn "Couldn't open $opt_f: $!. Using STDOUT instead.\n"; - undef $opt_f; - }; - -}; - -my $handle = (defined $opt_f ? \*FILE : \*STDOUT); - -(my $file = shift) or &usage; # display usage if no filename is supplied -my $args = (@ARGV ? ' ' . join ' ', @ARGV : ''); - -my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`; - -my $errors = 0; -foreach my $line (@lines) { - - chomp($line); - my ($file, $lineno, $message, $rest); - - if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) { - - ($message, $file, $lineno, $rest) = ($1, $2, $3, $4); - $errors++; - $message .= $rest if ($rest =~ s/^,//); - print $handle "$file:$lineno:$message\n"; - - } else { next }; - -} - -if (defined $opt_f) { - - my $msg; - if ($errors == 1) { - - $msg = "There was 1 error.\n"; - - } else { - - $msg = "There were $errors errors.\n"; - - }; - - print STDOUT $msg; - close FILE; - unlink $opt_f unless $errors; - -}; - -sub usage { - - (local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program - print<<EOT; -Usage: - $0 [-c] [-f <errorfile>] <programfile> [programargs] - - -c compile only, don't run (executes 'perl -wc') - -f write errors to <errorfile> - -Examples: - * At the command line: - $0 program.pl - Displays output on STDOUT. - - $0 -c -f errorfile program.pl - Then run 'vim -q errorfile' to edit the errors with Vim. - - * In Vim: - Edit in Vim (and save, if you don't have autowrite on), then - type ':mak' or ':mak args' (args being the program arguments) - to error check. -EOT - - exit 0; - -}; diff --git a/runtime/tools/mve.awk b/runtime/tools/mve.awk deleted file mode 100755 index 396f80677c..0000000000 --- a/runtime/tools/mve.awk +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/nawk -f -# -# Change "nawk" to "awk" or "gawk" if you get errors. -# -# Make Vim Errors -# Processes errors from cc for use by Vim's quick fix tools -# specifically it translates the ---------^ notation to a -# column number -# -BEGIN { FS="[:,]" } - -/^cfe/ { file=$3 - msg=$5 - split($4,s," ") - line=s[2] -} - -# You may have to substitute a tab character for the \t here: -/^[\t-]*\^/ { - p=match($0, ".*\\^" ) - col=RLENGTH-2 - printf("%s, line %d, col %d : %s\n", file,line,col,msg) -} diff --git a/runtime/tools/mve.txt b/runtime/tools/mve.txt deleted file mode 100644 index 8aa5cf66bf..0000000000 --- a/runtime/tools/mve.txt +++ /dev/null @@ -1,20 +0,0 @@ -[ The mve awk script was posted on the vimdev mailing list ] - -From: jimmer@barney.mdhc.mdc.com (J. McGlasson) -Date: Mon, 31 Mar 1997 13:16:49 -0700 (Mar) - -My compiler (SGI MIPSpro C compiler - IRIX 6.4) works like this. -I have written a script mve (make vim errors), through which I pipe my make -output, which translates output of the following form: - -cfe: Error: syntax.c, line 4: Syntax Error - int i[12; - ------------^ - -into: - - cl.c, line 4, col 12 : Syntax Error - -(in vim notation: %f, line %l, col %c : %m) - -You might be able to tailor this for your compiler's output. diff --git a/runtime/tools/pltags.pl b/runtime/tools/pltags.pl deleted file mode 100755 index 7a74682b87..0000000000 --- a/runtime/tools/pltags.pl +++ /dev/null @@ -1,300 +0,0 @@ -#!/usr/bin/env perl - -# pltags - create a tags file for Perl code, for use by vi(m) -# -# Distributed with Vim <http://www.vim.org/>, latest version always available -# at <http://www.mscha.com/mscha.html?pltags#tools> -# -# Version 2.3, 28 February 2002 -# -# Written by Michael Schaap <pltags@mscha.com>. Suggestions for improvement -# are very welcome! -# -# This script will not work with Perl 4 or below! -# -# Revision history: -# 1.0 1997? Original version, quickly hacked together -# 2.0 1999? Completely rewritten, better structured and documented, -# support for variables, packages, Exuberant Ctags extensions -# 2.1 Jun 2000 Fixed critical bug (typo in comment) ;-) -# Support multiple level packages (e.g. Archive::Zip::Member) -# 2.2 Jul 2001 'Glob' wildcards - especially useful under Windows -# (thanks to Serge Sivkov and Jason King) -# Bug fix: reset package name for each file -# 2.21 Jul 2001 Oops... bug in variable detection (/local../ -> /^local.../) -# 2.3 Feb 2002 Support variables declared with "our" -# (thanks to Lutz Mende) - -# Complain about undeclared variables -use strict; - -# Used modules -use Getopt::Long; - -# Options with their defaults -my $do_subs = 1; # --subs, --nosubs include subs in tags file? -my $do_vars = 1; # --vars, --novars include variables in tags file? -my $do_pkgs = 1; # --pkgs, --nopkgs include packages in tags file? -my $do_exts = 1; # --extensions, --noextensions - # include Exuberant Ctags extensions - -# Global variables -my $VERSION = "2.21"; # pltags version -my $status = 0; # GetOptions return value -my $file = ""; # File being processed -my @tags = (); # List of produced tags -my $is_pkg = 0; # Are we tagging a package? -my $has_subs = 0; # Has this file any subs yet? -my $package_name = ""; # Name of current package -my $var_continues = 0; # Variable declaration continues on last line -my $line = ""; # Current line in file -my $stmt = ""; # Current Perl statement -my @vars = (); # List of variables in declaration -my $var = ""; # Variable in declaration -my $tagline = ""; # Tag file line - -# Create a tag file line and push it on the list of found tags -sub MakeTag($$$$$) -{ - my ($tag, # Tag name - $type, # Type of tag - $is_static, # Is this a static tag? - $file, # File in which tag appears - $line) = @_; # Line in which tag appears - - my $tagline = ""; # Created tag line - - # Only process tag if not empty - if ($tag) - { - # Get rid of \n, and escape / and \ in line - chomp $line; - $line =~ s/\\/\\\\/g; - $line =~ s/\//\\\//g; - - # Create a tag line - $tagline = "$tag\t$file\t/^$line\$/"; - - # If we're told to do so, add extensions - if ($do_exts) - { - $tagline .= ";\"\t$type" - . ($is_static ? "\tfile:" : "") - . ($package_name ? "\tclass:$package_name" : ""); - } - - # Push it on the stack - push (@tags, $tagline); - } -} - -# Parse package name from statement -sub PackageName($) -{ - my ($stmt) = @_; # Statement - - # Look for the argument to "package". Return it if found, else return "" - if ($stmt =~ /^package\s+([\w:]+)/) - { - my $pkgname = $1; - - # Remove any parent package name(s) - $pkgname =~ s/.*://; - return $pkgname; - } - else - { - return ""; - } -} - -# Parse sub name from statement -sub SubName($) -{ - my ($stmt) = @_; # Statement - - # Look for the argument to "sub". Return it if found, else return "" - if ($stmt =~ /^sub\s+([\w:]+)/) - { - my $subname = $1; - - # Remove any parent package name(s) - $subname =~ s/.*://; - return $subname; - } - else - { - return ""; - } -} - -# Parse all variable names from statement -sub VarNames($) -{ - my ($stmt) = @_; - - # Remove my or local from statement, if present - $stmt =~ s/^(my|our|local)\s+//; - - # Remove any assignment piece - $stmt =~ s/\s*=.*//; - - # Now find all variable names, i.e. "words" preceded by $, @ or % - @vars = ($stmt =~ /[\$\@\%]([\w:]+)\b/g); - - # Remove any parent package name(s) - map(s/.*://, @vars); - - return (@vars); -} - -############### Start ############### - -print "\npltags $VERSION by Michael Schaap <mscha\@mscha.com>\n\n"; - -# Get options -$status = GetOptions("subs!" => \$do_subs, - "vars!" => \$do_vars, - "pkgs!" => \$do_pkgs, - "extensions!" => \$do_exts); - -# Usage if error in options or no arguments given -unless ($status && @ARGV) -{ - print "\n" unless ($status); - print " Usage: $0 [options] filename ...\n\n"; - print " Where options can be:\n"; - print " --subs (--nosubs) (don't) include sub declarations in tag file\n"; - print " --vars (--novars) (don't) include variable declarations in tag file\n"; - print " --pkgs (--nopkgs) (don't) include package declarations in tag file\n"; - print " --extensions (--noextensions)\n"; - print " (don't) include Exuberant Ctags / Vim style\n"; - print " extensions in tag file\n\n"; - print " Default options: "; - print ($do_subs ? "--subs " : "--nosubs "); - print ($do_vars ? "--vars " : "--novars "); - print ($do_pkgs ? "--pkgs " : "--nopkgs "); - print ($do_exts ? "--extensions\n\n" : "--noextensions\n\n"); - print " Example: $0 *.pl *.pm ../shared/*.pm\n\n"; - exit; -} - -# Loop through files on command line - 'glob' any wildcards, since Windows -# doesn't do this for us -foreach $file (map { glob } @ARGV) -{ - # Skip if this is not a file we can open. Also skip tags files and backup - # files - next unless ((-f $file) && (-r $file) && ($file !~ /tags$/) - && ($file !~ /~$/)); - - print "Tagging file $file...\n"; - - $is_pkg = 0; - $package_name = ""; - $has_subs = 0; - $var_continues = 0; - - open (IN, $file) or die "Can't open file '$file': $!"; - - # Loop through file - foreach $line (<IN>) - { - # Statement is line with comments and whitespace trimmed - ($stmt = $line) =~ s/#.*//; - $stmt =~ s/^\s*//; - $stmt =~ s/\s*$//; - - # Nothing left? Never mind. - next unless ($stmt); - - # This is a variable declaration if one was started on the previous - # line, or if this line starts with my or local - if ($var_continues or ($stmt =~/^my\b/) - or ($stmt =~/^our\b/) or ($stmt =~/^local\b/)) - { - # The declaration continues if the line does not end with ; - $var_continues = ($stmt !~ /;$/); - - # Loop through all variable names in the declaration - foreach $var (VarNames($stmt)) - { - # Make a tag for this variable unless we're told not to. We - # assume that a variable is always static, unless it appears - # in a package before any sub. (Not necessarily true, but - # it's ok for most purposes and Vim works fine even if it is - # incorrect) - if ($do_vars) - { - MakeTag($var, "v", (!$is_pkg or $has_subs), $file, $line); - } - } - } - - # This is a package declaration if the line starts with package - elsif ($stmt =~/^package\b/) - { - # Get name of the package - $package_name = PackageName($stmt); - - if ($package_name) - { - # Remember that we're doing a package - $is_pkg = 1; - - # Make a tag for this package unless we're told not to. A - # package is never static. - if ($do_pkgs) - { - MakeTag($package_name, "p", 0, $file, $line); - } - } - } - - # This is a sub declaration if the line starts with sub - elsif ($stmt =~/^sub\b/) - { - # Remember that this file has subs - $has_subs = 1; - - # Make a tag for this sub unless we're told not to. We assume - # that a sub is static, unless it appears in a package. (Not - # necessarily true, but it's ok for most purposes and Vim works - # fine even if it is incorrect) - if ($do_subs) - { - MakeTag(SubName($stmt), "s", (!$is_pkg), $file, $line); - } - } - } - close (IN); -} - -# Do we have any tags? If so, write them to the tags file -if (@tags) -{ - # Add some tag file extensions if we're told to - if ($do_exts) - { - push (@tags, "!_TAG_FILE_FORMAT\t2\t/extended format/"); - push (@tags, "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted/"); - push (@tags, "!_TAG_PROGRAM_AUTHOR\tMichael Schaap\t/mscha\@mscha.com/"); - push (@tags, "!_TAG_PROGRAM_NAME\tpltags\t//"); - push (@tags, "!_TAG_PROGRAM_VERSION\t$VERSION\t/supports multiple tags and extended format/"); - } - - print "\nWriting tags file.\n"; - - open (OUT, ">tags") or die "Can't open tags file: $!"; - - foreach $tagline (sort @tags) - { - print OUT "$tagline\n"; - } - - close (OUT); -} -else -{ - print "\nNo tags found.\n"; -} diff --git a/runtime/tools/ref b/runtime/tools/ref deleted file mode 100755 index 77bfc805e2..0000000000 --- a/runtime/tools/ref +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# -# ref - Check spelling of the arguments -# -# Usage: ref word .. -# -# can be used for the K command of Vim -# -spell <<EOF -$* -EOF diff --git a/runtime/tools/shtags.1 b/runtime/tools/shtags.1 deleted file mode 100644 index 314df883c7..0000000000 --- a/runtime/tools/shtags.1 +++ /dev/null @@ -1,61 +0,0 @@ -.TH shtags 1 "local Utilities" -.SH NAME -shtags \- Create tags for shell scripts -.SH SYNOPSIS -.B shtags -[\fI-mvw\fP] [\fI-t <file>\fP] [\fI-s <shell>\fP] <files> -.SH DESCRIPTION -\fBshtags\fP creates a \fBvi(1)\fP tags file for shell scripts - which -essentially turns your code into a hypertext document. \fBshtags\fP -attempts to create tags for all function and variable definitions, -although this is a little difficult, because in most shell languages, -variables don't need to be explicitly defined, and as such there is -often no distinct "variable definition". If this is the case, -\fBshtags\fP simply creates a tag for the first instance of a variable -which is being set in a simple way, ie: \fIset x = 5\fP. -.SH OPTIONS -.IP "\fB-t <file>\fP" -Name of tags file to create. (default is 'tags') -.IP "\fB-s <shell>\fP" -The name of the shell used by the script(s). By default, -\fBshtags\fP tries to work out which is the appropriate shell for each -file individually by looking at the first line of each file. This wont -work however, if the script starts as a bourne shell script and tries -to be clever about starting the shell it really wants. -.b -Currently supported shells are: -.RS -.IP \fBsh\fP -Bourne Shell -.IP \fBperl\fP -Perl (versions 4 and 5) -.IP \fBksh\fP -Korn Shell -.IP \fBtclsh\fP -The TCL shell -.IP \fBwish\fP -The TK Windowing shell (same as tclsh) -.RE - -.IP \fB-v\fP -Include variable definitions (variables mentioned at the start of a line) -.IP \fB-V\fP -Print version information. -.IP \fB-w\fP -Suppress "duplicate tag" warning messages. -.IP \fB-x\fP -Explicitly create a new tags file. Normally new tags are merged with -the old tags file. -.PP -\fBshtags\fP scans the specified files for subroutines and possibly -variable definitions, and creates a \fBvi\fP style tags file. -.SH FILES -.IP \fBtags\fP -A tags file contains a sorted list of tags, one tag per line. The -format is the same as that used by \fBvi\fP(1) -.SH AUTHOR -Stephen Riehm -.br -sr@pc-plus.de -.SH "SEE ALSO" -ctags(1), etags(1), perl(1), tclsh(1), wish(1), sh(1), ksh(1). diff --git a/runtime/tools/shtags.pl b/runtime/tools/shtags.pl deleted file mode 100755 index 48dcdc7476..0000000000 --- a/runtime/tools/shtags.pl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env perl -# -# shtags: create a tags file for perl scripts -# -# Author: Stephen Riehm -# Last Changed: 96/11/27 19:46:06 -# -# "@(#) shtags 1.1 by S. Riehm" -# - -# obvious... :-) -sub usage - { - print <<_EOUSAGE_ ; -USAGE: $program [-kvwVx] [-t <file>] <files> - -t <file> Name of tags file to create. (default is 'tags') - -s <shell> Name of the shell language in the script - -v Include variable definitions. - (variables mentioned at the start of a line) - -V Print version information. - -w Suppress "duplicate tag" warnings. - -x Explicitly create a new tags file. Normally tags are merged. - <files> List of files to scan for tags. -_EOUSAGE_ - exit 0 - } - -sub version -{ - # - # Version information - # - @id = split( ', ', 'scripts/bin/shtags, /usr/local/, LOCAL_SCRIPTS, 1.1, 96/11/27, 19:46:06' ); - $id[0] =~ s,.*/,,; - print <<_EOVERS; -$id[0]: $id[3] -Last Modified: @id[4,5] -Component: $id[1] -Release: $id[2] -_EOVERS - exit( 1 ); -} - -# -# initialisations -# -($program = $0) =~ s,.*/,,; -require 'getopts.pl'; - -# -# parse command line -# -&Getopts( "t:s:vVwx" ) || &usage(); -$tags_file = $opt_t || 'tags'; -$explicit = $opt_x; -$variable_tags = $opt_v; -$allow_warnings = ! $opt_w; -&version if $opt_V; -&usage() unless @ARGV != 0; - -# slurp up the existing tags. Some will be replaced, the ones that aren't -# will be re-written exactly as they were read -if( ! $explicit && open( TAGS, "< $tags_file" ) ) - { - while( <TAGS> ) - { - /^\S+/; - $tags{$&} = $_; - } - close( TAGS ); - } - -# -# for each line of every file listed on the command line, look for a -# 'sub' definition, or, if variables are wanted aswell, look for a -# variable definition at the start of a line -# -while( <> ) - { - &check_shell($_), ( $old_file = $ARGV ) if $ARGV ne $old_file; - next unless $shell; - if( $shell eq "sh" ) - { - next unless /^\s*(((\w+)))\s*\(\s*\)/ - || ( $variable_tags && /^(((\w+)=))/ ); - $match = $3; - } - if( $shell eq "ksh" ) - { - # ksh - next unless /^\s*function\s+(((\w+)))/ - || ( $variable_tags && /^(((\w+)=))/ ); - $match = $3; - } - if( $shell eq "perl" ) - { - # perl - next unless /^\s*sub\s+(\w+('|::))?(\w+)/ - || /^\s*(((\w+))):/ - || ( $variable_tags && /^(([(\s]*[\$\@\%]{1}(\w+).*=))/ ); - $match = $3; - } - if( $shell eq "tcl" ) - { - next unless /^\s*proc\s+(((\S+)))/ - || ( $variable_tags && /^\s*set\s+(((\w+)\s))/ ); - $match = $3; - } - chop; - warn "$match - duplicate ignored\n" - if ( $new{$match}++ - || !( $tags{$match} = sprintf( "%s\t%s\t?^%s\$?\n", $match, $ARGV, $_ ) ) ) - && $allow_warnings; - } - -# write the new tags to the tags file - note that the whole file is rewritten -open( TAGS, "> $tags_file" ); -foreach( sort( keys %tags ) ) - { - print TAGS "$tags{$_}"; - } -close( TAGS ); - -sub check_shell - { - local( $_ ) = @_; - # read the first line of a script, and work out which shell it is, - # unless a shell was specified on the command line - # - # This routine can't handle clever scripts which start sh and then - # use sh to start the shell they really wanted. - if( $opt_s ) - { - $shell = $opt_s; - } - else - { - $shell = "sh" if /^:$/ || /^#!.*\/bin\/sh/; - $shell = "ksh" if /^#!.*\/ksh/; - $shell = "perl" if /^#!.*\/perl/; - $shell = "tcl" if /^#!.*\/wish/; - printf "Using $shell for $ARGV\n"; - } - } diff --git a/runtime/tools/unicode.vim b/runtime/tools/unicode.vim deleted file mode 100644 index f3c58ed35a..0000000000 --- a/runtime/tools/unicode.vim +++ /dev/null @@ -1,290 +0,0 @@ -" Script to extract tables from Unicode .txt files, to be used in src/mbyte.c. -" The format of the UnicodeData.txt file is explained here: -" http://www.unicode.org/Public/5.1.0/ucd/UCD.html -" For the other files see the header. -" -" Usage: Vim -S <this-file> -" -" Author: Bram Moolenaar -" Last Update: 2010 Jan 12 - -" Parse lines of UnicodeData.txt. Creates a list of lists in s:dataprops. -func! ParseDataToProps() - let s:dataprops = [] - let lnum = 1 - while lnum <= line('$') - let l = split(getline(lnum), '\s*;\s*', 1) - if len(l) != 15 - echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 15' - return - endif - call add(s:dataprops, l) - let lnum += 1 - endwhile -endfunc - -" Parse lines of CaseFolding.txt. Creates a list of lists in s:foldprops. -func! ParseFoldProps() - let s:foldprops = [] - let lnum = 1 - while lnum <= line('$') - let line = getline(lnum) - if line !~ '^#' && line !~ '^\s*$' - let l = split(line, '\s*;\s*', 1) - if len(l) != 4 - echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 4' - return - endif - call add(s:foldprops, l) - endif - let lnum += 1 - endwhile -endfunc - -" Parse lines of EastAsianWidth.txt. Creates a list of lists in s:widthprops. -func! ParseWidthProps() - let s:widthprops = [] - let lnum = 1 - while lnum <= line('$') - let line = getline(lnum) - if line !~ '^#' && line !~ '^\s*$' - let l = split(line, '\s*;\s*', 1) - if len(l) != 2 - echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 2' - return - endif - call add(s:widthprops, l) - endif - let lnum += 1 - endwhile -endfunc - -" Build the toLower or toUpper table in a new buffer. -" Uses s:dataprops. -func! BuildCaseTable(name, index) - let start = -1 - let end = -1 - let step = 0 - let add = -1 - let ranges = [] - for p in s:dataprops - if p[a:index] != '' - let n = ('0x' . p[0]) + 0 - let nl = ('0x' . p[a:index]) + 0 - if start >= 0 && add == nl - n && (step == 0 || n - end == step) - " continue with same range. - let step = n - end - let end = n - else - if start >= 0 - " produce previous range - call Range(ranges, start, end, step, add) - endif - let start = n - let end = n - let step = 0 - let add = nl - n - endif - endif - endfor - if start >= 0 - call Range(ranges, start, end, step, add) - endif - - " New buffer to put the result in. - new - exe "file to" . a:name - call setline(1, "static convertStruct to" . a:name . "[] =") - call setline(2, "{") - call append('$', ranges) - call setline('$', getline('$')[:-2]) " remove last comma - call setline(line('$') + 1, "};") - wincmd p -endfunc - -" Build the foldCase table in a new buffer. -" Uses s:foldprops. -func! BuildFoldTable() - let start = -1 - let end = -1 - let step = 0 - let add = -1 - let ranges = [] - for p in s:foldprops - if p[1] == 'C' || p[1] == 'S' - let n = ('0x' . p[0]) + 0 - let nl = ('0x' . p[2]) + 0 - if start >= 0 && add == nl - n && (step == 0 || n - end == step) - " continue with same range. - let step = n - end - let end = n - else - if start >= 0 - " produce previous range - call Range(ranges, start, end, step, add) - endif - let start = n - let end = n - let step = 0 - let add = nl - n - endif - endif - endfor - if start >= 0 - call Range(ranges, start, end, step, add) - endif - - " New buffer to put the result in. - new - file foldCase - call setline(1, "static convertStruct foldCase[] =") - call setline(2, "{") - call append('$', ranges) - call setline('$', getline('$')[:-2]) " remove last comma - call setline(line('$') + 1, "};") - wincmd p -endfunc - -func! Range(ranges, start, end, step, add) - let s = printf("\t{0x%x,0x%x,%d,%d},", a:start, a:end, a:step == 0 ? -1 : a:step, a:add) - call add(a:ranges, s) -endfunc - -" Build the combining table. -" Uses s:dataprops. -func! BuildCombiningTable() - let start = -1 - let end = -1 - let ranges = [] - for p in s:dataprops - if p[2] == 'Mn' || p[2] == 'Mc' || p[2] == 'Me' - let n = ('0x' . p[0]) + 0 - if start >= 0 && end + 1 == n - " continue with same range. - let end = n - else - if start >= 0 - " produce previous range - call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) - endif - let start = n - let end = n - endif - endif - endfor - if start >= 0 - call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) - endif - - " New buffer to put the result in. - new - file combining - call setline(1, " static struct interval combining[] =") - call setline(2, " {") - call append('$', ranges) - call setline('$', getline('$')[:-2]) " remove last comma - call setline(line('$') + 1, " };") - wincmd p -endfunc - -" Build the double width or ambiguous width table in a new buffer. -" Uses s:widthprops and s:dataprops. -func! BuildWidthTable(pattern, tableName) - let start = -1 - let end = -1 - let ranges = [] - let dataidx = 0 - for p in s:widthprops - if p[1][0] =~ a:pattern - if p[0] =~ '\.\.' - " It is a range. we don't check for composing char then. - let rng = split(p[0], '\.\.') - if len(rng) != 2 - echoerr "Cannot parse range: '" . p[0] . "' in width table" - endif - let n = ('0x' . rng[0]) + 0 - let n_last = ('0x' . rng[1]) + 0 - else - let n = ('0x' . p[0]) + 0 - let n_last = n - endif - " Find this char in the data table. - while 1 - let dn = ('0x' . s:dataprops[dataidx][0]) + 0 - if dn >= n - break - endif - let dataidx += 1 - endwhile - if dn != n && n_last == n - echoerr "Cannot find character " . n . " in data table" - endif - " Only use the char when it's not a composing char. - " But use all chars from a range. - let dp = s:dataprops[dataidx] - if n_last > n || (dp[2] != 'Mn' && dp[2] != 'Mc' && dp[2] != 'Me') - if start >= 0 && end + 1 == n - " continue with same range. - else - if start >= 0 - " produce previous range - call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) - endif - let start = n - endif - let end = n_last - endif - endif - endfor - if start >= 0 - call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) - endif - - " New buffer to put the result in. - new - exe "file " . a:tableName - call setline(1, " static struct interval " . a:tableName . "[] =") - call setline(2, " {") - call append('$', ranges) - call setline('$', getline('$')[:-2]) " remove last comma - call setline(line('$') + 1, " };") - wincmd p -endfunc - - - -" Edit the Unicode text file. Requires the netrw plugin. -edit http://unicode.org/Public/UNIDATA/UnicodeData.txt - -" Parse each line, create a list of lists. -call ParseDataToProps() - -" Build the toLower table. -call BuildCaseTable("Lower", 13) - -" Build the toUpper table. -call BuildCaseTable("Upper", 12) - -" Build the ranges of composing chars. -call BuildCombiningTable() - -" Edit the case folding text file. Requires the netrw plugin. -edit http://www.unicode.org/Public/UNIDATA/CaseFolding.txt - -" Parse each line, create a list of lists. -call ParseFoldProps() - -" Build the foldCase table. -call BuildFoldTable() - -" Edit the width text file. Requires the netrw plugin. -edit http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt - -" Parse each line, create a list of lists. -call ParseWidthProps() - -" Build the double width table. -call BuildWidthTable('[WF]', 'doublewidth') - -" Build the ambiguous width table. -call BuildWidthTable('A', 'ambiguous') diff --git a/runtime/tools/vim132 b/runtime/tools/vim132 deleted file mode 100755 index 29ea4ce1ff..0000000000 --- a/runtime/tools/vim132 +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/csh -# -# Shell script for use with UNIX -# Starts up Vim with the terminal in 132 column mode -# Only works on VT-100 terminals and lookalikes -# You need to have a termcap entry "vt100-w". Same as vt100 but 132 columns. -# -set oldterm=$term -echo "[?3h" -setenv TERM vt100-w -vim $* -set term=$oldterm -echo "[?3l" diff --git a/runtime/tools/vim_vs_net.cmd b/runtime/tools/vim_vs_net.cmd deleted file mode 100644 index bea6353f67..0000000000 --- a/runtime/tools/vim_vs_net.cmd +++ /dev/null @@ -1,24 +0,0 @@ -@rem -@rem To use this with Visual Studio .Net -@rem Tools->External Tools... -@rem Add -@rem Title - Vim -@rem Command - d:\files\util\vim_vs_net.cmd -@rem Arguments - +$(CurLine) $(ItemPath) -@rem Init Dir - Empty -@rem -@rem Courtesy of Brian Sturk -@rem -@rem --remote-silent +%1 is a command +954, move ahead 954 lines -@rem --remote-silent %2 full path to file -@rem In Vim -@rem :h --remote-silent for more details -@rem -@rem --servername VS_NET -@rem This will create a new instance of vim called VS_NET. So if you -open -@rem multiple files from VS, they will use the same instance of Vim. -@rem This allows you to have multiple copies of Vim running, but you can -@rem control which one has VS files in it. -@rem -start /b gvim.exe --servername VS_NET --remote-silent "%1" "%2" diff --git a/runtime/tools/vimm b/runtime/tools/vimm deleted file mode 100755 index 7b84cb255e..0000000000 --- a/runtime/tools/vimm +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# enable DEC locator input model on remote terminal -printf "\033[1;2'z\033[1;3'{\c" -vim "$@" -# disable DEC locator input model on remote terminal -printf "\033[2;4'{\033[0'z\c" diff --git a/runtime/tools/vimspell.sh b/runtime/tools/vimspell.sh deleted file mode 100755 index d336fe6c31..0000000000 --- a/runtime/tools/vimspell.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -# -# Spell a file & generate the syntax statements necessary to -# highlight in vim. Based on a program from Krishna Gadepalli -# <krishna@stdavids.picker.com>. -# -# I use the following mappings (in .vimrc): -# -# noremap <F8> :so `vimspell.sh %`<CR><CR> -# noremap <F7> :syntax clear SpellErrors<CR> -# -# Neil Schemenauer <nascheme@ucalgary.ca> -# March 1999 -# updated 2008 Jul 17 by Bram -# -# Safe method for the temp file by Javier Fernndez-Sanguino_Pea - -INFILE=$1 -tmp="${TMPDIR-/tmp}" -OUTFILE=`mktemp -t vimspellXXXXXX || tempfile -p vimspell || echo none` -# If the standard commands failed then create the file -# since we cannot create a directory (we cannot remove it on exit) -# create a file in the safest way possible. -if test "$OUTFILE" = none; then - OUTFILE=$tmp/vimspell$$ - [ -e $OUTFILE ] && { echo "Cannot use temporary file $OUTFILE, it already exists!"; exit 1 ; } - (umask 077; touch $OUTFILE) -fi -# Note the copy of vimspell cannot be deleted on exit since it is -# used by vim, otherwise it should do this: -# trap "rm -f $OUTFILE" 0 1 2 3 9 11 13 15 - - -# -# local spellings -# -LOCAL_DICT=${LOCAL_DICT-$HOME/local/lib/local_dict} - -if [ -f $LOCAL_DICT ] -then - SPELL_ARGS="+$LOCAL_DICT" -fi - -spell $SPELL_ARGS $INFILE | sort -u | -awk ' - { - printf "syntax match SpellErrors \"\\<%s\\>\"\n", $0 ; - } - -END { - printf "highlight link SpellErrors ErrorMsg\n\n" ; - } -' > $OUTFILE -echo "!rm $OUTFILE" >> $OUTFILE -echo $OUTFILE diff --git a/runtime/tools/vimspell.txt b/runtime/tools/vimspell.txt deleted file mode 100644 index 2842af7bd8..0000000000 --- a/runtime/tools/vimspell.txt +++ /dev/null @@ -1,22 +0,0 @@ -vimspell.sh -=========== - -This is a simple script to spell check a file and generate the syntax -statements necessary to highlight the errors in vim. It is based on a -similar program by Krishna Gadepalli <krishna@stdavids.picker.com>. - -To use this script, first place it in a directory in your path. Next, -you should add some convenient key mappings. I use the following (in -.vimrc): - - noremap <F8> :so `vimspell.sh %`<CR><CR> - noremap <F7> :syntax clear SpellErrors<CR> - -This program requires the old Unix "spell" command. On my Debian -system, "spell" is a wrapper around "ispell". For better security, -you should uncomment the line in the script that uses "tempfile" to -create a temporary file. As all systems don't have "tempfile" the -insecure "pid method" is used. - - - Neil Schemenauer <nascheme@ucalgary.ca> diff --git a/runtime/tools/xcmdsrv_client.c b/runtime/tools/xcmdsrv_client.c deleted file mode 100644 index a0e6211a1d..0000000000 --- a/runtime/tools/xcmdsrv_client.c +++ /dev/null @@ -1,584 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * X-Windows communication by Flemming Madsen - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - * - * Client for sending commands to an '+xcmdsrv' enabled vim. - * This is mostly a de-Vimified version of if_xcmdsrv.c in vim. - * See that file for a protocol specification. - * - * You can make a test program with a Makefile like: - * xcmdsrv_client: xcmdsrv_client.c - * cc -o $@ -g -DMAIN -I/usr/X11R6/include -L/usr/X11R6/lib $< -lX11 - * - */ - -#include <stdio.h> -#include <string.h> -#ifdef HAVE_SELECT -#include <sys/time.h> -#include <sys/types.h> -#include <unistd.h> -#else -#include <sys/poll.h> -#endif -#include <X11/Intrinsic.h> -#include <X11/Xatom.h> - -#define __ARGS(x) x - -/* Client API */ -char * sendToVim __ARGS((Display *dpy, char *name, char *cmd, int asKeys, int *code)); - -#ifdef MAIN -/* A sample program */ -main(int argc, char **argv) -{ - char *res; - int code; - - if (argc == 4) - { - if ((res = sendToVim(XOpenDisplay(NULL), argv[2], argv[3], - argv[1][0] != 'e', &code)) != NULL) - { - if (code) - printf("Error code returned: %d\n", code); - puts(res); - } - exit(0); - } - else - fprintf(stderr, "Usage: %s {k|e} <server> <command>", argv[0]); - - exit(1); -} -#endif - -/* - * Maximum size property that can be read at one time by - * this module: - */ - -#define MAX_PROP_WORDS 100000 - -/* - * Forward declarations for procedures defined later in this file: - */ - -static int x_error_check __ARGS((Display *dpy, XErrorEvent *error_event)); -static int AppendPropCarefully __ARGS((Display *display, - Window window, Atom property, char *value, int length)); -static Window LookupName __ARGS((Display *dpy, char *name, - int delete, char **loose)); -static int SendInit __ARGS((Display *dpy)); -static char *SendEventProc __ARGS((Display *dpy, XEvent *eventPtr, - int expect, int *code)); -static int IsSerialName __ARGS((char *name)); - -/* Private variables */ -static Atom registryProperty = None; -static Atom commProperty = None; -static Window commWindow = None; -static int got_x_error = FALSE; - - -/* - * sendToVim -- - * Send to an instance of Vim via the X display. - * - * Results: - * A string with the result or NULL. Caller must free if non-NULL - */ - - char * -sendToVim(dpy, name, cmd, asKeys, code) - Display *dpy; /* Where to send. */ - char *name; /* Where to send. */ - char *cmd; /* What to send. */ - int asKeys; /* Interpret as keystrokes or expr ? */ - int *code; /* Return code. 0 => OK */ -{ - Window w; - Atom *plist; - XErrorHandler old_handler; -#define STATIC_SPACE 500 - char *property, staticSpace[STATIC_SPACE]; - int length; - int res; - static int serial = 0; /* Running count of sent commands. - * Used to give each command a - * different serial number. */ - XEvent event; - XPropertyEvent *e = (XPropertyEvent *)&event; - time_t start; - char *result; - char *loosename = NULL; - - if (commProperty == None && dpy != NULL) - { - if (SendInit(dpy) < 0) - return NULL; - } - - /* - * Bind the server name to a communication window. - * - * Find any survivor with a serialno attached to the name if the - * original registrant of the wanted name is no longer present. - * - * Delete any lingering names from dead editors. - */ - - old_handler = XSetErrorHandler(x_error_check); - while (TRUE) - { - got_x_error = FALSE; - w = LookupName(dpy, name, 0, &loosename); - /* Check that the window is hot */ - if (w != None) - { - plist = XListProperties(dpy, w, &res); - XSync(dpy, False); - if (plist != NULL) - XFree(plist); - if (got_x_error) - { - LookupName(dpy, loosename ? loosename : name, - /*DELETE=*/TRUE, NULL); - continue; - } - } - break; - } - if (w == None) - { - fprintf(stderr, "no registered server named %s\n", name); - return NULL; - } - else if (loosename != NULL) - name = loosename; - - /* - * Send the command to target interpreter by appending it to the - * comm window in the communication window. - */ - - length = strlen(name) + strlen(cmd) + 10; - if (length <= STATIC_SPACE) - property = staticSpace; - else - property = (char *) malloc((unsigned) length); - - serial++; - sprintf(property, "%c%c%c-n %s%c-s %s", - 0, asKeys ? 'k' : 'c', 0, name, 0, cmd); - if (name == loosename) - free(loosename); - if (!asKeys) - { - /* Add a back reference to our comm window */ - sprintf(property + length, "%c-r %x %d", 0, (uint) commWindow, serial); - length += strlen(property + length + 1) + 1; - } - - res = AppendPropCarefully(dpy, w, commProperty, property, length + 1); - if (length > STATIC_SPACE) - free(property); - if (res < 0) - { - fprintf(stderr, "Failed to send command to the destination program\n"); - return NULL; - } - - if (asKeys) /* There is no answer for this - Keys are sent async */ - return NULL; - - - /* - * Enter a loop processing X events & pooling chars until we see the result - */ - -#define SEND_MSEC_POLL 50 - - time(&start); - while ((time((time_t *) 0) - start) < 60) - { - /* Look out for the answer */ -#ifndef HAVE_SELECT - struct pollfd fds; - - fds.fd = ConnectionNumber(dpy); - fds.events = POLLIN; - if (poll(&fds, 1, SEND_MSEC_POLL) < 0) - break; -#else - fd_set fds; - struct timeval tv; - - tv.tv_sec = 0; - tv.tv_usec = SEND_MSEC_POLL * 1000; - FD_ZERO(&fds); - FD_SET(ConnectionNumber(dpy), &fds); - if (select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &tv) < 0) - break; -#endif - while (XEventsQueued(dpy, QueuedAfterReading) > 0) - { - XNextEvent(dpy, &event); - if (event.type == PropertyNotify && e->window == commWindow) - if ((result = SendEventProc(dpy, &event, serial, code)) != NULL) - return result; - } - } - return NULL; -} - - -/* - * SendInit -- - * This procedure is called to initialize the - * communication channels for sending commands and - * receiving results. - */ - - static int -SendInit(dpy) - Display *dpy; -{ - XErrorHandler old_handler; - - /* - * Create the window used for communication, and set up an - * event handler for it. - */ - old_handler = XSetErrorHandler(x_error_check); - got_x_error = FALSE; - - commProperty = XInternAtom(dpy, "Comm", False); - /* Change this back to "InterpRegistry" to talk to tk processes */ - registryProperty = XInternAtom(dpy, "VimRegistry", False); - - if (commWindow == None) - { - commWindow = - XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), - getpid(), 0, 10, 10, 0, - WhitePixel(dpy, DefaultScreen(dpy)), - WhitePixel(dpy, DefaultScreen(dpy))); - XSelectInput(dpy, commWindow, PropertyChangeMask); - } - - XSync(dpy, False); - (void) XSetErrorHandler(old_handler); - - return got_x_error ? -1 : 0; -} - -/* - * LookupName -- - * Given an interpreter name, see if the name exists in - * the interpreter registry for a particular display. - * - * Results: - * If the given name is registered, return the ID of - * the window associated with the name. If the name - * isn't registered, then return 0. - */ - - static Window -LookupName(dpy, name, delete, loose) - Display *dpy; /* Display whose registry to check. */ - char *name; /* Name of an interpreter. */ - int delete; /* If non-zero, delete info about name. */ - char **loose; /* Do another search matching -999 if not found - Return result here if a match is found */ -{ - unsigned char *regProp, *entry; - unsigned char *p; - int result, actualFormat; - unsigned long numItems, bytesAfter; - Atom actualType; - Window returnValue; - - /* - * Read the registry property. - */ - - regProp = NULL; - result = XGetWindowProperty(dpy, RootWindow(dpy, 0), registryProperty, 0, - MAX_PROP_WORDS, False, XA_STRING, &actualType, - &actualFormat, &numItems, &bytesAfter, - ®Prop); - - if (actualType == None) - return 0; - - /* - * If the property is improperly formed, then delete it. - */ - - if ((result != Success) || (actualFormat != 8) || (actualType != XA_STRING)) - { - if (regProp != NULL) - XFree(regProp); - XDeleteProperty(dpy, RootWindow(dpy, 0), registryProperty); - return 0; - } - - /* - * Scan the property for the desired name. - */ - - returnValue = None; - entry = NULL; /* Not needed, but eliminates compiler warning. */ - for (p = regProp; (p - regProp) < numItems; ) - { - entry = p; - while ((*p != 0) && (!isspace(*p))) - p++; - if ((*p != 0) && (strcasecmp(name, p + 1) == 0)) - { - sscanf(entry, "%x", (uint*) &returnValue); - break; - } - while (*p != 0) - p++; - p++; - } - - if (loose != NULL && returnValue == None && !IsSerialName(name)) - { - for (p = regProp; (p - regProp) < numItems; ) - { - entry = p; - while ((*p != 0) && (!isspace(*p))) - p++; - if ((*p != 0) && IsSerialName(p + 1) - && (strncmp(name, p + 1, strlen(name)) == 0)) - { - sscanf(entry, "%x", (uint*) &returnValue); - *loose = strdup(p + 1); - break; - } - while (*p != 0) - p++; - p++; - } - } - - /* - * Delete the property, if that is desired (copy down the - * remainder of the registry property to overlay the deleted - * info, then rewrite the property). - */ - - if ((delete) && (returnValue != None)) - { - int count; - - while (*p != 0) - p++; - p++; - count = numItems - (p-regProp); - if (count > 0) - memcpy(entry, p, count); - XChangeProperty(dpy, RootWindow(dpy, 0), registryProperty, XA_STRING, - 8, PropModeReplace, regProp, - (int) (numItems - (p-entry))); - XSync(dpy, False); - } - - XFree(regProp); - return returnValue; -} - - static char * -SendEventProc(dpy, eventPtr, expected, code) - Display *dpy; - XEvent *eventPtr; /* Information about event. */ - int expected; /* The one were waiting for */ - int *code; /* Return code. 0 => OK */ -{ - unsigned char *propInfo; - unsigned char *p; - int result, actualFormat; - int retCode; - unsigned long numItems, bytesAfter; - Atom actualType; - - if ((eventPtr->xproperty.atom != commProperty) - || (eventPtr->xproperty.state != PropertyNewValue)) - { - return; - } - - /* - * Read the comm property and delete it. - */ - - propInfo = NULL; - result = XGetWindowProperty(dpy, commWindow, commProperty, 0, - MAX_PROP_WORDS, True, XA_STRING, &actualType, - &actualFormat, &numItems, &bytesAfter, - &propInfo); - - /* - * If the property doesn't exist or is improperly formed - * then ignore it. - */ - - if ((result != Success) || (actualType != XA_STRING) - || (actualFormat != 8)) - { - if (propInfo != NULL) - { - XFree(propInfo); - } - return; - } - - /* - * Several commands and results could arrive in the property at - * one time; each iteration through the outer loop handles a - * single command or result. - */ - - for (p = propInfo; (p - propInfo) < numItems; ) - { - /* - * Ignore leading NULs; each command or result starts with a - * NUL so that no matter how badly formed a preceding command - * is, we'll be able to tell that a new command/result is - * starting. - */ - - if (*p == 0) - { - p++; - continue; - } - - if ((*p == 'r') && (p[1] == 0)) - { - int serial, gotSerial; - char *res; - - /* - * This is a reply to some command that we sent out. Iterate - * over all of its options. Stop when we reach the end of the - * property or something that doesn't look like an option. - */ - - p += 2; - gotSerial = 0; - res = ""; - retCode = 0; - while (((p-propInfo) < numItems) && (*p == '-')) - { - switch (p[1]) - { - case 'r': - if (p[2] == ' ') - res = p + 3; - break; - case 's': - if (sscanf(p + 2, " %d", &serial) == 1) - gotSerial = 1; - break; - case 'c': - if (sscanf(p + 2, " %d", &retCode) != 1) - retCode = 0; - break; - } - while (*p != 0) - p++; - p++; - } - - if (!gotSerial) - continue; - - if (code != NULL) - *code = retCode; - return serial == expected ? strdup(res) : NULL; - } - else - { - /* - * Didn't recognize this thing. Just skip through the next - * null character and try again. - * Also, throw away commands that we cant process anyway. - */ - - while (*p != 0) - p++; - p++; - } - } - XFree(propInfo); -} - -/* - * AppendPropCarefully -- - * - * Append a given property to a given window, but set up - * an X error handler so that if the append fails this - * procedure can return an error code rather than having - * Xlib panic. - * - * Return: - * 0 on OK - -1 on error - *-------------------------------------------------------------- - */ - - static int -AppendPropCarefully(dpy, window, property, value, length) - Display *dpy; /* Display on which to operate. */ - Window window; /* Window whose property is to - * be modified. */ - Atom property; /* Name of property. */ - char *value; /* Characters to append to property. */ - int length; /* How much to append */ -{ - XErrorHandler old_handler; - - old_handler = XSetErrorHandler(x_error_check); - got_x_error = FALSE; - XChangeProperty(dpy, window, property, XA_STRING, 8, - PropModeAppend, value, length); - XSync(dpy, False); - (void) XSetErrorHandler(old_handler); - return got_x_error ? -1 : 0; -} - - -/* - * Another X Error handler, just used to check for errors. - */ -/* ARGSUSED */ - static int -x_error_check(dpy, error_event) - Display *dpy; - XErrorEvent *error_event; -{ - got_x_error = TRUE; - return 0; -} - -/* - * Check if "str" looks like it had a serial number appended. - * Actually just checks if the name ends in a digit. - */ - static int -IsSerialName(str) - char *str; -{ - int len = strlen(str); - - return (len > 1 && isdigit(str[len - 1])); -} diff --git a/scripts/legacy2luatest.pl b/scripts/legacy2luatest.pl index 51997c037b..1a3f54146e 100755 --- a/scripts/legacy2luatest.pl +++ b/scripts/legacy2luatest.pl @@ -42,15 +42,8 @@ sub read_in_file { my $command_lines = $_[1]; my $test_body_lines = $_[2]; - # Only keep first input line if it is not empty. - my $first_input_line = shift @{$input_lines}; - if ($first_input_line =~ /^$/) { - unshift @{$input_lines}, $first_input_line; - } - - # If there are input lines left, wrap them with - # `insert` command and add before the previous command - # block. + # If there are input lines, wrap with an `insert` + # command and add before the previous command block. if (@{$input_lines}) { my $last_input_line = pop @{$input_lines}; unshift @{$command_lines}, ''; @@ -168,7 +161,10 @@ sub read_in_file { return EMIT_COMMAND; } - push @input_lines, ' ' . $_; + # Skip initial lines if they are empty. + if (@input_lines or !/^$/) { + push @input_lines, ' ' . $_; + } return EMIT_INPUT; }, ); diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua index 9ff9b4cf6f..bb37ae94da 100644 --- a/scripts/msgpack-gen.lua +++ b/scripts/msgpack-gen.lua @@ -183,13 +183,20 @@ for i = 1, #functions do local converted, convert_arg, param, arg param = fn.parameters[j] converted = 'arg_'..j - if real_type(param[1]) ~= 'Object' then - output:write('\n if (args.items['..(j - 1)..'].type != kObjectType'..real_type(param[1])..') {') + local rt = real_type(param[1]) + if rt ~= 'Object' then + output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..') {') + output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..rt:lower()..';') + if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') or rt:match('^Boolean$') then + -- accept positive integers for Buffers, Windows and Tabpages + output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer > 0) {') + output:write('\n '..converted..' = (unsigned)args.items['..(j - 1)..'].data.integer;') + end + output:write('\n } else {') output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong type for argument '..j..', expecting '..param[1]..'");') output:write('\n error->set = true;') output:write('\n goto cleanup;') - output:write('\n }') - output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..real_type(param[1]):lower()..';\n') + output:write('\n }\n') else output:write('\n '..converted..' = args.items['..(j - 1)..'];\n') end diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 47782e8b6b..dc44c9135d 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -1,11 +1,5 @@ include(CheckLibraryExists) -option(SANITIZE "Enable Clang sanitizers for nvim binary" OFF) -if(SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang") - message(WARNING "SANITIZE is only supported for Clang ... disabling") - set(SANITIZE OFF) -endif() - set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto) set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua) file(GLOB API_HEADERS api/*.h) @@ -58,9 +52,7 @@ set(CONV_SOURCES ex_cmds.c ex_docmd.c ex_getln.c - farsi.c fileio.c - fold.c getchar.c if_cscope.c mbyte.c @@ -68,11 +60,9 @@ set(CONV_SOURCES menu.c message.c misc1.c - move.c normal.c ops.c path.c - popupmnu.c quickfix.c regexp.c screen.c @@ -180,9 +170,16 @@ list(APPEND NVIM_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ) +set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES}) + +if(USE_JEMALLOC) + # dont use jemalloc in the unit test library + list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES}) +endif() + add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) -target_link_libraries(nvim ${NVIM_LINK_LIBRARIES}) +target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES}) install_helper(TARGETS nvim) if(SANITIZE) @@ -203,5 +200,6 @@ set_property(TARGET libnvim APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB ") add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES}) +set_target_properties(nvim-test PROPERTIES COMPILE_FLAGS -DUNIT_TESTING) add_subdirectory(po) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 5bd48fc19f..c9ada8dfc0 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -58,7 +58,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) rv = slice.items[0].data.string; } - free(slice.items); + xfree(slice.items); return rv; } @@ -144,10 +144,10 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, end: if (err->set) { for (size_t i = 0; i < rv.size; i++) { - free(rv.items[i].data.string.data); + xfree(rv.items[i].data.string.data); } - free(rv.items); + xfree(rv.items); rv.items = NULL; } @@ -280,7 +280,7 @@ void buffer_set_line_slice(Buffer buffer, } // Same as with replacing, but we also need to free lines - free(lines[i]); + xfree(lines[i]); lines[i] = NULL; extra++; } @@ -301,10 +301,10 @@ void buffer_set_line_slice(Buffer buffer, end: for (size_t i = 0; i < new_len; i++) { - free(lines[i]); + xfree(lines[i]); } - free(lines); + xfree(lines); restore_win_for_buf(save_curwin, save_curtab, save_curbuf); try_end(err); } diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 76ac23a521..6c8e324649 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -22,6 +22,15 @@ typedef enum { kErrorTypeValidation } ErrorType; +typedef enum { + kMessageTypeRequest, + kMessageTypeResponse, + kMessageTypeNotification +} MessageType; + +/// Used as the message ID of notifications. +#define NO_RESPONSE UINT64_MAX + typedef struct { ErrorType type; char msg[1024]; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 39ca0756f3..67ff77ebac 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -61,7 +61,7 @@ bool try_end(Error *err) free_global_msglist(); if (should_free) { - free(msg); + xfree(msg); } } else if (did_throw) { api_set_error(err, Exception, "%s", current_exception->value); @@ -405,6 +405,9 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) tv->vval.v_number = obj.data.boolean; break; + case kObjectTypeBuffer: + case kObjectTypeWindow: + case kObjectTypeTabpage: case kObjectTypeInteger: if (obj.data.integer > INT_MAX || obj.data.integer < INT_MIN) { api_set_error(err, Validation, _("Integer value outside range")); @@ -489,7 +492,7 @@ void api_free_string(String value) return; } - free(value.data); + xfree(value.data); } void api_free_object(Object value) @@ -527,7 +530,7 @@ void api_free_array(Array value) api_free_object(value.items[i]); } - free(value.items); + xfree(value.items); } void api_free_dictionary(Dictionary value) @@ -537,7 +540,7 @@ void api_free_dictionary(Dictionary value) api_free_object(value.items[i].value); } - free(value.items); + xfree(value.items); } Dictionary api_metadata(void) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 587e19fe35..1204c9e1d1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -85,7 +85,7 @@ void vim_feedkeys(String keys, String mode, Boolean escape_csi) insert ? 0 : typebuf.tb_len, !typed, false); if (escape_csi) { - free(keys_esc); + xfree(keys_esc); } if (vgetc_busy) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 11cb7bdeac..4585278714 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -443,8 +443,8 @@ close_buffer ( * Remove the buffer from the list. */ if (wipe_buf) { - free(buf->b_ffname); - free(buf->b_sfname); + xfree(buf->b_ffname); + xfree(buf->b_sfname); if (buf->b_prev == NULL) firstbuf = buf->b_next; else @@ -563,7 +563,7 @@ static void free_buffer(buf_T *buf) buf->b_next = au_pending_free_buf; au_pending_free_buf = buf; } else { - free(buf); + xfree(buf); } } @@ -587,7 +587,7 @@ free_buffer_stuff ( buf_delete_signs(buf); /* delete any signs */ map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ - free(buf->b_start_fenc); + xfree(buf->b_start_fenc); buf->b_start_fenc = NULL; } @@ -605,7 +605,7 @@ static void clear_wininfo(buf_T *buf) clear_winopt(&wip->wi_opt); deleteFoldRecurse(&wip->wi_folds); } - free(wip); + xfree(wip); } } @@ -1332,7 +1332,7 @@ buflist_new ( if (ffname != NULL && !(flags & BLN_DUMMY) && (buf = buflist_findname_file_id(ffname, &file_id, file_id_valid)) != NULL) { - free(ffname); + xfree(ffname); if (lnum != 0) buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); /* copy the options now, if 'cpo' doesn't have 's' and not done @@ -1396,9 +1396,9 @@ buflist_new ( buf->b_wininfo = xcalloc(1, sizeof(wininfo_T)); if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) { - free(buf->b_ffname); + xfree(buf->b_ffname); buf->b_ffname = NULL; - free(buf->b_sfname); + xfree(buf->b_sfname); buf->b_sfname = NULL; if (buf != curbuf) free_buffer(buf); @@ -1672,7 +1672,7 @@ buf_T *buflist_findname_exp(char_u *fname) ); if (ffname != NULL) { buf = buflist_findname(ffname); - free(ffname); + xfree(ffname); } return buf; } @@ -1767,7 +1767,7 @@ buflist_findpat ( ++p; prog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); if (prog == NULL) { - free(pat); + xfree(pat); return -1; } @@ -1809,7 +1809,7 @@ buflist_findpat ( find_listed = FALSE; } - free(pat); + xfree(pat); } if (match == -2) @@ -1855,7 +1855,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) prog = vim_regcomp(patc + attempt * 11, RE_MAGIC); if (prog == NULL) { if (patc != pat) - free(patc); + xfree(patc); return FAIL; } @@ -1893,7 +1893,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) } if (patc != pat) - free(patc); + xfree(patc); *num_file = count; return count == 0 ? FAIL : OK; @@ -1938,7 +1938,7 @@ static char_u *fname_match(regprog_T *prog, char_u *name, bool ignore_case) p = home_replace_save(NULL, name); if (vim_regexec(®match, p, (colnr_T)0)) match = name; - free(p); + xfree(p); } } @@ -2223,8 +2223,8 @@ setfname ( if (ffname == NULL || *ffname == NUL) { /* Removing the name. */ - free(buf->b_ffname); - free(buf->b_sfname); + xfree(buf->b_ffname); + xfree(buf->b_sfname); buf->b_ffname = NULL; buf->b_sfname = NULL; } else { @@ -2245,7 +2245,7 @@ setfname ( if (obuf->b_ml.ml_mfp != NULL) { /* it's loaded, fail */ if (message) EMSG(_("E95: Buffer with this name already exists")); - free(ffname); + xfree(ffname); return FAIL; } /* delete from the list */ @@ -2255,8 +2255,8 @@ setfname ( #ifdef USE_FNAME_CASE path_fix_case(sfname); /* set correct case for short file name */ #endif - free(buf->b_ffname); - free(buf->b_sfname); + xfree(buf->b_ffname); + xfree(buf->b_sfname); buf->b_ffname = ffname; buf->b_sfname = sfname; } @@ -2282,8 +2282,8 @@ void buf_set_name(int fnum, char_u *name) buf = buflist_findnr(fnum); if (buf != NULL) { - free(buf->b_sfname); - free(buf->b_ffname); + xfree(buf->b_sfname); + xfree(buf->b_ffname); buf->b_ffname = vim_strsave(name); buf->b_sfname = NULL; /* Allocate ffname and expand into full path. Also resolves .lnk @@ -2561,7 +2561,7 @@ fileinfo ( set_keep_msg(p, 0); } - free(buffer); + xfree(buffer); } void col_print(char_u *buf, size_t buflen, int col, int vcol) @@ -2636,7 +2636,7 @@ void maketitle(void) else { p = transstr(path_tail(curbuf->b_fname)); STRLCPY(buf, p, SPACE_FOR_FNAME + 1); - free(p); + xfree(p); } switch (bufIsChanged(curbuf) @@ -2677,7 +2677,7 @@ void maketitle(void) if (off < SPACE_FOR_DIR) { p = transstr(buf + off); STRLCPY(buf + off, p, SPACE_FOR_DIR - off + 1); - free(p); + xfree(p); } else { STRLCPY(buf + off, "...", SPACE_FOR_ARGNR - off + 1); } @@ -2749,7 +2749,7 @@ static int ti_change(char_u *str, char_u **last) { if ((str == NULL) != (*last == NULL) || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) { - free(*last); + xfree(*last); if (str == NULL) *last = NULL; else @@ -2771,8 +2771,8 @@ void resettitle(void) # if defined(EXITFREE) void free_titles(void) { - free(lasttitle); - free(lasticon); + xfree(lasttitle); + xfree(lasticon); } # endif @@ -3124,7 +3124,7 @@ build_stl_str_hl ( if (str != NULL && *str != 0) { if (*skipdigits(str) == NUL) { num = atoi((char *)str); - free(str); + xfree(str); str = NULL; itemisflag = FALSE; } @@ -3381,7 +3381,7 @@ build_stl_str_hl ( item[curitem].type = Empty; if (opt == STL_VIM_EXPR) - free(str); + xfree(str); if (num >= 0 || (!itemisflag && str && *str)) prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ @@ -3391,7 +3391,7 @@ build_stl_str_hl ( itemcnt = curitem; if (usefmt != fmt) - free(usefmt); + xfree(usefmt); width = vim_strsize(out); if (maxwidth > 0 && width > maxwidth) { @@ -3585,7 +3585,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname) /* If the file name is a shortcut file, use the file it links to. */ rfname = mch_resolve_shortcut(*ffname); if (rfname != NULL) { - free(*ffname); + xfree(*ffname); *ffname = rfname; *sfname = rfname; } @@ -3844,7 +3844,7 @@ do_arg_all ( win_enter(new_curwin, false); --autocmd_no_leave; - free(opened); + xfree(opened); } /* @@ -4161,7 +4161,7 @@ chk_modeline ( sourcing_lnum = save_sourcing_lnum; sourcing_name = save_sourcing_name; - free(linecopy); + xfree(linecopy); return retval; } @@ -4208,7 +4208,7 @@ int read_viminfo_bufferlist(vir_T *virp, int writing) buflist_setfpos(buf, curwin, lnum, col, FALSE); } } - free(xline); + xfree(xline); return viminfo_readline(virp); } @@ -4249,7 +4249,7 @@ void write_viminfo_bufferlist(FILE *fp) buf->b_last_cursor.col); viminfo_writestring(fp, line); } - free(line); + xfree(line); } @@ -4426,7 +4426,7 @@ linenr_T buf_delsign( if (sign->id == id) { *lastp = next; lnum = sign->lnum; - free(sign); + xfree(sign); break; } else { lastp = &sign->next; @@ -4498,7 +4498,7 @@ void buf_delete_signs(buf_T *buf) while (buf->b_signlist != NULL) { next = buf->b_signlist->next; - free(buf->b_signlist); + xfree(buf->b_signlist); buf->b_signlist = next; } } @@ -4621,7 +4621,7 @@ int buf_contents_changed(buf_T *buf) } } } - free(ea.cmd); + xfree(ea.cmd); /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 35fa3978b6..9c8cdd41ae 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -6,6 +6,8 @@ // for FILE #include <stdio.h> +typedef struct file_buffer buf_T; // Forward declaration + // for garray_T #include "nvim/garray.h" // for pos_T, lpos_T and linenr_T @@ -16,7 +18,7 @@ #include "nvim/iconv.h" // for jump list and tag stack sizes in a buffer and mark types #include "nvim/mark_defs.h" -// for u_header_T +// for u_header_T; needs buf_T. #include "nvim/undo_defs.h" // for hashtab_T #include "nvim/hashtab.h" @@ -80,7 +82,6 @@ typedef struct window_S win_T; typedef struct wininfo_S wininfo_T; typedef struct frame_S frame_T; typedef int scid_T; /* script ID */ -typedef struct file_buffer buf_T; /* forward declaration */ // for struct memline (it needs memfile_T) #include "nvim/memline_defs.h" diff --git a/src/nvim/diff.c b/src/nvim/diff.c index e50b096270..937baad648 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -393,7 +393,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, } } dprev->df_next = dp->df_next; - free(dp); + xfree(dp); dp = dprev->df_next; } else { // Advance to next entry. @@ -416,7 +416,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, if (i == DB_COUNT) { diff_T *dnext = dp->df_next; - free(dp); + xfree(dp); dp = dnext; if (dprev == NULL) { @@ -527,7 +527,7 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) break; } } - free(line_org); + xfree(line_org); // Stop when a line isn't equal in all diff buffers. if (i_new != DB_COUNT) { @@ -786,9 +786,9 @@ void ex_diffupdate(exarg_T *eap) diff_redraw(TRUE); theend: - free(tmp_orig); - free(tmp_new); - free(tmp_diff); + xfree(tmp_orig); + xfree(tmp_new); + xfree(tmp_diff); } /// Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". @@ -828,7 +828,7 @@ static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff) NULL ); unblock_autocmds(); - free(cmd); + xfree(cmd); } } @@ -989,16 +989,16 @@ theend: if (tmp_orig != NULL) { os_remove((char *)tmp_orig); } - free(tmp_orig); + xfree(tmp_orig); if (tmp_new != NULL) { os_remove((char *)tmp_new); } - free(tmp_new); - free(newname); - free(buf); + xfree(tmp_new); + xfree(newname); + xfree(buf); #ifdef UNIX - free(fullname); + xfree(fullname); #endif // ifdef UNIX } @@ -1340,7 +1340,7 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) while (dn != dp->df_next) { dpl = dn->df_next; - free(dn); + xfree(dn); dn = dpl; } } else { @@ -1407,7 +1407,7 @@ void diff_clear(tabpage_T *tp) diff_T *next_p; for (p = tp->tp_first_diff; p != NULL; p = next_p) { next_p = p->df_next; - free(p); + xfree(p); } tp->tp_first_diff = NULL; } @@ -1559,7 +1559,7 @@ static int diff_equal_entry(diff_T *dp, int idx1, int idx2) int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], dp->df_lnum[idx2] + i, FALSE)); - free(line); + xfree(line); if (cmp != 0) { return FALSE; @@ -1863,7 +1863,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) int idx = diff_buf_idx(wp->w_buffer); if (idx == DB_COUNT) { // cannot happen - free(line_org); + xfree(line_org); return FALSE; } @@ -1876,7 +1876,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) { - free(line_org); + xfree(line_org); return FALSE; } @@ -1956,7 +1956,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } } - free(line_org); + xfree(line_org); return added; } @@ -2262,7 +2262,7 @@ void ex_diffgetput(exarg_T *eap) } p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE)); ml_append(lnum + i - 1, p, 0, FALSE); - free(p); + xfree(p); added++; if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) { // Added the first line into an empty buffer, need to @@ -2317,7 +2317,7 @@ void ex_diffgetput(exarg_T *eap) if (dfree != NULL) { // Diff is deleted, update folds in other windows. diff_fold_update(dfree, idx_to); - free(dfree); + xfree(dfree); } else { // mark_adjust() may have changed the count in a wrong way dp->df_count[idx_to] = new_count; diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index cb6bfc9cc9..cf998c041d 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1538,7 +1538,7 @@ static int getexactdigraph(int char1, int char2, int meta_char) if (to != NULL) { retval = (*mb_ptr2char)(to); - free(to); + xfree(to); } (void)convert_setup(&vc, NULL, NULL); } @@ -1763,11 +1763,11 @@ char_u* keymap_init(void) curbuf->b_p_keymap); if (source_runtime((char_u *)buf, FALSE) == FAIL) { - free(buf); + xfree(buf); return (char_u *)N_("E544: Keymap file not found"); } } - free(buf); + xfree(buf); } return NULL; @@ -1824,12 +1824,12 @@ void ex_loadkeymap(exarg_T *eap) if (*kp->to == NUL) { EMSG(_("E791: Empty keymap entry")); } - free(kp->from); - free(kp->to); + xfree(kp->from); + xfree(kp->to); --curbuf->b_kmap_ga.ga_len; } } - free(line); + xfree(line); } // setup ":lnoremap" to map the keys @@ -1866,8 +1866,8 @@ static void keymap_unload(void) for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); (void)do_map(1, buf, LANGMAP, FALSE); - free(kp[i].from); - free(kp[i].to); + xfree(kp[i].from); + xfree(kp[i].to); } p_cpo = save_cpo; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 8b2ac1943f..26665aa84c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -246,7 +246,7 @@ edit ( ) { if (curbuf->terminal) { - terminal_enter(curbuf->terminal, true); + terminal_enter(true); return false; } @@ -482,7 +482,7 @@ edit ( new_insert_skip = 0; else { new_insert_skip = (int)STRLEN(ptr); - free(ptr); + xfree(ptr); } old_indent = 0; @@ -652,7 +652,7 @@ edit ( if (str != NULL) { for (p = str; *p != NUL; mb_ptr_adv(p)) ins_compl_addleader(PTR2CHAR(p)); - free(str); + xfree(str); } else ins_compl_addleader(c); continue; @@ -1153,7 +1153,7 @@ normalchar: } AppendToRedobuffLit(str, -1); } - free(str); + xfree(str); c = NUL; } @@ -1569,7 +1569,7 @@ change_indent ( memset(ptr, ' ', i); new_cursor_col += i; ins_str(ptr); - free(ptr); + xfree(ptr); } /* @@ -1648,7 +1648,7 @@ change_indent ( /* Insert new stuff into line again */ ins_bytes(new_line); - free(new_line); + xfree(new_line); } } @@ -1970,7 +1970,7 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int *(p++) = wca[i++]; *p = NUL; - free(wca); + xfree(wca); return ins_compl_add(IObuff, len, icase, fname, NULL, dir, flags, FALSE); @@ -2273,7 +2273,7 @@ static void ins_compl_del_pum(void) { if (compl_match_array != NULL) { pum_undisplay(); - free(compl_match_array); + xfree(compl_match_array); compl_match_array = NULL; } } @@ -2490,8 +2490,8 @@ ins_compl_dictionaries ( ptr = xmalloc(len); vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc); regmatch.regprog = vim_regcomp(ptr, RE_MAGIC); - free(pat_esc); - free(ptr); + xfree(pat_esc); + xfree(ptr); } else { regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) @@ -2539,7 +2539,7 @@ ins_compl_dictionaries ( theend: p_scs = save_p_scs; vim_regfree(regmatch.regprog); - free(buf); + xfree(buf); } static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir) @@ -2689,9 +2689,9 @@ static void ins_compl_free(void) compl_T *match; int i; - free(compl_pattern); + xfree(compl_pattern); compl_pattern = NULL; - free(compl_leader); + xfree(compl_leader); compl_leader = NULL; if (compl_first_match == NULL) @@ -2704,13 +2704,13 @@ static void ins_compl_free(void) do { match = compl_curr_match; compl_curr_match = compl_curr_match->cp_next; - free(match->cp_str); + xfree(match->cp_str); /* several entries may use the same fname, free it just once. */ if (match->cp_flags & FREE_FNAME) - free(match->cp_fname); + xfree(match->cp_fname); for (i = 0; i < CPT_COUNT; ++i) - free(match->cp_text[i]); - free(match); + xfree(match->cp_text[i]); + xfree(match); } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); compl_first_match = compl_curr_match = NULL; compl_shown_match = NULL; @@ -2721,12 +2721,12 @@ static void ins_compl_clear(void) compl_cont_status = 0; compl_started = FALSE; compl_matches = 0; - free(compl_pattern); + xfree(compl_pattern); compl_pattern = NULL; - free(compl_leader); + xfree(compl_leader); compl_leader = NULL; edit_submode_extra = NULL; - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = NULL; compl_enter_selects = FALSE; } @@ -2767,7 +2767,7 @@ static int ins_compl_bs(void) || ins_compl_need_restart()) ins_compl_restart(); - free(compl_leader); + xfree(compl_leader); compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col); ins_compl_new_leader(); if (compl_shown_match != NULL) @@ -2871,7 +2871,7 @@ static void ins_compl_addleader(int c) * cursor doesn't point original position, changing compl_leader would * break redo. */ if (!compl_opt_refresh_always) { - free(compl_leader); + xfree(compl_leader); compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col, (int)(curwin->w_cursor.col - compl_col)); ins_compl_new_leader(); @@ -2898,7 +2898,7 @@ static void ins_compl_set_original_text(char_u *str) { /* Replace the original text entry. */ if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */ - free(compl_first_match->cp_str); + xfree(compl_first_match->cp_str); compl_first_match->cp_str = vim_strsave(str); } } @@ -4449,13 +4449,13 @@ static int ins_complete(int c) ins_compl_fixRedoBufForLeader(NULL); /* Always add completion for the original text. */ - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = vim_strnsave(line + compl_col, compl_length); if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) { - free(compl_pattern); + xfree(compl_pattern); compl_pattern = NULL; - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = NULL; return FAIL; } @@ -5326,7 +5326,7 @@ internal_format ( * moved, now we re-insert it into the new line. */ ins_bytes(saved_text); - free(saved_text); + xfree(saved_text); } else { /* * Check if cursor is not past the NUL off the line, cindent @@ -5661,11 +5661,11 @@ stop_insert ( ptr = get_inserted(); if (did_restart_edit == 0 || (ptr != NULL && (int)STRLEN(ptr) > new_insert_skip)) { - free(last_insert); + xfree(last_insert); last_insert = ptr; last_insert_skip = new_insert_skip; } else - free(ptr); + xfree(ptr); if (!arrow_used && end_insert_pos != NULL) { /* Auto-format now. It may seem strange to do this when stopping an @@ -5770,7 +5770,7 @@ void set_last_insert(int c) { char_u *s; - free(last_insert); + xfree(last_insert); last_insert = xmalloc(MB_MAXBYTES * 3 + 5); s = last_insert; /* Use the CTRL-V only when entering a special char */ @@ -5785,9 +5785,9 @@ void set_last_insert(int c) #if defined(EXITFREE) void free_last_insert(void) { - free(last_insert); + xfree(last_insert); last_insert = NULL; - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = NULL; } @@ -6307,7 +6307,7 @@ static void mb_replace_pop_ins(int cc) */ static void replace_flush(void) { - free(replace_stack); + xfree(replace_stack); replace_stack = NULL; replace_stack_len = 0; replace_stack_nr = 0; @@ -7354,9 +7354,9 @@ static int ins_bs(int c, int mode, int *inserted_space_p) *inserted_space_p = FALSE; if (p_sta && in_indent) - ts = (int)get_sw_value(curbuf); + ts = get_sw_value(curbuf); else - ts = (int)get_sts_value(); + ts = get_sts_value(); /* Compute the virtual column where we want to be. Since * 'showbreak' may get in the way, need to get the last column of * the previous character. */ @@ -7826,9 +7826,9 @@ static int ins_tab(void) AppendToRedobuff((char_u *)"\t"); if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ - temp = (int)get_sw_value(curbuf); + temp = get_sw_value(curbuf); else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ - temp = (int)get_sts_value(); + temp = get_sts_value(); else /* otherwise use 'tabstop' */ temp = (int)curbuf->b_p_ts; temp -= get_nolist_virtcol() % temp; @@ -7966,7 +7966,7 @@ static int ins_tab(void) } if (State & VREPLACE_FLAG) - free(saved_line); + xfree(saved_line); curwin->w_p_list = save_list; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4ab31985b5..1dab9df9cb 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21,8 +21,6 @@ #include <math.h> #include <limits.h> -#include "nvim/lib/klist.h" - #include "nvim/assert.h" #include "nvim/vim.h" #include "nvim/ascii.h" @@ -89,6 +87,7 @@ #include "nvim/os/rstream_defs.h" #include "nvim/os/time.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/msgpack_rpc/server.h" #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/os/dl.h" @@ -469,10 +468,7 @@ typedef struct { list_T *received; int status; } JobEvent; -#define JobEventFreer(x) -KMEMPOOL_INIT(JobEventPool, JobEvent, JobEventFreer) -static kmempool_t(JobEventPool) *job_event_pool = NULL; -static bool defer_job_callbacks = true; +static int disable_job_defer = 0; /* * Initialize the global and v: variables. @@ -508,8 +504,6 @@ void eval_init(void) set_vim_var_nr(VV_SEARCHFORWARD, 1L); set_vim_var_nr(VV_HLSEARCH, 1L); set_reg_var(0); /* default for v:register is not 0 but '"' */ - - job_event_pool = kmp_init(JobEventPool); } #if defined(EXITFREE) @@ -520,7 +514,7 @@ void eval_clear(void) for (int i = 0; i < VV_LEN; ++i) { p = &vimvars[i]; if (p->vv_di.di_tv.v_type == VAR_STRING) { - free(p->vv_str); + xfree(p->vv_str); p->vv_str = NULL; } else if (p->vv_di.di_tv.v_type == VAR_LIST) { list_unref(p->vv_list); @@ -546,7 +540,7 @@ void eval_clear(void) for (int i = 1; i <= ga_scripts.ga_len; ++i) vars_clear(&SCRIPT_VARS(i)); for (int i = 1; i <= ga_scripts.ga_len; ++i) - free(SCRIPT_SV(i)); + xfree(SCRIPT_SV(i)); ga_clear(&ga_scripts); /* unreferenced lists and dicts */ @@ -742,13 +736,13 @@ void var_redir_stop(void) } /* free the collected output */ - free(redir_ga.ga_data); + xfree(redir_ga.ga_data); redir_ga.ga_data = NULL; - free(redir_lval); + xfree(redir_lval); redir_lval = NULL; } - free(redir_varname); + xfree(redir_varname); redir_varname = NULL; } @@ -1066,7 +1060,7 @@ typval_T *eval_expr(char_u *arg, char_u **nextcmd) typval_T *tv = xmalloc(sizeof(typval_T)); if (eval0(arg, tv, nextcmd, TRUE) == FAIL) { - free(tv); + xfree(tv); return NULL; } @@ -1133,7 +1127,7 @@ call_vim_function ( --sandbox; restore_funccal(save_funccalp); } - free(argvars); + xfree(argvars); if (ret == FAIL) clear_tv(rettv); @@ -1698,14 +1692,14 @@ static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first) s == NULL ? (char_u *)"" : s, first); *arg = c; - free(tf); + xfree(tf); } clear_tv(&tv); } } } - free(tofree); + xfree(tofree); } arg = skipwhite(arg); @@ -1763,7 +1757,7 @@ ex_let_one ( if (s != NULL) { p = tofree = concat_str(s, p); if (mustfree) - free(s); + xfree(s); } } if (p != NULL) { @@ -1778,7 +1772,7 @@ ex_let_one ( arg_end = arg; } name[len] = c1; - free(tofree); + xfree(tofree); } } } @@ -1819,7 +1813,7 @@ ex_let_one ( n = numval - n; } else if (opt_type == 0 && stringval != NULL) { /* string */ s = concat_str(stringval, s); - free(stringval); + xfree(stringval); stringval = s; } } @@ -1829,7 +1823,7 @@ ex_let_one ( arg_end = p; } *p = c1; - free(stringval); + xfree(stringval); } } /* @@ -1851,14 +1845,14 @@ ex_let_one ( s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); if (s != NULL) { p = ptofree = concat_str(s, p); - free(s); + xfree(s); } } if (p != NULL) { write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE); arg_end = arg + 1; } - free(ptofree); + xfree(ptofree); } } /* @@ -2218,8 +2212,8 @@ get_lval ( */ static void clear_lval(lval_T *lp) { - free(lp->ll_exp_name); - free(lp->ll_newkey); + xfree(lp->ll_exp_name); + xfree(lp->ll_newkey); } /* @@ -2312,7 +2306,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, ch /* Need to add an item to the Dictionary. */ di = dictitem_alloc(lp->ll_newkey); if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) { - free(di); + xfree(di); return; } lp->ll_tv = &di->di_tv; @@ -2547,7 +2541,7 @@ void free_for_info(void *fi_void) list_rem_watch(fi->fi_list, &fi->fi_lw); list_unref(fi->fi_list); } - free(fi); + xfree(fi); } @@ -2661,7 +2655,7 @@ void ex_call(exarg_T *eap) if (fudi.fd_newkey != NULL) { /* Still need to give an error message for missing key. */ EMSG2(_(e_dictkey), fudi.fd_newkey); - free(fudi.fd_newkey); + xfree(fudi.fd_newkey); } if (tofree == NULL) return; @@ -2741,7 +2735,7 @@ void ex_call(exarg_T *eap) end: dict_unref(fudi.fd_dict); - free(tofree); + xfree(tofree); } /* @@ -3062,7 +3056,7 @@ static char_u *cat_prefix_varname(int prefix, char_u *name) size_t len = STRLEN(name) + 3; if (len > varnamebuflen) { - free(varnamebuf); + xfree(varnamebuf); len += 10; /* some additional space */ varnamebuf = xmalloc(len); varnamebuflen = len; @@ -3149,7 +3143,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) if (vidx < VV_LEN) return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); - free(varnamebuf); + xfree(varnamebuf); varnamebuf = NULL; varnamebuflen = 0; return NULL; @@ -4157,7 +4151,7 @@ eval7 ( else ret = OK; } - free(alias); + xfree(alias); } *arg = skipwhite(*arg); @@ -4791,9 +4785,9 @@ list_free ( if (recurse || (item->li_tv.v_type != VAR_LIST && item->li_tv.v_type != VAR_DICT)) clear_tv(&item->li_tv); - free(item); + xfree(item); } - free(l); + xfree(l); } /* @@ -4810,7 +4804,7 @@ listitem_T *listitem_alloc(void) FUNC_ATTR_NONNULL_RET void listitem_free(listitem_T *item) { clear_tv(&item->li_tv); - free(item); + xfree(item); } /* @@ -5282,7 +5276,7 @@ static list_T *list_copy(list_T *orig, int deep, int copyID) ni = listitem_alloc(); if (deep) { if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL) { - free(ni); + xfree(ni); break; } } else @@ -5337,7 +5331,7 @@ static char_u *list2string(typval_T *tv, int copyID) ga_init(&ga, (int)sizeof(char), 80); ga_append(&ga, '['); if (list_join(&ga, tv->vval.v_list, (char_u *)", ", FALSE, copyID) == FAIL) { - free(ga.ga_data); + xfree(ga.ga_data); return NULL; } ga_append(&ga, ']'); @@ -5430,7 +5424,7 @@ static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int ga_init(&join_ga, (int)sizeof(join_T), l->lv_len); retval = list_join_inner(gap, l, sep, echo_style, copyID, &join_ga); -# define FREE_JOIN_TOFREE(join) free((join)->tofree) +# define FREE_JOIN_TOFREE(join) xfree((join)->tofree) GA_DEEP_CLEAR(&join_ga, join_T, FREE_JOIN_TOFREE); return retval; @@ -5736,12 +5730,12 @@ dict_free ( if (recurse || (di->di_tv.v_type != VAR_LIST && di->di_tv.v_type != VAR_DICT)) clear_tv(&di->di_tv); - free(di); + xfree(di); --todo; } } hash_clear(&d->dv_hashtab); - free(d); + xfree(d); } /* @@ -5794,7 +5788,7 @@ static void dictitem_remove(dict_T *dict, dictitem_T *item) void dictitem_free(dictitem_T *item) { clear_tv(&item->di_tv); - free(item); + xfree(item); } /* @@ -5827,7 +5821,7 @@ static dict_T *dict_copy(dict_T *orig, int deep, int copyID) if (deep) { if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, deep, copyID) == FAIL) { - free(di); + xfree(di); break; } } else @@ -5936,33 +5930,39 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len) } hi = hash_find(&d->dv_hashtab, akey); - free(tofree); + xfree(tofree); if (HASHITEM_EMPTY(hi)) return NULL; return HI2DI(hi); } -// Get a function from a dictionary -static ufunc_T *get_dict_callback(dict_T *d, char *key) +/// Get a function from a dictionary +/// @param[out] result The address where a pointer to the wanted callback +/// will be left. +/// @return true/false on success/failure. +static bool get_dict_callback(dict_T *d, char *key, ufunc_T **result) { dictitem_T *di = dict_find(d, (uint8_t *)key, -1); if (di == NULL) { - return NULL; + *result = NULL; + return true; } if (di->di_tv.v_type != VAR_FUNC && di->di_tv.v_type != VAR_STRING) { EMSG(_("Argument is not a function or function name")); - return NULL; + *result = NULL; + return false; } uint8_t *name = di->di_tv.vval.v_string; uint8_t *n = name; - ufunc_T *rv; + ufunc_T *rv = NULL; if (*n > '9' || *n < '0') { - n = trans_function_name(&n, false, TFN_INT|TFN_QUIET, NULL); - rv = find_func(n); - free(n); + if ((n = trans_function_name(&n, false, TFN_INT|TFN_QUIET, NULL))) { + rv = find_func(n); + xfree(n); + } } else { // dict function, name is already translated rv = find_func(n); @@ -5970,11 +5970,13 @@ static ufunc_T *get_dict_callback(dict_T *d, char *key) if (!rv) { EMSG2(_("Function %s doesn't exist"), name); - return NULL; + *result = NULL; + return false; } rv->uf_refcount++; - return rv; + *result = rv; + return true; } /* @@ -6044,20 +6046,20 @@ static char_u *dict2string(typval_T *tv, int copyID) tofree = string_quote(hi->hi_key, FALSE); if (tofree != NULL) { ga_concat(&ga, tofree); - free(tofree); + xfree(tofree); } ga_concat(&ga, (char_u *)": "); s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID); if (s != NULL) ga_concat(&ga, s); - free(tofree); + xfree(tofree); if (s == NULL || did_echo_string_emsg) { break; } line_breakcheck(); } if (todo > 0) { - free(ga.ga_data); + xfree(ga.ga_data); return NULL; } @@ -6373,13 +6375,13 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) } } else { if (mustfree) { - free(string); + xfree(string); } // Next try expanding things like $VIM and ${HOME}. string = expand_env_save(name - 1); if (string != NULL && *string == '$') { - free(string); + xfree(string); string = NULL; } } @@ -6604,6 +6606,9 @@ static struct fst { {"searchpair", 3, 7, f_searchpair}, {"searchpairpos", 3, 7, f_searchpairpos}, {"searchpos", 1, 4, f_searchpos}, + {"serverlist", 0, 0, f_serverlist}, + {"serverstart", 0, 1, f_serverstart}, + {"serverstop", 1, 1, f_serverstop}, {"setbufvar", 3, 3, f_setbufvar}, {"setcmdpos", 1, 1, f_setcmdpos}, {"setline", 2, 2, f_setline}, @@ -7029,8 +7034,8 @@ call_func ( } if (fname != name && fname != fname_buf) - free(fname); - free(name); + xfree(fname); + xfree(name); return ret; } @@ -7049,7 +7054,7 @@ static void emsg_funcname(char *ermsg, char_u *name) p = name; EMSG2(_(ermsg), p); if (p != name) - free(p); + xfree(p); } /* @@ -8199,7 +8204,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv) p = expand_env_save(p); if (p != NULL && *p != '$') n = TRUE; - free(p); + xfree(p); } } else if (*p == '&' || *p == '+') { /* option */ n = (get_option_tv(&p, NULL, TRUE) == OK); @@ -8235,7 +8240,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv) if (*p != NUL) n = FALSE; - free(tofree); + xfree(tofree); } rettv->vval.v_number = n; @@ -8528,7 +8533,7 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what) if (*fname != NUL && !error) { do { if (rettv->v_type == VAR_STRING || rettv->v_type == VAR_LIST) - free(fresult); + xfree(fresult); fresult = find_file_in_path_option(first ? fname : NULL, first ? (int)STRLEN(fname) : 0, 0, first, path, @@ -8791,7 +8796,7 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv) rettv->vval.v_string = NULL; else rettv->vval.v_string = vim_strnsave(fname, len); - free(fbuf); + xfree(fbuf); } @@ -9274,7 +9279,7 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv) slash_adjust(rettv->vval.v_string); #endif } - free(cwd); + xfree(cwd); } /* @@ -10251,8 +10256,8 @@ static void f_iconv(typval_T *argvars, typval_T *rettv) rettv->vval.v_string = string_convert(&vimconv, str, NULL); convert_setup(&vimconv, NULL, NULL); - free(from); - free(to); + xfree(from); + xfree(to); } /* @@ -10390,7 +10395,7 @@ static void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog) rettv->vval.v_string = vim_strsave(get_tv_string_buf( &argvars[2], buf)); - free(xp_arg); + xfree(xp_arg); /* since the user typed this, no need to wait for return */ need_wait_return = FALSE; @@ -10741,7 +10746,7 @@ static void f_jobsend(typval_T *argvars, typval_T *rettv) return; } - WBuffer *buf = wstream_new_buffer(input, input_len, 1, free); + WBuffer *buf = wstream_new_buffer(input, input_len, 1, xfree); rettv->vval.v_number = job_write(job, buf); } @@ -10810,9 +10815,12 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) return; } - if (!os_can_exe(args->lv_first->li_tv.vval.v_string, NULL)) { + assert(args->lv_first); + + const char_u *exe = get_tv_string(&args->lv_first->li_tv); + if (!os_can_exe(exe, NULL)) { // String is not executable - EMSG2(e_jobexe, args->lv_first->li_tv.vval.v_string); + EMSG2(e_jobexe, exe); return; } @@ -10820,8 +10828,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) ufunc_T *on_stdout = NULL, *on_stderr = NULL, *on_exit = NULL; if (argvars[1].v_type == VAR_DICT) { job_opts = argvars[1].vval.v_dict; - common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit); - if (did_emsg) { + if (!common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit)) { return; } } @@ -10830,7 +10837,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) int i = 0; char **argv = xcalloc(argc + 1, sizeof(char *)); for (listitem_T *arg = args->lv_first; arg != NULL; arg = arg->li_next) { - argv[i++] = xstrdup((char *)arg->li_tv.vval.v_string); + argv[i++] = xstrdup((char *) get_tv_string(&arg->li_tv)); } JobOptions opts = common_job_options(argv, on_stdout, on_stderr, on_exit, @@ -10912,9 +10919,16 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv) list_T *args = argvars[0].vval.v_list; list_T *rv = list_alloc(); - // must temporarily disable job event deferring so the callbacks are - // processed while waiting. - defer_job_callbacks = false; + ui_busy_start(); + // disable breakchecks, which could result in job callbacks being executed + // at unexpected places + disable_breakcheck++; + // disable job event deferring so the callbacks are processed while waiting. + if (!disable_job_defer++) { + // process any pending job events in the deferred queue, but only do this if + // deferred is not disabled(at the top-level `jobwait()` call) + event_process(); + } // For each item in the input list append an integer to the output list. -3 // is used to represent an invalid job id, -2 is for a interrupted job and // -1 for jobs that were skipped or timed out. @@ -10987,8 +11001,9 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv) // job exits data->status_ptr = NULL; } - // restore defer flag - defer_job_callbacks = true; + disable_job_defer--; + disable_breakcheck--; + ui_busy_stop(); rv->lv_refcount++; rettv->v_type = VAR_LIST; @@ -11228,7 +11243,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) keys = replace_termcodes(keys, &keys_buf, TRUE, TRUE, FALSE); rhs = check_map(keys, mode, exact, FALSE, abbr, &mp, &buffer_local); - free(keys_buf); + xfree(keys_buf); if (!get_dict) { /* Return a string. */ @@ -11253,8 +11268,8 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) dict_add_nr_str(dict, "nowait", mp->m_nowait ? 1L : 0L, NULL); dict_add_nr_str(dict, "mode", 0L, mapmode); - free(lhs); - free(mapmode); + xfree(lhs); + xfree(mapmode); } } } @@ -11401,7 +11416,7 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type) match = FALSE; break; } - free(tofree); + xfree(tofree); str = echo_string(&li->li_tv, &tofree, strbuf, 0); if (str == NULL) break; @@ -11465,7 +11480,7 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type) } theend: - free(tofree); + xfree(tofree); p_cpo = save_cpo; } @@ -11699,7 +11714,7 @@ static int mkdir_recurse(char_u *dir, int prot) r = OK; else if (mkdir_recurse(updir, prot) == OK) r = vim_mkdir_emsg(updir, prot); - free(updir); + xfree(updir); return r; } @@ -12128,7 +12143,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv) --cnt; } - free(prev); + xfree(prev); fclose(fd); } @@ -12278,7 +12293,7 @@ static void f_remove(typval_T *argvars, typval_T *rettv) // Remove one item, return its value. vim_list_remove(l, item, item); *rettv = item->li_tv; - free(item); + xfree(item); } else { /* Remove range of items, return list with values. */ end = get_tv_number_chk(&argvars[2], &error); @@ -12421,8 +12436,8 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) buf[len] = NUL; if (limit-- == 0) { - free(p); - free(remain); + xfree(p); + xfree(remain); EMSG(_("E655: Too many symbolic links (cycle?)")); rettv->vval.v_string = NULL; goto fail; @@ -12440,7 +12455,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) cpy = remain; remain = remain ? concat_str(q - 1, remain) : (char_u *) xstrdup((char *)q - 1); - free(cpy); + xfree(cpy); q[-1] = NUL; } @@ -12455,10 +12470,10 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) cpy = xmalloc(STRLEN(p) + STRLEN(buf) + 1); STRCPY(cpy, p); STRCPY(path_tail(cpy), buf); - free(p); + xfree(p); p = cpy; } else { - free(p); + xfree(p); p = vim_strsave(buf); } } @@ -12471,14 +12486,14 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) len = q - remain - (*q != NUL); cpy = vim_strnsave(p, STRLEN(p) + len); STRNCAT(cpy, remain, len); - free(p); + xfree(p); p = cpy; /* Shorten "remain". */ if (*q != NUL) STRMOVE(remain, q - 1); else { - free(remain); + xfree(remain); remain = NULL; } } @@ -12496,7 +12511,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) || vim_ispathsep(p[2])))))) { /* Prepend "./". */ cpy = concat_str((char_u *)"./", p); - free(p); + xfree(p); p = cpy; } else if (!is_relative_to_current) { /* Strip leading "./". */ @@ -12527,7 +12542,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) #ifdef HAVE_READLINK fail: - free(buf); + xfree(buf); #endif rettv->v_type = VAR_STRING; } @@ -12742,7 +12757,7 @@ static void f_rpcnotify(typval_T *argvars, typval_T *rettv) } if (!channel_send_event((uint64_t)argvars[0].vval.v_number, - (char *)argvars[1].vval.v_string, + (char *)get_tv_string(&argvars[1]), args)) { EMSG2(_(e_invarg2), "Channel doesn't exist"); return; @@ -12809,7 +12824,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv) Error err = ERROR_INIT; Object result = channel_send_call((uint64_t)argvars[0].vval.v_number, - (char *)argvars[1].vval.v_string, + (char *)get_tv_string(&argvars[1]), args, &err); @@ -12873,13 +12888,17 @@ static void f_rpcstart(typval_T *argvars, typval_T *rettv) char **argv = xmalloc(sizeof(char_u *) * argvl); // Copy program name + if (argvars[0].vval.v_string == NULL || argvars[0].vval.v_string[0] == NUL) { + EMSG(_(e_api_spawn_failed)); + return; + } argv[0] = xstrdup((char *)argvars[0].vval.v_string); int i = 1; // Copy arguments to the vector if (argsl > 0) { for (listitem_T *arg = args->lv_first; arg != NULL; arg = arg->li_next) { - argv[i++] = xstrdup((char *)arg->li_tv.vval.v_string); + argv[i++] = xstrdup((char *) get_tv_string(&arg->li_tv)); } } @@ -13241,8 +13260,8 @@ do_searchpair ( if ((flags & SP_NOMOVE) || retval == 0) curwin->w_cursor = save_cursor; - free(pat2); - free(pat3); + xfree(pat2); + xfree(pat3); if (p_cpo == empty_option) p_cpo = save_cpo; else @@ -13277,6 +13296,69 @@ static void f_searchpos(typval_T *argvars, typval_T *rettv) list_append_number(rettv->vval.v_list, (varnumber_T)n); } +/// "serverlist()" function +static void f_serverlist(typval_T *argvars, typval_T *rettv) +{ + size_t n; + char **addrs = server_address_list(&n); + + // Copy addrs into a linked list. + list_T *l = rettv_list_alloc(rettv); + for (size_t i = 0; i < n; i++) { + listitem_T *li = listitem_alloc(); + li->li_tv.v_type = VAR_STRING; + li->li_tv.v_lock = 0; + li->li_tv.vval.v_string = (char_u *) addrs[i]; + list_append(l, li); + } + xfree(addrs); +} + +/// "serverstart()" function +static void f_serverstart(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; // Will hold the address of the new server. + + if (check_restricted() || check_secure()) { + return; + } + + // If the user supplied an address, use it, otherwise use a temp. + if (argvars[0].v_type != VAR_UNKNOWN) { + if (argvars[0].v_type != VAR_STRING) { + EMSG(_(e_invarg)); + return; + } else { + rettv->vval.v_string = vim_strsave(get_tv_string(argvars)); + } + } else { + rettv->vval.v_string = vim_tempname(); + } + + int result = server_start((char *) rettv->vval.v_string); + if (result != 0) { + EMSG2("Failed to start server: %s", uv_strerror(result)); + } +} + +/// "serverstop()" function +static void f_serverstop(typval_T *argvars, typval_T *rettv) +{ + if (check_restricted() || check_secure()) { + return; + } + + if (argvars[0].v_type == VAR_UNKNOWN || argvars[0].v_type != VAR_STRING) { + EMSG(_(e_invarg)); + return; + } + + if (argvars[0].vval.v_string) { + server_stop((char *) argvars[0].vval.v_string); + } +} + /* * "setbufvar()" function */ @@ -13314,7 +13396,7 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv) STRCPY(bufvarname, "b:"); STRCPY(bufvarname + 2, varname); set_var(bufvarname, varp, TRUE); - free(bufvarname); + xfree(bufvarname); } /* reset notion of buffer */ @@ -13617,8 +13699,8 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) free_lstval: while (curallocval > allocval) - free(*--curallocval); - free(lstval); + xfree(*--curallocval); + xfree(lstval); } else { char_u *strval = get_tv_string_chk(&argvars[1]); if (strval == NULL) { @@ -13658,7 +13740,7 @@ static void f_settabvar(typval_T *argvars, typval_T *rettv) STRCPY(tabvarname, "t:"); STRCPY(tabvarname + 2, varname); set_var(tabvarname, varp, TRUE); - free(tabvarname); + xfree(tabvarname); /* Restore current tabpage */ if (valid_tabpage(save_curtab)) @@ -13724,7 +13806,7 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off) STRCPY(winvarname, "w:"); STRCPY(winvarname + 2, varname); set_var(winvarname, varp, TRUE); - free(winvarname); + xfree(winvarname); } restore_win(save_curwin, save_curtab, TRUE); } @@ -13873,8 +13955,8 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero) res = si1->idx > si2->idx ? 1 : -1; } - free(tofree1); - free(tofree2); + xfree(tofree1); + xfree(tofree2); return res; } @@ -14080,7 +14162,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort) } } - free(ptrs); + xfree(ptrs); } } @@ -14350,7 +14432,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv) result_buf[0] = NUL; if (conv.vc_type != CONV_NONE) - free(p); + xfree(p); convert_setup(&conv, enc, p_enc); if (conv.vc_type != CONV_NONE) rettv->vval.v_string = string_convert(&conv, result_buf, NULL); @@ -14359,7 +14441,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv) /* Release conversion descriptors */ convert_setup(&conv, NULL, NULL); - free(enc); + xfree(enc); } } @@ -14847,7 +14929,7 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, char *res = NULL; int status = os_system(cmd, input, input_len, &res, &nread); - free(input); + xfree(input); set_vim_var_nr(VV_SHELL_ERROR, (long) status); @@ -14855,6 +14937,8 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, if (retlist) { // return an empty list when there's no output rettv_list_alloc(rettv); + } else { + rettv->vval.v_string = (char_u *) xstrdup(""); } return; } @@ -14868,7 +14952,7 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, rettv->vval.v_list->lv_refcount++; rettv->v_type = VAR_LIST; - free(res); + xfree(res); } else { // res may contain several NULs before the final terminating one. // Replace them with SOH (1) like in get_cmd_output() to avoid truncation. @@ -15026,7 +15110,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv) } tagname_free(&tn); - free(fname); + xfree(fname); } /* @@ -15077,8 +15161,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv) dict_T *job_opts = NULL; if (argvars[1].v_type == VAR_DICT) { job_opts = argvars[1].vval.v_dict; - common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit); - if (did_emsg) { + if (!common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit)) { return; } } @@ -15356,7 +15439,7 @@ static void f_undofile(typval_T *argvars, typval_T *rettv) if (ffname != NULL) rettv->vval.v_string = u_get_undo_file_name(ffname, FALSE); - free(ffname); + xfree(ffname); } } } @@ -16099,7 +16182,7 @@ static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u * STRCAT(retval, temp_result); STRCAT(retval, expr_end + 1); } - free(temp_result); + xfree(temp_result); *in_end = c1; /* put char back for error messages */ *expr_start = '{'; @@ -16111,7 +16194,7 @@ static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u * /* Further expansion! */ temp_result = make_expanded_name(retval, expr_start, expr_end, temp_result); - free(retval); + xfree(retval); retval = temp_result; } } @@ -16212,7 +16295,7 @@ set_vim_var_string ( * Will always be invoked when "v:progname" is set. */ vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; - free(vimvars[idx].vv_str); + xfree(vimvars[idx].vv_str); if (val == NULL) vimvars[idx].vv_str = NULL; else if (len == -1) @@ -16291,7 +16374,7 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) oldval = vimvars[VV_CMDARG].vv_str; if (eap == NULL) { - free(oldval); + xfree(oldval); vimvars[VV_CMDARG].vv_str = oldarg; return NULL; } @@ -16474,7 +16557,7 @@ void free_tv(typval_T *varp) func_unref(varp->vval.v_string); /*FALLTHROUGH*/ case VAR_STRING: - free(varp->vval.v_string); + xfree(varp->vval.v_string); break; case VAR_LIST: list_unref(varp->vval.v_list); @@ -16490,7 +16573,7 @@ void free_tv(typval_T *varp) EMSG2(_(e_intern2), "free_tv()"); break; } - free(varp); + xfree(varp); } } @@ -16504,12 +16587,12 @@ void clear_tv(typval_T *varp) case VAR_FUNC: func_unref(varp->vval.v_string); if (varp->vval.v_string != empty_string) { - free(varp->vval.v_string); + xfree(varp->vval.v_string); } varp->vval.v_string = NULL; break; case VAR_STRING: - free(varp->vval.v_string); + xfree(varp->vval.v_string); varp->vval.v_string = NULL; break; case VAR_LIST: @@ -16913,7 +16996,7 @@ static void vars_clear_ext(hashtab_T *ht, int free_val) if (free_val) clear_tv(&v->di_tv); if ((v->di_flags & DI_FLAGS_FIX) == 0) - free(v); + xfree(v); } } hash_clear(ht); @@ -16930,7 +17013,7 @@ static void delete_var(hashtab_T *ht, hashitem_T *hi) hash_remove(ht, hi); clear_tv(&di->di_tv); - free(di); + xfree(di); } /* @@ -16946,7 +17029,7 @@ static void list_one_var(dictitem_T *v, char_u *prefix, int *first) s = echo_string(&v->di_tv, &tofree, numbuf, current_copyID); list_one_var_a(prefix, v->di_key, v->di_tv.v_type, s == NULL ? (char_u *)"" : s, first); - free(tofree); + xfree(tofree); } static void @@ -17041,7 +17124,7 @@ set_var ( */ if (ht == &vimvarht) { if (v->di_tv.v_type == VAR_STRING) { - free(v->di_tv.vval.v_string); + xfree(v->di_tv.vval.v_string); if (copy || tv->v_type != VAR_STRING) v->di_tv.vval.v_string = vim_strsave(get_tv_string(tv)); else { @@ -17078,7 +17161,7 @@ set_var ( v = xmalloc(sizeof(dictitem_T) + STRLEN(varname)); STRCPY(v->di_key, varname); if (hash_add(ht, DI2HIKEY(v)) == FAIL) { - free(v); + xfree(v); return; } v->di_flags = 0; @@ -17369,7 +17452,7 @@ void ex_echo(exarg_T *eap) (void)msg_outtrans_len_attr(p, 1, echo_attr); } } - free(tofree); + xfree(tofree); } clear_tv(&rettv); arg = skipwhite(arg); @@ -17615,7 +17698,7 @@ void ex_function(exarg_T *eap) if (!aborting()) { if (!eap->skip && fudi.fd_newkey != NULL) EMSG2(_(e_dictkey), fudi.fd_newkey); - free(fudi.fd_newkey); + xfree(fudi.fd_newkey); return; } else eap->skip = TRUE; @@ -17731,7 +17814,7 @@ void ex_function(exarg_T *eap) for (int i = 0; i < newargs.ga_len; ++i) if (STRCMP(((char_u **)(newargs.ga_data))[i], arg) == 0) { EMSG2(_("E853: Duplicate argument name: %s"), arg); - free(arg); + xfree(arg); goto erret; } @@ -17837,7 +17920,7 @@ void ex_function(exarg_T *eap) /* between ":append" and "." and between ":python <<EOF" and "EOF" * don't check for ":endfunc". */ if (STRCMP(theline, skip_until) == 0) { - free(skip_until); + xfree(skip_until); skip_until = NULL; } } else { @@ -17848,7 +17931,7 @@ void ex_function(exarg_T *eap) /* Check for "endfunction". */ if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { if (line_arg == NULL) - free(theline); + xfree(theline); break; } @@ -17868,7 +17951,7 @@ void ex_function(exarg_T *eap) p = skipwhite(p + 1); } p += eval_fname_script(p); - free(trans_function_name(&p, TRUE, 0, NULL)); + xfree(trans_function_name(&p, TRUE, 0, NULL)); if (*skipwhite(p) == '(') { nesting++; indent += 2; @@ -17884,7 +17967,7 @@ void ex_function(exarg_T *eap) (p[2] == 's')))))) skip_until = vim_strsave((char_u *)"."); - /* Check for ":python <<EOF", ":tcl <<EOF", etc. */ + // Check for ":python <<EOF", ":lua <<EOF", etc. arg = skipwhite(skiptowhite(p)); if (arg[0] == '<' && arg[1] =='<' && ((p[0] == 'p' && p[1] == 'y' @@ -17917,7 +18000,7 @@ void ex_function(exarg_T *eap) * is an extra alloc/free. */ p = vim_strsave(theline); if (line_arg == NULL) - free(theline); + xfree(theline); theline = p; ((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline; @@ -17962,7 +18045,7 @@ void ex_function(exarg_T *eap) /* redefine existing function */ ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_lines)); - free(name); + xfree(name); name = NULL; } } else { @@ -17984,7 +18067,7 @@ void ex_function(exarg_T *eap) /* Give the function a sequential number. Can only be used with a * Funcref! */ - free(name); + xfree(name); sprintf(numbuf, "%d", ++func_nr); name = vim_strsave((char_u *)numbuf); } @@ -18004,7 +18087,7 @@ void ex_function(exarg_T *eap) if (slen > plen && fnamecmp(p, sourcing_name + slen - plen) == 0) j = OK; - free(scriptname); + xfree(scriptname); } if (j == FAIL) { EMSG2(_( @@ -18021,8 +18104,8 @@ void ex_function(exarg_T *eap) /* add new dict entry */ fudi.fd_di = dictitem_alloc(fudi.fd_newkey); if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL) { - free(fudi.fd_di); - free(fp); + xfree(fudi.fd_di); + xfree(fp); goto erret; } } else @@ -18059,9 +18142,9 @@ erret: ga_clear_strings(&newargs); ga_clear_strings(&newlines); ret_free: - free(skip_until); - free(fudi.fd_newkey); - free(name); + xfree(skip_until); + xfree(fudi.fd_newkey); + xfree(name); did_emsg |= saved_did_emsg; need_wait_return |= saved_wait_return; } @@ -18373,7 +18456,7 @@ static int function_exists(char_u *name) * "funcname(...", not "funcname!...". */ if (p != NULL && (*nm == NUL || *nm == '(')) n = translated_function_exists(p); - free(p); + xfree(p); return n; } @@ -18480,7 +18563,7 @@ void func_dump_profile(FILE *fd) prof_sort_list(fd, sorttab, st_len, "SELF", TRUE); } - free(sorttab); + xfree(sorttab); } static void @@ -18596,7 +18679,7 @@ script_autoload ( ret = TRUE; } - free(tofree); + xfree(tofree); return ret; } @@ -18686,14 +18769,14 @@ void ex_delfunction(exarg_T *eap) p = eap->arg; name = trans_function_name(&p, eap->skip, 0, &fudi); - free(fudi.fd_newkey); + xfree(fudi.fd_newkey); if (name == NULL) { if (fudi.fd_dict != NULL && !eap->skip) EMSG(_(e_funcref)); return; } if (!ends_excmd(*skipwhite(p))) { - free(name); + xfree(name); EMSG(_(e_trailing)); return; } @@ -18703,7 +18786,7 @@ void ex_delfunction(exarg_T *eap) if (!eap->skip) fp = find_func(name); - free(name); + xfree(name); if (!eap->skip) { if (fp == NULL) { @@ -18739,9 +18822,9 @@ static void func_free(ufunc_T *fp) /* clear this function */ ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_lines)); - free(fp->uf_tml_count); - free(fp->uf_tml_total); - free(fp->uf_tml_self); + xfree(fp->uf_tml_count); + xfree(fp->uf_tml_total); + xfree(fp->uf_tml_self); /* remove the function from the function hashtable */ hi = hash_find(&func_hashtab, UF2HIKEY(fp)); @@ -18750,7 +18833,7 @@ static void func_free(ufunc_T *fp) else hash_remove(&func_hashtab, hi); - free(fp); + xfree(fp); } /* @@ -18987,7 +19070,7 @@ call_user_func ( s = buf; } msg_puts(s); - free(tofree); + xfree(tofree); } } } @@ -19074,7 +19157,7 @@ call_user_func ( s = buf; } smsg((char_u *)_("%s returning %s"), sourcing_name, s); - free(tofree); + xfree(tofree); } } msg_puts((char_u *)"\n"); /* don't overwrite this either */ @@ -19083,7 +19166,7 @@ call_user_func ( --no_wait_return; } - free(sourcing_name); + xfree(sourcing_name); sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; current_SID = save_current_SID; @@ -19180,7 +19263,7 @@ free_funccal ( for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next) clear_tv(&li->li_tv); - free(fc); + xfree(fc); } /* @@ -19311,7 +19394,7 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) clear_tv(current_funccal->rettv); *current_funccal->rettv = *(typval_T *)rettv; if (!is_cmd) - free(rettv); + xfree(rettv); } } @@ -19345,7 +19428,7 @@ char_u *get_return_cmd(void *rettv) STRNCPY(IObuff + 8, s, IOSIZE - 8); if (STRLEN(s) + 8 >= IOSIZE) STRCPY(IObuff + IOSIZE - 4, "..."); - free(tofree); + xfree(tofree); return vim_strsave(IObuff); } @@ -19533,16 +19616,16 @@ int read_viminfo_varlist(vir_T *virp, int writing) * string. */ tv.v_type = VAR_STRING; else { - free(tv.vval.v_string); + xfree(tv.vval.v_string); tv = *etv; - free(etv); + xfree(etv); } } set_var(virp->vir_line + 1, &tv, FALSE); if (tv.v_type == VAR_STRING) - free(tv.vval.v_string); + xfree(tv.vval.v_string); else if (tv.v_type == VAR_DICT || tv.v_type == VAR_LIST) clear_tv(&tv); } @@ -19588,7 +19671,7 @@ void write_viminfo_varlist(FILE *fp) p = echo_string(&this_var->di_tv, &tofree, numbuf, 0); if (p != NULL) viminfo_writestring(fp, p); - free(tofree); + xfree(tofree); } } } @@ -19626,10 +19709,10 @@ int store_session_globals(FILE *fd) (this_var->di_tv.v_type == VAR_STRING) ? '"' : ' ') < 0) || put_eol(fd) == FAIL) { - free(p); + xfree(p); return FAIL; } - free(p); + xfree(p); } else if (this_var->di_tv.v_type == VAR_FLOAT && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) { float_T f = this_var->di_tv.vval.v_float; @@ -19660,7 +19743,7 @@ void last_set_msg(scid_T scriptID) verbose_enter(); MSG_PUTS(_("\n\tLast set from ")); MSG_PUTS(p); - free(p); + xfree(p); verbose_leave(); } } @@ -19740,7 +19823,7 @@ repeat: #endif ) { *fnamep = expand_env_save(*fnamep); - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; @@ -19760,7 +19843,7 @@ repeat: /* FullName_save() is slow, don't use it when not needed. */ if (*p != NUL || !vim_isAbsName(*fnamep)) { *fnamep = FullName_save(*fnamep, *p != NUL); - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; @@ -19770,7 +19853,7 @@ repeat: if (os_isdir(*fnamep)) { /* Make room for one or two extra characters. */ *fnamep = vim_strnsave(*fnamep, (int)STRLEN(*fnamep) + 2); - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; @@ -19806,7 +19889,7 @@ repeat: if (s != NULL) { *fnamep = s; if (pbuf != NULL) { - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = pbuf; pbuf = NULL; } @@ -19817,11 +19900,11 @@ repeat: if (*dirname == '~') { s = vim_strsave(dirname); *fnamep = s; - free(*bufp); + xfree(*bufp); *bufp = s; } } - free(pbuf); + xfree(pbuf); } } @@ -19839,7 +19922,7 @@ repeat: *fnamelen = (int)(tail - *fnamep); if (*fnamelen == 0) { /* Result is empty. Turn it into "." to make ":cd %:h" work. */ - free(*bufp); + xfree(*bufp); *bufp = *fnamep = tail = vim_strsave((char_u *)"."); *fnamelen = 1; } else { @@ -19924,13 +20007,13 @@ repeat: s = do_string_sub(str, pat, sub, flags); *fnamep = s; *fnamelen = (int)STRLEN(s); - free(*bufp); + xfree(*bufp); *bufp = s; didit = TRUE; - free(sub); - free(str); + xfree(sub); + xfree(str); } - free(pat); + xfree(pat); } /* after using ":s", repeat all the modifiers */ if (didit) @@ -19940,7 +20023,7 @@ repeat: if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S') { p = vim_strsave_shellescape(*fnamep, false, false); - free(*bufp); + xfree(*bufp); *bufp = *fnamep = p; *fnamelen = (int)STRLEN(p); *usedlen += 2; @@ -20051,27 +20134,27 @@ static inline JobOptions common_job_options(char **argv, ufunc_T *on_stdout, return opts; } -static inline void common_job_callbacks(dict_T *vopts, ufunc_T **on_stdout, - ufunc_T **on_stderr, ufunc_T **on_exit) +/// Return true/false on success/failure. +static inline bool common_job_callbacks(dict_T *vopts, ufunc_T **on_stdout, + ufunc_T **on_stderr, ufunc_T **on_exit) { - *on_stdout = get_dict_callback(vopts, "on_stdout"); - *on_stderr = get_dict_callback(vopts, "on_stderr"); - *on_exit = get_dict_callback(vopts, "on_exit"); - if (did_emsg) { - if (*on_stdout) { - user_func_unref(*on_stdout); - } - if (*on_stderr) { - user_func_unref(*on_stderr); - } - if (*on_exit) { - user_func_unref(*on_exit); - } - return; + if (get_dict_callback(vopts, "on_stdout", on_stdout) + && get_dict_callback(vopts, "on_stderr", on_stderr) + && get_dict_callback(vopts, "on_exit", on_exit)) { + vopts->internal_refcount++; + vopts->dv_refcount++; + return true; } - - vopts->internal_refcount++; - vopts->dv_refcount++; + if (*on_stdout) { + user_func_unref(*on_stdout); + } + if (*on_stderr) { + user_func_unref(*on_stderr); + } + if (*on_exit) { + user_func_unref(*on_exit); + } + return false; } static inline Job *common_job_start(JobOptions opts, typval_T *rettv) @@ -20083,7 +20166,7 @@ static inline Job *common_job_start(JobOptions opts, typval_T *rettv) if (rettv->vval.v_number <= 0) { if (rettv->vval.v_number == 0) { EMSG(_(e_jobtblfull)); - free(opts.term_name); + xfree(opts.term_name); free_term_job_data(data); } else { EMSG(_(e_jobexe)); @@ -20109,7 +20192,7 @@ static inline void free_term_job_data(TerminalJobData *data) { data->self->internal_refcount--; dict_unref(data->self); } - free(data); + xfree(data); } static inline bool is_user_job(Job *job) @@ -20126,7 +20209,7 @@ static inline bool is_user_job(Job *job) static inline void push_job_event(Job *job, ufunc_T *callback, const char *type, char *data, size_t count, int status) { - JobEvent *event_data = kmp_alloc(JobEventPool, job_event_pool); + JobEvent *event_data = xmalloc(sizeof(JobEvent)); event_data->received = NULL; if (data) { event_data->received = list_alloc(); @@ -20161,7 +20244,7 @@ static inline void push_job_event(Job *job, ufunc_T *callback, event_push((Event) { .handler = on_job_event, .data = event_data - }, defer_job_callbacks); + }, !disable_job_defer); } static void on_job_stdout(RStream *rstream, void *job, bool eof) @@ -20220,7 +20303,7 @@ static void on_job_exit(Job *job, int status, void *d) static void term_write(char *buf, size_t size, void *data) { Job *job = ((TerminalJobData *)data)->job; - WBuffer *wbuf = wstream_new_buffer(xmemdup(buf, size), size, 1, free); + WBuffer *wbuf = wstream_new_buffer(xmemdup(buf, size), size, 1, xfree); job_write(job, wbuf); } @@ -20290,11 +20373,11 @@ static void on_job_event(Event event) clear_tv(&rettv); end: - kmp_free(JobEventPool, job_event_pool, ev); if (!ev->received) { // exit event, safe to free job data now term_job_data_decref(ev->data); } + xfree(ev); } static void script_host_eval(char *name, typval_T *argvars, typval_T *rettv) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c686c5effa..c57861282d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -533,9 +533,9 @@ void ex_sort(exarg_T *eap) beginline(BL_WHITE | BL_FIX); sortend: - free(nrs); - free(sortbuf1); - free(sortbuf2); + xfree(nrs); + xfree(sortbuf1); + xfree(sortbuf2); vim_regfree(regmatch.regprog); if (got_int) EMSG(_(e_interr)); @@ -698,7 +698,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) for (extra = 0, l = line1; l <= line2; l++) { str = vim_strsave(ml_get(l + extra)); ml_append(dest + l - line1, str, (colnr_T)0, FALSE); - free(str); + xfree(str); if (dest < line1) extra++; } @@ -804,7 +804,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) * ml_append() */ p = vim_strsave(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); - free(p); + xfree(p); /* situation 2: skip already copied lines */ if (line1 == n) @@ -827,7 +827,7 @@ static char_u *prevcmd = NULL; /* the previous command */ #if defined(EXITFREE) void free_prev_shellcmd(void) { - free(prevcmd); + xfree(prevcmd); } #endif @@ -878,7 +878,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) if (ins_prevcmd) { if (prevcmd == NULL) { EMSG(_(e_noprev)); - free(newcmd); + xfree(newcmd); return; } len += (int)STRLEN(prevcmd); @@ -891,7 +891,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) STRCAT(t, prevcmd); p = t + STRLEN(t); STRCAT(t, trailarg); - free(newcmd); + xfree(newcmd); newcmd = t; /* @@ -914,7 +914,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) } } while (trailarg != NULL); - free(prevcmd); + xfree(prevcmd); prevcmd = newcmd; if (bangredo) { /* put cmd in redo buffer for ! command */ @@ -924,7 +924,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); AppendToRedobuffLit(cmd, -1); - free(cmd); + xfree(cmd); AppendToRedobuff((char_u *)"\n"); bangredo = FALSE; } @@ -955,7 +955,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); } if (free_newcmd) - free(newcmd); + xfree(newcmd); } /* @@ -1076,7 +1076,7 @@ do_filter ( if (do_out) { if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) { - free(cmd_buf); + xfree(cmd_buf); goto error; } redraw_curbuf_later(VALID); @@ -1100,7 +1100,7 @@ do_filter ( redraw_later_clear(); wait_return(FALSE); } - free(cmd_buf); + xfree(cmd_buf); did_check_timestamps = FALSE; need_check_timestamps = TRUE; @@ -1197,8 +1197,8 @@ filterend: os_remove((char *)itmp); if (otmp != NULL) os_remove((char *)otmp); - free(itmp); - free(otmp); + xfree(itmp); + xfree(otmp); } /* @@ -1448,7 +1448,7 @@ read_viminfo ( verbose_leave(); } - free(fname); + xfree(fname); if (fp == NULL) return FAIL; @@ -1550,7 +1550,7 @@ void write_viminfo(char_u *file, int forceit) * write the viminfo file then. */ if (*wp == 'a') { - free(tempname); + xfree(tempname); tempname = NULL; break; } @@ -1586,7 +1586,7 @@ void write_viminfo(char_u *file, int forceit) * "normal" temp file. */ if (fp_out == NULL) { - free(tempname); + xfree(tempname); if ((tempname = vim_tempname()) != NULL) fp_out = mch_fopen((char *)tempname, WRITEBIN); } @@ -1639,8 +1639,8 @@ void write_viminfo(char_u *file, int forceit) } end: - free(fname); - free(tempname); + xfree(fname); + xfree(tempname); } /* @@ -1721,7 +1721,7 @@ static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags) && (flags & (VIF_WANT_MARKS | VIF_GET_OLDFILES | VIF_FORCEIT))) copy_viminfo_marks(&vir, fp_out, count, eof, flags); - free(vir.vir_line); + xfree(vir.vir_line); if (vir.vir_conv.vc_type != CONV_NONE) convert_setup(&vir.vir_conv, NULL, NULL); } @@ -1886,7 +1886,7 @@ viminfo_readstring ( if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) { d = string_convert(&virp->vir_conv, retval, NULL); if (d != NULL) { - free(retval); + xfree(retval); retval = d; } } @@ -2000,8 +2000,8 @@ int rename_buffer(char_u *new_fname) if (buf != NULL && !cmdmod.keepalt) curwin->w_alt_fnum = buf->b_fnum; } - free(fname); - free(sfname); + xfree(fname); + xfree(sfname); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); /* Change directories when the 'acd' option is set. */ do_autochdir(); @@ -2206,7 +2206,7 @@ int do_write(exarg_T *eap) } theend: - free(free_fname); + xfree(free_fname); return retval; } @@ -2279,7 +2279,7 @@ check_overwrite ( copy_option_part(&p, dir, MAXPATHL, ","); } swapname = makeswapname(fname, ffname, curbuf, dir); - free(dir); + xfree(dir); if (os_file_exists(swapname)) { if (p_confirm || cmdmod.confirm) { char_u buff[DIALOG_MSG_SIZE]; @@ -2289,18 +2289,18 @@ check_overwrite ( swapname); if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) { - free(swapname); + xfree(swapname); return FAIL; } eap->forceit = TRUE; } else { EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), swapname); - free(swapname); + xfree(swapname); return FAIL; } } - free(swapname); + xfree(swapname); } } return OK; @@ -2486,7 +2486,7 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum, retval = 1; /* error encountered */ theend: - free(free_me); + xfree(free_me); return retval; } @@ -2623,7 +2623,7 @@ do_ecmd ( } set_vim_var_string(VV_SWAPCOMMAND, p, -1); did_set_swapcommand = TRUE; - free(p); + xfree(p); } /* @@ -2712,7 +2712,7 @@ do_ecmd ( goto theend; } if (aborting()) { /* autocmds may abort script processing */ - free(new_name); + xfree(new_name); goto theend; } if (buf == curbuf) /* already in new buffer */ @@ -2737,7 +2737,7 @@ do_ecmd ( } if (aborting()) { /* autocmds may abort script processing */ - free(new_name); + xfree(new_name); goto theend; } /* Be careful again, like above. */ @@ -2775,7 +2775,7 @@ do_ecmd ( did_get_winopts = TRUE; } - free(new_name); + xfree(new_name); au_new_curbuf = NULL; } else ++curbuf->b_nwindows; @@ -2849,7 +2849,7 @@ do_ecmd ( delbuf_msg(new_name); /* frees new_name */ goto theend; } - free(new_name); + xfree(new_name); /* If autocommands change buffers under our fingers, forget about * re-editing the file. Should do the buf_clear_file(), but perhaps @@ -3040,7 +3040,7 @@ do_ecmd ( theend: if (did_set_swapcommand) set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); - free(free_fname); + xfree(free_fname); return retval; } @@ -3048,7 +3048,7 @@ static void delbuf_msg(char_u *name) { EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), name == NULL ? (char_u *)"" : name); - free(name); + xfree(name); au_new_curbuf = NULL; } @@ -3140,7 +3140,7 @@ void ex_append(exarg_T *eap) if ((p[0] == '.' && p[1] == NUL) || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) == FAIL)) { - free(theline); + xfree(theline); break; } @@ -3152,7 +3152,7 @@ void ex_append(exarg_T *eap) ml_append(lnum, theline, (colnr_T)0, FALSE); appended_lines_mark(lnum, 1L); - free(theline); + xfree(theline); ++lnum; if (empty) { @@ -3481,7 +3481,7 @@ void do_sub(exarg_T *eap) } sub = old_sub; } else { - free(old_sub); + xfree(old_sub); old_sub = vim_strsave(sub); } } @@ -3742,7 +3742,7 @@ void do_sub(exarg_T *eap) lnum += regmatch.startpos[0].lnum; sub_firstlnum += regmatch.startpos[0].lnum; nmatch -= regmatch.startpos[0].lnum; - free(sub_firstline); + xfree(sub_firstline); sub_firstline = NULL; } @@ -3846,7 +3846,7 @@ void do_sub(exarg_T *eap) resp = getexmodeline('?', NULL, 0); if (resp != NULL) { typed = *resp; - free(resp); + xfree(resp); } } else { char_u *orig_line = NULL; @@ -4061,7 +4061,7 @@ void do_sub(exarg_T *eap) * line and continue in that one. */ if (nmatch > 1) { sub_firstlnum += nmatch - 1; - free(sub_firstline); + xfree(sub_firstline); sub_firstline = vim_strsave(ml_get(sub_firstlnum)); /* When going beyond the last line, stop substituting. */ if (sub_firstlnum <= line2) @@ -4076,7 +4076,7 @@ void do_sub(exarg_T *eap) if (skip_match) { /* Already hit end of the buffer, sub_firstlnum is one * less than what it ought to be. */ - free(sub_firstline); + xfree(sub_firstline); sub_firstline = vim_strsave((char_u *)""); copycol = 0; } @@ -4204,7 +4204,7 @@ skip: } sub_firstlnum = lnum; - free(sub_firstline); /* free the temp buffer */ + xfree(sub_firstline); /* free the temp buffer */ sub_firstline = new_start; new_start = NULL; matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; @@ -4234,8 +4234,8 @@ skip: if (did_sub) ++sub_nlines; - free(new_start); /* for when substitute was cancelled */ - free(sub_firstline); /* free the copy of the original line */ + xfree(new_start); /* for when substitute was cancelled */ + xfree(sub_firstline); /* free the copy of the original line */ sub_firstline = NULL; } @@ -4250,7 +4250,7 @@ skip: changed_lines(first_line, 0, last_line - i, i); } - free(sub_firstline); /* may have to free allocated copy of the line */ + xfree(sub_firstline); /* may have to free allocated copy of the line */ /* ":s/pat//n" doesn't move the cursor */ if (do_count) @@ -4510,7 +4510,7 @@ void global_exe(char_u *cmd) int read_viminfo_sub_string(vir_T *virp, int force) { if (force) - free(old_sub); + xfree(old_sub); if (force || old_sub == NULL) old_sub = viminfo_readstring(virp, 1, TRUE); return viminfo_readline(virp); @@ -4527,7 +4527,7 @@ void write_viminfo_sub_string(FILE *fp) #if defined(EXITFREE) void free_old_sub(void) { - free(old_sub); + xfree(old_sub); } #endif @@ -4739,7 +4739,7 @@ void ex_help(exarg_T *eap) curwin->w_alt_fnum = alt_fnum; erret: - free(tag); + xfree(tag); } @@ -5003,7 +5003,7 @@ int find_help_tags(char_u *arg, int *num_matches, char_u ***matches, int keep_la sizeof(char_u *), help_compare); /* Delete more than TAG_MANY to reduce the size of the listing. */ while (*num_matches > TAG_MANY) - free((*matches)[--*num_matches]); + xfree((*matches)[--*num_matches]); } return OK; } @@ -5165,7 +5165,7 @@ void fix_help_buffer(void) if (fnamecmp(e1, ".txt") != 0 && fnamecmp(e1, fname + 4) != 0) { /* Not .txt and not .abx, remove it. */ - free(fnames[i1]); + xfree(fnames[i1]); fnames[i1] = NULL; continue; } @@ -5174,7 +5174,7 @@ void fix_help_buffer(void) if (fnamecmp(e1, ".txt") == 0 && fnamecmp(e2, fname + 4) == 0) { /* use .abx instead of .txt */ - free(fnames[i1]); + xfree(fnames[i1]); fnames[i1] = NULL; } } @@ -5234,7 +5234,7 @@ void fix_help_buffer(void) ml_append(lnum, cp, (colnr_T)0, FALSE); if (cp != IObuff) - free(cp); + xfree(cp); ++lnum; } fclose(fd); @@ -5243,7 +5243,7 @@ void fix_help_buffer(void) } } if (mustfree) - free(rt); + xfree(rt); } break; } @@ -5310,7 +5310,7 @@ void ex_helptags(exarg_T *eap) EW_FILE|EW_SILENT) == FAIL || filecount == 0) { EMSG2("E151: No match: %s", NameBuff); - free(dirname); + xfree(dirname); return; } @@ -5372,7 +5372,7 @@ void ex_helptags(exarg_T *eap) ga_clear(&ga); FreeWild(filecount, files); - free(dirname); + xfree(dirname); } static void @@ -5722,7 +5722,7 @@ void ex_sign(exarg_T *eap) next_sign_typenr = 1; if (next_sign_typenr == start) { - free(sp); + xfree(sp); EMSG(_("E612: Too many signs defined")); return; } @@ -5755,7 +5755,7 @@ void ex_sign(exarg_T *eap) if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; - free(sp->sn_icon); + xfree(sp->sn_icon); sp->sn_icon = vim_strnsave(arg, (int)(p - arg)); backslash_halve(sp->sn_icon); } @@ -5794,7 +5794,7 @@ void ex_sign(exarg_T *eap) return; } - free(sp->sn_text); + xfree(sp->sn_text); /* Allocate one byte more if we need to pad up * with a space. */ len = (int)(p - arg + ((cells == 1) ? 1 : 0)); @@ -5983,7 +5983,7 @@ void ex_sign(exarg_T *eap) sprintf((char *)cmd, "e +%" PRId64 " %s", (int64_t)lnum, buf->b_fname); do_cmdline_cmd(cmd); - free(cmd); + xfree(cmd); } foldOpenCursor(); @@ -6076,14 +6076,14 @@ static void sign_list_defined(sign_T *sp) */ static void sign_undefine(sign_T *sp, sign_T *sp_prev) { - free(sp->sn_name); - free(sp->sn_icon); - free(sp->sn_text); + xfree(sp->sn_name); + xfree(sp->sn_icon); + xfree(sp->sn_text); if (sp_prev == NULL) first_sign = sp->sn_next; else sp_prev->sn_next = sp->sn_next; - free(sp); + xfree(sp); } /* diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index cd1b066fdd..463cc794c7 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -278,11 +278,11 @@ void do_debug(char_u *cmd) DOCMD_VERBOSE|DOCMD_EXCRESET); debug_break_level = n; - free(cmdline); + xfree(cmdline); } lines_left = Rows - 1; } - free(cmdline); + xfree(cmdline); --RedrawingDisabled; --no_wait_return; @@ -491,12 +491,12 @@ dbg_parsearg ( if (q == NULL) return FAIL; p = expand_env_save(q); - free(q); + xfree(q); if (p == NULL) return FAIL; if (*p != '*') { bp->dbg_name = fix_fname(p); - free(p); + xfree(p); } else bp->dbg_name = p; } @@ -526,10 +526,10 @@ void ex_breakadd(exarg_T *eap) pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); if (pat != NULL) { bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); - free(pat); + xfree(pat); } if (pat == NULL || bp->dbg_prog == NULL) - free(bp->dbg_name); + xfree(bp->dbg_name); else { if (bp->dbg_lnum == 0) /* default line number is 1 */ bp->dbg_lnum = 1; @@ -598,14 +598,14 @@ void ex_breakdel(exarg_T *eap) best_lnum = bpi->dbg_lnum; } } - free(bp->dbg_name); + xfree(bp->dbg_name); } if (todel < 0) EMSG2(_("E161: Breakpoint not found: %s"), eap->arg); else { while (!GA_EMPTY(gap)) { - free(DEBUGGY(gap, todel).dbg_name); + xfree(DEBUGGY(gap, todel).dbg_name); vim_regfree(DEBUGGY(gap, todel).dbg_prog); --gap->ga_len; if (todel < gap->ga_len) @@ -727,7 +727,7 @@ debuggy_find ( } } if (name != fname) - free(name); + xfree(name); return lnum; } @@ -759,8 +759,8 @@ void ex_profile(exarg_T *eap) e = skipwhite(e); if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) { - free(profile_fname); - profile_fname = vim_strsave(e); + xfree(profile_fname); + profile_fname = expand_env_save_opt(e, true); do_profiling = PROF_YES; profile_set_wait(profile_zero()); set_vim_var_nr(VV_PROFILING, 1L); @@ -1293,7 +1293,7 @@ buf_found: set_curbuf(buf, DOBUF_GOTO); theend: - free(bufnrs); + xfree(bufnrs); return ret; } @@ -1450,7 +1450,7 @@ do_arglist ( break; regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) { - free(p); + xfree(p); break; } @@ -1459,7 +1459,7 @@ do_arglist ( if (vim_regexec(®match, alist_name(&ARGLIST[match]), (colnr_T)0)) { didone = TRUE; - free(ARGLIST[match].ae_fname); + xfree(ARGLIST[match].ae_fname); memmove(ARGLIST + match, ARGLIST + match + 1, (ARGCOUNT - match - 1) * sizeof(aentry_T)); --ALIST(curwin)->al_ga.ga_len; @@ -1469,7 +1469,7 @@ do_arglist ( } vim_regfree(regmatch.regprog); - free(p); + xfree(p); if (!didone) EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); } @@ -1487,7 +1487,7 @@ do_arglist ( if (what == AL_ADD) { (void)alist_add_list(exp_count, exp_files, after); - free(exp_files); + xfree(exp_files); } else /* what == AL_SET */ alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); } @@ -1683,7 +1683,7 @@ void do_argfile(exarg_T *eap, int argn) if (P_HID(curbuf)) { p = fix_fname(alist_name(&ARGLIST[argn])); other = otherfile(p); - free(p); + xfree(p); } if ((!P_HID(curbuf) || !other) && check_changed(curbuf, CCGD_AW @@ -1793,7 +1793,7 @@ void ex_argdelete(exarg_T *eap) EMSG(_(e_invarg)); else { for (int i = eap->line1; i <= eap->line2; ++i) - free(ARGLIST[i - 1].ae_fname); + xfree(ARGLIST[i - 1].ae_fname); memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T))); ALIST(curwin)->al_ga.ga_len -= n; @@ -1858,7 +1858,7 @@ void ex_listdo(exarg_T *eap) set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); do_argfile(eap, i); set_option_value((char_u *)"shm", 0L, p_shm_save, 0); - free(p_shm_save); + xfree(p_shm_save); } if (curwin->w_arg_idx != i) break; @@ -1915,7 +1915,7 @@ void ex_listdo(exarg_T *eap) set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); set_option_value((char_u *)"shm", 0L, p_shm_save, 0); - free(p_shm_save); + xfree(p_shm_save); /* If autocommands took us elsewhere, quit here */ if (curbuf->b_fnum != next_fnum) @@ -2011,7 +2011,7 @@ void ex_compiler(exarg_T *eap) sprintf((char *)buf, "compiler/%s.vim", eap->arg); if (source_runtime(buf, TRUE) == FAIL) EMSG2(_("E666: compiler not supported: %s"), eap->arg); - free(buf); + xfree(buf); do_cmdline_cmd((char_u *)":delcommand CompilerSet"); @@ -2025,7 +2025,7 @@ void ex_compiler(exarg_T *eap) if (old_cur_comp != NULL) { set_internal_string_var((char_u *)"g:current_compiler", old_cur_comp); - free(old_cur_comp); + xfree(old_cur_comp); } else do_unlet((char_u *)"g:current_compiler", TRUE); } @@ -2135,8 +2135,8 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, } } } - free(buf); - free(rtp_copy); + xfree(buf); + xfree(rtp_copy); if (p_verbose > 0 && !did_one && name != NULL) { verbose_enter(); smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name); @@ -2273,7 +2273,7 @@ do_source ( if (p == NULL) return retval; fname_exp = fix_fname(p); - free(p); + xfree(p); if (fname_exp == NULL) return retval; if (os_isdir(fname_exp)) { @@ -2391,7 +2391,7 @@ do_source ( p = string_convert(&cookie.conv, firstline + 3, NULL); if (p == NULL) p = vim_strsave(firstline + 3); - free(firstline); + xfree(firstline); firstline = p; } @@ -2518,12 +2518,12 @@ do_source ( if (l_do_profiling == PROF_YES) prof_child_exit(&wait_start); /* leaving a child now */ fclose(cookie.fp); - free(cookie.nextline); - free(firstline); + xfree(cookie.nextline); + xfree(firstline); convert_setup(&cookie.conv, NULL, NULL); theend: - free(fname_exp); + xfree(fname_exp); return retval; } @@ -2577,7 +2577,7 @@ char_u *get_scriptname(scid_T id) # if defined(EXITFREE) void free_scriptnames() { -# define FREE_SCRIPTNAME(item) free((item)->sn_name) +# define FREE_SCRIPTNAME(item) xfree((item)->sn_name) GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME); } # endif @@ -2636,7 +2636,7 @@ char_u *getsourceline(int c, void *cookie, int indent) ga_concat(&ga, line); ga_concat(&ga, p + 1); for (;; ) { - free(sp->nextline); + xfree(sp->nextline); sp->nextline = get_one_sourceline(sp); if (sp->nextline == NULL) break; @@ -2651,7 +2651,7 @@ char_u *getsourceline(int c, void *cookie, int indent) ga_concat(&ga, p + 1); } ga_append(&ga, NUL); - free(line); + xfree(line); line = ga.ga_data; } } @@ -2662,7 +2662,7 @@ char_u *getsourceline(int c, void *cookie, int indent) /* Convert the encoding of the script line. */ s = string_convert(&sp->conv, line, NULL); if (s != NULL) { - free(line); + xfree(line); line = s; } } @@ -2771,7 +2771,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp) if (have_read) return (char_u *)ga.ga_data; - free(ga.ga_data); + xfree(ga.ga_data); return NULL; } @@ -2874,7 +2874,7 @@ void ex_scriptencoding(exarg_T *eap) convert_setup(&sp->conv, name, p_enc); if (name != eap->arg) - free(name); + xfree(name); } /* @@ -3192,7 +3192,7 @@ static char_u **find_locales(void) GA_APPEND(char_u *, &locales_ga, loc); loc = (char_u *)strtok(NULL, "\n"); } - free(locale_a); + xfree(locale_a); // Guarantee that .ga_data is NULL terminated ga_grow(&locales_ga, 1); ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; @@ -3205,8 +3205,8 @@ void free_locales(void) int i; if (locales != NULL) { for (i = 0; locales[i] != NULL; i++) - free(locales[i]); - free(locales); + xfree(locales[i]); + xfree(locales); locales = NULL; } } @@ -3260,7 +3260,7 @@ static void script_host_execute(char *name, exarg_T *eap) (void)eval_call_provider(name, "execute", args); } - free(script); + xfree(script); } static void script_host_execute_file(char *name, exarg_T *eap) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index cf22477dc9..f7f6b84e6e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -104,7 +104,7 @@ typedef struct { linenr_T lnum; /* sourcing_lnum of the line */ } wcmd_T; -#define FREE_WCMD(wcmd) free((wcmd)->line) +#define FREE_WCMD(wcmd) xfree((wcmd)->line) /* * Structure used to store info for line position in a while or for loop. @@ -458,7 +458,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) { /* Each '|' separated command is stored separately in lines_ga, to * be able to jump to it. Don't use next_cmdline now. */ - free(cmdline_copy); + xfree(cmdline_copy); cmdline_copy = NULL; /* Check if a function has returned or, unless it has an unclosed @@ -554,7 +554,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, * Keep the first typed line. Clear it when more lines are typed. */ if (flags & DOCMD_KEEPLINE) { - free(repeat_cmdline); + xfree(repeat_cmdline); if (count == 0) repeat_cmdline = vim_strsave(next_cmdline); else @@ -628,7 +628,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, current_line = cmd_loop_cookie.current_line; if (next_cmdline == NULL) { - free(cmdline_copy); + xfree(cmdline_copy); cmdline_copy = NULL; /* * If the command was typed, remember it for the ':' register. @@ -636,7 +636,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, */ if (getline_equal(fgetline, cookie, getexline) && new_last_cmdline != NULL) { - free(last_cmdline); + xfree(last_cmdline); last_cmdline = new_last_cmdline; new_last_cmdline = NULL; } @@ -777,7 +777,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, || cstack.cs_idx >= 0 || (flags & DOCMD_REPEAT))); - free(cmdline_copy); + xfree(cmdline_copy); did_emsg_syntax = FALSE; GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD); @@ -875,15 +875,15 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, do { next = messages->next; emsg(messages->msg); - free(messages->msg); - free(messages); + xfree(messages->msg); + xfree(messages); messages = next; } while (messages != NULL); } else if (p != NULL) { emsg(p); - free(p); + xfree(p); } - free(sourcing_name); + xfree(sourcing_name); sourcing_name = saved_sourcing_name; sourcing_lnum = saved_sourcing_lnum; } @@ -1459,7 +1459,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, } p = vim_strnsave(ea.cmd, p - ea.cmd); int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); - free(p); + xfree(p); if (ret && !aborting()) { p = find_command(&ea, NULL); } @@ -3275,7 +3275,7 @@ void ex_ni(exarg_T *eap) { if (!eap->skip) eap->errmsg = (char_u *)N_( - "E319: Sorry, the command is not available in this version"); + "E319: The command is not available in this version"); } /// Stub function for script command which is Not Implemented. NI! @@ -3285,7 +3285,7 @@ static void ex_script_ni(exarg_T *eap) if (!eap->skip) ex_ni(eap); else - free(script_get(eap, eap->arg)); + xfree(script_get(eap, eap->arg)); } /* @@ -3400,7 +3400,7 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep) msg_make(p); /* 'eap->cmd' is not set here, because it is not used at CMD_make */ - free(*cmdlinep); + xfree(*cmdlinep); *cmdlinep = new_cmdline; p = new_cmdline; } @@ -3464,7 +3464,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) char_u *l = repl; repl = expand_env_save(repl); - free(l); + xfree(l); } /* Need to escape white space et al. with a backslash. @@ -3500,7 +3500,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) for (l = repl; *l; ++l) if (vim_strchr(ESCAPE_CHARS, *l) != NULL) { l = vim_strsave_escaped(repl, ESCAPE_CHARS); - free(repl); + xfree(repl); repl = l; break; } @@ -3512,12 +3512,12 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) char_u *l; l = vim_strsave_escaped(repl, (char_u *)"!"); - free(repl); + xfree(repl); repl = l; } p = repl_cmdline(eap, p, srclen, repl, cmdlinep); - free(repl); + xfree(repl); } /* @@ -3595,7 +3595,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) if (p != NULL) { (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), p, cmdlinep); - free(p); + xfree(p); } } } @@ -3649,7 +3649,7 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, int srclen, char_u *repl, eap->arg = new_cmdline + (eap->arg - *cmdlinep); if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != dollar_command) eap->do_ecmd_cmd = new_cmdline + (eap->do_ecmd_cmd - *cmdlinep); - free(*cmdlinep); + xfree(*cmdlinep); *cmdlinep = new_cmdline; return src; @@ -4141,9 +4141,9 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, goto fail; } - free(cmd->uc_rep); + xfree(cmd->uc_rep); cmd->uc_rep = NULL; - free(cmd->uc_compl_arg); + xfree(cmd->uc_compl_arg); cmd->uc_compl_arg = NULL; break; } @@ -4177,8 +4177,8 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, return OK; fail: - free(rep_buf); - free(compl_arg); + xfree(rep_buf); + xfree(compl_arg); return FAIL; } @@ -4531,9 +4531,9 @@ void ex_comclear(exarg_T *eap) } static void free_ucmd(ucmd_T* cmd) { - free(cmd->uc_name); - free(cmd->uc_rep); - free(cmd->uc_compl_arg); + xfree(cmd->uc_name); + xfree(cmd->uc_rep); + xfree(cmd->uc_compl_arg); } /* @@ -4569,9 +4569,9 @@ static void ex_delcommand(exarg_T *eap) return; } - free(cmd->uc_name); - free(cmd->uc_rep); - free(cmd->uc_compl_arg); + xfree(cmd->uc_name); + xfree(cmd->uc_rep); + xfree(cmd->uc_compl_arg); --gap->ga_len; @@ -4937,8 +4937,8 @@ static void do_ucmd(exarg_T *eap) (void)do_cmdline(buf, eap->getline, eap->cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); current_SID = save_current_SID; - free(buf); - free(split_buf); + xfree(buf); + xfree(split_buf); } static char_u *get_user_command_name(int idx) @@ -5064,11 +5064,11 @@ static void ex_colorscheme(exarg_T *eap) ++emsg_off; p = eval_to_string(expr, NULL, FALSE); --emsg_off; - free(expr); + xfree(expr); if (p != NULL) { MSG(p); - free(p); + xfree(p); } else MSG("default"); } else if (load_colors(eap->arg) == FAIL) @@ -5468,7 +5468,7 @@ static void ex_goto(exarg_T *eap) */ void alist_clear(alist_T *al) { -# define FREE_AENTRY_FNAME(arg) free(arg->ae_fname) +# define FREE_AENTRY_FNAME(arg) xfree(arg->ae_fname) GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME); } @@ -5490,7 +5490,7 @@ void alist_unlink(alist_T *al) { if (al != &global_alist && --al->al_refcount <= 0) { alist_clear(al); - free(al); + xfree(al); } } @@ -5556,7 +5556,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum /* When adding many buffers this can take a long time. Allow * interrupting here. */ while (i < count) - free(files[i++]); + xfree(files[i++]); break; } @@ -5568,7 +5568,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum alist_add(al, files[i], use_curbuf ? 2 : 1); os_breakcheck(); } - free(files); + xfree(files); } if (al == &global_alist) @@ -5729,7 +5729,7 @@ void ex_splitview(exarg_T *eap) theend: - free(fname); + xfree(fname); } /* @@ -5908,7 +5908,7 @@ static void ex_find(exarg_T *eap) * appears several times in the path. */ count = eap->line2; while (fname != NULL && --count > 0) { - free(fname); + xfree(fname); fname = find_file_in_path(NULL, 0, FNAME_MESS, FALSE, curbuf->b_ffname); } @@ -5917,7 +5917,7 @@ static void ex_find(exarg_T *eap) if (fname != NULL) { eap->arg = fname; do_exedit(eap, NULL); - free(fname); + xfree(fname); } } @@ -6236,10 +6236,10 @@ static char_u *prev_dir = NULL; #if defined(EXITFREE) void free_cd_dir(void) { - free(prev_dir); + xfree(prev_dir); prev_dir = NULL; - free(globaldir); + xfree(globaldir); globaldir = NULL; } @@ -6251,7 +6251,7 @@ void free_cd_dir(void) */ void post_chdir(int local) { - free(curwin->w_localdir); + xfree(curwin->w_localdir); curwin->w_localdir = NULL; if (local) { /* If still in global directory, need to remember current @@ -6264,7 +6264,7 @@ void post_chdir(int local) } else { /* We are now in the global directory, no need to remember its * name. */ - free(globaldir); + xfree(globaldir); globaldir = NULL; } @@ -6330,7 +6330,7 @@ void ex_cd(exarg_T *eap) if (KeyTyped || p_verbose >= 5) ex_pwd(eap); } - free(tofree); + xfree(tofree); } } @@ -6733,7 +6733,7 @@ static void ex_redir(exarg_T *eap) return; redir_fd = open_exfile(fname, eap->forceit, mode); - free(fname); + xfree(fname); } else if (*arg == '@') { /* redirect to a register a-z (resp. A-Z for appending) */ close_redir(); @@ -6970,7 +6970,7 @@ static void ex_mkrc(exarg_T *eap) shorten_fnames(TRUE); } } - free(dirnow); + xfree(dirnow); } else { failed |= (put_view(fd, curwin, !using_vdir, flagp, -1) == FAIL); @@ -6999,14 +6999,14 @@ static void ex_mkrc(exarg_T *eap) tbuf = xmalloc(MAXPATHL); if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK) set_vim_var_string(VV_THIS_SESSION, tbuf, -1); - free(tbuf); + xfree(tbuf); } #ifdef MKSESSION_NL mksession_nl = FALSE; #endif } - free(viewFile); + xfree(viewFile); } int vim_mkdir_emsg(char_u *name, int prot) @@ -7189,7 +7189,7 @@ static void ex_normal(exarg_T *eap) State = save_State; setmouse(); ui_cursor_shape(); /* may show different cursor shape */ - free(arg); + xfree(arg); } /* @@ -7609,7 +7609,7 @@ eval_vars ( * postponed to avoid a delay when <afile> is not used. */ autocmd_fname_full = TRUE; result = FullName_save(autocmd_fname, FALSE); - free(autocmd_fname); + xfree(autocmd_fname); autocmd_fname = result; } if (result == NULL) { @@ -7686,7 +7686,7 @@ eval_vars ( result = NULL; } else result = vim_strnsave(result, resultlen); - free(resultbuf); + xfree(resultbuf); return result; } @@ -7772,7 +7772,7 @@ char_u *expand_sfile(char_u *arg) if (errormsg != NULL) { if (*errormsg) emsg(errormsg); - free(result); + xfree(result); return NULL; } if (repl == NULL) { /* no match (cannot happen) */ @@ -7785,8 +7785,8 @@ char_u *expand_sfile(char_u *arg) STRCPY(newres + (p - result), repl); len = (int)STRLEN(newres); STRCAT(newres, p + srclen); - free(repl); - free(result); + xfree(repl); + xfree(result); result = newres; p = newres + len; /* continue after the match */ } @@ -7850,10 +7850,10 @@ makeopens ( if (fputs("cd ", fd) < 0 || ses_put_fname(fd, sname, &ssop_flags) == FAIL || put_eol(fd) == FAIL) { - free(sname); + xfree(sname); return FAIL; } - free(sname); + xfree(sname); } /* @@ -8434,10 +8434,10 @@ ses_arglist ( } if (fputs("argadd ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL || put_eol(fd) == FAIL) { - free(buf); + xfree(buf); return FAIL; } - free(buf); + xfree(buf); } } return OK; @@ -8491,11 +8491,11 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp) /* escape special characters */ p = vim_strsave_fnameescape(sname, FALSE); - free(sname); + xfree(sname); /* write the result */ bool retval = fputs((char *)p, fd) < 0 ? FAIL : OK; - free(p); + xfree(p); return retval; } @@ -8511,7 +8511,7 @@ static void ex_loadview(exarg_T *eap) if (do_source(fname, FALSE, DOSO_NONE) == FAIL) { EMSG2(_(e_notopen), fname); } - free(fname); + xfree(fname); } } @@ -8564,7 +8564,7 @@ static char_u *get_view_file(int c) *s++ = c; STRCPY(s, ".vim"); - free(sname); + xfree(sname); return retval; } @@ -8829,7 +8829,7 @@ static void ex_match(exarg_T *eap) c = *end; *end = NUL; match_add(curwin, g, p + 1, 10, id, NULL); - free(g); + xfree(g); *end = c; } } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index d2774804f8..5ed7a35209 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -281,8 +281,8 @@ static void free_msglist(struct msglist *l) messages = l; while (messages != NULL) { next = messages->next; - free(messages->msg); - free(messages); + xfree(messages->msg); + xfree(messages); messages = next; } } @@ -505,7 +505,7 @@ static int throw_exception(void *value, int type, char_u *cmdname) return OK; nomem: - free(excp); + xfree(excp); suppress_errthrow = TRUE; EMSG(_(e_outofmem)); fail: @@ -550,14 +550,14 @@ static void discard_exception(except_T *excp, int was_finished) else verbose_leave(); STRCPY(IObuff, saved_IObuff); - free(saved_IObuff); + xfree(saved_IObuff); } if (excp->type != ET_INTERRUPT) - free(excp->value); + xfree(excp->value); if (excp->type == ET_ERROR) free_msglist(excp->messages); - free(excp->throw_name); - free(excp); + xfree(excp->throw_name); + xfree(excp); } /* @@ -727,9 +727,9 @@ static void report_pending(int action, int pending, void *value) msg_silent = save_msg_silent; if (pending == CSTP_RETURN) - free(s); + xfree(s); else if (pending & CSTP_THROW) - free(mesg); + xfree(mesg); } /* @@ -1165,7 +1165,7 @@ void ex_throw(exarg_T *eap) * not throw. */ if (!eap->skip && value != NULL) { if (throw_exception(value, ET_USER, NULL) == FAIL) - free(value); + xfree(value); else do_throw(eap->cstack); } @@ -1977,7 +1977,7 @@ int cleanup_conditionals(struct condstack *cstack, int searched_cond, int inclus elem = cstack->cs_emsg_silent_list; cstack->cs_emsg_silent_list = elem->next; emsg_silent = elem->saved_emsg_silent; - free(elem); + xfree(elem); cstack->cs_flags[idx] &= ~CSF_SILENT; } if (stop) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f0beef87e7..7dac4a9565 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -354,7 +354,7 @@ getcmdline ( && c != K_KPAGEDOWN && c != K_KPAGEUP && c != K_LEFT && c != K_RIGHT && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) { - free(lookfor); + xfree(lookfor); lookfor = NULL; } @@ -593,7 +593,7 @@ getcmdline ( realloc_cmdbuff(len + 1); ccline.cmdlen = len; STRCPY(ccline.cmdbuff, p); - free(p); + xfree(p); /* Restore the cursor or use the position set with * set_cmdline_pos(). */ @@ -825,7 +825,7 @@ getcmdline ( ) goto cmdline_not_changed; - free(ccline.cmdbuff); /* no commandline to return */ + xfree(ccline.cmdbuff); /* no commandline to return */ ccline.cmdbuff = NULL; if (!cmd_silent) { if (cmdmsg_rl) @@ -1193,7 +1193,7 @@ getcmdline ( int len; int old_firstc; - free(ccline.cmdbuff); + xfree(ccline.cmdbuff); xpc.xp_context = EXPAND_NOTHING; if (hiscnt == hislen) p = lookfor; /* back to the old one */ @@ -1476,13 +1476,13 @@ returncmd: add_to_history(histype, ccline.cmdbuff, TRUE, histype == HIST_SEARCH ? firstc : NUL); if (firstc == ':') { - free(new_last_cmdline); + xfree(new_last_cmdline); new_last_cmdline = vim_strsave(ccline.cmdbuff); } } if (gotesc) { /* abandon command line */ - free(ccline.cmdbuff); + xfree(ccline.cmdbuff); ccline.cmdbuff = NULL; if (msg_scrolled == 0) compute_cmdrow(); @@ -1784,7 +1784,7 @@ getexmodeline ( } if (c1 == Ctrl_T) { - long sw = get_sw_value(curbuf); + int sw = get_sw_value(curbuf); p = (char_u *)line_ga.ga_data; p[line_ga.ga_len] = NUL; @@ -1958,7 +1958,7 @@ static void realloc_cmdbuff(int len) * there, thus copy up to the NUL and add a NUL. */ memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); ccline.cmdbuff[ccline.cmdlen] = NUL; - free(p); + xfree(p); if (ccline.xpc != NULL && ccline.xpc->xp_pattern != NULL @@ -1978,7 +1978,7 @@ static char_u *arshape_buf = NULL; # if defined(EXITFREE) void free_cmdline_buf(void) { - free(arshape_buf); + xfree(arshape_buf); } # endif @@ -2017,7 +2017,7 @@ static void draw_cmdline(int start, int len) if (len * 2 + 2 > buflen) { /* Re-allocate the buffer. We keep it around to avoid a lot of * alloc()/free() calls. */ - free(arshape_buf); + xfree(arshape_buf); buflen = len * 2 + 2; arshape_buf = xmalloc(buflen); } @@ -2291,7 +2291,7 @@ char_u *save_cmdline_alloc(void) void restore_cmdline_alloc(char_u *p) { restore_cmdline((struct cmdline_info *)p); - free(p); + xfree(p); } /* @@ -2368,7 +2368,7 @@ cmdline_paste ( cmdline_paste_str(p, literally); if (allocated) - free(arg); + xfree(arg); return OK; } @@ -2616,7 +2616,7 @@ nextwild ( p2 = ExpandOne(xp, p1, vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), use_options, type); - free(p1); + xfree(p1); /* longest match: make sure it is not shorter, happens with :help */ if (p2 != NULL && type == WILD_LONGEST) { for (j = 0; j < xp->xp_pattern_len; ++j) @@ -2624,7 +2624,7 @@ nextwild ( || ccline.cmdbuff[i + j] == '?') break; if ((int)STRLEN(p2) < j) { - free(p2); + xfree(p2); p2 = NULL; } } @@ -2644,7 +2644,7 @@ nextwild ( ccline.cmdlen += difflen; ccline.cmdpos += difflen; } - free(p2); + xfree(p2); redrawcmd(); cursorcmd(); @@ -2755,7 +2755,7 @@ ExpandOne ( if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) { FreeWild(xp->xp_numfiles, xp->xp_files); xp->xp_numfiles = -1; - free(orig_save); + xfree(orig_save); orig_save = NULL; } findex = 0; @@ -2764,7 +2764,7 @@ ExpandOne ( return NULL; if (xp->xp_numfiles == -1) { - free(orig_save); + xfree(orig_save); orig_save = orig; orig_saved = TRUE; @@ -2872,7 +2872,7 @@ ExpandOne ( /* Free "orig" if it wasn't stored in "orig_save". */ if (!orig_saved) - free(orig); + xfree(orig); return ss; } @@ -2930,11 +2930,11 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o /* for ":set path=" we need to escape spaces twice */ if (xp->xp_backslash == XP_BS_THREE) { p = vim_strsave_escaped(files[i], (char_u *)" "); - free(files[i]); + xfree(files[i]); files[i] = p; #if defined(BACKSLASH_IN_FILENAME) p = vim_strsave_escaped(files[i], (char_u *)" "); - free(files[i]); + xfree(files[i]); files[i] = p; #endif } @@ -2943,7 +2943,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o #else p = vim_strsave_fnameescape(files[i], xp->xp_shell); #endif - free(files[i]); + xfree(files[i]); files[i] = p; /* If 'str' starts with "\~", replace "~" at start of @@ -2964,7 +2964,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o */ for (i = 0; i < numfiles; ++i) { p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); - free(files[i]); + xfree(files[i]); files[i] = p; } } @@ -2998,7 +2998,7 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell) FUNC_ATTR_NONNULL_RET /* For csh and similar shells need to put two backslashes before '!'. * One is taken by Vim, one by the shell. */ char_u *s = vim_strsave_escaped(p, (char_u *)"!"); - free(p); + xfree(p); p = s; } #endif @@ -3020,7 +3020,7 @@ static void escape_fname(char_u **pp) char_u *p = xmalloc(STRLEN(*pp) + 2); p[0] = '\\'; STRCPY(p + 1, *pp); - free(*pp); + xfree(*pp); *pp = p; } @@ -3036,7 +3036,7 @@ void tilde_replace(char_u *orig_pat, int num_files, char_u **files) if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) { for (i = 0; i < num_files; ++i) { p = home_replace_save(NULL, files[i]); - free(files[i]); + xfree(files[i]); files[i] = p; } } @@ -3154,8 +3154,8 @@ static int showmatches(expand_T *xp, int wildmenu) halved_slash = backslash_halve_save( exp_path != NULL ? exp_path : files_found[k]); j = os_isdir(halved_slash); - free(exp_path); - free(halved_slash); + xfree(exp_path); + xfree(halved_slash); } else /* Expansion was done here, file names are literal. */ j = os_isdir(files_found[k]); @@ -3515,7 +3515,7 @@ expand_cmdline ( *matchcount = 0; *matches = NULL; } - free(file_str); + xfree(file_str); return EXPAND_OK; } @@ -3610,7 +3610,7 @@ ExpandFromContext ( /* Expand wildcards, supporting %:h and the like. */ ret = expand_wildcards_eval(&pat, num_file, file, flags); if (free_pat) - free(pat); + xfree(pat); return ret; } @@ -3887,9 +3887,9 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, STRMOVE(s, s + l); ((char_u **)ga.ga_data)[ga.ga_len++] = s; } else - free(s); + xfree(s); } - free(*file); + xfree(*file); } } if (*e != NUL) @@ -3898,10 +3898,10 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, *file = ga.ga_data; *num_file = ga.ga_len; - free(buf); - free(pat); + xfree(buf); + xfree(pat); if (mustfree) - free(path); + xfree(path); } /* @@ -3946,7 +3946,7 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func, if (ccline.cmdbuff != NULL) ccline.cmdbuff[ccline.cmdlen] = keep; - free(args[0]); + xfree(args[0]); return ret; } @@ -3986,7 +3986,7 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, if (*e != NUL) ++e; } - free(retstr); + xfree(retstr); *file = ga.ga_data; *num_file = ga.ga_len; return OK; @@ -4039,7 +4039,7 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname char_u *s = xmalloc(size); snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat); globpath(p_rtp, s, &ga, 0); - free(s); + xfree(s); } for (int i = 0; i < ga.ga_len; i++) { @@ -4108,7 +4108,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options) } } - free(buf); + xfree(buf); } @@ -4210,7 +4210,7 @@ void init_history(void) if (i >= 0) /* copy newest entries */ temp[i] = history[type][j]; else { /* remove older entries */ - free(history[type][j].hisstr); + xfree(history[type][j].hisstr); history[type][j].hisstr = NULL; } if (--j < 0) @@ -4220,7 +4220,7 @@ void init_history(void) } hisidx[type] = newlen - 1; } - free(history[type]); + xfree(history[type]); history[type] = temp; } } @@ -4347,7 +4347,7 @@ add_to_history ( if (maptick == last_maptick) { /* Current line is from the same mapping, remove it */ hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; - free(hisptr->hisstr); + xfree(hisptr->hisstr); clear_hist_entry(hisptr); --hisnum[histype]; if (--hisidx[HIST_SEARCH] < 0) @@ -4359,7 +4359,7 @@ add_to_history ( if (++hisidx[histype] == hislen) hisidx[histype] = 0; hisptr = &history[histype][hisidx[histype]]; - free(hisptr->hisstr); + xfree(hisptr->hisstr); /* Store the separator after the NUL of the string. */ len = (int)STRLEN(new_entry); @@ -4532,7 +4532,7 @@ int clr_history(int histype) if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) { hisptr = history[histype]; for (i = hislen; i--; ) { - free(hisptr->hisstr); + xfree(hisptr->hisstr); clear_hist_entry(hisptr); } hisidx[histype] = -1; /* mark history as cleared */ @@ -4571,7 +4571,7 @@ int del_history_entry(int histype, char_u *str) break; if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { found = TRUE; - free(hisptr->hisstr); + xfree(hisptr->hisstr); clear_hist_entry(hisptr); } else { if (i != last) { @@ -4603,7 +4603,7 @@ int del_history_idx(int histype, int idx) if (i < 0) return FALSE; idx = hisidx[histype]; - free(history[histype][i].hisstr); + xfree(history[histype][i].hisstr); /* When deleting the last added search string in a mapping, reset * last_maptick, so that the last added search string isn't deleted again. @@ -4837,7 +4837,7 @@ int read_viminfo_history(vir_T *virp, int writing) viminfo_history[type][viminfo_hisidx[type]++] = p; } } - free(val); + xfree(val); } return viminfo_readline(virp); } @@ -4875,7 +4875,7 @@ void finish_viminfo_history(void) idx = hislen - 1; } for (i = 0; i < viminfo_hisidx[type]; i++) { - free(history[type][idx].hisstr); + xfree(history[type][idx].hisstr); history[type][idx].hisstr = viminfo_history[type][i]; history[type][idx].viminfo = TRUE; if (--idx < 0) @@ -4887,7 +4887,7 @@ void finish_viminfo_history(void) history[type][idx++].hisnum = ++hisnum[type]; idx %= hislen; } - free(viminfo_history[type]); + xfree(viminfo_history[type]); viminfo_history[type] = NULL; viminfo_hisidx[type] = 0; } @@ -4974,8 +4974,8 @@ void write_viminfo_history(FILE *fp, int merge) } for (i = 0; i < viminfo_hisidx[type]; ++i) if (viminfo_history[type] != NULL) - free(viminfo_history[type][i]); - free(viminfo_history[type]); + xfree(viminfo_history[type][i]); + xfree(viminfo_history[type]); viminfo_history[type] = NULL; viminfo_hisidx[type] = 0; } @@ -5161,7 +5161,7 @@ static int ex_window(void) if (aborting() && cmdwin_result != K_IGNORE) cmdwin_result = Ctrl_C; /* Set the new command line from the cmdline buffer. */ - free(ccline.cmdbuff); + xfree(ccline.cmdbuff); if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) { /* :qa[!] typed */ char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; @@ -5257,13 +5257,13 @@ char_u *script_get(exarg_T *eap, char_u *cmd) NUL, eap->cookie, 0); if (theline == NULL || STRCMP(end_pattern, theline) == 0) { - free(theline); + xfree(theline); break; } ga_concat(&ga, theline); ga_append(&ga, '\n'); - free(theline); + xfree(theline); } ga_append(&ga, NUL); diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c index 2ca581ebd3..f9d6b14edc 100644 --- a/src/nvim/farsi.c +++ b/src/nvim/farsi.c @@ -2,6 +2,7 @@ /// /// Functions for Farsi language +#include <assert.h> #include <stdbool.h> #include "nvim/cursor.h" @@ -29,26 +30,23 @@ // Special Farsi text messages const char_u farsi_text_1[] = { - YE_, _SIN, RE, ALEF_, _FE, ' ', 'V', 'I', 'M', - ' ', F_HE, _BE, ' ', SHIN, RE, _GAF, DAL, ' ', NOON, - ALEF_, _YE, ALEF_, _PE, '\0' + YE_, _SIN, RE, ALEF_, _FE, ' ', 'V', 'I', 'M', ' ', F_HE, _BE, ' ', SHIN, RE, + _GAF, DAL, ' ', NOON, ALEF_, _YE, ALEF_, _PE, '\0' }; const char_u farsi_text_2[] = { - YE_, _SIN, RE, ALEF_, _FE, ' ', FARSI_3, FARSI_3, - FARSI_4, FARSI_2, ' ', DAL, RE, ALEF, DAL, _NOON, - ALEF_, _TE, _SIN, ALEF, ' ', F_HE, _BE, ' ', SHIN, - RE, _GAF, DAL, ' ', NOON, ALEF_, _YE, ALEF_, _PE, '\0' + YE_, _SIN, RE, ALEF_, _FE, ' ', FARSI_3, FARSI_3, FARSI_4, FARSI_2, ' ', DAL, + RE, ALEF, DAL, _NOON, ALEF_, _TE, _SIN, ALEF, ' ', F_HE, _BE, ' ', SHIN, RE, + _GAF, DAL, ' ', NOON, ALEF_, _YE, ALEF_, _PE, '\0' }; const char_u farsi_text_3[] = { - DAL, WAW, _SHIN, _YE, _MIM, _NOON, ' ', YE_, _NOON, - ALEF_, _BE, _YE, _TE, _SHIN, _PE, ' ', 'R', 'E', 'P', 'L', - 'A', 'C', 'E', ' ', NOON, ALEF_, _MIM, RE, _FE, ZE, ALEF, - ' ', 'R', 'E', 'V', 'E', 'R', 'S', 'E', ' ', 'I', 'N', - 'S', 'E', 'R', 'T', ' ', SHIN, WAW, RE, ' ', ALEF_, _BE, - ' ', YE_, _SIN, RE, ALEF_, _FE, ' ', RE, DAL, ' ', RE, - ALEF_, _KAF, ' ', MIM, ALEF_, _GAF, _NOON, _HE, '\0' + DAL, WAW, _SHIN, _YE, _MIM, _NOON, ' ', YE_, _NOON, ALEF_, _BE, _YE, _TE, + _SHIN, _PE, ' ', 'R', 'E', 'P', 'L', 'A', 'C', 'E', ' ', NOON, ALEF_, _MIM, + RE, _FE, ZE, ALEF, ' ', 'R', 'E', 'V', 'E', 'R', 'S', 'E', ' ', 'I', 'N', 'S', + 'E', 'R', 'T', ' ', SHIN, WAW, RE, ' ', ALEF_, _BE, ' ', YE_, _SIN, RE, ALEF_, + _FE, ' ', RE, DAL, ' ', RE, ALEF_, _KAF, ' ', MIM, ALEF_, _GAF, _NOON, _HE, + '\0' }; const char_u farsi_text_5[] = { @@ -65,93 +63,41 @@ const char_u farsi_text_5[] = { /// @param c The character to convert. /// /// @return Farsi character converted to a _X or _X_ type. -static int toF_Xor_X_(int c) +static char_u toF_Xor_X_(int c) { - int tempc; + char_u tempc; switch (c) { - case BE: - return _BE; - - case PE: - return _PE; - - case TE: - return _TE; - - case SE: - return _SE; - - case JIM: - return _JIM; - - case CHE: - return _CHE; - - case HE_J: - return _HE_J; - - case XE: - return _XE; - - case SIN: - return _SIN; - - case SHIN: - return _SHIN; - - case SAD: - return _SAD; - - case ZAD: - return _ZAD; - - case AYN: - return _AYN; - - case AYN_: - return _AYN_; - - case GHAYN: - return _GHAYN; - - case GHAYN_: - return _GHAYN_; - - case FE: - return _FE; - - case GHAF: - return _GHAF; - - case KAF: - return _KAF; - - case GAF: - return _GAF; - - case LAM: - return _LAM; - - case MIM: - return _MIM; - - case NOON: - return _NOON; - - case YE: - case YE_: - return _YE; - - case YEE: - case YEE_: - return _YEE; - - case IE: - case IE_: - return _IE; - - case F_HE: + case BE : tempc = _BE ; break; + case PE : tempc = _PE ; break; + case TE : tempc = _TE ; break; + case SE : tempc = _SE ; break; + case JIM : tempc = _JIM ; break; + case CHE : tempc = _CHE ; break; + case HE_J : tempc = _HE_J ; break; + case XE : tempc = _XE ; break; + case SIN : tempc = _SIN ; break; + case SHIN : tempc = _SHIN ; break; + case SAD : tempc = _SAD ; break; + case ZAD : tempc = _ZAD ; break; + case AYN : tempc = _AYN ; break; + case AYN_ : tempc = _AYN_ ; break; + case GHAYN : tempc = _GHAYN ; break; + case GHAYN_ : tempc = _GHAYN_ ; break; + case FE : tempc = _FE ; break; + case GHAF : tempc = _GHAF ; break; + case KAF : tempc = _KAF ; break; + case GAF : tempc = _GAF ; break; + case LAM : tempc = _LAM ; break; + case MIM : tempc = _MIM ; break; + case NOON : tempc = _NOON ; break; + case YE : + case YE_ : tempc = _YE ; break; + case YEE : + case YEE_ : tempc = _YEE ; break; + case IE : + case IE_ : tempc = _IE ; break; + case F_HE : tempc = _HE; if (p_ri && @@ -171,9 +117,13 @@ static int toF_Xor_X_(int c) inc_cursor(); } - return tempc; + break; + + default: + tempc = 0; } - return 0; + + return tempc; } /// Convert the given Farsi character into Farsi capital character. @@ -181,104 +131,51 @@ static int toF_Xor_X_(int c) /// @param c The character to convert. /// /// @return Character converted to the Farsi capital leter. -int toF_TyA(int c) +char_u toF_TyA(char_u c) { - switch (c) { - case ALEF_: - return ALEF; - - case ALEF_U_H_: - return ALEF_U_H; - - case _BE: - return BE; - - case _PE: - return PE; - - case _TE: - return TE; - - case _SE: - return SE; - - case _JIM: - return JIM; - - case _CHE: - return CHE; - - case _HE_J: - return HE_J; - - case _XE: - return XE; - - case _SIN: - return SIN; - - case _SHIN: - return SHIN; - - case _SAD: - return SAD; - - case _ZAD: - return ZAD; - - case _AYN: - case AYN_: - case _AYN_: - return AYN; - - case _GHAYN: - case GHAYN_: - case _GHAYN_: - return GHAYN; - - case _FE: - return FE; + char_u tempc; - case _GHAF: - return GHAF; - - // I am not sure what it is !!! - // case _KAF_H: - case _KAF: - return KAF; - - case _GAF: - return GAF; - - case _LAM: - return LAM; - - case _MIM: - return MIM; - - case _NOON: - return NOON; - - case _YE: - case YE_: - return YE; - - case _YEE: - case YEE_: - return YEE; - - case TEE_: - return TEE; - - case _IE: - case IE_: - return IE; - - case _HE: - case _HE_: - return F_HE; + switch (c) { + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case _BE : tempc = BE ; break; + case _PE : tempc = PE ; break; + case _TE : tempc = TE ; break; + case _SE : tempc = SE ; break; + case _JIM : tempc = JIM ; break; + case _CHE : tempc = CHE ; break; + case _HE_J : tempc = HE_J ; break; + case _XE : tempc = XE ; break; + case _SIN : tempc = SIN ; break; + case _SHIN : tempc = SHIN ; break; + case _SAD : tempc = SAD ; break; + case _ZAD : tempc = ZAD ; break; + case _AYN : + case AYN_ : + case _AYN_ : tempc = AYN ; break; + case _GHAYN : + case GHAYN_ : + case _GHAYN_ : tempc = GHAYN ; break; + case _FE : tempc = FE ; break; + case _GHAF : tempc = GHAF ; break; + case _KAF : tempc = KAF ; break; + case _GAF : tempc = GAF ; break; + case _LAM : tempc = LAM ; break; + case _MIM : tempc = MIM ; break; + case _NOON : tempc = NOON ; break; + case _YE : + case YE_ : tempc = YE ; break; + case _YEE : + case YEE_ : tempc = YEE ; break; + case TEE_ : tempc = TEE ; break; + case _IE : + case IE_ : tempc = IE ; break; + case _HE : + case _HE_ : tempc = F_HE ; break; + default : tempc = c ; } - return c; + + return tempc; } /// Is the character under the cursor+offset in the given buffer a join type. @@ -388,51 +285,34 @@ static bool F_is_TyC_TyD(int c) /// @param c The character to convert. /// /// @return The character converted into a leading type. -static int toF_TyB(int c) +static char_u toF_TyB(int c) { - switch (c) { - case ALEF_: - return ALEF; - - case ALEF_U_H_: - return ALEF_U_H; - - case _AYN_: - return _AYN; - - case AYN_: - // exception - there are many of them - return AYN; - - case _GHAYN_: - return _GHAYN; - - case GHAYN_: - // exception - there are many of them - return GHAYN; - - case _HE_: - return _HE; - - case YE_: - return YE; - - case IE_: - return IE; - - case TEE_: - return TEE; + char_u tempc; - case YEE_: - return YEE; + switch (c) { + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case _AYN_ : tempc = _AYN ; break; + case AYN_ : tempc = AYN ; break; // exception - there are many + case _GHAYN_ : tempc = _GHAYN ; break; + case GHAYN_ : tempc = GHAYN ; break; // exception - there are many + case _HE_ : tempc = _HE ; break; + case YE_ : tempc = YE ; break; + case IE_ : tempc = IE ; break; + case TEE_ : tempc = TEE ; break; + case YEE_ : tempc = YEE ; break; + default: + assert(c >= 0 && c <= UCHAR_MAX); + tempc = (char_u)c; } - return c; + + return tempc; } /// Overwrite the current redo and cursor characters + left adjust /// /// @param c -static void put_curr_and_l_to_X(int c) +static void put_curr_and_l_to_X(char_u c) { int tempc; @@ -465,7 +345,7 @@ static void put_curr_and_l_to_X(int c) put_and_redo(c); } -static void put_and_redo(int c) +static void put_and_redo(char_u c) { pchar_cursor(c); AppendCharToRedobuff(K_BS); @@ -475,110 +355,39 @@ static void put_and_redo(int c) /// Change the char. under the cursor to a X_ or X type static void chg_c_toX_orX(void) { - int tempc, curc; + int curc; + char_u tempc; switch ((curc = gchar_cursor())) { - case _BE: - tempc = BE; - break; - - case _PE: - tempc = PE; - break; - - case _TE: - tempc = TE; - break; - - case _SE: - tempc = SE; - break; - - case _JIM: - tempc = JIM; - break; - - case _CHE: - tempc = CHE; - break; - - case _HE_J: - tempc = HE_J; - break; - - case _XE: - tempc = XE; - break; - - case _SIN: - tempc = SIN; - break; - - case _SHIN: - tempc = SHIN; - break; - - case _SAD: - tempc = SAD; - break; - - case _ZAD: - tempc = ZAD; - break; - - case _FE: - tempc = FE; - break; - - case _GHAF: - tempc = GHAF; - break; - - case _KAF_H: - case _KAF: - tempc = KAF; - break; - - case _GAF: - tempc = GAF; - break; - - case _AYN: - tempc = AYN; - break; - - case _AYN_: - tempc = AYN_; - break; - - case _GHAYN: - tempc = GHAYN; - break; - - case _GHAYN_: - tempc = GHAYN_; - break; - - case _LAM: - tempc = LAM; - break; - - case _MIM: - tempc = MIM; - break; - - case _NOON: - tempc = NOON; - break; - - case _HE: - case _HE_: - tempc = F_HE; - break; - - case _YE: - case _IE: - case _YEE: + case _BE : tempc = BE ; break ; + case _PE : tempc = PE ; break ; + case _TE : tempc = TE ; break ; + case _SE : tempc = SE ; break ; + case _JIM : tempc = JIM ; break ; + case _CHE : tempc = CHE ; break ; + case _HE_J : tempc = HE_J ; break ; + case _XE : tempc = XE ; break ; + case _SIN : tempc = SIN ; break ; + case _SHIN : tempc = SHIN ; break ; + case _SAD : tempc = SAD ; break ; + case _ZAD : tempc = ZAD ; break ; + case _FE : tempc = FE ; break ; + case _GHAF : tempc = GHAF ; break ; + case _KAF_H : + case _KAF : tempc = KAF ; break ; + case _GAF : tempc = GAF ; break ; + case _AYN : tempc = AYN ; break ; + case _AYN_ : tempc = AYN_ ; break ; + case _GHAYN : tempc = GHAYN ; break ; + case _GHAYN_ : tempc = GHAYN_ ; break ; + case _LAM : tempc = LAM ; break ; + case _MIM : tempc = MIM ; break ; + case _NOON : tempc = NOON ; break ; + case _HE : + case _HE_ : tempc = F_HE ; break; + case _YE : + case _IE : + case _YEE : if (p_ri) { inc_cursor(); @@ -621,55 +430,21 @@ static void chg_c_toX_orX(void) /// Change the char. under the cursor to a _X_ or X_ type static void chg_c_to_X_orX_(void) { - int tempc; + char_u tempc; switch (gchar_cursor()) { - case ALEF: - tempc = ALEF_; - break; - - case ALEF_U_H: - tempc = ALEF_U_H_; - break; - - case _AYN: - tempc = _AYN_; - break; - - case AYN: - tempc = AYN_; - break; - - case _GHAYN: - tempc = _GHAYN_; - break; - - case GHAYN: - tempc = GHAYN_; - break; - - case _HE: - tempc = _HE_; - break; - - case YE: - tempc = YE_; - break; - - case IE: - tempc = IE_; - break; - - case TEE: - tempc = TEE_; - break; - - case YEE: - tempc = YEE_; - break; - - default: - tempc = 0; + case ALEF : tempc = ALEF_ ; break; + case ALEF_U_H : tempc = ALEF_U_H_ ; break; + case _AYN : tempc = _AYN_ ; break; + case AYN : tempc = AYN_ ; break; + case _GHAYN : tempc = _GHAYN_ ; break; + case GHAYN : tempc = GHAYN_ ; break; + case _HE : tempc = _HE_ ; break; + case YE : tempc = YE_ ; break; + case IE : tempc = IE_ ; break; + case TEE : tempc = TEE_ ; break; + case YEE : tempc = YEE_ ; break; + default : tempc = 0 ; } if (tempc) { @@ -689,15 +464,14 @@ static void chg_c_to_X_or_X(void) if ((tempc == F_HE) && (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))) { tempc = _HE_; dec_cursor(); - put_and_redo(tempc); + put_and_redo((char_u)tempc); return; } - dec_cursor(); } if ((tempc = toF_Xor_X_(tempc)) != 0) { - put_and_redo(tempc); + put_and_redo((char_u)tempc); } } @@ -722,56 +496,22 @@ static void chg_l_to_X_orX_(void) } switch (gchar_cursor()) { - case ALEF: - tempc = ALEF_; - break; - - case ALEF_U_H: - tempc = ALEF_U_H_; - break; - - case _AYN: - tempc = _AYN_; - break; - - case AYN: - tempc = AYN_; - break; - - case _GHAYN: - tempc = _GHAYN_; - break; - - case GHAYN: - tempc = GHAYN_; - break; - - case _HE: - tempc = _HE_; - break; - - case YE: - tempc = YE_; - break; - - case IE: - tempc = IE_; - break; - - case TEE: - tempc = TEE_; - break; - - case YEE: - tempc = YEE_; - break; - - default: - tempc = 0; + case ALEF : tempc = ALEF_ ; break; + case ALEF_U_H : tempc = ALEF_U_H_ ; break; + case _AYN : tempc = _AYN_ ; break; + case AYN : tempc = AYN_ ; break; + case _GHAYN : tempc = _GHAYN_ ; break; + case GHAYN : tempc = GHAYN_ ; break; + case _HE : tempc = _HE_ ; break; + case YE : tempc = YE_ ; break; + case IE : tempc = IE_ ; break; + case TEE : tempc = TEE_ ; break; + case YEE : tempc = YEE_ ; break; + default : tempc = 0 ; } if (tempc) { - put_and_redo(tempc); + put_and_redo((char_u)tempc); } if (p_ri) { @@ -784,7 +524,7 @@ static void chg_l_to_X_orX_(void) /// Change the character left to the cursor to a X or _X type static void chg_l_toXor_X(void) { - int tempc; + char_u tempc; if ((curwin->w_cursor.col != 0) && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) { @@ -802,52 +542,18 @@ static void chg_l_toXor_X(void) } switch (gchar_cursor()) { - case ALEF_: - tempc = ALEF; - break; - - case ALEF_U_H_: - tempc = ALEF_U_H; - break; - - case _AYN_: - tempc = _AYN; - break; - - case AYN_: - tempc = AYN; - break; - - case _GHAYN_: - tempc = _GHAYN; - break; - - case GHAYN_: - tempc = GHAYN; - break; - - case _HE_: - tempc = _HE; - break; - - case YE_: - tempc = YE; - break; - - case IE_: - tempc = IE; - break; - - case TEE_: - tempc = TEE; - break; - - case YEE_: - tempc = YEE; - break; - - default: - tempc = 0; + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case _AYN_ : tempc = _AYN ; break; + case AYN_ : tempc = AYN ; break; + case _GHAYN_ : tempc = _GHAYN ; break; + case GHAYN_ : tempc = GHAYN ; break; + case _HE_ : tempc = _HE ; break; + case YE_ : tempc = YE ; break; + case IE_ : tempc = IE ; break; + case TEE_ : tempc = TEE ; break; + case YEE_ : tempc = YEE ; break; + default : tempc = 0 ; } if (tempc) { @@ -864,7 +570,8 @@ static void chg_l_toXor_X(void) /// Change the character right to the cursor to a _X or _X_ type static void chg_r_to_Xor_X_(void) { - int tempc, c; + int tempc; + char_u c; if (curwin->w_cursor.col) { if (!p_ri) { @@ -893,13 +600,13 @@ int fkmap(int c) } if (VIM_ISDIGIT(c) - || (((c == '.') - || (c == '+') - || (c == '-') - || (c == '^') - || (c == '%') - || (c == '#') - || (c == '=')) + || ((c == '.' + || c == '+' + || c == '-' + || c == '^' + || c == '%' + || c == '#' + || c == '=') && revins)) { if (!revins) { if (curwin->w_cursor.col) { @@ -1060,158 +767,57 @@ int fkmap(int c) if (!p_ri) { if (!curwin->w_cursor.col) { switch (c) { - case '0': - return FARSI_0; - - case '1': - return FARSI_1; - - case '2': - return FARSI_2; - - case '3': - return FARSI_3; - - case '4': - return FARSI_4; - - case '5': - return FARSI_5; - - case '6': - return FARSI_6; - - case '7': - return FARSI_7; - - case '8': - return FARSI_8; - - case '9': - return FARSI_9; - - case 'B': - return F_PSP; - - case 'E': - return JAZR_N; - - case 'F': - return ALEF_D_H; - - case 'H': - return ALEF_A; - - case 'I': - return TASH; - - case 'K': - return F_LQUOT; - - case 'L': - return F_RQUOT; - - case 'M': - return HAMZE; - - case 'O': - return '['; - - case 'P': - return ']'; - - case 'Q': - return OO; - - case 'R': - return MAD_N; - - case 'T': - return OW; - - case 'U': - return MAD; - - case 'W': - return OW_OW; - - case 'Y': - return JAZR; - - case '`': - return F_PCN; - - case '!': - return F_EXCL; - - case '@': - return F_COMMA; - - case '#': - return F_DIVIDE; - - case '$': - return F_CURRENCY; - - case '%': - return F_PERCENT; - - case '^': - return F_MUL; - - case '&': - return F_BCOMMA; - - case '*': - return F_STAR; - - case '(': - return F_LPARENT; - - case ')': - return F_RPARENT; - - case '-': - return F_MINUS; - - case '_': - return F_UNDERLINE; - - case '=': - return F_EQUALS; - - case '+': - return F_PLUS; - - case '\\': - return F_BSLASH; - - case '|': - return F_PIPE; - - case ':': - return F_DCOLON; - - case '"': - return F_SEMICOLON; - - case '.': - return F_PERIOD; - - case '/': - return F_SLASH; - - case '<': - return F_LESS; - - case '>': - return F_GREATER; - - case '?': - return F_QUESTION; - - case ' ': - return F_BLANK; + case '0' : return FARSI_0 ; + case '1' : return FARSI_1 ; + case '2' : return FARSI_2 ; + case '3' : return FARSI_3 ; + case '4' : return FARSI_4 ; + case '5' : return FARSI_5 ; + case '6' : return FARSI_6 ; + case '7' : return FARSI_7 ; + case '8' : return FARSI_8 ; + case '9' : return FARSI_9 ; + case 'B' : return F_PSP ; + case 'E' : return JAZR_N ; + case 'F' : return ALEF_D_H ; + case 'H' : return ALEF_A ; + case 'I' : return TASH ; + case 'K' : return F_LQUOT ; + case 'L' : return F_RQUOT ; + case 'M' : return HAMZE ; + case 'O' : return '[' ; + case 'P' : return ']' ; + case 'Q' : return OO ; + case 'R' : return MAD_N ; + case 'T' : return OW ; + case 'U' : return MAD ; + case 'W' : return OW_OW ; + case 'Y' : return JAZR ; + case '`' : return F_PCN ; + case '!' : return F_EXCL ; + case '@' : return F_COMMA ; + case '#' : return F_DIVIDE ; + case '$' : return F_CURRENCY ; + case '%' : return F_PERCENT ; + case '^' : return F_MUL ; + case '&' : return F_BCOMMA ; + case '*' : return F_STAR ; + case '(' : return F_LPARENT ; + case ')' : return F_RPARENT ; + case '-' : return F_MINUS ; + case '_' : return F_UNDERLINE ; + case '=' : return F_EQUALS ; + case '+' : return F_PLUS ; + case '\\' : return F_BSLASH ; + case '|' : return F_PIPE ; + case ':' : return F_DCOLON ; + case '"' : return F_SEMICOLON ; + case '.' : return F_PERIOD ; + case '/' : return F_SLASH ; + case '<' : return F_LESS ; + case '>' : return F_GREATER ; + case '?' : return F_QUESTION ; + case ' ' : return F_BLANK ; } break; } @@ -1246,7 +852,7 @@ int fkmap(int c) case _HE_: case _TA: case _ZA: - put_curr_and_l_to_X(toF_TyA(tempc)); + put_curr_and_l_to_X(toF_TyA((char_u)tempc)); break; case _AYN: @@ -1276,7 +882,7 @@ int fkmap(int c) inc_cursor(); } - put_curr_and_l_to_X(tempc); + put_curr_and_l_to_X((char_u)tempc); break; case _GHAYN: @@ -1307,7 +913,7 @@ int fkmap(int c) inc_cursor(); } - put_curr_and_l_to_X(tempc); + put_curr_and_l_to_X((char_u)tempc); break; case _YE: @@ -1316,8 +922,8 @@ int fkmap(int c) if (!p_ri) { if (!curwin->w_cursor.col) { - put_curr_and_l_to_X((tempc == _YE ? YE : - (tempc == _IE ? IE : YEE))); + put_curr_and_l_to_X( + (tempc == _YE ? YE : tempc == _IE ? IE : YEE)); break; } } @@ -1329,11 +935,9 @@ int fkmap(int c) } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { - tempc = (tempc == _YE ? YE_ : - (tempc == _IE ? IE_ : YEE_)); + tempc = (tempc == _YE ? YE_ : tempc == _IE ? IE_ : YEE_); } else { - tempc = (tempc == _YE ? YE : - (tempc == _IE ? IE : YEE)); + tempc = (tempc == _YE ? YE : tempc == _IE ? IE : YEE); } if (p_ri) { @@ -1342,7 +946,7 @@ int fkmap(int c) inc_cursor(); } - put_curr_and_l_to_X(tempc); + put_curr_and_l_to_X((char_u)tempc); break; } @@ -1353,200 +957,70 @@ int fkmap(int c) tempc = 0; switch (c) { - case '0': - return FARSI_0; - - case '1': - return FARSI_1; - - case '2': - return FARSI_2; - - case '3': - return FARSI_3; - - case '4': - return FARSI_4; - - case '5': - return FARSI_5; - - case '6': - return FARSI_6; - - case '7': - return FARSI_7; - - case '8': - return FARSI_8; - - case '9': - return FARSI_9; - - case 'B': - return F_PSP; - - case 'E': - return JAZR_N; - - case 'F': - return ALEF_D_H; - - case 'H': - return ALEF_A; - - case 'I': - return TASH; - - case 'K': - return F_LQUOT; - - case 'L': - return F_RQUOT; - - case 'M': - return HAMZE; - - case 'O': - return '['; - - case 'P': - return ']'; - - case 'Q': - return OO; - - case 'R': - return MAD_N; - - case 'T': - return OW; - - case 'U': - return MAD; - - case 'W': - return OW_OW; - - case 'Y': - return JAZR; - - case '`': - return F_PCN; - - case '!': - return F_EXCL; - - case '@': - return F_COMMA; - - case '#': - return F_DIVIDE; - - case '$': - return F_CURRENCY; - - case '%': - return F_PERCENT; - - case '^': - return F_MUL; - - case '&': - return F_BCOMMA; - - case '*': - return F_STAR; - - case '(': - return F_LPARENT; - - case ')': - return F_RPARENT; - - case '-': - return F_MINUS; - - case '_': - return F_UNDERLINE; - - case '=': - return F_EQUALS; - - case '+': - return F_PLUS; - - case '\\': - return F_BSLASH; - - case '|': - return F_PIPE; - - case ':': - return F_DCOLON; - - case '"': - return F_SEMICOLON; - - case '.': - return F_PERIOD; - - case '/': - return F_SLASH; - - case '<': - return F_LESS; - - case '>': - return F_GREATER; - - case '?': - return F_QUESTION; - - case ' ': - return F_BLANK; + case '0' : return FARSI_0 ; + case '1' : return FARSI_1 ; + case '2' : return FARSI_2 ; + case '3' : return FARSI_3 ; + case '4' : return FARSI_4 ; + case '5' : return FARSI_5 ; + case '6' : return FARSI_6 ; + case '7' : return FARSI_7 ; + case '8' : return FARSI_8 ; + case '9' : return FARSI_9 ; + case 'B' : return F_PSP ; + case 'E' : return JAZR_N ; + case 'F' : return ALEF_D_H ; + case 'H' : return ALEF_A ; + case 'I' : return TASH ; + case 'K' : return F_LQUOT ; + case 'L' : return F_RQUOT ; + case 'M' : return HAMZE ; + case 'O' : return '[' ; + case 'P' : return ']' ; + case 'Q' : return OO ; + case 'R' : return MAD_N ; + case 'T' : return OW ; + case 'U' : return MAD ; + case 'W' : return OW_OW ; + case 'Y' : return JAZR ; + case '`' : return F_PCN ; + case '!' : return F_EXCL ; + case '@' : return F_COMMA ; + case '#' : return F_DIVIDE ; + case '$' : return F_CURRENCY ; + case '%' : return F_PERCENT ; + case '^' : return F_MUL ; + case '&' : return F_BCOMMA ; + case '*' : return F_STAR ; + case '(' : return F_LPARENT ; + case ')' : return F_RPARENT ; + case '-' : return F_MINUS ; + case '_' : return F_UNDERLINE ; + case '=' : return F_EQUALS ; + case '+' : return F_PLUS ; + case '\\' : return F_BSLASH ; + case '|' : return F_PIPE ; + case ':' : return F_DCOLON ; + case '"' : return F_SEMICOLON ; + case '.' : return F_PERIOD ; + case '/' : return F_SLASH ; + case '<' : return F_LESS ; + case '>' : return F_GREATER ; + case '?' : return F_QUESTION ; + case ' ' : return F_BLANK ; } break; - case 'a': - tempc = _SHIN; - break; - - case 'A': - tempc = WAW_H; - break; - - case 'b': - tempc = ZAL; - break; - - case 'c': - tempc = ZE; - break; - - case 'C': - tempc = JE; - break; - - case 'd': - tempc = _YE; - break; - - case 'D': - tempc = _YEE; - break; - - case 'e': - tempc = _SE; - break; - - case 'f': - tempc = _BE; - break; - - case 'g': - tempc = _LAM; - break; + case 'a' : tempc = _SHIN ; break; + case 'A' : tempc = WAW_H ; break; + case 'b' : tempc = ZAL ; break; + case 'c' : tempc = ZE ; break; + case 'C' : tempc = JE ; break; + case 'd' : tempc = _YE ; break; + case 'D' : tempc = _YEE ; break; + case 'e' : tempc = _SE ; break; + case 'f' : tempc = _BE ; break; + case 'g' : tempc = _LAM ; break; case 'G': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { @@ -1621,7 +1095,6 @@ int fkmap(int c) return tempc; case 'i': - if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (!p_ri && !F_is_TyE(tempc)) { chg_c_to_X_orX_(); @@ -1656,7 +1129,6 @@ int fkmap(int c) break; case 'J': - if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (p_ri) { chg_c_to_X_or_X(); @@ -1683,50 +1155,18 @@ int fkmap(int c) return tempc; - case 'k': - tempc = _NOON; - break; - - case 'l': - tempc = _MIM; - break; - - case 'm': - tempc = _PE; - break; - - case 'n': - case 'N': - tempc = DAL; - break; - - case 'o': - tempc = _XE; - break; - - case 'p': - tempc = _HE_J; - break; - - case 'q': - tempc = _ZAD; - break; - - case 'r': - tempc = _GHAF; - break; - - case 's': - tempc = _SIN; - break; - - case 'S': - tempc = _IE; - break; - - case 't': - tempc = _FE; - break; + case 'k' : tempc = _NOON ; break; + case 'l' : tempc = _MIM ; break; + case 'm' : tempc = _PE ; break; + case 'n' : + case 'N' : tempc = DAL ; break; + case 'o' : tempc = _XE ; break; + case 'p' : tempc = _HE_J ; break; + case 'q' : tempc = _ZAD ; break; + case 'r' : tempc = _GHAF ; break; + case 's' : tempc = _SIN ; break; + case 'S' : tempc = _IE ; break; + case 't' : tempc = _FE ; break; case 'u': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { @@ -1758,19 +1198,11 @@ int fkmap(int c) } break; - case 'v': - case 'V': - tempc = RE; - break; - - case 'w': - tempc = _SAD; - break; - - case 'x': - case 'X': - tempc = _TA; - break; + case 'v' : + case 'V' : tempc = RE ; break; + case 'w' : tempc = _SAD ; break; + case 'x' : + case 'X' : tempc = _TA ; break; case 'y': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { @@ -1803,33 +1235,13 @@ int fkmap(int c) break; - case 'z': - tempc = _ZA; - break; - - case 'Z': - tempc = _KAF_H; - break; - - case ';': - tempc = _KAF; - break; - - case '\'': - tempc = _GAF; - break; - - case ',': - tempc = WAW; - break; - - case '[': - tempc = _JIM; - break; - - case ']': - tempc = _CHE; - break; + case 'z' : tempc = _ZA ; break; + case 'Z' : tempc = _KAF_H ; break; + case ';' : tempc = _KAF ; break; + case '\'' : tempc = _GAF ; break; + case ',' : tempc = WAW ; break; + case '[' : tempc = _JIM ; break; + case ']' : tempc = _CHE ; break; } if ((F_isalpha(tempc) || F_isdigit(tempc))) { @@ -1871,99 +1283,50 @@ int fkmap(int c) /// @param c The character to convert. /// /// @return The non-leading Farsi character converted to a leading type. -static int toF_leading(int c) +static char_u toF_leading(char_u c) { - switch (c) { - case ALEF_: - return ALEF; - - case ALEF_U_H_: - return ALEF_U_H; - - case BE: - return _BE; - - case PE: - return _PE; + char_u tempc; - case TE: - return _TE; - - case SE: - return _SE; - - case JIM: - return _JIM; - - case CHE: - return _CHE; - - case HE_J: - return _HE_J; - - case XE: - return _XE; - - case SIN: - return _SIN; - - case SHIN: - return _SHIN; - - case SAD: - return _SAD; - - case ZAD: - return _ZAD; - - case AYN: - case AYN_: - case _AYN_: - return _AYN; - - case GHAYN: - case GHAYN_: - case _GHAYN_: - return _GHAYN; - - case FE: - return _FE; - - case GHAF: - return _GHAF; - - case KAF: - return _KAF; - - case GAF: - return _GAF; - - case LAM: - return _LAM; - - case MIM: - return _MIM; - - case NOON: - return _NOON; - - case _HE_: - case F_HE: - return _HE; - - case YE: - case YE_: - return _YE; - - case IE_: - case IE: - return _IE; - - case YEE: - case YEE_: - return _YEE; + switch (c) { + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case BE : tempc = _BE ; break; + case PE : tempc = _PE ; break; + case TE : tempc = _TE ; break; + case SE : tempc = _SE ; break; + case JIM : tempc = _JIM ; break; + case CHE : tempc = _CHE ; break; + case HE_J : tempc = _HE_J ; break; + case XE : tempc = _XE ; break; + case SIN : tempc = _SIN ; break; + case SHIN : tempc = _SHIN ; break; + case SAD : tempc = _SAD ; break; + case ZAD : tempc = _ZAD ; break; + case AYN : + case AYN_ : + case _AYN_ : tempc = _AYN ; break; + case GHAYN : + case GHAYN_ : + case _GHAYN_ : tempc = _GHAYN ; break; + case FE : tempc = _FE ; break; + case GHAF : tempc = _GHAF ; break; + case KAF : tempc = _KAF ; break; + case GAF : tempc = _GAF ; break; + case LAM : tempc = _LAM ; break; + case MIM : tempc = _MIM ; break; + case NOON : tempc = _NOON ; break; + case _HE_ : + case F_HE : tempc = _HE ; break; + case YE : + case YE_ : tempc = _YE ; break; + case IE_ : + case IE : tempc = _IE ; break; + case YEE : + case YEE_ : tempc = _YEE ; break; + default : tempc = c; } - return c; + + return tempc; } /// Convert a given Farsi char into right joining type. @@ -1971,102 +1334,51 @@ static int toF_leading(int c) /// @param c The character to convert. /// /// @return The Farsi character converted into a right joining type -static int toF_Rjoin(int c) +static char_u toF_Rjoin(char_u c) { - switch (c) { - case ALEF: - return ALEF_; - - case ALEF_U_H: - return ALEF_U_H_; - - case BE: - return _BE; - - case PE: - return _PE; - - case TE: - return _TE; - - case SE: - return _SE; - - case JIM: - return _JIM; + char_u tempc; - case CHE: - return _CHE; - - case HE_J: - return _HE_J; - - case XE: - return _XE; - - case SIN: - return _SIN; - - case SHIN: - return _SHIN; - - case SAD: - return _SAD; - - case ZAD: - return _ZAD; - - case AYN: - case AYN_: - case _AYN: - return _AYN_; - - case GHAYN: - case GHAYN_: - case _GHAYN_: - return _GHAYN_; - - case FE: - return _FE; - - case GHAF: - return _GHAF; - - case KAF: - return _KAF; - - case GAF: - return _GAF; - - case LAM: - return _LAM; - - case MIM: - return _MIM; - - case NOON: - return _NOON; - - case _HE: - case F_HE: - return _HE_; - - case YE: - case YE_: - return _YE; - - case IE_: - case IE: - return _IE; - - case TEE: - return TEE_; - - case YEE: - case YEE_: - return _YEE; + switch (c) { + case ALEF : tempc = ALEF_ ; break; + case ALEF_U_H : tempc = ALEF_U_H_ ; break; + case BE : tempc = _BE ; break; + case PE : tempc = _PE ; break; + case TE : tempc = _TE ; break; + case SE : tempc = _SE ; break; + case JIM : tempc = _JIM ; break; + case CHE : tempc = _CHE ; break; + case HE_J : tempc = _HE_J ; break; + case XE : tempc = _XE ; break; + case SIN : tempc = _SIN ; break; + case SHIN : tempc = _SHIN ; break; + case SAD : tempc = _SAD ; break; + case ZAD : tempc = _ZAD ; break; + case AYN : + case AYN_ : + case _AYN : tempc = _AYN_ ; break; + case GHAYN : + case GHAYN_ : + case _GHAYN_ : tempc = _GHAYN_ ; break; + case FE : tempc = _FE ; break; + case GHAF : tempc = _GHAF ; break; + case KAF : tempc = _KAF ; break; + case GAF : tempc = _GAF ; break; + case LAM : tempc = _LAM ; break; + case MIM : tempc = _MIM ; break; + case NOON : tempc = _NOON ; break; + case _HE : + case F_HE : tempc = _HE_ ; break; + case YE : + case YE_ : tempc = _YE ; break; + case IE_ : + case IE : tempc = _IE ; break; + case TEE : tempc = TEE_ ; break; + case YEE : + case YEE_ : tempc = _YEE ; break; + default : tempc = c ; } - return c; + + return tempc; } /// Can a given Farsi character join via its left edj. @@ -2074,7 +1386,7 @@ static int toF_Rjoin(int c) /// @param c The character to check. /// /// @return true if the character can join via its left edj. -static bool canF_Ljoin(int c) +static bool canF_Ljoin(char_u c) { switch (c) { case _BE: @@ -2148,7 +1460,7 @@ static bool canF_Ljoin(int c) /// @param c /// /// @return true if the character can join via its right edj. -static bool canF_Rjoin(int c) +static bool canF_Rjoin(char_u c) { switch (c) { case ALEF: @@ -2174,7 +1486,7 @@ static bool canF_Rjoin(int c) /// @param c /// /// @return true if the character is a terminating type. -static bool F_isterm(int c) +static bool F_isterm(char_u c) { switch (c) { case ALEF: @@ -2200,105 +1512,48 @@ static bool F_isterm(int c) /// @param c The character to convert. /// /// @return The character converted into an ending type. -static int toF_ending(int c) +static char_u toF_ending(char_u c) { - switch (c) { - case _BE: - return BE; - - case _PE: - return PE; - - case _TE: - return TE; - - case _SE: - return SE; - - case _JIM: - return JIM; - - case _CHE: - return CHE; - - case _HE_J: - return HE_J; - - case _XE: - return XE; - - case _SIN: - return SIN; - - case _SHIN: - return SHIN; - - case _SAD: - return SAD; + char_u tempc; - case _ZAD: - return ZAD; - - case _AYN: - return AYN; - - case _AYN_: - return AYN_; - - case _GHAYN: - return GHAYN; - - case _GHAYN_: - return GHAYN_; - - case _FE: - return FE; - - case _GHAF: - return GHAF; - - case _KAF_H: - case _KAF: - return KAF; - - case _GAF: - return GAF; - - case _LAM: - return LAM; - - case _MIM: - return MIM; - - case _NOON: - return NOON; - - case _YE: - return YE_; - - case YE_: - return YE; - - case _YEE: - return YEE_; - - case YEE_: - return YEE; - - case TEE: - return TEE_; - - case _IE: - return IE_; - - case IE_: - return IE; - - case _HE: - case _HE_: - return F_HE; + switch (c) { + case _BE : tempc = BE ; break; + case _PE : tempc = PE ; break; + case _TE : tempc = TE ; break; + case _SE : tempc = SE ; break; + case _JIM : tempc = JIM ; break; + case _CHE : tempc = CHE ; break; + case _HE_J : tempc = HE_J ; break; + case _XE : tempc = XE ; break; + case _SIN : tempc = SIN ; break; + case _SHIN : tempc = SHIN ; break; + case _SAD : tempc = SAD ; break; + case _ZAD : tempc = ZAD ; break; + case _AYN : tempc = AYN ; break; + case _AYN_ : tempc = AYN_ ; break; + case _GHAYN : tempc = GHAYN ; break; + case _GHAYN_ : tempc = GHAYN_ ; break; + case _FE : tempc = FE ; break; + case _GHAF : tempc = GHAF ; break; + case _KAF_H : + case _KAF : tempc = KAF ; break; + case _GAF : tempc = GAF ; break; + case _LAM : tempc = LAM ; break; + case _MIM : tempc = MIM ; break; + case _NOON : tempc = NOON ; break; + case _YE : tempc = YE_ ; break; + case YE_ : tempc = YE ; break; + case _YEE : tempc = YEE_ ; break; + case YEE_ : tempc = YEE ; break; + case TEE : tempc = TEE_ ; break; + case _IE : tempc = IE_ ; break; + case IE_ : tempc = IE ; break; + case _HE : + case _HE_ : tempc = F_HE ; break; + default : tempc = c ; } - return c; + + return tempc; } /// Convert the Farsi 3342 standard into Farsi VIM. @@ -2369,7 +1624,7 @@ void conv_to_pstd(void) static void lrswapbuf(char_u *buf, int len) { char_u *s, *e; - int c; + char_u c; s = buf; e = buf + len - 1; @@ -2442,6 +1697,7 @@ char_u* lrF_sub(char_u *ibuf) // Find the boundary of the search path while (((p = vim_strchr(p + 1, '/')) != NULL) && p[-1] == '\\') { + // empty } if (p == NULL) { @@ -2560,15 +1816,15 @@ int cmdl_fkmap(int c) case _NOON: case _HE: case _HE_: - cmd_pchar(toF_TyA(tempc), AT_CURSOR); + cmd_pchar(toF_TyA((char_u)tempc), AT_CURSOR); break; case _AYN_: - cmd_pchar(AYN_, AT_CURSOR); + cmd_pchar(AYN_, AT_CURSOR); break; case _GHAYN_: - cmd_pchar(GHAYN_, AT_CURSOR); + cmd_pchar(GHAYN_, AT_CURSOR); break; case _IE: @@ -2596,190 +1852,70 @@ int cmdl_fkmap(int c) } switch (c) { - case '0': - return FARSI_0; - - case '1': - return FARSI_1; - - case '2': - return FARSI_2; - - case '3': - return FARSI_3; - - case '4': - return FARSI_4; - - case '5': - return FARSI_5; - - case '6': - return FARSI_6; - - case '7': - return FARSI_7; - - case '8': - return FARSI_8; - - case '9': - return FARSI_9; - - case 'B': - return F_PSP; - - case 'E': - return JAZR_N; - - case 'F': - return ALEF_D_H; - - case 'H': - return ALEF_A; - - case 'I': - return TASH; - - case 'K': - return F_LQUOT; - - case 'L': - return F_RQUOT; - - case 'M': - return HAMZE; - - case 'O': - return '['; - - case 'P': - return ']'; - - case 'Q': - return OO; - - case 'R': - return MAD_N; - - case 'T': - return OW; - - case 'U': - return MAD; - - case 'W': - return OW_OW; - - case 'Y': - return JAZR; - - case '`': - return F_PCN; - - case '!': - return F_EXCL; - - case '@': - return F_COMMA; - - case '#': - return F_DIVIDE; - - case '$': - return F_CURRENCY; - - case '%': - return F_PERCENT; - - case '^': - return F_MUL; - - case '&': - return F_BCOMMA; - - case '*': - return F_STAR; - - case '(': - return F_LPARENT; - - case ')': - return F_RPARENT; - - case '-': - return F_MINUS; - - case '_': - return F_UNDERLINE; - - case '=': - return F_EQUALS; - - case '+': - return F_PLUS; - - case '\\': - return F_BSLASH; - - case '|': - return F_PIPE; - - case ':': - return F_DCOLON; - - case '"': - return F_SEMICOLON; - - case '.': - return F_PERIOD; - - case '/': - return F_SLASH; - - case '<': - return F_LESS; - - case '>': - return F_GREATER; - - case '?': - return F_QUESTION; - - case ' ': - return F_BLANK; + case '0' : return FARSI_0 ; + case '1' : return FARSI_1 ; + case '2' : return FARSI_2 ; + case '3' : return FARSI_3 ; + case '4' : return FARSI_4 ; + case '5' : return FARSI_5 ; + case '6' : return FARSI_6 ; + case '7' : return FARSI_7 ; + case '8' : return FARSI_8 ; + case '9' : return FARSI_9 ; + case 'B' : return F_PSP ; + case 'E' : return JAZR_N ; + case 'F' : return ALEF_D_H ; + case 'H' : return ALEF_A ; + case 'I' : return TASH ; + case 'K' : return F_LQUOT ; + case 'L' : return F_RQUOT ; + case 'M' : return HAMZE ; + case 'O' : return '[' ; + case 'P' : return ']' ; + case 'Q' : return OO ; + case 'R' : return MAD_N ; + case 'T' : return OW ; + case 'U' : return MAD ; + case 'W' : return OW_OW ; + case 'Y' : return JAZR ; + case '`' : return F_PCN ; + case '!' : return F_EXCL ; + case '@' : return F_COMMA ; + case '#' : return F_DIVIDE ; + case '$' : return F_CURRENCY ; + case '%' : return F_PERCENT ; + case '^' : return F_MUL ; + case '&' : return F_BCOMMA ; + case '*' : return F_STAR ; + case '(' : return F_LPARENT ; + case ')' : return F_RPARENT ; + case '-' : return F_MINUS ; + case '_' : return F_UNDERLINE ; + case '=' : return F_EQUALS ; + case '+' : return F_PLUS ; + case '\\' : return F_BSLASH ; + case '|' : return F_PIPE ; + case ':' : return F_DCOLON ; + case '"' : return F_SEMICOLON ; + case '.' : return F_PERIOD ; + case '/' : return F_SLASH ; + case '<' : return F_LESS ; + case '>' : return F_GREATER ; + case '?' : return F_QUESTION ; + case ' ' : return F_BLANK ; } break; - case 'a': - return _SHIN; - - case 'A': - return WAW_H; - - case 'b': - return ZAL; - - case 'c': - return ZE; - - case 'C': - return JE; - - case 'd': - return _YE; - - case 'D': - return _YEE; - - case 'e': - return _SE; - - case 'f': - return _BE; - - case 'g': - return _LAM; + case 'a' : return _SHIN ; + case 'A' : return WAW_H ; + case 'b' : return ZAL ; + case 'c' : return ZE ; + case 'C' : return JE ; + case 'd' : return _YE ; + case 'D' : return _YEE ; + case 'e' : return _SE ; + case 'f' : return _BE ; + case 'g' : return _LAM ; case 'G': if (cmd_gchar(AT_CURSOR) == _LAM) { @@ -2823,39 +1959,18 @@ int cmdl_fkmap(int c) return TEE; } - case 'k': - return _NOON; - - case 'l': - return _MIM; - - case 'm': - return _PE; - - case 'n': - case 'N': - return DAL; - - case 'o': - return _XE; - - case 'p': - return _HE_J; - - case 'q': - return _ZAD; - - case 'r': - return _GHAF; - - case 's': - return _SIN; - - case 'S': - return _IE; - - case 't': - return _FE; + case 'k' : return _NOON ; + case 'l' : return _MIM ; + case 'm' : return _PE ; + case 'n' : + case 'N' : return DAL ; + case 'o' : return _XE ; + case 'p' : return _HE_J ; + case 'q' : return _ZAD ; + case 'r' : return _GHAF ; + case 's' : return _SIN ; + case 'S' : return _IE ; + case 't' : return _FE ; case 'u': if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR)) { @@ -2864,16 +1979,11 @@ int cmdl_fkmap(int c) return _AYN; } - case 'v': - case 'V': - return RE; - - case 'w': - return _SAD; - - case 'x': - case 'X': - return _TA; + case 'v' : + case 'V' : return RE ; + case 'w' : return _SAD ; + case 'x' : + case 'X' : return _TA ; case 'y': if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR)) { @@ -2882,24 +1992,13 @@ int cmdl_fkmap(int c) return _GHAYN; } - case 'z': - case 'Z': - return _ZA; - - case ';': - return _KAF; - - case '\'': - return _GAF; - - case ',': - return WAW; - - case '[': - return _JIM; - - case ']': - return _CHE; + case 'z' : + case 'Z' : return _ZA ; + case ';' : return _KAF ; + case '\'' : return _GAF ; + case ',' : return WAW ; + case '[' : return _JIM ; + case ']' : return _CHE ; } return c; diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 9267e7991c..42779d6b71 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -496,19 +496,19 @@ vim_findfile_init ( } if (temp == NULL || wc_path == NULL) { - free(buf); - free(temp); - free(wc_path); + xfree(buf); + xfree(temp); + xfree(wc_path); goto error_return; } STRCPY(temp, search_ctx->ffsc_fix_path + len); STRCAT(temp, search_ctx->ffsc_wc_path); - free(search_ctx->ffsc_wc_path); - free(wc_path); + xfree(search_ctx->ffsc_wc_path); + xfree(wc_path); search_ctx->ffsc_wc_path = temp; } - free(buf); + xfree(buf); } sptr = ff_create_stack_element(ff_expand_buffer, @@ -563,7 +563,7 @@ void vim_findfile_cleanup(void *ctx) vim_findfile_free_visited(ctx); ff_clear(ctx); - free(ctx); + xfree(ctx); } /* @@ -947,7 +947,7 @@ char_u *vim_findfile(void *search_ctx_arg) break; } - free(file_path); + xfree(file_path); return NULL; } @@ -975,8 +975,8 @@ static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp) vp = (*list_headp)->ffvl_next; ff_free_visited_list((*list_headp)->ffvl_visited_list); - free((*list_headp)->ffvl_filename); - free(*list_headp); + xfree((*list_headp)->ffvl_filename); + xfree(*list_headp); *list_headp = vp; } *list_headp = NULL; @@ -988,8 +988,8 @@ static void ff_free_visited_list(ff_visited_T *vl) while (vl != NULL) { vp = vl->ffv_next; - free(vl->ffv_wc_path); - free(vl); + xfree(vl->ffv_wc_path); + xfree(vl); vl = vp; } vl = NULL; @@ -1205,13 +1205,13 @@ static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx) static void ff_free_stack_element(ff_stack_T *stack_ptr) { /* free handles possible NULL pointers */ - free(stack_ptr->ffs_fix_path); - free(stack_ptr->ffs_wc_path); + xfree(stack_ptr->ffs_fix_path); + xfree(stack_ptr->ffs_wc_path); if (stack_ptr->ffs_filearray != NULL) FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); - free(stack_ptr); + xfree(stack_ptr); } /* @@ -1225,19 +1225,19 @@ static void ff_clear(ff_search_ctx_T *search_ctx) while ((sptr = ff_pop(search_ctx)) != NULL) ff_free_stack_element(sptr); - free(search_ctx->ffsc_file_to_search); - free(search_ctx->ffsc_start_dir); - free(search_ctx->ffsc_fix_path); - free(search_ctx->ffsc_wc_path); + xfree(search_ctx->ffsc_file_to_search); + xfree(search_ctx->ffsc_start_dir); + xfree(search_ctx->ffsc_fix_path); + xfree(search_ctx->ffsc_wc_path); if (search_ctx->ffsc_stopdirs_v != NULL) { int i = 0; while (search_ctx->ffsc_stopdirs_v[i] != NULL) { - free(search_ctx->ffsc_stopdirs_v[i]); + xfree(search_ctx->ffsc_stopdirs_v[i]); i++; } - free(search_ctx->ffsc_stopdirs_v); + xfree(search_ctx->ffsc_stopdirs_v); } search_ctx->ffsc_stopdirs_v = NULL; @@ -1327,9 +1327,9 @@ static void *fdip_search_ctx = NULL; #if defined(EXITFREE) void free_findfile(void) { - free(ff_file_to_find); + xfree(ff_file_to_find); vim_findfile_cleanup(fdip_search_ctx); - free(ff_expand_buffer); + xfree(ff_expand_buffer); } #endif @@ -1382,7 +1382,7 @@ find_file_in_path_option ( expand_env(ptr, NameBuff, MAXPATHL); ptr[len] = save_char; - free(ff_file_to_find); + xfree(ff_file_to_find); ff_file_to_find = vim_strsave(NameBuff); } @@ -1487,7 +1487,7 @@ find_file_in_path_option ( fdip_search_ctx, FALSE, rel_fname); if (fdip_search_ctx != NULL) did_findfile_init = TRUE; - free(buf); + xfree(buf); } } } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 80f843048a..def1cc1d1a 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -724,7 +724,7 @@ readfile ( * always using the GUI. */ if (read_stdin) { - mch_msg(_("Vim: Reading from stdin...\n")); + mch_msg(_("Nvim: Reading from stdin...\n")); } else if (!read_buffer) filemess(curbuf, sfname, (char_u *)"", 0); } @@ -881,12 +881,12 @@ retry: notconverted = TRUE; conv_error = 0; if (fenc_alloced) - free(fenc); + xfree(fenc); fenc = (char_u *)""; fenc_alloced = FALSE; } else { if (fenc_alloced) - free(fenc); + xfree(fenc); if (fenc_next != NULL) { fenc = next_fenc(&fenc_next); fenc_alloced = (fenc_next != NULL); @@ -897,7 +897,7 @@ retry: } if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - free(tmpname); + xfree(tmpname); tmpname = NULL; } } @@ -1026,7 +1026,7 @@ retry: } if (linerest) /* copy characters from the previous buffer */ memmove(new_buffer, ptr - linerest, (size_t)linerest); - free(buffer); + xfree(buffer); buffer = new_buffer; ptr = buffer + linerest; line_start = buffer; @@ -1215,7 +1215,7 @@ retry: } else { /* BOM detected: set "fenc" and jump back */ if (fenc_alloced) - free(fenc); + xfree(fenc); fenc = ccname; fenc_alloced = FALSE; } @@ -1738,7 +1738,7 @@ failed: OPT_FREE | OPT_LOCAL, 0); } if (fenc_alloced) - free(fenc); + xfree(fenc); # ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { iconv_close(iconv_fd); @@ -1757,7 +1757,7 @@ failed: fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); } #endif - free(buffer); + xfree(buffer); #ifdef HAVE_DUP if (read_stdin) { @@ -1769,7 +1769,7 @@ failed: if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - free(tmpname); + xfree(tmpname); } --no_wait_return; /* may wait for return now */ @@ -1886,7 +1886,7 @@ failed: c = TRUE; msg_add_lines(c, (long)linecnt, filesize); - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; msg_scrolled_ign = TRUE; p = msg_trunc_attr(IObuff, FALSE, 0); @@ -2084,7 +2084,7 @@ void set_forced_fenc(exarg_T *eap) if (eap->force_enc != 0) { char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); - free(fenc); + xfree(fenc); } } @@ -2113,7 +2113,7 @@ static char_u *next_fenc(char_u **pp) r = vim_strnsave(*pp, (int)(p - *pp)); *pp = p + 1; p = enc_canonize(r); - free(r); + xfree(r); r = p; } return r; @@ -2157,7 +2157,7 @@ readfile_charconvert ( MSG(errmsg); if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - free(tmpname); + xfree(tmpname); tmpname = NULL; } } @@ -2816,7 +2816,7 @@ buf_write ( */ backup = modname(rootname, backup_ext, FALSE); if (backup == NULL) { - free(rootname); + xfree(rootname); some_error = TRUE; /* out of memory */ goto nobackup; } @@ -2832,7 +2832,7 @@ buf_write ( * link). If we don't check here, we either ruin the file when * copying or erase it after writing. */ - free(backup); + xfree(backup); backup = NULL; /* no backup file to delete */ } else if (!p_bk) { /* @@ -2851,13 +2851,13 @@ buf_write ( } /* They all exist??? Must be something wrong. */ if (*wp == 'a') { - free(backup); + xfree(backup); backup = NULL; } } } } - free(rootname); + xfree(rootname); /* * Try to create the backup file @@ -2871,7 +2871,7 @@ buf_write ( O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW, perm & 0777); if (bfd < 0) { - free(backup); + xfree(backup); backup = NULL; } else { /* set file protection same as original file, but @@ -2939,7 +2939,7 @@ buf_write ( } nobackup: close(fd); /* ignore errors for closing read file */ - free(copybuf); + xfree(copybuf); if (backup == NULL && errmsg == NULL) errmsg = (char_u *)_( @@ -2986,7 +2986,7 @@ nobackup: backup = NULL; else { backup = modname(rootname, backup_ext, FALSE); - free(rootname); + xfree(rootname); } if (backup != NULL) { @@ -3004,7 +3004,7 @@ nobackup: --*p; /* They all exist??? Must be something wrong! */ if (*p == 'a') { - free(backup); + xfree(backup); backup = NULL; } } @@ -3023,7 +3023,7 @@ nobackup: if (vim_rename(fname, backup) == 0) break; - free(backup); /* don't do the rename below */ + xfree(backup); /* don't do the rename below */ backup = NULL; } } @@ -3250,7 +3250,7 @@ restore_backup: } if (wfname != fname) - free(wfname); + xfree(wfname); goto fail; } errmsg = NULL; @@ -3446,7 +3446,7 @@ restore_backup: } } os_remove((char *)wfname); - free(wfname); + xfree(wfname); } if (end == 0) { @@ -3606,7 +3606,7 @@ restore_backup: EMSG(_("E205: Patchmode: can't save original file")); else if (!os_file_exists((char_u *)org)) { vim_rename(backup, (char_u *)org); - free(backup); /* don't delete the file */ + xfree(backup); /* don't delete the file */ backup = NULL; #ifdef UNIX set_file_time((char_u *)org, @@ -3632,7 +3632,7 @@ restore_backup: } if (org != NULL) { os_setperm((char_u *)org, os_getperm(fname) & 0777); - free(org); + xfree(org); } } @@ -3655,11 +3655,11 @@ nofail: /* Done saving, we accept changed buffer warnings again */ buf->b_saving = false; - free(backup); + xfree(backup); if (buffer != smallbuf) - free(buffer); - free(fenc_tofree); - free(write_info.bw_conv_buf); + xfree(buffer); + xfree(fenc_tofree); + xfree(write_info.bw_conv_buf); # ifdef USE_ICONV if (write_info.bw_iconv_fd != (iconv_t)-1) { iconv_close(write_info.bw_iconv_fd); @@ -3692,7 +3692,7 @@ nofail: STRCAT(IObuff, errmsg); emsg(IObuff); if (errmsg_allocated) - free(errmsg); + xfree(errmsg); retval = FAIL; if (end == 0) { @@ -4314,7 +4314,7 @@ void shorten_fnames(int force) && (force || buf->b_sfname == NULL || path_is_absolute_path(buf->b_sfname))) { - free(buf->b_sfname); + xfree(buf->b_sfname); buf->b_sfname = NULL; p = path_shorten_fname(buf->b_ffname, dirname); if (p != NULL) { @@ -4366,7 +4366,7 @@ modname ( retval = xmalloc(MAXPATHL + extlen + 3); if (os_dirname(retval, MAXPATHL) == FAIL || (fnamelen = (int)STRLEN(retval)) == 0) { - free(retval); + xfree(retval); return NULL; } if (!after_pathsep(retval, retval + fnamelen)) { @@ -4596,7 +4596,7 @@ int vim_rename(char_u *from, char_u *to) break; } - free(buffer); + xfree(buffer); close(fd_in); if (close(fd_out) < 0) errmsg = _("E209: Error closing \"%s\""); @@ -4705,11 +4705,11 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf) for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); if (ml_append(lnum - 1, p, 0, FALSE) == FAIL) { - free(p); + xfree(p); retval = FAIL; break; } - free(p); + xfree(p); } /* Delete all the lines in "frombuf". */ @@ -4922,8 +4922,8 @@ buf_check_timestamp ( already_warned = TRUE; } - free(path); - free(tbuf); + xfree(path); + xfree(tbuf); } if (reload) { @@ -5041,7 +5041,7 @@ void buf_reload(buf_T *buf, int orig_mode) } } } - free(ea.cmd); + xfree(ea.cmd); if (savebuf != NULL && buf_valid(savebuf)) wipe_buffer(savebuf, FALSE); @@ -5315,7 +5315,7 @@ static void show_autocmd(AutoPat *ap, event_T event) */ static void au_remove_pat(AutoPat *ap) { - free(ap->pat); + xfree(ap->pat); ap->pat = NULL; ap->buflocal_nr = -1; au_need_clean = TRUE; @@ -5329,7 +5329,7 @@ static void au_remove_cmds(AutoPat *ap) AutoCmd *ac; for (ac = ap->cmds; ac != NULL; ac = ac->next) { - free(ac->cmd); + xfree(ac->cmd); ac->cmd = NULL; } au_need_clean = TRUE; @@ -5361,8 +5361,8 @@ static void au_cleanup(void) * the command has been marked for deletion */ if (ap->pat == NULL || ac->cmd == NULL) { *prev_ac = ac->next; - free(ac->cmd); - free(ac); + xfree(ac->cmd); + xfree(ac); } else prev_ac = &(ac->next); } @@ -5371,7 +5371,7 @@ static void au_cleanup(void) if (ap->pat == NULL) { *prev_ap = ap->next; vim_regfree(ap->reg_prog); - free(ap); + xfree(ap); } else prev_ap = &(ap->next); } @@ -5445,7 +5445,7 @@ static void au_del_group(char_u *name) if (i == AUGROUP_ERROR) /* the group doesn't exist */ EMSG2(_("E367: No such group: \"%s\""), name); else { - free(AUGROUP_NAME(i)); + xfree(AUGROUP_NAME(i)); AUGROUP_NAME(i) = NULL; } } @@ -5637,7 +5637,7 @@ char_u *au_event_disable(char *what) else STRCAT(new_ei, what); set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE); - free(new_ei); + xfree(new_ei); return save_ei; } @@ -5647,7 +5647,7 @@ void au_event_restore(char_u *old_ei) if (old_ei != NULL) { set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE, SID_NONE); - free(old_ei); + xfree(old_ei); } } @@ -5782,8 +5782,8 @@ void do_autocmd(char_u *arg, int forceit) } if (need_free) - free(cmd); - free(envpat); + xfree(cmd); + xfree(envpat); } /* @@ -5807,7 +5807,7 @@ static int au_get_grouparg(char_u **argp) group = AUGROUP_ALL; /* no match, use all groups */ else *argp = skipwhite(p); /* match, skip over group name */ - free(group_name); + xfree(group_name); } return group; } @@ -5984,10 +5984,10 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd, &ap->allow_dirs, TRUE); if (reg_pat != NULL) ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC); - free(reg_pat); + xfree(reg_pat); if (reg_pat == NULL || ap->reg_prog == NULL) { - free(ap->pat); - free(ap); + xfree(ap->pat); + xfree(ap); return FAIL; } } @@ -6186,7 +6186,7 @@ aucmd_prepbuf ( /* Make sure w_localdir and globaldir are NULL to avoid a chdir() in * win_enter_ext(). */ - free(aucmd_win->w_localdir); + xfree(aucmd_win->w_localdir); aucmd_win->w_localdir = NULL; aco->globaldir = globaldir; globaldir = NULL; @@ -6262,7 +6262,7 @@ win_found: hash_init(&aucmd_win->w_vars->dv_hashtab); /* re-use the hashtab */ curbuf = curwin->w_buffer; - free(globaldir); + xfree(globaldir); globaldir = aco->globaldir; /* the buffer contents may have changed */ @@ -6584,23 +6584,22 @@ apply_autocmds_group ( fname = vim_strsave(fname); /* make a copy, so we can change it */ } else { sfname = vim_strsave(fname); - /* Don't try expanding FileType, Syntax, FuncUndefined, WindowID, - * ColorScheme, QuickFixCmd or JobActivity */ - if (event == EVENT_FILETYPE - || event == EVENT_SYNTAX + // don't try expanding the following events + if (event == EVENT_COLORSCHEME + || event == EVENT_FILETYPE || event == EVENT_FUNCUNDEFINED + || event == EVENT_QUICKFIXCMDPOST + || event == EVENT_QUICKFIXCMDPRE || event == EVENT_REMOTEREPLY || event == EVENT_SPELLFILEMISSING - || event == EVENT_QUICKFIXCMDPRE - || event == EVENT_COLORSCHEME - || event == EVENT_QUICKFIXCMDPOST + || event == EVENT_SYNTAX || event == EVENT_TABCLOSED) fname = vim_strsave(fname); else fname = FullName_save(fname, FALSE); } if (fname == NULL) { /* out of memory */ - free(sfname); + xfree(sfname); retval = FALSE; goto BYPASS_AU; } @@ -6706,10 +6705,10 @@ apply_autocmds_group ( autocmd_busy = save_autocmd_busy; filechangeshell_busy = FALSE; autocmd_nested = save_autocmd_nested; - free(sourcing_name); + xfree(sourcing_name); sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; - free(autocmd_fname); + xfree(autocmd_fname); autocmd_fname = save_autocmd_fname; autocmd_fname_full = save_autocmd_fname_full; autocmd_bufnr = save_autocmd_bufnr; @@ -6718,8 +6717,8 @@ apply_autocmds_group ( restore_funccal(save_funccalp); if (do_profiling == PROF_YES) prof_child_exit(&wait_time); - free(fname); - free(sfname); + xfree(fname); + xfree(sfname); --nesting; /* see matching increment above */ // When stopping to execute autocommands, restore the search patterns and @@ -6731,12 +6730,12 @@ apply_autocmds_group ( did_filetype = FALSE; while (au_pending_free_buf != NULL) { buf_T *b = au_pending_free_buf->b_next; - free(au_pending_free_buf); + xfree(au_pending_free_buf); au_pending_free_buf = b; } while (au_pending_free_win != NULL) { win_T *w = au_pending_free_win->w_next; - free(au_pending_free_win); + xfree(au_pending_free_win); au_pending_free_win = w; } } @@ -6807,7 +6806,7 @@ auto_next_pat ( char_u *name; char *s; - free(sourcing_name); + xfree(sourcing_name); sourcing_name = NULL; for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) { @@ -6943,9 +6942,9 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf) break; } - free(fname); + xfree(fname); #ifdef BACKSLASH_IN_FILENAME - free(sfname); + xfree(sfname); #endif return retval; @@ -7125,7 +7124,7 @@ int au_exists(char_u *arg) } theend: - free(arg_save); + xfree(arg_save); return retval; } @@ -7204,7 +7203,7 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname) break; match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs); - free(regpat); + xfree(regpat); if (match) return TRUE; } @@ -7400,7 +7399,7 @@ file_pat_to_reg_pat ( EMSG(_("E219: Missing {.")); else EMSG(_("E220: Missing }.")); - free(reg_pat); + xfree(reg_pat); reg_pat = NULL; } return reg_pat; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 267c586543..8e6c2a598e 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -114,9 +114,9 @@ static int prev_lnum_lvl = -1; #define DONE_ACTION 1 /* did close or open a fold */ #define DONE_FOLD 2 /* did find a fold */ -static int foldstartmarkerlen; +static size_t foldstartmarkerlen; static char_u *foldendmarker; -static int foldendmarkerlen; +static size_t foldendmarkerlen; /* Exported folding functions. {{{1 */ /* copyFoldingState() {{{2 */ @@ -622,7 +622,7 @@ void foldCreate(linenr_T start, linenr_T end) if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; /* Move contained folds to inside new fold. */ - memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); + memmove(fold_ga.ga_data, fp, sizeof(fold_T) * (size_t)cont); fold_ga.ga_len += cont; i += cont; @@ -634,7 +634,7 @@ void foldCreate(linenr_T start, linenr_T end) /* Move remaining entries to after the new fold. */ if (i < gap->ga_len) memmove(fp + 1, (fold_T *)gap->ga_data + i, - sizeof(fold_T) * (gap->ga_len - i)); + sizeof(fold_T) * (size_t)(gap->ga_len - i)); gap->ga_len = gap->ga_len + 1 - cont; /* insert new fold */ @@ -1051,7 +1051,7 @@ static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp) low = 0; high = gap->ga_len - 1; while (low <= high) { - int i = (low + high) / 2; + linenr_T i = (low + high) / 2; if (fp[i].fd_top > lnum) /* fold below lnum, adjust high */ high = i - 1; @@ -1292,7 +1292,6 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) { fold_T *fp; int i; - long moved; fold_T *nfp; fp = (fold_T *)gap->ga_data + idx; @@ -1301,12 +1300,12 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) deleteFoldRecurse(&fp->fd_nested); --gap->ga_len; if (idx < gap->ga_len) - memmove(fp, fp + 1, sizeof(fold_T) * (gap->ga_len - idx)); + memmove(fp, fp + 1, sizeof(fold_T) * (size_t)(gap->ga_len - idx)); } else { /* Move nested folds one level up, to overwrite the fold that is * deleted. */ - moved = fp->fd_nested.ga_len; - ga_grow(gap, (int)(moved - 1)); + int moved = fp->fd_nested.ga_len; + ga_grow(gap, moved - 1); { /* Get "fp" again, the array may have been reallocated. */ fp = (fold_T *)gap->ga_data + idx; @@ -1324,10 +1323,10 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) /* move the existing folds down to make room */ if (idx + 1 < gap->ga_len) memmove(fp + moved, fp + 1, - sizeof(fold_T) * (gap->ga_len - (idx + 1))); + sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1))); /* move the contained folds one level up */ - memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved)); - free(nfp); + memmove(fp, nfp, sizeof(fold_T) * (size_t)moved); + xfree(nfp); gap->ga_len += moved - 1; } } @@ -1584,17 +1583,16 @@ static void foldCreateMarkers(linenr_T start, linenr_T end) /* * Add "marker[markerlen]" in 'commentstring' to line "lnum". */ -static void foldAddMarker(linenr_T lnum, char_u *marker, int markerlen) +static void foldAddMarker(linenr_T lnum, char_u *marker, size_t markerlen) { char_u *cms = curbuf->b_p_cms; char_u *line; - int line_len; char_u *newline; char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s"); /* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */ line = ml_get(lnum); - line_len = (int)STRLEN(line); + size_t line_len = STRLEN(line); if (u_save(lnum - 1, lnum + 1) == OK) { newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1); @@ -1629,8 +1627,8 @@ deleteFoldMarkers ( } } foldDelMarker(fp->fd_top + lnum_off, curwin->w_p_fmr, foldstartmarkerlen); - foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1, - foldendmarker, foldendmarkerlen); + foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1, foldendmarker, + foldendmarkerlen); } /* foldDelMarker() {{{2 */ @@ -1640,7 +1638,7 @@ deleteFoldMarkers ( * If the marker is not found, there is no error message. Could a missing * close-marker. */ -static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) +static void foldDelMarker(linenr_T lnum, char_u *marker, size_t markerlen) { char_u *newline; char_u *cms = curbuf->b_p_cms; @@ -1652,7 +1650,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) continue; } /* Found the marker, include a digit if it's there. */ - int len = markerlen; + size_t len = markerlen; if (VIM_ISDIGIT(p[len])) ++len; if (*cms != NUL) { @@ -1662,7 +1660,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 && STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0) { p -= cms2 - cms; - len += (int)STRLEN(cms) - 2; + len += STRLEN(cms) - 2; } } if (u_save(lnum - 1, lnum + 1) == OK) { @@ -1762,7 +1760,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, } if (*p != NUL) { p = transstr(text); - free(text); + xfree(text); text = p; } } @@ -1781,27 +1779,23 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, */ void foldtext_cleanup(char_u *str) { - char_u *cms_start; /* first part or the whole comment */ - int cms_slen = 0; /* length of cms_start */ - char_u *cms_end; /* last part of the comment or NULL */ - int cms_elen = 0; /* length of cms_end */ char_u *s; char_u *p; - int len; int did1 = FALSE; int did2 = FALSE; /* Ignore leading and trailing white space in 'commentstring'. */ - cms_start = skipwhite(curbuf->b_p_cms); - cms_slen = (int)STRLEN(cms_start); + char_u *cms_start = skipwhite(curbuf->b_p_cms); + size_t cms_slen = STRLEN(cms_start); while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1])) --cms_slen; /* locate "%s" in 'commentstring', use the part before and after it. */ - cms_end = (char_u *)strstr((char *)cms_start, "%s"); + char_u *cms_end = (char_u *)strstr((char *)cms_start, "%s"); + size_t cms_elen = 0; if (cms_end != NULL) { - cms_elen = cms_slen - (int)(cms_end - cms_start); - cms_slen = (int)(cms_end - cms_start); + cms_elen = cms_slen - (size_t)(cms_end - cms_start); + cms_slen = (size_t)(cms_end - cms_start); /* exclude white space before "%s" */ while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1])) @@ -1809,13 +1803,13 @@ void foldtext_cleanup(char_u *str) /* skip "%s" and white space after it */ s = skipwhite(cms_end + 2); - cms_elen -= (int)(s - cms_end); + cms_elen -= (size_t)(s - cms_end); cms_end = s; } parseMarker(curwin); for (s = str; *s != NUL; ) { - len = 0; + size_t len = 0; if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) len = foldstartmarkerlen; else if (STRNCMP(s, foldendmarker, foldendmarkerlen) == 0) @@ -1830,7 +1824,7 @@ void foldtext_cleanup(char_u *str) ; if (p >= str + cms_slen && STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) { - len += (int)(s - p) + cms_slen; + len += (size_t)(s - p) + cms_slen; s = p - cms_slen; } } else if (cms_end != NULL) { @@ -2035,8 +2029,8 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot) if (fline.lvl > 0) { invalid_top = fline.lnum; invalid_bot = end; - end = foldUpdateIEMSRecurse(&wp->w_folds, - 1, start, &fline, getlevel, end, FD_LEVEL); + end = foldUpdateIEMSRecurse(&wp->w_folds, 1, start, &fline, getlevel, end, + FD_LEVEL); start = fline.lnum; } else { if (fline.lnum == wp->w_buffer->b_ml.ml_line_count) @@ -2095,7 +2089,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, linenr_T startlnum, fline_T *flp, LevelGetter getlevel, linenr_T bot, - int topflags /* flags used by containing fold */ + char topflags /* containing fold flags */ ) { linenr_T ll; @@ -2333,8 +2327,8 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, flp->off += fp->fd_top; i = (int)(fp - (fold_T *)gap->ga_data); bot = foldUpdateIEMSRecurse(&fp->fd_nested, level + 1, - startlnum2 - fp->fd_top, flp, getlevel, - bot - fp->fd_top, fp->fd_flags); + startlnum2 - fp->fd_top, flp, getlevel, + bot - fp->fd_top, fp->fd_flags); fp = (fold_T *)gap->ga_data + i; flp->lnum += fp->fd_top; flp->lnum_save += fp->fd_top; @@ -2468,7 +2462,7 @@ static void foldInsert(garray_T *gap, int i) fp = (fold_T *)gap->ga_data + i; if (i < gap->ga_len) - memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i)); + memmove(fp + 1, fp, sizeof(fold_T) * (size_t)(gap->ga_len - i)); ++gap->ga_len; ga_init(&fp->fd_nested, (int)sizeof(fold_T), 10); } @@ -2649,9 +2643,7 @@ static void foldlevelIndent(fline_T *flp) } else flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(curbuf); if (flp->lvl > flp->wp->w_p_fdn) { - flp->lvl = flp->wp->w_p_fdn; - if (flp->lvl < 0) - flp->lvl = 0; + flp->lvl = (int) MAX(0, flp->wp->w_p_fdn); } } @@ -2768,8 +2760,8 @@ static void foldlevelExpr(fline_T *flp) static void parseMarker(win_T *wp) { foldendmarker = vim_strchr(wp->w_p_fmr, ','); - foldstartmarkerlen = (int)(foldendmarker++ - wp->w_p_fmr); - foldendmarkerlen = (int)STRLEN(foldendmarker); + foldstartmarkerlen = (size_t)(foldendmarker++ - wp->w_p_fmr); + foldendmarkerlen = STRLEN(foldendmarker); } /* foldlevelMarker() {{{2 */ @@ -2822,9 +2814,8 @@ static void foldlevelMarker(fline_T *flp) ++flp->lvl_next; ++flp->start; } - } else if (*s == cend - && STRNCMP(s + 1, foldendmarker + 1, - foldendmarkerlen - 1) == 0) { + } else if (*s == cend && STRNCMP(s + 1, foldendmarker + 1, + foldendmarkerlen - 1) == 0) { /* found endmarker: set flp->lvl_next */ s += foldendmarkerlen; if (VIM_ISDIGIT(*s)) { diff --git a/src/nvim/fold.h b/src/nvim/fold.h index 1cbd7af5da..2ff10c0e91 100644 --- a/src/nvim/fold.h +++ b/src/nvim/fold.h @@ -1,14 +1,16 @@ #ifndef NVIM_FOLD_H #define NVIM_FOLD_H +#include "nvim/pos.h" + /* * Info used to pass info about a fold from the fold-detection code to the * code that displays the foldcolumn. */ typedef struct foldinfo { + linenr_T fi_lnum; /* line number where fold starts */ int fi_level; /* level of the fold; when this is zero the other fields are invalid */ - int fi_lnum; /* line number where fold starts */ int fi_low_level; /* lowest fold level that starts in the same line */ } foldinfo_T; diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 31a79db209..953eb58841 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -24,7 +24,7 @@ /// Clear an allocated growing array. void ga_clear(garray_T *gap) { - free(gap->ga_data); + xfree(gap->ga_data); // Initialize growing array without resetting itemsize or growsize gap->ga_data = NULL; @@ -114,7 +114,7 @@ void ga_remove_duplicate_strings(garray_T *gap) // loop over the growing array in reverse for (int i = gap->ga_len - 1; i > 0; i--) { if (fnamecmp(fnames[i - 1], fnames[i]) == 0) { - free(fnames[i]); + xfree(fnames[i]); // close the gap (move all strings one slot lower) for (int j = i + 1; j < gap->ga_len; j++) { diff --git a/src/nvim/garray.h b/src/nvim/garray.h index b758fce5da..642eaf54f0 100644 --- a/src/nvim/garray.h +++ b/src/nvim/garray.h @@ -61,7 +61,7 @@ static inline void *ga_append_via_ptr(garray_T *gap, size_t item_size) ga_clear(_gap); \ } while (false) -#define FREE_PTR_PTR(ptr) free(*(ptr)) +#define FREE_PTR_PTR(ptr) xfree(*(ptr)) /// Call `free` for every pointer stored in the garray and then frees the /// garray. diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index d901e99a2d..f45ee609bd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -167,7 +167,7 @@ void free_buff(buffheader_T *buf) for (p = buf->bh_first.b_next; p != NULL; p = np) { np = p->b_next; - free(p); + xfree(p); } buf->bh_first.b_next = NULL; } @@ -365,7 +365,7 @@ static int read_readbuf(buffheader_T *buf, int advance) if (advance) { if (curr->b_str[++buf->bh_index] == NUL) { buf->bh_first.b_next = curr->b_next; - free(curr); + xfree(curr); buf->bh_index = 0; } } @@ -495,7 +495,7 @@ void saveRedobuff(void) s = get_buffcont(&save_redobuff, FALSE); if (s != NULL) { add_buff(&redobuff, s, -1L); - free(s); + xfree(s); } } } @@ -904,7 +904,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent) typebuf.tb_buf + typebuf.tb_off + offset, (size_t)(typebuf.tb_len - offset + 1)); if (typebuf.tb_buf != typebuf_init) - free(typebuf.tb_buf); + xfree(typebuf.tb_buf); typebuf.tb_buf = s1; memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off, @@ -913,7 +913,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent) typebuf.tb_noremap + typebuf.tb_off + offset, (size_t)(typebuf.tb_len - offset)); if (typebuf.tb_noremap != noremapbuf_init) - free(typebuf.tb_noremap); + xfree(typebuf.tb_noremap); typebuf.tb_noremap = s2; typebuf.tb_off = newoff; @@ -1162,11 +1162,11 @@ void free_typebuf(void) if (typebuf.tb_buf == typebuf_init) EMSG2(_(e_intern2), "Free typebuf 1"); else - free(typebuf.tb_buf); + xfree(typebuf.tb_buf); if (typebuf.tb_noremap == noremapbuf_init) EMSG2(_(e_intern2), "Free typebuf 2"); else - free(typebuf.tb_noremap); + xfree(typebuf.tb_noremap); } /* @@ -2068,10 +2068,10 @@ static int vgetorpeek(int advance) i = ins_typebuf(s, noremap, 0, TRUE, cmd_silent || save_m_silent); if (save_m_expr) - free(s); + xfree(s); } - free(save_m_keys); - free(save_m_str); + xfree(save_m_keys); + xfree(save_m_str); if (i == FAIL) { c = -1; break; @@ -2906,9 +2906,9 @@ do_map ( } else { /* new rhs for existing entry */ mp->m_mode &= ~mode; /* remove mode bits */ if (mp->m_mode == 0 && !did_it) { /* reuse entry */ - free(mp->m_str); + xfree(mp->m_str); mp->m_str = vim_strsave(rhs); - free(mp->m_orig_str); + xfree(mp->m_orig_str); mp->m_orig_str = vim_strsave(orig_rhs); mp->m_noremap = noremap; mp->m_nowait = nowait; @@ -2998,8 +2998,8 @@ do_map ( } theend: - free(keys_buf); - free(arg_buf); + xfree(keys_buf); + xfree(arg_buf); return retval; } @@ -3012,11 +3012,11 @@ static void map_free(mapblock_T **mpp) mapblock_T *mp; mp = *mpp; - free(mp->m_keys); - free(mp->m_str); - free(mp->m_orig_str); + xfree(mp->m_keys); + xfree(mp->m_str); + xfree(mp->m_orig_str); *mpp = mp->m_next; - free(mp); + xfree(mp); } /* @@ -3211,7 +3211,7 @@ showmap ( if (mapchars != NULL) { msg_puts(mapchars); len = (int)STRLEN(mapchars); - free(mapchars); + xfree(mapchars); } while (++len <= 3) @@ -3246,7 +3246,7 @@ showmap ( char_u *s = vim_strsave(mp->m_str); vim_unescape_csi(s); msg_outtrans_special(s, FALSE); - free(s); + xfree(s); } if (p_verbose > 0) last_set_msg(mp->m_script_ID); @@ -3285,7 +3285,7 @@ int map_to_exists(char_u *str, char_u *modechars, int abbr) mode |= CMDLINE; retval = map_to_exists_mode(rhs, mode, abbr); - free(buf); + xfree(buf); return retval; } @@ -3469,7 +3469,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) p = NULL; } } - free(p); + xfree(p); } } /* for (mp) */ } /* for (hash) */ @@ -3499,7 +3499,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) if (STRCMP(*ptr1, *ptr2)) *++ptr1 = *ptr2++; else { - free(*ptr2++); + xfree(*ptr2++); count--; } } @@ -3617,7 +3617,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) && qlen == len && !STRNCMP(q, ptr, (size_t)len); if (q != mp->m_keys) { - free(q); + xfree(q); } if (match) { break; @@ -3669,7 +3669,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) /* no abbrev. for these chars */ typebuf.tb_no_abbr_cnt += (int)STRLEN(s) + j + 1; if (mp->m_expr) - free(s); + xfree(s); } tb[0] = Ctrl_H; @@ -3725,13 +3725,13 @@ eval_map_expr ( msg_row = save_msg_row; restore_cmdline_alloc(save_cmd); - free(expr); + xfree(expr); if (p == NULL) return NULL; /* Escape CSI in the result to be able to use the string as typeahead. */ res = vim_strsave_escape_csi(p); - free(p); + xfree(p); return res; } @@ -4171,7 +4171,7 @@ void add_map(char_u *map, int mode) p_cpo = (char_u *)""; /* Allow <> notation */ s = vim_strsave(map); (void)do_map(0, s, mode, FALSE); - free(s); + xfree(s); p_cpo = cpo_save; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index d7087ee928..a8c97c800d 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -404,7 +404,9 @@ EXTERN int no_check_timestamps INIT(= 0); /* Don't check timestamps */ typedef enum { HLF_8 = 0 /* Meta & special keys listed with ":map", text that is displayed different from what it is */ - , HLF_EOB // after the last line in the buffer + , HLF_EOB //< after the last line in the buffer + , HLF_TERM //< terminal cursor focused + , HLF_TERMNC //< terminal cursor unfocused , HLF_AT /* @ characters at end of screen, characters that don't really exist in the text */ , HLF_D /* directories in CTRL-D listing */ @@ -451,10 +453,10 @@ typedef enum { /* The HL_FLAGS must be in the same order as the HLF_ enums! * When changing this also adjust the default for 'highlight'. */ -#define HL_FLAGS {'8', '~', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', 'N', 'r', \ - 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', 'A', 'C', \ - 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', 'x', 'X', \ - '*', '#', '_', '!', '.', 'o'} +#define HL_FLAGS {'8', '~', 'z', 'Z', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', \ + 'N', 'r', 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', \ + 'A', 'C', 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', \ + 'x', 'X', '*', '#', '_', '!', '.', 'o'} EXTERN int highlight_attr[HLF_COUNT]; /* Highl. attr for each context. */ EXTERN int highlight_user[9]; /* User[1-9] attributes */ @@ -896,6 +898,14 @@ EXTERN FILE *scriptout INIT(= NULL); /* stream to write script to */ /* volatile because it is used in signal handler catch_sigint(). */ EXTERN volatile int got_int INIT(= FALSE); /* set to TRUE when interrupt signal occurred */ +EXTERN int disable_breakcheck INIT(= 0); // > 0 if breakchecks should be + // ignored. FIXME(tarruda): Hacky + // way to run functions that would + // result in *_breakcheck calls + // while events that would normally + // be deferred are being processed + // immediately. Ref: + // neovim/neovim#2371 EXTERN int bangredo INIT(= FALSE); /* set to TRUE with ! command */ EXTERN int searchcmdlen; /* length of previous search cmd */ EXTERN int reg_do_extmatch INIT(= 0); /* Used when compiling regexp: @@ -972,8 +982,8 @@ EXTERN char breakat_flags[256]; /* which characters are in 'breakat' */ * Makefile to make their value depend on the Makefile. */ #ifdef HAVE_PATHDEF -extern char_u *default_vim_dir; -extern char_u *default_vimruntime_dir; +extern char *default_vim_dir; +extern char *default_vimruntime_dir; extern char_u *compiled_user; extern char_u *compiled_sys; #endif @@ -1122,8 +1132,7 @@ EXTERN char_u e_nesting[] INIT(= N_("E22: Scripts nested too deep")); EXTERN char_u e_noalt[] INIT(= N_("E23: No alternate file")); EXTERN char_u e_noabbr[] INIT(= N_("E24: No such abbreviation")); EXTERN char_u e_nobang[] INIT(= N_("E477: No ! allowed")); -EXTERN char_u e_nogvim[] INIT(= N_( - "E25: GUI cannot be used: Not enabled at compile time")); +EXTERN char_u e_nogvim[] INIT(= N_("E25: Nvim does not have a built-in GUI")); EXTERN char_u e_nogroup[] INIT(= N_("E28: No such highlight group name: %s")); EXTERN char_u e_noinstext[] INIT(= N_("E29: No inserted text yet")); EXTERN char_u e_nolastcmd[] INIT(= N_("E30: No previous command line")); diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index b5e7ec414c..6e9ad02b3a 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -551,7 +551,7 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum) p += l; } - free(tbuf); + xfree(tbuf); if (psettings->do_syntax) /* Set colors for next character. */ @@ -1539,7 +1539,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name, resource->filename) && resource->filename[0] != NUL); - free(buffer); + xfree(buffer); return retval; } @@ -1921,7 +1921,7 @@ void mch_print_cleanup(void) */ for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { if (prt_ps_mb_font.ps_fontname[i] != NULL) - free(prt_ps_mb_font.ps_fontname[i]); + xfree(prt_ps_mb_font.ps_fontname[i]); prt_ps_mb_font.ps_fontname[i] = NULL; } } @@ -1936,7 +1936,7 @@ void mch_print_cleanup(void) prt_file_error = FALSE; } if (prt_ps_file_name != NULL) { - free(prt_ps_file_name); + xfree(prt_ps_file_name); prt_ps_file_name = NULL; } } @@ -2342,7 +2342,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) p = expand_env_save(psettings->outfile); if (p != NULL) { prt_ps_fd = mch_fopen((char *)p, WRITEBIN); - free(p); + xfree(p); } } if (prt_ps_fd == NULL) { @@ -3032,7 +3032,7 @@ int mch_print_text_out(char_u *p, size_t len) /* Need to free any translated characters */ if (prt_do_conv) - free(p); + xfree(p); prt_text_run += char_width; prt_pos_x += char_width; diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 6b90c4fee4..2da937633e 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -53,7 +53,7 @@ void hash_init(hashtab_T *ht) void hash_clear(hashtab_T *ht) { if (ht->ht_array != ht->ht_smallarray) { - free(ht->ht_array); + xfree(ht->ht_array); } } @@ -65,7 +65,7 @@ void hash_clear_all(hashtab_T *ht, unsigned int off) size_t todo = ht->ht_used; for (hashitem_T *hi = ht->ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { - free(hi->hi_key - off); + xfree(hi->hi_key - off); todo--; } } @@ -351,7 +351,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) } if (ht->ht_array != ht->ht_smallarray) { - free(ht->ht_array); + xfree(ht->ht_array); } ht->ht_array = newarray; ht->ht_mask = newmask; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index bd9e005676..48d8522865 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -433,7 +433,7 @@ static void cs_stat_emsg(char *fname) (void)sprintf(buf, stat_emsg, fname, errno); (void)EMSG(buf); - free(buf); + xfree(buf); } @@ -470,7 +470,7 @@ cs_add_common ( if (fname == NULL) goto add_err; fname = (char *)vim_strnsave((char_u *)fname, len); - free(fbuf); + xfree(fbuf); FileInfo file_info; bool file_info_ok = os_fileinfo(fname, &file_info); if (!file_info_ok) { @@ -538,15 +538,15 @@ staterr: } } - free(fname); - free(fname2); - free(ppath); + xfree(fname); + xfree(fname2); + xfree(ppath); return CSCOPE_SUCCESS; add_err: - free(fname2); - free(fname); - free(ppath); + xfree(fname2); + xfree(fname); + xfree(ppath); return CSCOPE_FAILURE; } /* cs_add_common */ @@ -605,7 +605,7 @@ static int cs_cnt_matches(int idx) cs_reading_emsg(idx); - free(buf); + xfree(buf); return -1; } @@ -636,7 +636,7 @@ static int cs_cnt_matches(int idx) break; } - free(buf); + xfree(buf); return nlines; } /* cs_cnt_matches */ @@ -805,9 +805,9 @@ err_closing: } # ifdef UNIX /* on Win32 we still need prog */ - free(prog); + xfree(prog); # endif - free(ppath); + xfree(ppath); #if defined(UNIX) # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) @@ -852,8 +852,8 @@ err_closing: si.hStdInput = stdin_rd; created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); - free(prog); - free(cmd); + xfree(prog); + xfree(cmd); if (!created) { PERROR(_("cs_create_connection exec failed")); @@ -982,7 +982,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us sprintf(buf, nf, *qfpos, *(qfpos-1)); (void)EMSG(buf); - free(buf); + xfree(buf); return FALSE; } @@ -1022,22 +1022,22 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us if (nummatches[i] == 0) (void)cs_read_prompt(i); } - free(cmd); + xfree(cmd); if (totmatches == 0) { char *nf = _("E259: no matches found for cscope query %s of %s"); char *buf; if (!verbose) { - free(nummatches); + xfree(nummatches); return FALSE; } buf = xmalloc(strlen(opt) + strlen(pat) + strlen(nf)); sprintf(buf, nf, opt, pat); (void)EMSG(buf); - free(buf); - free(nummatches); + xfree(buf); + xfree(nummatches); return FALSE; } @@ -1079,8 +1079,8 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us } } os_remove((char *)tmp); - free(tmp); - free(nummatches); + xfree(tmp); + xfree(nummatches); return TRUE; } else { char **matches = NULL, **contexts = NULL; @@ -1089,7 +1089,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us /* read output */ cs_fill_results((char *)pat, totmatches, nummatches, &matches, &contexts, &matched); - free(nummatches); + xfree(nummatches); if (matches == NULL) return FALSE; @@ -1424,12 +1424,12 @@ static char *cs_manage_matches(char **matches, char **contexts, int totmatches, if (mp != NULL) { if (cnt > 0) while (cnt--) { - free(mp[cnt]); + xfree(mp[cnt]); if (cp != NULL) - free(cp[cnt]); + xfree(cp[cnt]); } - free(mp); - free(cp); + xfree(mp); + xfree(cp); } mp = NULL; cp = NULL; @@ -1537,14 +1537,14 @@ static void cs_file_results(FILE *f, int *nummatches_a) else fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search); - free(context); - free(fullname); + xfree(context); + xfree(fullname); } /* for all matches */ (void)cs_read_prompt(i); } /* for all cscope connections */ - free(buf); + xfree(buf); } /* @@ -1583,7 +1583,7 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search, tagstr); - free(fullname); + xfree(fullname); if (strcmp(cntx, "<global>") == 0) cntxts[totsofar] = NULL; @@ -1601,16 +1601,16 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha if (totsofar == 0) { /* No matches, free the arrays and return NULL in "*matches_p". */ - free(matches); + xfree(matches); matches = NULL; - free(cntxts); + xfree(cntxts); cntxts = NULL; } *matched = totsofar; *matches_p = matches; *cntxts_p = cntxts; - free(buf); + xfree(buf); } /* cs_fill_results */ @@ -1661,7 +1661,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) (void)sprintf(buf, cstag_msg, ptag); MSG_PUTS_ATTR(buf, hl_attr(HLF_T)); - free(tbuf); + xfree(tbuf); MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T)); /* strlen is 7 */ msg_advance(msg_col + 2); @@ -1727,7 +1727,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) MSG_PUTS_LONG(extra); } - free(tbuf); /* only after printing extra due to strtok use */ + xfree(tbuf); /* only after printing extra due to strtok use */ if (msg_col) msg_putchar('\n'); @@ -1741,7 +1741,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) num++; } /* for all matches */ - free(buf); + xfree(buf); } /* cs_print_tags_priv */ @@ -1806,7 +1806,7 @@ static int cs_read_prompt(int i) else if (p_csverbose) cs_reading_emsg(i); /* don't have additional information */ cs_release_csp(i, TRUE); - free(buf); + xfree(buf); return CSCOPE_FAILURE; } @@ -1821,7 +1821,7 @@ static int cs_read_prompt(int i) break; /* did find the prompt */ } - free(buf); + xfree(buf); return CSCOPE_SUCCESS; } @@ -1947,9 +1947,9 @@ static void cs_release_csp(int i, int freefnpp) (void)fclose(csinfo[i].to_fp); if (freefnpp) { - free(csinfo[i].fname); - free(csinfo[i].ppath); - free(csinfo[i].flags); + xfree(csinfo[i].fname); + xfree(csinfo[i].ppath); + xfree(csinfo[i].flags); } clear_csinfo(i); @@ -1996,13 +1996,13 @@ static int cs_reset(exarg_T *eap) MSG_PUTS_ATTR(buf, hl_attr(HLF_R)); } } - free(dblist[i]); - free(pplist[i]); - free(fllist[i]); + xfree(dblist[i]); + xfree(pplist[i]); + xfree(fllist[i]); } - free(dblist); - free(pplist); - free(fllist); + xfree(dblist); + xfree(pplist); + xfree(fllist); if (p_csverbose) MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R) | MSG_HIST); @@ -2061,7 +2061,7 @@ static char *cs_resolve_file(int i, char *name) fullname = xstrdup(name); } - free(csdir); + xfree(csdir); return fullname; } @@ -2109,7 +2109,7 @@ void cs_end(void) for (i = 0; i < csinfo_size; i++) cs_release_csp(i, TRUE); - free(csinfo); + xfree(csinfo); csinfo_size = 0; } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 5711207933..183456d3f7 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -297,7 +297,7 @@ int set_indent(int size, int flags) } retval = true; } else { - free(newline); + xfree(newline); } curwin->w_cursor.col = ind_len; return retval; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 8310f635c9..c0613331cf 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -136,7 +136,7 @@ bool cin_is_cinword(char_u *line) } } - free(cinw_buf); + xfree(cinw_buf); return retval; } @@ -1332,7 +1332,7 @@ void parse_cino(buf_T *buf) char_u *l; int divider; int fraction = 0; - int sw = (int)get_sw_value(buf); + int sw = get_sw_value(buf); /* * Set the default values. @@ -3280,7 +3280,7 @@ theend: /* put the cursor back where it belongs */ curwin->w_cursor = cur_curpos; - free(linecopy); + xfree(linecopy); if (amount < 0) return 0; diff --git a/src/nvim/lib/khash.h b/src/nvim/lib/khash.h index c9198e048c..96e7ea6df0 100644 --- a/src/nvim/lib/khash.h +++ b/src/nvim/lib/khash.h @@ -181,7 +181,7 @@ typedef khint_t khiter_t; #define krealloc(P,Z) xrealloc(P,Z) #endif #ifndef kfree -#define kfree(P) free(P) +#define kfree(P) xfree(P) #endif static const double __ac_HASH_UPPER = 0.77; diff --git a/src/nvim/lib/klist.h b/src/nvim/lib/klist.h index f8dc7d4c43..7df809f07b 100644 --- a/src/nvim/lib/klist.h +++ b/src/nvim/lib/klist.h @@ -44,9 +44,9 @@ static inline void kmp_destroy_##name(kmp_##name##_t *mp) { \ size_t k; \ for (k = 0; k < mp->n; ++k) { \ - kmpfree_f(mp->buf[k]); free(mp->buf[k]); \ + kmpfree_f(mp->buf[k]); xfree(mp->buf[k]); \ } \ - free(mp->buf); free(mp); \ + xfree(mp->buf); xfree(mp); \ } \ static inline kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \ ++mp->cnt; \ @@ -95,7 +95,7 @@ kmp_free(name, kl->mp, p); \ kmp_free(name, kl->mp, p); \ kmp_destroy(name, kl->mp); \ - free(kl); \ + xfree(kl); \ } \ static inline kltype_t *kl_pushp_##name(kl_##name##_t *kl) { \ kl1_##name *q, *p = kmp_alloc(name, kl->mp); \ diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h index 982b5d6f1c..0466cb229c 100644 --- a/src/nvim/lib/kvec.h +++ b/src/nvim/lib/kvec.h @@ -55,7 +55,7 @@ int main() { #define kvec_t(type) struct { size_t size, capacity; type *items; } #define kv_init(v) ((v).size = (v).capacity = 0, (v).items = 0) -#define kv_destroy(v) free((v).items) +#define kv_destroy(v) xfree((v).items) #define kv_A(v, i) ((v).items[(i)]) #define kv_pop(v) ((v).items[--(v).size]) #define kv_size(v) ((v).size) diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 93812683d6..e14e998e7a 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -59,12 +59,12 @@ /* Use our own isdigit() replacement, because on MS-Windows isdigit() returns * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers * below 0 and above 255. */ -#define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10) +#define VIM_ISDIGIT(c) ((unsigned)(c) >= '0' && (unsigned)(c) <= '9') /* Like isalpha() but reject non-ASCII characters. Can't be used with a * special key (negative value). */ -# define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26) -# define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26) +# define ASCII_ISLOWER(c) ((unsigned)(c) >= 'a' && (unsigned)(c) <= 'z') +# define ASCII_ISUPPER(c) ((unsigned)(c) >= 'A' && (unsigned)(c) <= 'Z') # define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c)) # define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c)) diff --git a/src/nvim/main.c b/src/nvim/main.c index a03fd2e8a9..4753dc31c3 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -644,7 +644,7 @@ main_loop ( // duplicates. p = keep_msg; msg_attr(p, keep_msg_attr); - free(p); + xfree(p); } if (need_fileinfo) { /* show file info after redraw */ fileinfo(FALSE, TRUE, FALSE); @@ -840,7 +840,7 @@ static void init_locale(void) bindtextdomain(VIMPACKAGE, (char *)NameBuff); } if (mustfree) - free(p); + xfree(p); textdomain(VIMPACKAGE); } TIME_MSG("locale set"); @@ -1285,7 +1285,7 @@ scripterror: char_u *r; r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), TRUE); - free(p); + xfree(p); p = r; } @@ -1322,7 +1322,7 @@ scripterror: p = xmalloc(STRLEN(parmp->commands[0]) + 3); sprintf((char *)p, ":%s\r", parmp->commands[0]); set_vim_var_string(VV_SWAPCOMMAND, p, -1); - free(p); + xfree(p); } TIME_MSG("parsing arguments"); } @@ -1753,7 +1753,7 @@ static void exe_commands(mparm_T *parmp) for (i = 0; i < parmp->n_commands; ++i) { do_cmdline_cmd(parmp->commands[i]); if (parmp->cmds_tofree[i]) - free(parmp->commands[i]); + xfree(parmp->commands[i]); } sourcing_name = NULL; current_SID = 0; diff --git a/src/nvim/map.c b/src/nvim/map.c index 06ae19f5bc..5d83020619 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -45,7 +45,7 @@ void map_##T##_##U##_free(Map(T, U) *map) \ { \ kh_destroy(T##_##U##_map, map->table); \ - free(map); \ + xfree(map); \ } \ \ U map_##T##_##U##_get(Map(T, U) *map, T key) \ diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 2737380a8e..a142d12c13 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -131,7 +131,7 @@ int setmark_pos(int c, pos_T *pos, int fnum) i = c - 'A'; namedfm[i].fmark.mark = *pos; namedfm[i].fmark.fnum = fnum; - free(namedfm[i].fname); + xfree(namedfm[i].fname); namedfm[i].fname = NULL; return OK; } @@ -146,9 +146,6 @@ void setpcmark(void) { int i; xfmark_T *fm; -#ifdef JUMPLIST_ROTATE - xfmark_T tempmark; -#endif /* for :global the mark is set only once */ if (global_busy || listcmd_busy || cmdmod.keepjumps) @@ -157,27 +154,10 @@ void setpcmark(void) curwin->w_prev_pcmark = curwin->w_pcmark; curwin->w_pcmark = curwin->w_cursor; -# ifdef JUMPLIST_ROTATE - /* - * If last used entry is not at the top, put it at the top by rotating - * the stack until it is (the newer entries will be at the bottom). - * Keep one entry (the last used one) at the top. - */ - if (curwin->w_jumplistidx < curwin->w_jumplistlen) - ++curwin->w_jumplistidx; - while (curwin->w_jumplistidx < curwin->w_jumplistlen) { - tempmark = curwin->w_jumplist[curwin->w_jumplistlen - 1]; - for (i = curwin->w_jumplistlen - 1; i > 0; --i) - curwin->w_jumplist[i] = curwin->w_jumplist[i - 1]; - curwin->w_jumplist[0] = tempmark; - ++curwin->w_jumplistidx; - } -# endif - /* If jumplist is full: remove oldest entry */ if (++curwin->w_jumplistlen > JUMPLISTSIZE) { curwin->w_jumplistlen = JUMPLISTSIZE; - free(curwin->w_jumplist[0].fname); + xfree(curwin->w_jumplist[0].fname); for (i = 1; i < JUMPLISTSIZE; ++i) curwin->w_jumplist[i - 1] = curwin->w_jumplist[i]; } @@ -516,7 +496,7 @@ void fmarks_check_names(buf_T *buf) } } - free(name); + xfree(name); } static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) @@ -525,7 +505,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) && fm->fname != NULL && fnamecmp(name, fm->fname) == 0) { fm->fmark.fnum = buf->b_fnum; - free(fm->fname); + xfree(fm->fname); fm->fname = NULL; } } @@ -643,7 +623,7 @@ void do_marks(exarg_T *eap) arg, &namedfm[i].fmark.mark, name, namedfm[i].fmark.fnum == curbuf->b_fnum); if (namedfm[i].fmark.fnum != 0) - free(name); + xfree(name); } } show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE); @@ -698,7 +678,7 @@ show_one_mark ( if (name != NULL) { msg_outtrans_attr(name, current ? hl_attr(HLF_D) : 0); if (mustfree) - free(name); + xfree(name); } } ui_flush(); /* show one line at a time */ @@ -755,7 +735,7 @@ void ex_delmarks(exarg_T *eap) else n = i - 'A'; namedfm[n].fmark.mark.lnum = 0; - free(namedfm[n].fname); + xfree(namedfm[n].fname); namedfm[n].fname = NULL; } } @@ -797,7 +777,7 @@ void ex_jumps(exarg_T *eap) msg_putchar('\n'); if (got_int) { - free(name); + xfree(name); break; } sprintf((char *)IObuff, "%c %2d %5ld %4d ", @@ -810,7 +790,7 @@ void ex_jumps(exarg_T *eap) msg_outtrans_attr(name, curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum ? hl_attr(HLF_D) : 0); - free(name); + xfree(name); os_breakcheck(); } ui_flush(); @@ -844,7 +824,7 @@ void ex_changes(exarg_T *eap) msg_outtrans(IObuff); name = mark_line(&curbuf->b_changelist[i], 17); msg_outtrans_attr(name, hl_attr(HLF_D)); - free(name); + xfree(name); os_breakcheck(); } ui_flush(); @@ -1140,7 +1120,7 @@ static void cleanup_jumplist(void) if (i >= curwin->w_jumplistlen) /* no duplicate */ curwin->w_jumplist[to++] = curwin->w_jumplist[from]; else - free(curwin->w_jumplist[from].fname); + xfree(curwin->w_jumplist[from].fname); } if (curwin->w_jumplistidx == curwin->w_jumplistlen) curwin->w_jumplistidx = to; @@ -1171,7 +1151,7 @@ void free_jumplist(win_T *wp) int i; for (i = 0; i < wp->w_jumplistlen; ++i) - free(wp->w_jumplist[i].fname); + xfree(wp->w_jumplist[i].fname); } void set_last_cursor(win_T *win) @@ -1187,7 +1167,7 @@ void free_all_marks(void) for (i = 0; i < NMARKS + EXTRA_MARKS; i++) if (namedfm[i].fmark.mark.lnum != 0) - free(namedfm[i].fname); + xfree(namedfm[i].fname); } #endif @@ -1232,7 +1212,7 @@ int read_viminfo_filemark(vir_T *virp, int force) fm->fmark.mark.coladd = 0; fm->fmark.fnum = 0; str = skipwhite(str); - free(fm->fname); + xfree(fm->fname); fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line), FALSE); } @@ -1267,9 +1247,9 @@ void write_viminfo_filemarks(FILE *fp) : (name != NULL && STRCMP(name, namedfm[i].fname) == 0))) break; - free(name); + xfree(name); - free(namedfm[i].fname); + xfree(namedfm[i].fname); for (; i > NMARKS; --i) namedfm[i] = namedfm[i - 1]; namedfm[NMARKS].fmark.mark = curwin->w_cursor; @@ -1313,7 +1293,7 @@ static void write_one_filemark(FILE *fp, xfmark_T *fm, int c1, int c2) } if (fm->fmark.fnum != 0) - free(name); + xfree(name); } /* @@ -1337,7 +1317,7 @@ int removable(char_u *name) } } } - free(name); + xfree(name); return retval; } @@ -1494,7 +1474,7 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags count++; } } - free(str); + xfree(str); pos.coladd = 0; while (!(eof = viminfo_readline(virp)) && line[0] == TAB) { @@ -1540,5 +1520,5 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags break; } } - free(name_buf); + xfree(name_buf); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index fd6050f2d6..e45d43270a 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -523,7 +523,7 @@ char_u * mb_init(void) convert_setup(&vimconv, p_enc, (char_u *)"utf-8"); vimconv.vc_fail = true; } - free(p); + xfree(p); } #endif @@ -549,7 +549,7 @@ char_u * mb_init(void) */ p = string_convert(&vimconv, (char_u *)buf, NULL); if (p != NULL) { - free(p); + xfree(p); n = 1; } else n = 2; @@ -3103,7 +3103,7 @@ void utf_find_illegal(void) for (;; ) { p = get_cursor_pos_ptr(); if (vimconv.vc_type != CONV_NONE) { - free(tofree); + xfree(tofree); tofree = string_convert(&vimconv, p, NULL); if (tofree == NULL) break; @@ -3142,7 +3142,7 @@ void utf_find_illegal(void) beep_flush(); theend: - free(tofree); + xfree(tofree); convert_setup(&vimconv, NULL, NULL); } @@ -3375,7 +3375,7 @@ char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET STRMOVE(r, p); } else if ((i = enc_alias_search(p)) >= 0) { /* alias recognized, get canonical name */ - free(r); + xfree(r); r = vim_strsave((char_u *)enc_canon_table[i].name); } return r; @@ -3537,7 +3537,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen, p = xmalloc(len); if (done > 0) memmove(p, result, done); - free(result); + xfree(result); result = p; } @@ -3582,7 +3582,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen, fromlen -= l; } else if (ICONV_ERRNO != ICONV_E2BIG) { /* conversion failed */ - free(result); + xfree(result); result = NULL; break; } @@ -3891,7 +3891,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, if (l_w == 0) { /* Illegal utf-8 byte cannot be converted */ - free(retval); + xfree(retval); return NULL; } if (unconvlenp != NULL && l_w > len - i) { @@ -3925,7 +3925,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, if (c < 0x100) *d++ = c; else if (vcp->vc_fail) { - free(retval); + xfree(retval); return NULL; } else { *d++ = 0xbf; diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 26542759be..bbe2e62021 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -99,7 +99,7 @@ memfile_T *mf_open(char_u *fname, int flags) mf_do_open(mfp, fname, flags); if (mfp->mf_fd < 0) { // fail if file could not be opened - free(mfp); + xfree(mfp); return NULL; } } @@ -210,12 +210,12 @@ void mf_close(memfile_T *mfp, bool del_file) mf_free_bhdr(hp); } while (mfp->mf_free_first != NULL) // free entries in free list - free(mf_rem_free(mfp)); + xfree(mf_rem_free(mfp)); mf_hash_free(&mfp->mf_hash); mf_hash_free_all(&mfp->mf_trans); // free hashtable and its items - free(mfp->mf_fname); - free(mfp->mf_ffname); - free(mfp); + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); + xfree(mfp); } /// Close the swap file for a memfile. Used when 'swapfile' is reset. @@ -242,8 +242,8 @@ void mf_close_file(buf_T *buf, bool getlines) if (mfp->mf_fname != NULL) { os_remove((char *)mfp->mf_fname); // delete the swap file - free(mfp->mf_fname); - free(mfp->mf_ffname); + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); mfp->mf_fname = NULL; mfp->mf_ffname = NULL; } @@ -302,7 +302,7 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count) } else { // use the number, remove entry from free list freep = mf_rem_free(mfp); hp->bh_bnum = freep->bh_bnum; - free(freep); + xfree(freep); } } else { // get a new number if (hp == NULL) { @@ -398,11 +398,11 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile) /// Signal block as no longer used (may put it in the free list). void mf_free(memfile_T *mfp, bhdr_T *hp) { - free(hp->bh_data); // free data + xfree(hp->bh_data); // free data mf_rem_hash(mfp, hp); // get *hp out of the hash list mf_rem_used(mfp, hp); // get *hp out of the used list if (hp->bh_bnum < 0) { - free(hp); // don't want negative numbers in free list + xfree(hp); // don't want negative numbers in free list mfp->mf_neg_count--; } else { mf_ins_free(mfp, hp); // put *hp in the free list @@ -627,7 +627,7 @@ static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count) /// Make sure page_count of bh_data is right. if (hp->bh_page_count != page_count) { - free(hp->bh_data); + xfree(hp->bh_data); hp->bh_data = xmalloc(mfp->mf_page_size * page_count); hp->bh_page_count = page_count; } @@ -682,8 +682,8 @@ static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, unsigned page_count) /// Free a block header and its block memory. static void mf_free_bhdr(bhdr_T *hp) { - free(hp->bh_data); - free(hp); + xfree(hp->bh_data); + xfree(hp); } /// Insert a block in the free list. @@ -843,7 +843,7 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp) freep->bh_page_count -= page_count; } else { freep = mf_rem_free(mfp); - free(freep); + xfree(freep); } } else { new_bnum = mfp->mf_blocknr_max; @@ -881,7 +881,7 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr) // remove entry from the trans list mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np); - free(np); + xfree(np); return new_bnum; } @@ -902,7 +902,7 @@ void mf_set_ffname(memfile_T *mfp) void mf_fullname(memfile_T *mfp) { if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) { - free(mfp->mf_fname); + xfree(mfp->mf_fname); mfp->mf_fname = mfp->mf_ffname; mfp->mf_ffname = NULL; } @@ -940,8 +940,8 @@ static void mf_do_open(memfile_T *mfp, char_u *fname, int flags) // If the file cannot be opened, use memory only if (mfp->mf_fd < 0) { - free(mfp->mf_fname); - free(mfp->mf_ffname); + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); mfp->mf_fname = NULL; mfp->mf_ffname = NULL; } else { @@ -979,7 +979,7 @@ static void mf_hash_init(mf_hashtab_T *mht) static void mf_hash_free(mf_hashtab_T *mht) { if (mht->mht_buckets != mht->mht_small_buckets) - free(mht->mht_buckets); + xfree(mht->mht_buckets); } /// Free the array of a hash table and all the items it contains. @@ -990,7 +990,7 @@ static void mf_hash_free_all(mf_hashtab_T *mht) for (size_t idx = 0; idx <= mht->mht_mask; idx++) for (mf_hashitem_T *mhi = mht->mht_buckets[idx]; mhi != NULL; mhi = next) { next = mhi->mhi_next; - free(mhi); + xfree(mhi); } mf_hash_free(mht); @@ -1088,7 +1088,7 @@ static void mf_hash_grow(mf_hashtab_T *mht) } if (mht->mht_buckets != mht->mht_small_buckets) - free(mht->mht_buckets); + xfree(mht->mht_buckets); mht->mht_buckets = buckets; mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 8b2ebfe554..a72dc43eb4 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -91,8 +91,6 @@ typedef struct pointer_entry PTR_EN; /* block/line-count pair */ #define PTR_ID (('p' << 8) + 't') /* pointer block id */ #define BLOCK0_ID0 'b' /* block 0 id 0 */ #define BLOCK0_ID1 '0' /* block 0 id 1 */ -#define BLOCK0_ID1_C0 'c' /* block 0 id 1 'cm' 0 */ -#define BLOCK0_ID1_C1 'C' /* block 0 id 1 'cm' 1 */ /* * pointer to a block, used in a pointer block @@ -176,8 +174,7 @@ struct data_block { * variables, because the rest of the swap file is not portable. */ struct block0 { - char_u b0_id[2]; /* id for block 0: BLOCK0_ID0 and BLOCK0_ID1, - * BLOCK0_ID1_C0, BLOCK0_ID1_C1 */ + char_u b0_id[2]; ///< ID for block 0: BLOCK0_ID0 and BLOCK0_ID1. char_u b0_version[10]; /* Vim version string */ char_u b0_page_size[4]; /* number of bytes per page */ char_u b0_mtime[4]; /* last modification time of file */ @@ -376,7 +373,7 @@ error: if (mfp != NULL) { if (hp) mf_put(mfp, hp, false, false); - mf_close(mfp, true); /* will also free(mfp->mf_fname) */ + mf_close(mfp, true); /* will also xfree(mfp->mf_fname) */ } buf->b_ml.ml_mfp = NULL; return FAIL; @@ -421,7 +418,7 @@ void ml_setname(buf_T *buf) /* if the file name is the same we don't have to do anything */ if (fnamecmp(fname, mfp->mf_fname) == 0) { - free(fname); + xfree(fname); success = TRUE; break; } @@ -434,14 +431,14 @@ void ml_setname(buf_T *buf) /* try to rename the swap file */ if (vim_rename(mfp->mf_fname, fname) == 0) { success = TRUE; - free(mfp->mf_fname); + xfree(mfp->mf_fname); mfp->mf_fname = fname; - free(mfp->mf_ffname); + xfree(mfp->mf_ffname); mf_set_ffname(mfp); ml_upd_block0(buf, UB_SAME_DIR); break; } - free(fname); /* this fname didn't work, try another */ + xfree(fname); /* this fname didn't work, try another */ } if (mfp->mf_fd == -1) { /* need to (re)open the swap file */ @@ -570,9 +567,9 @@ void ml_close(buf_T *buf, int del_file) return; mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */ if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) - free(buf->b_ml.ml_line_ptr); - free(buf->b_ml.ml_stack); - free(buf->b_ml.ml_chunksize); + xfree(buf->b_ml.ml_line_ptr); + xfree(buf->b_ml.ml_stack); + xfree(buf->b_ml.ml_chunksize); buf->b_ml.ml_chunksize = NULL; buf->b_ml.ml_mfp = NULL; @@ -619,22 +616,16 @@ void ml_timestamp(buf_T *buf) ml_upd_block0(buf, UB_FNAME); } -/* - * Return FAIL when the ID of "b0p" is wrong. - */ -static int ml_check_b0_id(ZERO_BL *b0p) +/// Checks whether the IDs in b0 are valid. +static bool ml_check_b0_id(ZERO_BL *b0p) + FUNC_ATTR_NONNULL_ALL { - if (b0p->b0_id[0] != BLOCK0_ID0 - || (b0p->b0_id[1] != BLOCK0_ID1 - && b0p->b0_id[1] != BLOCK0_ID1_C0 - && b0p->b0_id[1] != BLOCK0_ID1_C1) - ) - return FAIL; - return OK; + return b0p->b0_id[0] == BLOCK0_ID0 && b0p->b0_id[1] == BLOCK0_ID1; } -/// Return true if all strings in b0 are correct (nul-terminated). -static bool ml_check_b0_strings(ZERO_BL *b0p) FUNC_ATTR_NONNULL_ALL +/// Checks whether all strings in b0 are valid (i.e. nul-terminated). +static bool ml_check_b0_strings(ZERO_BL *b0p) + FUNC_ATTR_NONNULL_ALL { return (memchr(b0p->b0_version, NUL, 10) && memchr(b0p->b0_uname, NUL, B0_UNAME_SIZE) @@ -833,7 +824,7 @@ void ml_recover(void) (void)recover_names(fname, FALSE, i, &fname_used); } if (fname_used == NULL) - goto theend; /* out of memory */ + goto theend; // user chose invalid number. /* When called from main() still need to initialize storage structure */ if (called_from_main && ml_open(curbuf) == FAIL) @@ -944,7 +935,7 @@ void ml_recover(void) /* need to reallocate the memory used to store the data */ p = xmalloc(mfp->mf_page_size); memmove(p, hp->bh_data, previous_page_size); - free(hp->bh_data); + xfree(hp->bh_data); hp->bh_data = p; b0p = hp->bh_data; } @@ -1017,7 +1008,7 @@ void ml_recover(void) set_fileformat(b0_ff - 1, OPT_LOCAL); if (b0_fenc != NULL) { set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL); - free(b0_fenc); + xfree(b0_fenc); } unchanged(curbuf, TRUE); @@ -1203,7 +1194,7 @@ void ml_recover(void) /* Need to copy one line, fetching the other one may flush it. */ p = vim_strsave(ml_get(idx)); i = STRCMP(p, ml_get(idx + lnum)); - free(p); + xfree(p); if (i != 0) { changed_int(); ++curbuf->b_changedtick; @@ -1246,15 +1237,17 @@ void ml_recover(void) redraw_curbuf_later(NOT_VALID); theend: - free(fname_used); + xfree(fname_used); recoverymode = FALSE; if (mfp != NULL) { if (hp != NULL) mf_put(mfp, hp, false, false); - mf_close(mfp, false); /* will also free(mfp->mf_fname) */ + mf_close(mfp, false); /* will also xfree(mfp->mf_fname) */ + } + if (buf != NULL) { //may be NULL if swap file not found. + xfree(buf->b_ml.ml_stack); + xfree(buf); } - free(buf->b_ml.ml_stack); - free(buf); if (serious_error && called_from_main) ml_close(curbuf, TRUE); else { @@ -1330,53 +1323,35 @@ recover_names ( if (dir_name[0] == '.' && dir_name[1] == NUL) { /* check current dir */ if (fname == NULL) { names[0] = vim_strsave((char_u *)"*.sw?"); -#if defined(UNIX) || defined(WIN3264) /* For Unix names starting with a dot are special. MS-Windows * supports this too, on some file systems. */ names[1] = vim_strsave((char_u *)".*.sw?"); names[2] = vim_strsave((char_u *)".sw?"); num_names = 3; -#else - num_names = 1; -#endif } else num_names = recov_file_names(names, fname_res, TRUE); } else { /* check directory dir_name */ if (fname == NULL) { names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); -#if defined(UNIX) || defined(WIN3264) /* For Unix names starting with a dot are special. MS-Windows * supports this too, on some file systems. */ names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); num_names = 3; -#else - num_names = 1; -#endif } else { -#if defined(UNIX) || defined(WIN3264) p = dir_name + STRLEN(dir_name); if (after_pathsep(dir_name, p) && p[-1] == p[-2]) { /* Ends with '//', Use Full path for swap name */ tail = make_percent_swname(dir_name, fname_res); - } else -#endif - tail = path_tail(fname_res); - tail = concat_fnames(dir_name, tail, TRUE); + } else { + tail = path_tail(fname_res); + tail = concat_fnames(dir_name, tail, TRUE); + } num_names = recov_file_names(names, tail, FALSE); - free(tail); + xfree(tail); } } - // check for out-of-memory - for (int i = 0; i < num_names; ++i) { - if (names[i] == NULL) { - for (int j = 0; j < num_names; ++j) - free(names[j]); - num_names = 0; - break; - } - } if (num_names == 0) num_files = 0; else if (expand_wildcards(num_names, names, &num_files, &files, @@ -1397,7 +1372,7 @@ recover_names ( swapname = NULL; num_files = 1; } - free(swapname); + xfree(swapname); } } @@ -1411,9 +1386,9 @@ recover_names ( /* Remove the name from files[i]. Move further entries * down. When the array becomes empty free it here, since * FreeWild() won't be called below. */ - free(files[i]); + xfree(files[i]); if (--num_files == 0) - free(files); + xfree(files); else for (; i < num_files; ++i) files[i] = files[i + 1]; @@ -1454,15 +1429,14 @@ recover_names ( file_count += num_files; for (int i = 0; i < num_names; ++i) - free(names[i]); + xfree(names[i]); if (num_files > 0) FreeWild(num_files, files); } - free(dir_name); + xfree(dir_name); return file_count; } -#if defined(UNIX) || defined(WIN3264) /* Need _very_ long file names */ /* * Append the full path to name with path separators made into percent * signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"") @@ -1479,12 +1453,11 @@ static char_u *make_percent_swname(char_u *dir, char_u *name) if (vim_ispathsep(*d)) *d = '%'; d = concat_fnames(dir, s, TRUE); - free(s); - free(f); + xfree(s); + xfree(f); } return d; } -#endif #ifdef UNIX static int process_still_running; @@ -1585,17 +1558,12 @@ static time_t swapfile_info(char_u *fname) } static int recov_file_names(char_u **names, char_u *path, int prepend_dot) + FUNC_ATTR_NONNULL_ALL { - int num_names; - char_u *p; - int i; - - num_names = 0; + int num_names = 0; - /* - * May also add the file name with a dot prepended, for swap file in same - * dir as original file. - */ + // May also add the file name with a dot prepended, for swap file in same + // dir as original file. if (prepend_dot) { names[num_names] = modname(path, (char_u *)".sw?", TRUE); if (names[num_names] == NULL) @@ -1606,15 +1574,15 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot) // Form the normal swap file name pattern by appending ".sw?". names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE); if (num_names >= 1) { /* check if we have the same name twice */ - p = names[num_names - 1]; - i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); + char_u *p = names[num_names - 1]; + int i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); if (i > 0) p += i; /* file name has been expanded to full path */ if (STRCMP(p, names[num_names]) != 0) ++num_names; else - free(names[num_names]); + xfree(names[num_names]); } else ++num_names; @@ -2371,7 +2339,7 @@ int ml_replace(linenr_T lnum, char_u *line, int copy) if (curbuf->b_ml.ml_line_lnum != lnum) /* other line buffered */ ml_flush_line(curbuf); /* flush it */ else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */ - free(curbuf->b_ml.ml_line_ptr); /* free it */ + xfree(curbuf->b_ml.ml_line_ptr); /* free it */ curbuf->b_ml.ml_line_ptr = line; curbuf->b_ml.ml_line_lnum = lnum; curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; @@ -2726,7 +2694,7 @@ static void ml_flush_line(buf_T *buf) (void)ml_delete_int(buf, lnum, FALSE); } } - free(new_line); + xfree(new_line); entered = FALSE; } @@ -2970,7 +2938,7 @@ static int ml_add_stack(buf_T *buf) infoptr_T *newstack = xmalloc(sizeof(infoptr_T) * (buf->b_ml.ml_stack_size + STACK_INCR)); memmove(newstack, buf->b_ml.ml_stack, (size_t)top * sizeof(infoptr_T)); - free(buf->b_ml.ml_stack); + xfree(buf->b_ml.ml_stack); buf->b_ml.ml_stack = newstack; buf->b_ml.ml_stack_size += STACK_INCR; } @@ -3097,17 +3065,15 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name char_u fname_buf[MAXPATHL]; #endif -#if defined(UNIX) || defined(WIN3264) /* Need _very_ long file names */ s = dir_name + STRLEN(dir_name); if (after_pathsep(dir_name, s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */ r = NULL; if ((s = make_percent_swname(dir_name, fname)) != NULL) { r = modname(s, (char_u *)".swp", FALSE); - free(s); + xfree(s); } return r; } -#endif #ifdef HAVE_READLINK /* Expand symlink in the file name, so that we put the swap file with the @@ -3123,7 +3089,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name return NULL; s = get_file_in_dir(r, dir_name); - free(r); + xfree(r); return s; } @@ -3163,7 +3129,7 @@ get_file_in_dir ( t = concat_fnames(fname, dname + 2, TRUE); *tail = save_char; retval = concat_fnames(t, tail, TRUE); - free(t); + xfree(t); } } else { retval = concat_fnames(dname, tail, TRUE); @@ -3298,7 +3264,7 @@ findswapname ( if (fname == NULL) /* must be out of memory */ break; if ((n = (int)STRLEN(fname)) == 0) { /* safety check */ - free(fname); + xfree(fname); fname = NULL; break; } @@ -3428,7 +3394,7 @@ findswapname ( if (process_still_running && choice >= 4) choice++; /* Skip missing "Delete it" button */ # endif - free(name); + xfree(name); /* pretend screen didn't scroll, need redraw anyway */ msg_scrolled = 0; @@ -3481,7 +3447,7 @@ findswapname ( if (fname[n - 1] == 'a') { /* ".s?a" */ if (fname[n - 2] == 'a') { /* ".saa": tried enough, give up */ EMSG(_("E326: Too many swap files found")); - free(fname); + xfree(fname); fname = NULL; break; } @@ -3491,7 +3457,7 @@ findswapname ( --fname[n - 1]; /* ".swo", ".swn", etc. */ } - free(dir_name); + xfree(dir_name); return fname; } diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 2223b65a93..2d4259a238 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -18,6 +18,14 @@ # include "memory.c.generated.h" #endif +#if defined(USE_JEMALLOC) && !defined(UNIT_TESTING) +#include "jemalloc/jemalloc.h" +#define malloc(size) je_malloc(size) +#define calloc(count, size) je_calloc(count, size) +#define realloc(ptr, size) je_realloc(ptr, size) +#define free(ptr) je_free(ptr) +#endif + /// Try to free memory. Used when trying to recover from out of memory errors. /// @see {xmalloc} static void try_to_free_memory(void) @@ -92,6 +100,12 @@ void *xmalloc(size_t size) return ret; } +/// free wrapper that returns delegates to the backing memory manager +void xfree(void *ptr) +{ + free(ptr); +} + /// calloc() wrapper /// /// @see {xmalloc} @@ -362,19 +376,7 @@ size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size) char *xstrdup(const char *str) FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET { - char *ret = strdup(str); - - if (!ret) { - try_to_free_memory(); - ret = strdup(str); - if (!ret) { - mch_errmsg(e_outofmem); - mch_errmsg("\n"); - preserve_exit(); - } - } - - return ret; + return xmemdupz(str, strlen(str)); } /// A version of memchr that starts the search at `src + len`. @@ -541,8 +543,8 @@ void free_all_mem(void) clear_sb_text(); /* free any scrollback text */ /* Free some global vars. */ - free(last_cmdline); - free(new_last_cmdline); + xfree(last_cmdline); + xfree(new_last_cmdline); set_keep_msg(NULL, 0); /* Clear cmdline history. */ diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 8d9b5045b9..1689e7419e 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -188,7 +188,7 @@ ex_menu ( if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); menu_nable_recurse(root_menu, p, MENU_ALL_MODES, enable); - free(p); + xfree(p); } } menu_nable_recurse(root_menu, menu_path, modes, enable); @@ -207,7 +207,7 @@ ex_menu ( if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); remove_menu(&root_menu, p, MENU_ALL_MODES, TRUE); - free(p); + xfree(p); } } @@ -241,11 +241,11 @@ ex_menu ( // Include all modes, to make ":amenu" work menuarg.modes = modes; add_menu_path(p, &menuarg, pri_tab, map_to); - free(p); + xfree(p); } } - free(map_buf); + xfree(map_buf); } @@ -391,12 +391,12 @@ add_menu_path ( menup = &menu->children; parent = menu; name = next_name; - free(dname); + xfree(dname); dname = NULL; if (pri_tab[pri_idx + 1] != -1) ++pri_idx; } - free(path_name); + xfree(path_name); /* * Only add system menu items which have not been defined yet. @@ -470,8 +470,8 @@ add_menu_path ( return OK; erret: - free(path_name); - free(dname); + xfree(path_name); + xfree(dname); /* Delete any empty submenu we added before discovering the error. Repeat * for higher levels. */ @@ -663,14 +663,14 @@ static void free_menu(vimmenu_T **menup) /* Don't change *menup until after calling gui_mch_destroy_menu(). The * MacOS code needs the original structure to properly delete the menu. */ *menup = menu->next; - free(menu->name); - free(menu->dname); - free(menu->en_name); - free(menu->en_dname); - free(menu->actext); + xfree(menu->name); + xfree(menu->dname); + xfree(menu->en_name); + xfree(menu->en_dname); + xfree(menu->actext); for (i = 0; i < MENU_MODES; i++) free_menu_string(menu, i); - free(menu); + xfree(menu); } @@ -686,7 +686,7 @@ static void free_menu_string(vimmenu_T *menu, int idx) if (menu->strings[i] == menu->strings[idx]) count++; if (count == 1) - free(menu->strings[idx]); + xfree(menu->strings[idx]); menu->strings[idx] = NULL; } @@ -711,11 +711,11 @@ static int show_menus(char_u *path_name, int modes) /* Found menu */ if (*p != NUL && menu->children == NULL) { EMSG(_(e_notsubmenu)); - free(path_name); + xfree(path_name); return FAIL; } else if ((menu->modes & modes) == 0x0) { EMSG(_(e_othermode)); - free(path_name); + xfree(path_name); return FAIL; } break; @@ -724,14 +724,14 @@ static int show_menus(char_u *path_name, int modes) } if (menu == NULL) { EMSG2(_(e_nomenu), name); - free(path_name); + xfree(path_name); return FAIL; } name = p; parent = menu; menu = menu->children; } - free(path_name); + xfree(path_name); /* Now we have found the matching menu, and we list the mappings */ /* Highlight title */ @@ -893,7 +893,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc * Menu path continues, but we have reached a leaf. * Or menu exists only in another mode. */ - free(path_name); + xfree(path_name); return NULL; } break; @@ -902,13 +902,13 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc } if (menu == NULL) { /* No menu found with the name we were looking for */ - free(path_name); + xfree(path_name); return NULL; } name = p; menu = menu->children; } - free(path_name); + xfree(path_name); xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS; xp->xp_pattern = after_dot; @@ -1289,7 +1289,7 @@ void ex_emenu(exarg_T *eap) menu = menu->children; name = p; } - free(saved_name); + xfree(saved_name); if (menu == NULL) { EMSG2(_("E334: Menu not found: %s"), eap->arg); return; @@ -1410,7 +1410,7 @@ vimmenu_T *gui_find_menu(char_u *path_name) if (menu == NULL) EMSG(_("E337: Menu not found - check menu names")); theend: - free(saved_name); + xfree(saved_name); return menu; } #endif @@ -1429,9 +1429,9 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE; #define FREE_MENUTRANS(mt) \ menutrans_T* _mt = (mt); \ - free(_mt->from); \ - free(_mt->from_noamp); \ - free(_mt->to) + xfree(_mt->from); \ + xfree(_mt->from_noamp); \ + xfree(_mt->to) /* * ":menutrans". @@ -1514,11 +1514,11 @@ static char_u *menutrans_lookup(char_u *name, int len) name[len] = c; for (int i = 0; i < menutrans_ga.ga_len; i++) { if (STRCMP(dname, tp[i].from_noamp) == 0) { - free(dname); + xfree(dname); return tp[i].to; } } - free(dname); + xfree(dname); return NULL; } diff --git a/src/nvim/message.c b/src/nvim/message.c index b2e9488388..ae4d0ec230 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -200,7 +200,7 @@ msg_attr_keep ( * Columns + sc_col) set_keep_msg(s, 0); - free(buf); + xfree(buf); --entered; return retval; } @@ -362,7 +362,7 @@ static char_u *last_sourcing_name = NULL; */ void reset_last_sourcing(void) { - free(last_sourcing_name); + xfree(last_sourcing_name); last_sourcing_name = NULL; last_sourcing_lnum = 0; } @@ -433,18 +433,18 @@ void msg_source(int attr) p = get_emsg_source(); if (p != NULL) { msg_attr(p, attr); - free(p); + xfree(p); } p = get_emsg_lnum(); if (p != NULL) { msg_attr(p, hl_attr(HLF_N)); - free(p); + xfree(p); last_sourcing_lnum = sourcing_lnum; /* only once for each line */ } /* remember the last sourcing name printed, also when it's empty */ if (sourcing_name == NULL || other_sourcing_name()) { - free(last_sourcing_name); + xfree(last_sourcing_name); if (sourcing_name == NULL) last_sourcing_name = NULL; else @@ -525,13 +525,13 @@ int emsg(char_u *s) if (p != NULL) { STRCAT(p, "\n"); redir_write(p, -1); - free(p); + xfree(p); } p = get_emsg_lnum(); if (p != NULL) { STRCAT(p, "\n"); redir_write(p, -1); - free(p); + xfree(p); } redir_write(s, -1); return TRUE; @@ -726,8 +726,8 @@ int delete_first_msg(void) assert(msg_hist_len == 1); last_msg_hist = NULL; } - free(p->msg); - free(p); + xfree(p->msg); + xfree(p); --msg_hist_len; return OK; } @@ -949,7 +949,7 @@ void wait_return(int redraw) reset_last_sourcing(); if (keep_msg != NULL && vim_strsize(keep_msg) >= (Rows - cmdline_row - 1) * Columns + sc_col) { - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; /* don't redisplay message, it's too long */ } @@ -985,7 +985,7 @@ static void hit_return_msg(void) */ void set_keep_msg(char_u *s, int attr) { - free(keep_msg); + xfree(keep_msg); if (s != NULL && msg_silent == 0) keep_msg = vim_strsave(s); else @@ -1002,7 +1002,7 @@ void msg_start(void) int did_return = FALSE; if (!msg_silent) { - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; /* don't display old message now */ } @@ -1088,7 +1088,7 @@ static void msg_home_replace_attr(char_u *fname, int attr) name = home_replace_save(NULL, fname); msg_outtrans_attr(name, attr); - free(name); + xfree(name); } /* @@ -1808,7 +1808,7 @@ static void inc_msg_scrolled(void) p = tofree; } set_vim_var_string(VV_SCROLLSTART, p, -1); - free(tofree); + xfree(tofree); } ++msg_scrolled; } @@ -1879,7 +1879,7 @@ void clear_sb_text(void) while (last_msgchunk != NULL) { mp = last_msgchunk->sb_prev; - free(last_msgchunk); + xfree(last_msgchunk); last_msgchunk = mp; } } @@ -2586,7 +2586,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1) ++no_wait_return; set_vim_var_string(VV_WARNINGMSG, message, -1); - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; if (hl) keep_msg_attr = hl_attr(HLF_W); @@ -2715,7 +2715,7 @@ do_dialog ( break; } - free(hotkeys); + xfree(hotkeys); State = oldState; setmouse(); @@ -2816,7 +2816,7 @@ static char_u * console_dialog_alloc(const char_u *message, // Now allocate space for the strings - free(confirm_msg); + xfree(confirm_msg); confirm_msg = xmalloc(len); *confirm_msg = NUL; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 5d8b88601e..d8b84293c3 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -796,7 +796,7 @@ open_line ( ) { ++curwin->w_cursor.lnum; if (did_si) { - int sw = (int)get_sw_value(curbuf); + int sw = get_sw_value(curbuf); if (p_sr) newindent -= newindent % sw; @@ -929,16 +929,16 @@ open_line ( curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; ins_bytes(p_extra); /* will call changed_bytes() */ - free(p_extra); + xfree(p_extra); next_line = NULL; } retval = TRUE; /* success! */ theend: curbuf->b_p_pi = saved_pi; - free(saved_line); - free(next_line); - free(allocated); + xfree(saved_line); + xfree(next_line); + xfree(allocated); return retval; } @@ -2432,7 +2432,7 @@ int get_keystroke(void) #endif break; } - free(buf); + xfree(buf); mapped_ctrl_c = save_mapped_ctrl_c; return n; @@ -2784,7 +2784,7 @@ get_cmd_output ( call_shell(command, kShellOptDoOut | kShellOptExpand | flags, NULL); --no_check_timestamps; - free(command); + xfree(command); /* * read the names from the file into memory @@ -2806,7 +2806,7 @@ get_cmd_output ( os_remove((char *)tempname); if (i != len) { EMSG2(_(e_notread), tempname); - free(buffer); + xfree(buffer); buffer = NULL; } else if (ret_len == NULL) { /* Change NUL into SOH, otherwise the string is truncated. */ @@ -2820,7 +2820,7 @@ get_cmd_output ( } done: - free(tempname); + xfree(tempname); return buffer; } @@ -2833,8 +2833,8 @@ void FreeWild(int count, char_u **files) if (count <= 0 || files == NULL) return; while (count--) - free(files[count]); - free(files); + xfree(files[count]); + xfree(files); } /* diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index fafce66c5f..7a584d4ea1 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -9,6 +9,7 @@ /* * misc2.c: Various functions. */ +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <string.h> @@ -29,6 +30,7 @@ #include "nvim/fileio.h" #include "nvim/fold.h" #include "nvim/getchar.h" +#include "nvim/macros.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memfile.h" @@ -327,10 +329,10 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\"" : p_sxq); retval = os_call_shell(ncmd, opts, extra_shell_arg); - free(ncmd); + xfree(ncmd); if (ecmd != cmd) - free(ecmd); + xfree(ecmd); } } @@ -385,7 +387,7 @@ int vim_chdir(char_u *new_dir) if (dir_name == NULL) return -1; r = os_chdir((char *)dir_name); - free(dir_name); + xfree(dir_name); return r; } @@ -451,7 +453,7 @@ char *read_string(FILE *fd, size_t cnt) for (size_t i = 0; i < cnt; i++) { int c = getc(fd); if (c == EOF) { - free(str); + xfree(str); return NULL; } str[i] = (uint8_t)c; @@ -459,22 +461,33 @@ char *read_string(FILE *fd, size_t cnt) return (char *)str; } -/// Write a number to file "fd", MSB first, in "len" bytes. -/// @return OK/FAIL. -int put_bytes(FILE *fd, uintmax_t number, unsigned int len) +/// Writes a number to file "fd", most significant bit first, in "len" bytes. +/// @returns false in case of an error. +bool put_bytes(FILE *fd, uintmax_t number, size_t len) { - for (unsigned int i = len - 1; i < len; --i) - if (putc((int)(number >> (i * 8)), fd) == EOF) - return FAIL; - return OK; + assert(len > 0); + for (size_t i = len - 1; i < len; i--) { + if (putc((int)(number >> (i * 8)), fd) == EOF) { + return false; + } + } + return true; } -/// Write time_t to file "fd" in 8 bytes. +/// Writes time_t to file "fd" in 8 bytes. void put_time(FILE *fd, time_t time_) { + uint8_t buf[8]; + time_to_bytes(time_, buf); + fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd); +} + +/// Writes time_t to "buf[8]". +void time_to_bytes(time_t time_, uint8_t buf[8]) +{ // time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits // systems, thus we can't use put_bytes() here. - for (unsigned int i = 7; i < 8; --i) { - putc((int)((uint64_t)time_ >> (i * 8)), fd); + for (size_t i = 7, bufi = 0; bufi < 8; i--, bufi++) { + buf[bufi] = (uint8_t)((uint64_t)time_ >> (i * 8)); } } diff --git a/src/nvim/move.c b/src/nvim/move.c index 1ba064c65f..65f2853073 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -16,6 +16,7 @@ * The 'scrolloff' option makes this a bit complicated. */ +#include <assert.h> #include <inttypes.h> #include <stdbool.h> @@ -135,13 +136,13 @@ void update_topline(void) { long line_count; int halfheight; - int n; + long n; linenr_T old_topline; int old_topfill; linenr_T lnum; int check_topline = FALSE; int check_botline = FALSE; - int save_so = p_so; + long save_so = p_so; if (!screen_valid(TRUE)) return; @@ -342,9 +343,9 @@ void update_topline_win(win_T* win) */ static int scrolljump_value(void) { - if (p_sj >= 0) - return (int)p_sj; - return (curwin->w_height * -p_sj) / 100; + long result = p_sj >= 0 ? p_sj : (curwin->w_height * -p_sj) / 100; + assert(result <= INT_MAX); + return (int)result; } /* @@ -711,7 +712,7 @@ int win_col_off(win_T *wp) { return ((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0) + (cmdwin_type == 0 || wp != curwin ? 0 : 1) - + wp->w_p_fdc + + (int)wp->w_p_fdc + (wp->w_buffer->b_signlist != NULL ? 2 : 0) ; } @@ -831,9 +832,9 @@ curs_columns ( * If we get closer to the edge than 'sidescrolloff', scroll a little * extra */ - off_left = (int)startcol - (int)curwin->w_leftcol - p_siso; - off_right = (int)endcol - (int)(curwin->w_leftcol + curwin->w_width - - p_siso) + 1; + assert(p_siso <= INT_MAX); + off_left = startcol - curwin->w_leftcol - (int)p_siso; + off_right = endcol - curwin->w_leftcol - curwin->w_width + (int)p_siso + 1; if (off_left < 0 || off_right > 0) { if (off_left < 0) diff = -off_left; @@ -845,8 +846,10 @@ curs_columns ( if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) new_leftcol = curwin->w_wcol - extra - textwidth / 2; else { - if (diff < p_ss) - diff = p_ss; + if (diff < p_ss) { + assert(p_ss <= INT_MAX); + diff = (int)p_ss; + } if (off_left < 0) new_leftcol = curwin->w_leftcol - diff; else @@ -902,8 +905,10 @@ curs_columns ( if (p_lines == 0) p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); --p_lines; - if (p_lines > curwin->w_wrow + p_so) - n = curwin->w_wrow + p_so; + if (p_lines > curwin->w_wrow + p_so) { + assert(p_so <= INT_MAX); + n = curwin->w_wrow + (int)p_so; + } else n = p_lines; if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width) @@ -922,7 +927,8 @@ curs_columns ( curwin->w_skipcol = n * width; } else if (extra == 1) { /* less then 'scrolloff' lines above, decrease skipcol */ - extra = (curwin->w_skipcol + p_so * width - curwin->w_virtcol + assert(p_so <= INT_MAX); + extra = (curwin->w_skipcol + (int)p_so * width - curwin->w_virtcol + width - 1) / width; if (extra > 0) { if ((colnr_T)(extra * width) > curwin->w_skipcol) @@ -974,7 +980,7 @@ scrolldown ( int byfold /* TRUE: count a closed fold as one line */ ) { - long done = 0; /* total # of physical lines done */ + int done = 0; /* total # of physical lines done */ int wrow; int moved = FALSE; @@ -1331,7 +1337,8 @@ void scroll_cursor_top(int min_scroll, int always) linenr_T old_topline = curwin->w_topline; linenr_T old_topfill = curwin->w_topfill; linenr_T new_topline; - int off = p_so; + assert(p_so <= INT_MAX); + int off = (int)p_so; if (mouse_dragging > 0) off = mouse_dragging - 1; @@ -1472,7 +1479,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot) int old_topfill = curwin->w_topfill; int fill_below_window; linenr_T old_botline = curwin->w_botline; - linenr_T old_valid = curwin->w_valid; + int old_valid = curwin->w_valid; int old_empty_rows = curwin->w_empty_rows; linenr_T cln; /* Cursor Line Number */ @@ -1708,8 +1715,9 @@ void cursor_correct(void) * How many lines we would like to have above/below the cursor depends on * whether the first/last line of the file is on screen. */ - above_wanted = p_so; - below_wanted = p_so; + assert(p_so <= INT_MAX); + above_wanted = (int)p_so; + below_wanted = (int)p_so; if (mouse_dragging > 0) { above_wanted = mouse_dragging - 1; below_wanted = mouse_dragging - 1; @@ -2040,14 +2048,14 @@ void halfpage(bool flag, linenr_T Prenum) { long scrolled = 0; int i; - int n; int room; if (Prenum) curwin->w_p_scr = (Prenum > curwin->w_height) ? curwin->w_height : Prenum; - n = (curwin->w_p_scr <= curwin->w_height) ? - curwin->w_p_scr : curwin->w_height; + assert(curwin->w_p_scr <= INT_MAX); + int n = curwin->w_p_scr <= curwin->w_height ? (int)curwin->w_p_scr + : curwin->w_height; validate_botline(); room = curwin->w_empty_rows; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 35549ce042..b671b8b545 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -5,8 +5,6 @@ #include <uv.h> #include <msgpack.h> -#include "nvim/lib/klist.h" - #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/msgpack_rpc/channel.h" @@ -69,10 +67,6 @@ typedef struct { uint64_t request_id; } RequestEvent; -#define _noop(x) -KMEMPOOL_INIT(RequestEventPool, RequestEvent, _noop) -static kmempool_t(RequestEventPool) *request_event_pool = NULL; - static uint64_t next_id = 1; static PMap(uint64_t) *channels = NULL; static PMap(cstr_t) *event_strings = NULL; @@ -85,7 +79,6 @@ static msgpack_sbuffer out_buffer; /// Initializes the module void channel_init(void) { - request_event_pool = kmp_init(RequestEventPool); channels = pmap_new(uint64_t)(); event_strings = pmap_new(cstr_t)(); msgpack_sbuffer_init(&out_buffer); @@ -232,7 +225,25 @@ Object channel_send_call(uint64_t id, channel->pending_requests--; if (frame.errored) { - api_set_error(err, Exception, "%s", frame.result.data.string.data); + if (frame.result.type == kObjectTypeString) { + api_set_error(err, Exception, "%s", frame.result.data.string.data); + } else if (frame.result.type == kObjectTypeArray) { + // Should be an error in the form [type, message] + Array array = frame.result.data.array; + if (array.size == 2 && array.items[0].type == kObjectTypeInteger + && (array.items[0].data.integer == kErrorTypeException + || array.items[0].data.integer == kErrorTypeValidation) + && array.items[1].type == kObjectTypeString) { + err->type = (ErrorType) array.items[0].data.integer; + xstrlcpy(err->msg, array.items[1].data.string.data, sizeof(err->msg)); + err->set = true; + } else { + api_set_error(err, Exception, "%s", "unknown error"); + } + } else { + api_set_error(err, Exception, "%s", "unknown error"); + } + api_free_object(frame.result); } @@ -442,20 +453,20 @@ static void handle_request(Channel *channel, msgpack_object *request) // Retrieve the request handler MsgpackRpcRequestHandler handler; - msgpack_object method = request->via.array.ptr[2]; + msgpack_object *method = msgpack_rpc_method(request); - if (method.type == MSGPACK_OBJECT_BIN || method.type == MSGPACK_OBJECT_STR) { - handler = msgpack_rpc_get_handler_for(method.via.bin.ptr, - method.via.bin.size); + if (method) { + handler = msgpack_rpc_get_handler_for(method->via.bin.ptr, + method->via.bin.size); } else { handler.fn = msgpack_rpc_handle_missing_method; handler.defer = false; } Array args = ARRAY_DICT_INIT; - msgpack_rpc_to_array(request->via.array.ptr + 3, &args); + msgpack_rpc_to_array(msgpack_rpc_args(request), &args); bool defer = (!kv_size(channel->call_stack) && handler.defer); - RequestEvent *event_data = kmp_alloc(RequestEventPool, request_event_pool); + RequestEvent *event_data = xmalloc(sizeof(RequestEvent)); event_data->channel = channel; event_data->handler = handler; event_data->args = args; @@ -476,18 +487,22 @@ static void on_request_event(Event event) uint64_t request_id = e->request_id; Error error = ERROR_INIT; Object result = handler.fn(channel->id, request_id, args, &error); - // send the response - msgpack_packer response; - msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write); - channel_write(channel, serialize_response(channel->id, - request_id, - &error, - result, - &out_buffer)); + if (request_id != NO_RESPONSE) { + // send the response + msgpack_packer response; + msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write); + channel_write(channel, serialize_response(channel->id, + request_id, + &error, + result, + &out_buffer)); + } else { + api_free_object(result); + } // All arguments were freed already, but we still need to free the array - free(args.items); + xfree(args.items); decref(channel); - kmp_free(RequestEventPool, request_event_pool, e); + xfree(e); } static bool channel_write(Channel *channel, WBuffer *buffer) @@ -608,7 +623,7 @@ static void unsubscribe(Channel *channel, char *event) // Since the string is no longer used by other channels, release it's memory pmap_del(cstr_t)(event_strings, event_string); - free(event_string); + xfree(event_string); } /// Close the channel streams/job and free the channel resources. @@ -662,13 +677,13 @@ static void free_channel(Channel *channel) pmap_free(cstr_t)(channel->subscribed_events); kv_destroy(channel->call_stack); kv_destroy(channel->delayed_notifications); - free(channel); + xfree(channel); } static void close_cb(uv_handle_t *handle) { - free(handle->data); - free(handle); + xfree(handle->data); + xfree(handle); } static Channel *register_channel(void) @@ -745,7 +760,7 @@ static WBuffer *serialize_request(uint64_t channel_id, WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), sbuffer->size, refcount, - free); + xfree); msgpack_sbuffer_clear(sbuffer); api_free_array(args); return rv; @@ -764,7 +779,7 @@ static WBuffer *serialize_response(uint64_t channel_id, WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), sbuffer->size, 1, // responses only go though 1 channel - free); + xfree); msgpack_sbuffer_clear(sbuffer); api_free_object(arg); return rv; diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c index 355176aa5f..7d0db9a9b8 100644 --- a/src/nvim/msgpack_rpc/helpers.c +++ b/src/nvim/msgpack_rpc/helpers.c @@ -351,49 +351,86 @@ void msgpack_rpc_serialize_response(uint64_t response_id, } } +static bool msgpack_rpc_is_notification(msgpack_object *req) +{ + return req->via.array.ptr[0].via.u64 == 2; +} + +msgpack_object *msgpack_rpc_method(msgpack_object *req) +{ + msgpack_object *obj = req->via.array.ptr + + (msgpack_rpc_is_notification(req) ? 1 : 2); + return obj->type == MSGPACK_OBJECT_STR || obj->type == MSGPACK_OBJECT_BIN ? + obj : NULL; +} + +msgpack_object *msgpack_rpc_args(msgpack_object *req) +{ + msgpack_object *obj = req->via.array.ptr + + (msgpack_rpc_is_notification(req) ? 2 : 3); + return obj->type == MSGPACK_OBJECT_ARRAY ? obj : NULL; +} + +static msgpack_object *msgpack_rpc_msg_id(msgpack_object *req) +{ + if (msgpack_rpc_is_notification(req)) { + return NULL; + } + msgpack_object *obj = &req->via.array.ptr[1]; + return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER ? obj : NULL; +} + void msgpack_rpc_validate(uint64_t *response_id, msgpack_object *req, Error *err) { // response id not known yet - *response_id = 0; + *response_id = NO_RESPONSE; // Validate the basic structure of the msgpack-rpc payload if (req->type != MSGPACK_OBJECT_ARRAY) { - api_set_error(err, Validation, _("Request is not an array")); + api_set_error(err, Validation, _("Message is not an array")); return; } - if (req->via.array.size != 4) { - api_set_error(err, Validation, _("Request array size should be 4")); + if (req->via.array.size == 0) { + api_set_error(err, Validation, _("Message is empty")); return; } - if (req->via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - api_set_error(err, Validation, _("Id must be a positive integer")); + if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { + api_set_error(err, Validation, _("Message type must be an integer")); return; } - // Set the response id, which is the same as the request - *response_id = req->via.array.ptr[1].via.u64; - - if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - api_set_error(err, Validation, _("Message type must be an integer")); + uint64_t type = req->via.array.ptr[0].via.u64; + if (type != kMessageTypeRequest && type != kMessageTypeNotification) { + api_set_error(err, Validation, _("Unknown message type")); return; } - if (req->via.array.ptr[0].via.u64 != 0) { - api_set_error(err, Validation, _("Message type must be 0")); + if ((type == kMessageTypeRequest && req->via.array.size != 4) || + (type == kMessageTypeNotification && req->via.array.size != 3)) { + api_set_error(err, Validation, _("Request array size should be 4 (request) " + "or 3 (notification)")); return; } - if (req->via.array.ptr[2].type != MSGPACK_OBJECT_BIN - && req->via.array.ptr[2].type != MSGPACK_OBJECT_STR) { + if (type == kMessageTypeRequest) { + msgpack_object *id_obj = msgpack_rpc_msg_id(req); + if (!id_obj) { + api_set_error(err, Validation, _("ID must be a positive integer")); + return; + } + *response_id = id_obj->via.u64; + } + + if (!msgpack_rpc_method(req)) { api_set_error(err, Validation, _("Method must be a string")); return; } - if (req->via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) { + if (!msgpack_rpc_args(req)) { api_set_error(err, Validation, _("Parameters must be an array")); return; } diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index b554d76bed..07d78dd9d7 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -48,9 +48,9 @@ void remote_ui_disconnect(uint64_t channel_id) // destroy pending screen updates api_free_array(data->buffer); pmap_del(uint64_t)(connected_uis, channel_id); - free(ui->data); + xfree(ui->data); ui_detach(ui); - free(ui); + xfree(ui); } static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, diff --git a/src/nvim/msgpack_rpc/server.c b/src/nvim/msgpack_rpc/server.c index 91aca0c37a..8fb2902b0b 100644 --- a/src/nvim/msgpack_rpc/server.c +++ b/src/nvim/msgpack_rpc/server.c @@ -9,11 +9,11 @@ #include "nvim/msgpack_rpc/server.h" #include "nvim/os/os.h" #include "nvim/ascii.h" +#include "nvim/garray.h" #include "nvim/vim.h" #include "nvim/memory.h" #include "nvim/log.h" #include "nvim/tempfile.h" -#include "nvim/map.h" #include "nvim/path.h" #define MAX_CONNECTIONS 32 @@ -27,6 +27,9 @@ typedef enum { } ServerType; typedef struct { + // The address of a pipe, or string value of a tcp address. + char addr[ADDRESS_MAX_SIZE]; + // Type of the union below ServerType type; @@ -38,12 +41,11 @@ typedef struct { } tcp; struct { uv_pipe_t handle; - char addr[ADDRESS_MAX_SIZE]; } pipe; } socket; } Server; -static PMap(cstr_t) *servers = NULL; +static garray_T servers = GA_EMPTY_INIT_VALUE; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "msgpack_rpc/server.c.generated.h" @@ -52,33 +54,40 @@ static PMap(cstr_t) *servers = NULL; /// Initializes the module bool server_init(void) { - servers = pmap_new(cstr_t)(); + ga_init(&servers, sizeof(Server *), 1); - if (!os_getenv(LISTEN_ADDRESS_ENV_VAR)) { - char *listen_address = (char *)vim_tempname(); - os_setenv(LISTEN_ADDRESS_ENV_VAR, listen_address, 1); - free(listen_address); + bool must_free = false; + const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); + if (listen_address == NULL || *listen_address == NUL) { + must_free = true; + listen_address = (char *)vim_tempname(); } - return server_start((char *)os_getenv(LISTEN_ADDRESS_ENV_VAR)) == 0; + bool ok = (server_start(listen_address) == 0); + if (must_free) { + xfree((char *) listen_address); + } + return ok; } -/// Teardown the server module -void server_teardown(void) +/// Retrieve the file handle from a server. +static uv_handle_t *server_handle(Server *server) { - if (!servers) { - return; - } + return server->type == kServerTypeTcp + ? (uv_handle_t *)&server->socket.tcp.handle + : (uv_handle_t *) &server->socket.pipe.handle; +} - Server *server; +/// Teardown a single server +static void server_close_cb(Server **server) +{ + uv_close(server_handle(*server), free_server); +} - map_foreach_value(servers, server, { - if (server->type == kServerTypeTcp) { - uv_close((uv_handle_t *)&server->socket.tcp.handle, free_server); - } else { - uv_close((uv_handle_t *)&server->socket.pipe.handle, free_server); - } - }); +/// Teardown the server module +void server_teardown(void) +{ + GA_DEEP_CLEAR(&servers, Server *, server_close_cb); } /// Starts listening on arbitrary tcp/unix addresses specified by @@ -106,9 +115,11 @@ int server_start(const char *endpoint) } // Check if the server already exists - if (pmap_has(cstr_t)(servers, addr)) { - ELOG("Already listening on %s", addr); - return 1; + for (int i = 0; i < servers.ga_len; i++) { + if (strcmp(addr, ((Server **)servers.ga_data)[i]->addr) == 0) { + ELOG("Already listening on %s", addr); + return 1; + } } ServerType server_type = kServerTypeTcp; @@ -154,6 +165,8 @@ int server_start(const char *endpoint) int result; uv_stream_t *stream = NULL; + xstrlcpy(server->addr, addr, sizeof(server->addr)); + if (server_type == kServerTypeTcp) { // Listen on tcp address/port uv_tcp_init(uv_default_loop(), &server->socket.tcp.handle); @@ -163,10 +176,8 @@ int server_start(const char *endpoint) stream = (uv_stream_t *)&server->socket.tcp.handle; } else { // Listen on named pipe or unix socket - xstrlcpy(server->socket.pipe.addr, addr, sizeof(server->socket.pipe.addr)); uv_pipe_init(uv_default_loop(), &server->socket.pipe.handle, 0); - result = uv_pipe_bind(&server->socket.pipe.handle, - server->socket.pipe.addr); + result = uv_pipe_bind(&server->socket.pipe.handle, server->addr); stream = (uv_stream_t *)&server->socket.pipe.handle; } @@ -193,9 +204,17 @@ int server_start(const char *endpoint) return result; } + // Update $NVIM_LISTEN_ADDRESS, if not set. + const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); + if (listen_address == NULL || *listen_address == NUL) { + os_setenv(LISTEN_ADDRESS_ENV_VAR, addr, 1); + } + server->type = server_type; - // Add the server to the hash table - pmap_put(cstr_t)(servers, addr, server); + + // Add the server to the list. + ga_grow(&servers, 1); + ((Server **)servers.ga_data)[servers.ga_len++] = server; return 0; } @@ -211,18 +230,49 @@ void server_stop(char *endpoint) // Trim to `ADDRESS_MAX_SIZE` xstrlcpy(addr, endpoint, sizeof(addr)); - if ((server = pmap_get(cstr_t)(servers, addr)) == NULL) { + int i = 0; // The index of the server whose address equals addr. + for (; i < servers.ga_len; i++) { + server = ((Server **)servers.ga_data)[i]; + if (strcmp(addr, server->addr) == 0) { + break; + } + } + + if (i == servers.ga_len) { ELOG("Not listening on %s", addr); return; } - if (server->type == kServerTypeTcp) { - uv_close((uv_handle_t *)&server->socket.tcp.handle, free_server); - } else { - uv_close((uv_handle_t *)&server->socket.pipe.handle, free_server); + // If we are invalidating the listen address, unset it. + const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); + if (listen_address && strcmp(addr, listen_address) == 0) { + os_unsetenv(LISTEN_ADDRESS_ENV_VAR); } - pmap_del(cstr_t)(servers, addr); + uv_close(server_handle(server), free_server); + + // Remove this server from the list by swapping it with the last item. + if (i != servers.ga_len - 1) { + ((Server **)servers.ga_data)[i] = + ((Server **)servers.ga_data)[servers.ga_len - 1]; + } + servers.ga_len--; +} + +/// Returns an allocated array of server addresses. +/// @param[out] size The size of the returned array. +char **server_address_list(size_t *size) + FUNC_ATTR_NONNULL_ALL +{ + if ((*size = (size_t) servers.ga_len) == 0) { + return NULL; + } + + char **addrs = xcalloc((size_t) servers.ga_len, sizeof(const char **)); + for (int i = 0; i < servers.ga_len; i++) { + addrs[i] = xstrdup(((Server **)servers.ga_data)[i]->addr); + } + return addrs; } static void connection_cb(uv_stream_t *server, int status) @@ -256,10 +306,10 @@ static void connection_cb(uv_stream_t *server, int status) static void free_client(uv_handle_t *handle) { - free(handle); + xfree(handle); } static void free_server(uv_handle_t *handle) { - free(handle->data); + xfree(handle->data); } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c210c8fe8f..0dbaf52b7e 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -914,7 +914,7 @@ getcount: && !oap->op_type && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) { clearop(oap); - set_reg_var(0); + set_reg_var(get_default_register_name()); } /* Get the length of mapped chars again after typing a count, second @@ -980,7 +980,7 @@ getcount: /* now reset it, otherwise it's put in the history again */ keep_msg = kmsg; msg_attr(kmsg, keep_msg_attr); - free(kmsg); + xfree(kmsg); } setcursor(); ui_flush(); @@ -1015,7 +1015,7 @@ normal_end: clear_showcmd(); checkpcmark(); /* check if we moved since setting pcmark */ - free(ca.searchbuf); + xfree(ca.searchbuf); if (has_mbyte) mb_adjust_cursor(); @@ -1160,7 +1160,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) else { AppendToRedobuffLit(repeat_cmdline, -1); AppendToRedobuff(NL_STR); - free(repeat_cmdline); + xfree(repeat_cmdline); repeat_cmdline = NULL; } } @@ -3342,7 +3342,7 @@ find_decl ( reset_search_dir(); } - free(pat); + xfree(pat); p_ws = save_p_ws; p_scs = save_p_scs; @@ -4261,7 +4261,7 @@ static void nv_ident(cmdarg_T *cap) } if (n == 0) { EMSG(_(e_noident)); /* found dashes only */ - free(buf); + xfree(buf); return; } @@ -4312,11 +4312,11 @@ static void nv_ident(cmdarg_T *cap) /* Escape the argument properly for a shell command */ ptr = vim_strnsave(ptr, n); p = vim_strsave_shellescape(ptr, true, true); - free(ptr); + xfree(ptr); newbuf = (char_u *)xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1); buf = newbuf; STRCAT(buf, p); - free(p); + xfree(p); } else { if (cmdchar == '*') aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); @@ -4365,7 +4365,7 @@ static void nv_ident(cmdarg_T *cap) } else do_cmdline_cmd(buf); - free(buf); + xfree(buf); } /* @@ -4724,7 +4724,7 @@ static void nv_gotofile(cmdarg_T *cap) check_cursor_lnum(); beginline(BL_SOL | BL_FIX); } - free(ptr); + xfree(ptr); } else clearop(cap->oap); } @@ -6934,7 +6934,7 @@ static void nv_esc(cmdarg_T *cap) && cmdwin_type == 0 && !VIsual_active && no_reason) - MSG(_("Type :quit<Enter> to exit Vim")); + MSG(_("Type :quit<Enter> to exit Nvim")); /* Don't reset "restart_edit" when 'insertmode' is set, it won't be * set again below when halfway through a mapping. */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 5921e27282..85b1244fa3 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -79,7 +79,7 @@ static struct yankreg { } y_regs[NUM_REGISTERS]; static struct yankreg *y_current; /* ptr to current yankreg */ -static int y_append; /* TRUE when appending */ +static bool y_append; /* true when appending */ static struct yankreg *y_previous = NULL; /* ptr to last written yankreg */ static bool clipboard_didwarn_unnamed = false; @@ -278,7 +278,7 @@ shift_line ( { int count; int i, j; - int p_sw = (int)get_sw_value(curbuf); + int p_sw = get_sw_value(curbuf); count = get_indent(); /* get current indent */ @@ -321,7 +321,7 @@ static void shift_block(oparg_T *oap, int amount) int total; char_u *newp, *oldp; int oldcol = curwin->w_cursor.col; - int p_sw = (int)get_sw_value(curbuf); + int p_sw = get_sw_value(curbuf); int p_ts = (int)curbuf->b_p_ts; struct block_def bd; int incr; @@ -668,7 +668,7 @@ int get_expr_register(void) if (new_line == NULL) return NUL; if (*new_line == NUL) /* use previous line */ - free(new_line); + xfree(new_line); else set_expr_line(new_line); return '='; @@ -680,7 +680,7 @@ int get_expr_register(void) */ void set_expr_line(char_u *new_line) { - free(expr_line); + xfree(expr_line); expr_line = new_line; } @@ -709,7 +709,7 @@ char_u *get_expr_line(void) ++nested; rv = eval_to_string(expr_copy, NULL, TRUE); --nested; - free(expr_copy); + xfree(expr_copy); return rv; } @@ -773,36 +773,35 @@ typedef enum { /// Obtain the location that would be read when pasting `regname`. void get_yank_register(int regname, int mode) { - int i; + y_append = false; - y_append = FALSE; - int unnamedclip = cb_flags & CB_UNNAMEDMASK; - if ((regname == 0 || regname == '"') && !unnamedclip && mode != YREG_YANK && y_previous != NULL) { + if (mode == YREG_PASTE && get_clipboard(regname, &y_current, false)) { + // y_current is set to clipboard contents. + return; + } else if (mode != YREG_YANK && (regname == 0 || regname == '"') && y_previous != NULL) { y_current = y_previous; return; } - i = regname; - if (VIM_ISDIGIT(i)) - i -= '0'; - else if (ASCII_ISLOWER(i)) - i = CharOrdLow(i) + 10; - else if (ASCII_ISUPPER(i)) { - i = CharOrdUp(i) + 10; - y_append = TRUE; + + int i = 0; // when not 0-9, a-z, A-Z or '-'/'+'/'*': use register 0 + if (VIM_ISDIGIT(regname)) + i = regname - '0'; + else if (ASCII_ISLOWER(regname)) + i = CharOrdLow(regname) + 10; + else if (ASCII_ISUPPER(regname)) { + i = CharOrdUp(regname) + 10; + y_append = true; } else if (regname == '-') i = DELETION_REGISTER; else if (regname == '*') i = STAR_REGISTER; else if (regname == '+') i = PLUS_REGISTER; - else /* not 0-9, a-z, A-Z or '-': use register 0 */ - i = 0; y_current = &(y_regs[i]); + if (mode == YREG_YANK) { // remember the written register for unnamed paste y_previous = y_current; - } else if (mode == YREG_PASTE) { - get_clipboard(regname, &y_current, false); } } @@ -844,7 +843,7 @@ void put_register(int name, void *reg) get_yank_register(name, YREG_PUT); free_yank_all(); *y_current = *(struct yankreg *)reg; - free(reg); + xfree(reg); set_clipboard(name); } @@ -924,11 +923,11 @@ static int stuff_yank(int regname, char_u *p) { /* check for read-only register */ if (regname != 0 && !valid_yank_reg(regname, TRUE)) { - free(p); + xfree(p); return FAIL; } if (regname == '_') { /* black hole: don't do anything */ - free(p); + xfree(p); return OK; } get_yank_register(regname, YREG_YANK); @@ -938,8 +937,8 @@ static int stuff_yank(int regname, char_u *p) STRCPY(lp, *pp); // TODO(philix): use xstpcpy() in stuff_yank() STRCAT(lp, p); - free(p); - free(*pp); + xfree(p); + xfree(*pp); *pp = lp; } else { free_yank_all(); @@ -993,7 +992,7 @@ do_execreg ( EMSG(_(e_nolastcmd)); return FAIL; } - free(new_last_cmdline); /* don't keep the cmdline containing @: */ + xfree(new_last_cmdline); /* don't keep the cmdline containing @: */ new_last_cmdline = NULL; /* Escape all control characters with a CTRL-V */ p = vim_strsave_escaped_ext( @@ -1007,13 +1006,13 @@ do_execreg ( retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); else retval = put_in_typebuf(p, TRUE, TRUE, silent); - free(p); + xfree(p); } else if (regname == '=') { p = get_expr_line(); if (p == NULL) return FAIL; retval = put_in_typebuf(p, TRUE, colon, silent); - free(p); + xfree(p); } else if (regname == '.') { /* use last inserted text */ p = get_last_insert_save(); if (p == NULL) { @@ -1021,7 +1020,7 @@ do_execreg ( return FAIL; } retval = put_in_typebuf(p, FALSE, colon, silent); - free(p); + xfree(p); } else { get_yank_register(regname, YREG_PASTE); if (y_current->y_array == NULL) @@ -1045,7 +1044,7 @@ do_execreg ( } escaped = vim_strsave_escape_csi(y_current->y_array[i]); retval = ins_typebuf(escaped, remap, 0, TRUE, silent); - free(escaped); + xfree(escaped); if (retval == FAIL) return FAIL; if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) @@ -1111,7 +1110,7 @@ put_in_typebuf ( retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, 0, TRUE, silent); if (esc) - free(p); + xfree(p); } if (colon && retval == OK) retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); @@ -1155,7 +1154,7 @@ insert_reg ( return FAIL; stuffescaped(arg, literally); if (allocated) - free(arg); + xfree(arg); } else { /* name or number register */ get_yank_register(regname, YREG_PASTE); if (y_current->y_array == NULL) @@ -1805,7 +1804,7 @@ int op_replace(oparg_T *oap, int c) ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); appended_lines_mark(curwin->w_cursor.lnum, 1L); oap->end.lnum++; - free(after_p); + xfree(after_p); } } } else { @@ -2187,7 +2186,7 @@ void op_insert(oparg_T *oap, long count1) curwin->w_cursor.col = oap->start.col; check_cursor(); - free(ins_text); + xfree(ins_text); } } } @@ -2300,7 +2299,7 @@ int op_change(oparg_T *oap) } check_cursor(); changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); - free(ins_text); + xfree(ins_text); } } @@ -2342,9 +2341,9 @@ static void free_yank(long n) long i; for (i = n; --i >= 0; ) { - free(y_current->y_array[i]); + xfree(y_current->y_array[i]); } - free(y_current->y_array); + xfree(y_current->y_array); y_current->y_array = NULL; } } @@ -2508,7 +2507,7 @@ int op_yank(oparg_T *oap, int deleting, int mess) new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size)); for (j = 0; j < curr->y_size; ++j) new_ptr[j] = curr->y_array[j]; - free(curr->y_array); + xfree(curr->y_array); curr->y_array = new_ptr; if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ @@ -2521,8 +2520,8 @@ int op_yank(oparg_T *oap, int deleting, int mess) + STRLEN(y_current->y_array[0]) + 1); STRCPY(pnew, curr->y_array[--j]); STRCAT(pnew, y_current->y_array[0]); - free(curr->y_array[j]); - free(y_current->y_array[0]); + xfree(curr->y_array[j]); + xfree(y_current->y_array[0]); curr->y_array[j++] = pnew; y_idx = 1; } else @@ -2530,7 +2529,7 @@ int op_yank(oparg_T *oap, int deleting, int mess) while (y_idx < y_current->y_size) curr->y_array[j++] = y_current->y_array[y_idx++]; curr->y_size = j; - free(y_current->y_array); + xfree(y_current->y_array); y_current = curr; } if (curwin->w_p_rnu) { @@ -2736,7 +2735,7 @@ do_put ( goto end; ptr = vim_strsave(get_cursor_pos_ptr()); ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); - free(ptr); + xfree(ptr); ptr = vim_strnsave(get_cursor_line_ptr(), curwin->w_cursor.col); ml_replace(curwin->w_cursor.lnum, ptr, FALSE); @@ -3050,7 +3049,7 @@ do_put ( STRCAT(newp, ptr); /* insert second line */ ml_append(lnum, newp, (colnr_T)0, FALSE); - free(newp); + xfree(newp); oldp = ml_get(lnum); newp = (char_u *) xmalloc((size_t)(col + yanklen + 1)); @@ -3155,9 +3154,9 @@ error: end: if (allocated) - free(insert_string); + xfree(insert_string); if (regname == '=') - free(y_array); + xfree(y_array); VIsual_active = FALSE; @@ -3619,9 +3618,9 @@ int do_join(long count, curwin->w_set_curswant = TRUE; theend: - free(spaces); + xfree(spaces); if (remove_comments) - free(comments); + xfree(comments); return ret; } @@ -3682,7 +3681,7 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in while (vim_iswhite(line1[idx1])) ++idx1; } - free(line1); + xfree(line1); return idx2 == leader2_len && idx1 == leader1_len; } @@ -4480,7 +4479,7 @@ int do_addsub(int command, linenr_T Prenum1) *ptr = NUL; STRCAT(buf1, buf2); ins_str(buf1); /* insert the new number */ - free(buf1); + xfree(buf1); } --curwin->w_cursor.col; curwin->w_set_curswant = TRUE; @@ -4557,7 +4556,7 @@ int read_viminfo_register(vir_T *virp, int force) if (do_it) { if (size == 0) { - free(array); + xfree(array); } else if (size < limit) { y_current->y_array = xrealloc(array, size * sizeof(char_u *)); } else { @@ -5019,7 +5018,7 @@ static void str_to_reg(struct yankreg *y_ptr, int yank_type, const char_u *str, ssize_t s_len = extra + line_len; if (append) { - free(pp[lnum]); + xfree(pp[lnum]); append = false; // only first line is appended } pp[lnum] = s; @@ -5310,7 +5309,28 @@ static void free_register(struct yankreg *reg) y_current = curr; } -// return target register +/// Check if the default register (used in an unnamed paste) should be a +/// clipboard register. This happens when `clipboard=unnamed[plus]` is set +/// and a provider is available. +/// +/// @returns the name of of a clipboard register that should be used, or `NUL` if none. +int get_default_register_name(void) +{ + int name = NUL; + adjust_clipboard_name(&name, true, false); + return name; +} + +/// Determine if register `*name` should be used as a clipboard. +/// In an unnammed operation, `*name` is `NUL` and will be adjusted to `'*'/'+'` if +/// `clipboard=unnamed[plus]` is set. +/// +/// @param name The name of register, or `NUL` if unnamed. +/// @param quiet Suppress error messages +/// @param writing if we're setting the contents of the clipboard +/// +/// @returns the yankreg that should be used, or `NULL` +/// if the register isn't a clipboard or provider isn't available. static struct yankreg* adjust_clipboard_name(int *name, bool quiet, bool writing) { if (*name == '*' || *name == '+') { if(!eval_has_provider("clipboard")) { @@ -5345,11 +5365,11 @@ static struct yankreg* adjust_clipboard_name(int *name, bool quiet, bool writing return NULL; } -static void get_clipboard(int name, struct yankreg** target, bool quiet) +static bool get_clipboard(int name, struct yankreg** target, bool quiet) { struct yankreg* reg = adjust_clipboard_name(&name, quiet, false); if (reg == NULL) { - return; + return false; } free_register(reg); @@ -5410,7 +5430,7 @@ static void get_clipboard(int name, struct yankreg** target, bool quiet) // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline if (reg->y_type != MCHAR) { - free(reg->y_array[reg->y_size-1]); + xfree(reg->y_array[reg->y_size-1]); reg->y_size--; if (reg->y_type == MAUTO) { reg->y_type = MLINE; @@ -5434,18 +5454,20 @@ static void get_clipboard(int name, struct yankreg** target, bool quiet) } *target = reg; - return; + return true; err: if (reg->y_array) { for (int i = 0; i < reg->y_size; i++) { - free(reg->y_array[i]); + xfree(reg->y_array[i]); } - free(reg->y_array); + xfree(reg->y_array); } reg->y_array = NULL; reg->y_size = 0; EMSG("clipboard: provider returned invalid data"); + *target = reg; + return false; } static void set_clipboard(int name) diff --git a/src/nvim/option.c b/src/nvim/option.c index 2d016d8350..23a23a0814 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -363,13 +363,14 @@ typedef struct vimoption { # define ISP_LATIN1 (char_u *)"@,161-255" #define HIGHLIGHT_INIT \ - "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch," \ - "l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine," \ - "S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg," \ - "W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete," \ - "T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare," \ - "L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine," \ - "#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn" + "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \ + "d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr," \ + "N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title," \ + "v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn," \ + "A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal," \ + "B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \ + "x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \ + "!:CursorColumn,.:CursorLine,o:ColorColumn" /* * options[] is initialized here. @@ -1826,11 +1827,11 @@ void set_init_1(void) ga.ga_len += len; } if (mustfree) - free(p); + xfree(p); } if (ga.ga_data != NULL) { set_string_default("bsk", ga.ga_data); - free(ga.ga_data); + xfree(ga.ga_data); } } @@ -1884,10 +1885,10 @@ void set_init_1(void) options[opt_idx].def_val[VI_DEFAULT] = buf; options[opt_idx].flags |= P_DEF_ALLOCED; } else - free(buf); /* cannot happen */ + xfree(buf); /* cannot happen */ } if (mustfree) - free(cdpath); + xfree(cdpath); } } @@ -1957,7 +1958,7 @@ void set_init_1(void) * split P_DEF_ALLOCED in two. */ if (options[opt_idx].flags & P_DEF_ALLOCED) - free(options[opt_idx].def_val[VI_DEFAULT]); + xfree(options[opt_idx].def_val[VI_DEFAULT]); options[opt_idx].def_val[VI_DEFAULT] = p; options[opt_idx].flags |= P_DEF_ALLOCED; } @@ -1997,7 +1998,7 @@ void set_init_1(void) * for practical purposes, thus use that. It's not an alias to * still support conversion between gb18030 and utf-8. */ p_enc = vim_strsave((char_u *)"cp936"); - free(p); + xfree(p); } if (mb_init() == NULL) { opt_idx = findoption((char_u *)"encoding"); @@ -2027,7 +2028,7 @@ void set_init_1(void) #endif } else { - free(p_enc); + xfree(p_enc); // mb_init() failed; fallback to utf8 and try again. p_enc = save_enc; mb_init(); @@ -2135,7 +2136,7 @@ void set_string_default(const char *name, const char_u *val) int opt_idx = findoption((char_u *)name); if (opt_idx >= 0) { if (options[opt_idx].flags & P_DEF_ALLOCED) { - free(options[opt_idx].def_val[VI_DEFAULT]); + xfree(options[opt_idx].def_val[VI_DEFAULT]); } options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val); @@ -2275,7 +2276,7 @@ void set_init_3(void) options[idx_srr].def_val[VI_DEFAULT] = p_srr; } } - free(p); + xfree(p); } #endif @@ -2781,7 +2782,7 @@ do_set ( (char_u *)"indent,eol,start"); break; } - free(oldval); + xfree(oldval); oldval = *(char_u **)varp; } /* @@ -2878,7 +2879,7 @@ do_set ( || (flags & P_COMMA)) { s = option_expand(opt_idx, newval); if (s != NULL) { - free(newval); + xfree(newval); newlen = (unsigned)STRLEN(s) + 1; if (adding || prepending || removing) newlen += (unsigned)STRLEN(origval) + 1; @@ -3372,13 +3373,13 @@ void check_buf_options(buf_T *buf) void free_string_option(char_u *p) { if (p != empty_option) - free(p); + xfree(p); } void clear_string_option(char_u **pp) { if (*pp != empty_option) - free(*pp); + xfree(*pp); *pp = empty_option; } @@ -3767,7 +3768,7 @@ did_set_string_option ( if (errmsg == NULL) { /* canonize the value, so that STRCMP() can be used on it */ p = enc_canonize(*varp); - free(*varp); + xfree(*varp); *varp = p; if (varp == &p_enc) { errmsg = mb_init(); @@ -3794,7 +3795,7 @@ did_set_string_option ( } else if (varp == &p_penc) { /* Canonize printencoding if VIM standard one */ p = enc_canonize(p_penc); - free(p_penc); + xfree(p_penc); p_penc = p; } else if (varp == &curbuf->b_p_keymap) { /* load or unload key mapping tables */ @@ -4455,7 +4456,7 @@ skip: return e_invarg; /* illegal trailing comma as in "set cc=80," */ } - free(wp->w_p_cc_cols); + xfree(wp->w_p_cc_cols); if (count == 0) wp->w_p_cc_cols = NULL; else { @@ -4648,7 +4649,7 @@ static char_u *compile_cap_prog(synblock_T *synblock) /* Prepend a ^ so that we only match at one column */ re = concat_str((char_u *)"^", synblock->b_p_spc); synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); - free(re); + xfree(re); if (synblock->b_cap_prog == NULL) { synblock->b_cap_prog = rp; /* restore the previous program */ return e_invarg; @@ -5929,7 +5930,7 @@ showoptions ( os_breakcheck(); } } - free(items); + xfree(items); } /* @@ -6156,10 +6157,10 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e buf = xmalloc(MAXPATHL); home_replace(NULL, *valuep, buf, MAXPATHL, FALSE); if (put_escstr(fd, buf, 2) == FAIL) { - free(buf); + xfree(buf); return FAIL; } - free(buf); + xfree(buf); } else if (put_escstr(fd, *valuep, 2) == FAIL) return FAIL; } @@ -7437,10 +7438,10 @@ void vimrc_found(char_u *fname, char_u *envname) p = FullName_save(fname, FALSE); if (p != NULL) { vim_setenv(envname, p); - free(p); + xfree(p); } } else if (dofree) - free(p); + xfree(p); } } @@ -7607,7 +7608,7 @@ void save_file_ff(buf_T *buf) /* Only use free/alloc when necessary, they take time. */ if (buf->b_start_fenc == NULL || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { - free(buf->b_start_fenc); + xfree(buf->b_start_fenc); buf->b_start_fenc = vim_strsave(buf->b_p_fenc); } } @@ -7653,18 +7654,22 @@ int check_ff_value(char_u *p) * Return the effective shiftwidth value for current buffer, using the * 'tabstop' value when 'shiftwidth' is zero. */ -long get_sw_value(buf_T *buf) +int get_sw_value(buf_T *buf) { - return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + long result = buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + assert(result >= 0 && result <= INT_MAX); + return (int)result; } /* * Return the effective softtabstop value for the current buffer, using the * 'tabstop' value when 'softtabstop' is negative. */ -long get_sts_value(void) +int get_sts_value(void) { - return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; + long result = curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; + assert(result >= 0 && result <= INT_MAX); + return (int)result; } /* diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 30e44341a9..be4b22de3a 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -37,6 +37,19 @@ int os_setenv(const char *name, const char *value, int overwrite) return setenv(name, value, overwrite); } +/// Unset environment variable +/// +/// For systems where unsetenv() is not available the value will be set as an +/// empty string +int os_unsetenv(const char *name) +{ +#ifdef HAVE_UNSETENV + return unsetenv(name); +#else + return os_setenv(name, "", 1); +#endif +} + char *os_getenvname_at_index(size_t index) { # if defined(HAVE__NSGETENVIRON) @@ -113,7 +126,7 @@ void init_homedir(void) char_u *var; /* In case we are called a second time (when 'encoding' changes). */ - free(homedir); + xfree(homedir); homedir = NULL; var = (char_u *)os_getenv("HOME"); @@ -144,7 +157,7 @@ void init_homedir(void) void free_homedir(void) { - free(homedir); + xfree(homedir); } #endif @@ -304,7 +317,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, char_u *p = vim_strsave(var); if (mustfree) { - free(var); + xfree(var); } var = p; mustfree = true; @@ -318,7 +331,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); if (mustfree) - free(var); + xfree(var); var = p; mustfree = true; } @@ -341,7 +354,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, copy_char = false; } if (mustfree) - free(var); + xfree(var); } if (copy_char) { /* copy at least one char */ @@ -371,33 +384,33 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, /// Check if the directory "vimdir/<version>" or "vimdir/runtime" exists. /// Return NULL if not, return its name in allocated memory otherwise. /// @param vimdir directory to test -static char_u *vim_version_dir(char_u *vimdir) +static char *vim_version_dir(char *vimdir) { char_u *p; if (vimdir == NULL || *vimdir == NUL) return NULL; - p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, true); + p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true); if (os_isdir(p)) - return p; - free(p); - p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, true); + return (char *)p; + xfree(p); + p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true); if (os_isdir(p)) - return p; - free(p); + return (char *)p; + xfree(p); return NULL; } /// If the string between "p" and "pend" ends in "name/", return "pend" minus /// the length of "name/". Otherwise return "pend". -static char_u *remove_tail(char_u *p, char_u *pend, char_u *name) +static char *remove_tail(char *p, char *pend, char *name) { - int len = (int)STRLEN(name) + 1; - char_u *newend = pend - len; + size_t len = STRLEN(name) + 1; + char *newend = pend - len; if (newend >= p - && fnamencmp(newend, name, len - 1) == 0 - && (newend == p || after_pathsep(p, newend))) + && fnamencmp((char_u *)newend, (char_u *)name, len - 1) == 0 + && (newend == p || after_pathsep((char_u *)p, (char_u *)newend))) return newend; return pend; } @@ -442,7 +455,7 @@ char_u *vim_getenv(char_u *name, bool *mustfree) if (p != NULL && *p == NUL) /* empty is the same as not set */ p = NULL; if (p != NULL) { - p = vim_version_dir(p); + p = (char_u *)vim_version_dir((char *)p); if (p != NULL) *mustfree = true; else @@ -464,12 +477,14 @@ char_u *vim_getenv(char_u *name, bool *mustfree) /* remove "doc/" from 'helpfile', if present */ if (p == p_hf) - pend = remove_tail(p, pend, (char_u *)"doc"); + pend = (char_u *)remove_tail((char *)p, (char *)pend, "doc"); /* for $VIM, remove "runtime/" or "vim54/", if present */ if (!vimruntime) { - pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); - pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); + pend = (char_u *)remove_tail((char *)p, (char *)pend, + RUNTIME_DIRNAME); + pend = (char_u *)remove_tail((char *)p, (char *)pend, + VIM_VERSION_NODOT); } /* remove trailing path separator */ @@ -481,7 +496,7 @@ char_u *vim_getenv(char_u *name, bool *mustfree) p = vim_strnsave(p, (size_t)(pend - p)); if (!os_isdir(p)) { - free(p); + xfree(p); p = NULL; } else { *mustfree = true; @@ -495,13 +510,14 @@ char_u *vim_getenv(char_u *name, bool *mustfree) if (p == NULL) { /* Only use default_vimruntime_dir when it is not empty */ if (vimruntime && *default_vimruntime_dir != NUL) { - p = default_vimruntime_dir; + p = (char_u *)default_vimruntime_dir; *mustfree = false; } else if (*default_vim_dir != NUL) { - if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL) { + if (vimruntime + && (p = (char_u *)vim_version_dir(default_vim_dir)) != NULL) { *mustfree = true; } else { - p = default_vim_dir; + p = (char_u *)default_vim_dir; *mustfree = false; } } @@ -631,7 +647,7 @@ void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one) *dst = NUL; if (homedir_env != homedir_env_orig) - free(homedir_env); + xfree(homedir_env); } /// Like home_replace, store the replaced string in allocated memory. @@ -660,7 +676,7 @@ void vim_setenv(char_u *name, char_u *val) if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) { char_u *buf = concat_str(val, (char_u *)"/lang"); bindtextdomain(VIMPACKAGE, (char *)buf); - free(buf); + xfree(buf); } } @@ -675,7 +691,7 @@ char_u *get_env_name(expand_T *xp, int idx) char *envname = os_getenvname_at_index((size_t)idx); if (envname) { STRLCPY(name, envname, ENVNAMELEN); - free(envname); + xfree(envname); return name; } else { return NULL; diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c index fd9ff5b230..0560da1e2e 100644 --- a/src/nvim/os/event.c +++ b/src/nvim/os/event.c @@ -28,12 +28,6 @@ #define _destroy_event(x) // do nothing KLIST_INIT(Event, Event, _destroy_event) -typedef struct { - bool timed_out; - int ms; - uv_timer_t *timer; -} TimerData; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/event.c.generated.h" #endif @@ -52,7 +46,6 @@ void event_init(void) // early msgpack-rpc initialization msgpack_rpc_init_method_table(); msgpack_rpc_helpers_init(); - wstream_init(); // Initialize input events input_init(); // Timer to wake the event loop if a timeout argument is passed to @@ -107,19 +100,12 @@ void event_poll(int ms) uv_run_mode run_mode = UV_RUN_ONCE; uv_timer_t timer; - uv_prepare_t timer_prepare; - TimerData timer_data = {.ms = ms, .timed_out = false, .timer = &timer}; if (ms > 0) { uv_timer_init(uv_default_loop(), &timer); - // This prepare handle that actually starts the timer - uv_prepare_init(uv_default_loop(), &timer_prepare); - // Timeout passed as argument to the timer - timer.data = &timer_data; - // We only start the timer after the loop is running, for that we - // use a prepare handle(pass the interval as data to it) - timer_prepare.data = &timer_data; - uv_prepare_start(&timer_prepare, timer_prepare_cb); + // Use a repeating timeout of ms milliseconds to make sure + // we do not block indefinitely for I/O. + uv_timer_start(&timer, timer_cb, (uint64_t)ms, (uint64_t)ms); } else if (ms == 0) { // For ms == 0, we need to do a non-blocking event poll by // setting the run mode to UV_RUN_NOWAIT. @@ -129,17 +115,19 @@ void event_poll(int ms) loop(run_mode); if (ms > 0) { - // Ensure the timer-related handles are closed and run the event loop + // Ensure the timer handle is closed and run the event loop // once more to let libuv perform it's cleanup uv_timer_stop(&timer); - uv_prepare_stop(&timer_prepare); uv_close((uv_handle_t *)&timer, NULL); - uv_close((uv_handle_t *)&timer_prepare, NULL); loop(UV_RUN_NOWAIT); } recursive--; // Can re-enter uv_run now - process_events_from(immediate_events); + + // In case this is run before event_init, don't process any events. + if (immediate_events) { + process_events_from(immediate_events); + } } bool event_has_deferred(void) @@ -183,19 +171,8 @@ static void process_events_from(klist_t(Event) *queue) } } -// Set a flag in the `event_poll` loop for signaling of a timeout static void timer_cb(uv_timer_t *handle) { - TimerData *data = handle->data; - data->timed_out = true; -} - -static void timer_prepare_cb(uv_prepare_t *handle) -{ - TimerData *data = handle->data; - assert(data->ms > 0); - uv_timer_start(data->timer, timer_cb, (uint32_t)data->ms, 0); - uv_prepare_stop(handle); } static void loop(uv_run_mode run_mode) diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d583323b1f..2a41001cde 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -152,14 +152,14 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath) *abspath = save_absolute_path(buf); } - free(buf); + xfree(buf); return true; } if (*e != ':') { // End of $PATH without finding any executable called name. - free(buf); + xfree(buf); return false; } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index a409a9ed13..8002d528ed 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -128,7 +128,9 @@ bool os_char_avail(void) // Check for CTRL-C typed by reading all available characters. void os_breakcheck(void) { - event_poll(0); + if (!disable_breakcheck && !got_int) { + event_poll(0); + } } /// Test whether a file descriptor refers to a terminal. diff --git a/src/nvim/os/job_private.h b/src/nvim/os/job_private.h index af13d2e636..983106d918 100644 --- a/src/nvim/os/job_private.h +++ b/src/nvim/os/job_private.h @@ -11,6 +11,7 @@ #include "nvim/os/pty_process.h" #include "nvim/os/shell.h" #include "nvim/log.h" +#include "nvim/memory.h" struct job { // Job id the index in the job table plus one. @@ -104,12 +105,12 @@ static inline void job_decref(Job *job) // Invoke the exit_cb job_exit_callback(job); // Free all memory allocated for the job - free(job->proc_stdin->data); - free(job->proc_stdout->data); - free(job->proc_stderr->data); + xfree(job->proc_stdin->data); + xfree(job->proc_stdout->data); + xfree(job->proc_stderr->data); shell_free_argv(job->opts.argv); process_destroy(job); - free(job); + xfree(job); } } diff --git a/src/nvim/os/pipe_process.c b/src/nvim/os/pipe_process.c index 5535c3fe93..2ac305e967 100644 --- a/src/nvim/os/pipe_process.c +++ b/src/nvim/os/pipe_process.c @@ -72,8 +72,8 @@ void pipe_process_init(Job *job) void pipe_process_destroy(Job *job) { UvProcess *pipeproc = job->process; - free(pipeproc->proc.data); - free(pipeproc); + xfree(pipeproc->proc.data); + xfree(pipeproc); job->process = NULL; } diff --git a/src/nvim/os/pty_process.c b/src/nvim/os/pty_process.c index 9a2721f769..c64f3f9932 100644 --- a/src/nvim/os/pty_process.c +++ b/src/nvim/os/pty_process.c @@ -65,8 +65,8 @@ void pty_process_init(Job *job) FUNC_ATTR_NONNULL_ALL void pty_process_destroy(Job *job) FUNC_ATTR_NONNULL_ALL { - free(job->opts.term_name); - free(job->process); + xfree(job->opts.term_name); + xfree(job->process); job->process = NULL; } diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 29b8a5a9e1..702f282d53 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -162,8 +162,8 @@ size_t rbuffer_available(RBuffer *rbuffer) void rbuffer_free(RBuffer *rbuffer) { - free(rbuffer->data); - free(rbuffer); + xfree(rbuffer->data); + xfree(rbuffer); } /// Creates a new RStream instance. A RStream encapsulates all the boilerplate @@ -216,7 +216,7 @@ void rstream_free(RStream *rstream) } rbuffer_free(rstream->buffer); - free(rstream); + xfree(rstream); } /// Sets the underlying `uv_stream_t` instance @@ -401,8 +401,8 @@ static void fread_idle_cb(uv_idle_t *handle) static void close_cb(uv_handle_t *handle) { - free(handle->data); - free(handle); + xfree(handle->data); + xfree(handle); } static void rbuffer_relocate(RBuffer *rbuffer) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 6fcb62a5f3..4f5928ba8a 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -80,11 +80,11 @@ void shell_free_argv(char **argv) while (*p != NULL) { // Free each argument - free(*p); + xfree(*p); p++; } - free(argv); + xfree(argv); } /// Calls the user-configured 'shell' (p_sh) for running a command or wildcard @@ -128,11 +128,11 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) emsg_silent, forward_output); - free(input.data); + xfree(input.data); if (output) { (void)write_output(output, nread, true, true); - free(output); + xfree(output); } if (!emsg_silent && status != 0 && !(opts & kShellOptSilent)) { @@ -250,7 +250,7 @@ static int shell(const char *cmd, if (buf.len == 0) { // no data received from the process, return NULL *output = NULL; - free(buf.data); + xfree(buf.data); } else { // NUL-terminate to make the output directly usable as a C string buf.data[buf.len] = NUL; diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index a332ad2314..f824543003 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -1,9 +1,8 @@ +#include <assert.h> #include <stdbool.h> #include <uv.h> -#include "nvim/lib/klist.h" - #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/globals.h" @@ -15,10 +14,6 @@ #include "nvim/os/signal.h" #include "nvim/os/event.h" -#define SignalEventFreer(x) -KMEMPOOL_INIT(SignalEventPool, int, SignalEventFreer) -kmempool_t(SignalEventPool) *signal_event_pool = NULL; - static uv_signal_t spipe, shup, squit, sterm; #ifdef SIGPWR static uv_signal_t spwr; @@ -32,7 +27,6 @@ static bool rejecting_deadly; void signal_init(void) { - signal_event_pool = kmp_init(SignalEventPool); uv_signal_init(uv_default_loop(), &spipe); uv_signal_init(uv_default_loop(), &shup); uv_signal_init(uv_default_loop(), &squit); @@ -119,18 +113,16 @@ static void deadly_signal(int signum) static void signal_cb(uv_signal_t *handle, int signum) { - int *n = kmp_alloc(SignalEventPool, signal_event_pool); - *n = signum; + assert(signum >= 0); event_push((Event) { .handler = on_signal_event, - .data = n + .data = (void *)(uintptr_t)signum }, false); } static void on_signal_event(Event event) { - int signum = *((int *)event.data); - kmp_free(SignalEventPool, signal_event_pool, event.data); + int signum = (int)(uintptr_t)event.data; switch (signum) { #ifdef SIGPWR diff --git a/src/nvim/os/wstream.c b/src/nvim/os/wstream.c index 13c6c0429f..73896c381d 100644 --- a/src/nvim/os/wstream.c +++ b/src/nvim/os/wstream.c @@ -5,8 +5,6 @@ #include <uv.h> -#include "nvim/lib/klist.h" - #include "nvim/os/uv_helpers.h" #include "nvim/os/wstream.h" #include "nvim/os/wstream_defs.h" @@ -41,24 +39,10 @@ typedef struct { uv_write_t uv_req; } WRequest; -#define WRequestFreer(x) -KMEMPOOL_INIT(WRequestPool, WRequest, WRequestFreer) -kmempool_t(WRequestPool) *wrequest_pool = NULL; -#define WBufferFreer(x) -KMEMPOOL_INIT(WBufferPool, WBuffer, WBufferFreer) -kmempool_t(WBufferPool) *wbuffer_pool = NULL; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/wstream.c.generated.h" #endif -/// Initialize pools for reusing commonly created objects -void wstream_init(void) -{ - wrequest_pool = kmp_init(WRequestPool); - wbuffer_pool = kmp_init(WBufferPool); -} - /// Creates a new WStream instance. A WStream encapsulates all the boilerplate /// necessary for writing to a libuv stream. /// @@ -92,7 +76,7 @@ void wstream_free(WStream *wstream) { uv_close((uv_handle_t *)wstream->stream, close_cb); } else { handle_set_wstream((uv_handle_t *)wstream->stream, NULL); - free(wstream); + xfree(wstream); } } else { wstream->freed = true; @@ -163,7 +147,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer) wstream->curmem += buffer->size; - WRequest *data = kmp_alloc(WRequestPool, wrequest_pool); + WRequest *data = xmalloc(sizeof(WRequest)); data->wstream = wstream; data->buffer = buffer; data->uv_req.data = data; @@ -173,7 +157,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer) uvbuf.len = buffer->size; if (uv_write(&data->uv_req, wstream->stream, &uvbuf, 1, write_cb)) { - kmp_free(WRequestPool, wrequest_pool, data); + xfree(data); goto err; } @@ -202,7 +186,7 @@ WBuffer *wstream_new_buffer(char *data, size_t refcount, wbuffer_data_finalizer cb) { - WBuffer *rv = kmp_alloc(WBufferPool, wbuffer_pool); + WBuffer *rv = xmalloc(sizeof(WBuffer)); rv->size = size; rv->refcount = refcount; rv->cb = cb; @@ -232,11 +216,11 @@ static void write_cb(uv_write_t *req, int status) if (data->wstream->free_handle) { uv_close((uv_handle_t *)data->wstream->stream, close_cb); } else { - free(data->wstream); + xfree(data->wstream); } } - kmp_free(WRequestPool, wrequest_pool, data); + xfree(data); } void wstream_release_wbuffer(WBuffer *buffer) @@ -246,14 +230,14 @@ void wstream_release_wbuffer(WBuffer *buffer) buffer->cb(buffer->data); } - kmp_free(WBufferPool, wbuffer_pool, buffer); + xfree(buffer); } } static void close_cb(uv_handle_t *handle) { - free(handle_get_wstream(handle)); - free(handle->data); - free(handle); + xfree(handle_get_wstream(handle)); + xfree(handle->data); + xfree(handle); } diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 26a4cdb083..e69b5ccc27 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -435,11 +435,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, if (ampersent) os_delay(10L, true); - free(command); + xfree(command); if (i) { /* os_call_shell() failed */ os_remove((char *)tempname); - free(tempname); + xfree(tempname); /* * With interactive completion, the error message is not printed. */ @@ -472,18 +472,18 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, MSG(_(e_wildexpand)); msg_start(); /* don't overwrite this message */ } - free(tempname); + xfree(tempname); goto notfound; } int fseek_res = fseek(fd, 0L, SEEK_END); if (fseek_res < 0) { - free(tempname); + xfree(tempname); fclose(fd); return FAIL; } long long templen = ftell(fd); /* get size of temp file */ if (templen < 0) { - free(tempname); + xfree(tempname); fclose(fd); return FAIL; } @@ -501,11 +501,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, if (readlen != len) { /* unexpected read error */ EMSG2(_(e_notread), tempname); - free(tempname); - free(buffer); + xfree(tempname); + xfree(buffer); return FAIL; } - free(tempname); + xfree(tempname); /* file names are separated with Space */ if (shell_style == STYLE_ECHO) { @@ -574,7 +574,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, * /bin/sh will happily expand it to nothing rather than returning an * error; and hey, it's good to check anyway -- webb. */ - free(buffer); + xfree(buffer); goto notfound; } *num_file = i; @@ -628,11 +628,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, add_pathsep(p); /* add '/' to a directory name */ (*file)[j++] = p; } - free(buffer); + xfree(buffer); *num_file = j; if (*num_file == 0) { /* rejected all entries */ - free(*file); + xfree(*file); *file = NULL; goto notfound; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 9515205643..36d550b764 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -83,15 +83,12 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname) return kDifferentFiles; } -/// Get the tail of a path: the file name. +/// Gets the tail (i.e., the filename segment) of a path `fname`. /// -/// @param fname A file path. -/// @return -/// - Empty string, if fname is NULL. -/// - The position of the last path separator + 1. (i.e. empty string, if -/// fname ends in a slash). -/// - Never NULL. +/// @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(char_u *fname) + FUNC_ATTR_NONNULL_RET { if (fname == NULL) { return (char_u *)""; @@ -383,7 +380,7 @@ FullName_save ( } else { new_fname = vim_strsave(fname); } - free(buf); + xfree(buf); return new_fname; } @@ -560,7 +557,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, starts_with_dot = (*s == '.'); pat = file_pat_to_reg_pat(s, e, NULL, FALSE); if (pat == NULL) { - free(buf); + xfree(buf); return 0; } @@ -577,10 +574,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, regmatch.regprog = vim_regcomp(pat, RE_MAGIC); if (flags & (EW_NOERROR | EW_NOTWILD)) --emsg_silent; - free(pat); + xfree(pat); if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0) { - free(buf); + xfree(buf); return 0; } @@ -637,7 +634,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, os_closedir(&dir); } - free(buf); + xfree(buf); vim_regfree(regmatch.regprog); matches = gap->ga_len - start_len; @@ -753,7 +750,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) GA_APPEND(char_u *, gap, vim_strsave(buf)); } - free(buf); + xfree(buf); } /* @@ -822,13 +819,13 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) file_pattern[1] = NUL; STRCAT(file_pattern, pattern); pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE); - free(file_pattern); + xfree(file_pattern); if (pat == NULL) return; regmatch.rm_ic = TRUE; /* always ignore case */ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); - free(pat); + xfree(pat); if (regmatch.regprog == NULL) return; @@ -913,16 +910,16 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) add_pathsep(rel_path); STRCAT(rel_path, short_name); - free(fnames[i]); + xfree(fnames[i]); fnames[i] = rel_path; sort_again = TRUE; os_breakcheck(); } - free(curdir); + xfree(curdir); for (int i = 0; i < gap->ga_len; i++) - free(in_curdir[i]); - free(in_curdir); + xfree(in_curdir[i]); + xfree(in_curdir); ga_clear_strings(&path_ga); vim_regfree(regmatch.regprog); @@ -981,7 +978,7 @@ expand_in_path ( ga_init(&path_ga, (int)sizeof(char_u *), 1); expand_path_option(curdir, &path_ga); - free(curdir); + xfree(curdir); if (GA_EMPTY(&path_ga)) return 0; @@ -989,7 +986,7 @@ expand_in_path ( ga_clear_strings(&path_ga); globpath(paths, pattern, gap, (flags & EW_ICASE) ? WILD_ICASE : 0); - free(paths); + xfree(paths); return gap->ga_len; } @@ -1113,7 +1110,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, * found file names and start all over again. */ else if (has_env_var(p) || *p == '~') { - free(p); + xfree(p); ga_clear_strings(&ga); i = mch_expand_wildcards(num_pat, pat, num_file, file, flags | EW_KEEPDOLLAR); @@ -1157,13 +1154,13 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, addfile(&ga, t, flags | EW_DIR | EW_FILE); else if (os_file_exists(t)) addfile(&ga, t, flags); - free(t); + xfree(t); } if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH)) uniquefy_paths(&ga, p); if (p != pat[i]) - free(p); + xfree(p); } *num_file = ga.ga_len; @@ -1209,7 +1206,7 @@ expand_backtick ( else buffer = get_cmd_output(cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, NULL); - free(cmd); + xfree(cmd); if (buffer == NULL) return 0; @@ -1232,7 +1229,7 @@ expand_backtick ( ++cmd; } - free(buffer); + xfree(buffer); return cnt; } @@ -1512,13 +1509,13 @@ find_file_name_in_path ( /* Repeat finding the file "count" times. This matters when it * appears several times in the path. */ while (file_name != NULL && --count > 0) { - free(file_name); + xfree(file_name); file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname); } } else file_name = vim_strnsave(ptr, len); - free(tofree); + xfree(tofree); return file_name; } @@ -1796,7 +1793,7 @@ char_u *path_shorten_fname_if_possible(char_u *full_path) p = full_path; } } - free(dirname); + xfree(dirname); return p; } @@ -1857,8 +1854,8 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file, ret = expand_wildcards(1, &exp_pat, num_file, file, flags); if (eval_pat != NULL) { - free(exp_pat); - free(eval_pat); + xfree(exp_pat); + xfree(eval_pat); } return ret; @@ -1906,13 +1903,13 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, break; if (match_file_list(p_wig, (*file)[i], ffname)) { /* remove this matching file from the list */ - free((*file)[i]); + xfree((*file)[i]); for (j = i; j + 1 < *num_file; ++j) (*file)[j] = (*file)[j + 1]; --*num_file; --i; } - free(ffname); + xfree(ffname); } } diff --git a/src/nvim/po/af.po b/src/nvim/po/af.po index b0bd5356d5..6bb93b9e02 100644 --- a/src/nvim/po/af.po +++ b/src/nvim/po/af.po @@ -1625,7 +1625,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Gebruik w of w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Jammer, die bevel is nie gemplementeer nie" #: ../ex_docmd.c:3752 @@ -2114,7 +2114,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: '*ReadPre' outobevele mag nie die huidige buffer verander nie" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lees nou vanaf 'stdin'...\n" #. Re-opening the original file failed! @@ -2761,7 +2761,7 @@ msgid "E477: No ! allowed" msgstr "E477: Geen ! toegelaat nie" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan nie gebruik word nie: Nie tydens kompilering gekies nie" #: ../globals.h:1036 @@ -4458,7 +4458,7 @@ msgid "E663: At end of changelist" msgstr "E663: By die einde van die veranderingslys" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Tik :quit<Enter> om Vim te verlaat" # Het te doen met < en > diff --git a/src/nvim/po/ca.po b/src/nvim/po/ca.po index 8d0a11ad41..79434cfdcd 100644 --- a/src/nvim/po/ca.po +++ b/src/nvim/po/ca.po @@ -1612,7 +1612,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Useu w o b w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Aquesta ordre no est disponible en aquesta versi" #: ../ex_docmd.c:3752 @@ -2101,7 +2101,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Les auto-ordres *ReadPre no poden canviar el buffer actual" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Llegint l'entrada estndard...\n" #. Re-opening the original file failed! @@ -2756,7 +2756,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! no perms" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: No es pot usar la GUI: No ha estat compilada" #: ../globals.h:1036 @@ -4447,7 +4447,7 @@ msgstr "E663: A l'inici de la llista de canvis" # amplada 53 carcters #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Feu :quit<Entrar> per sortir" #: ../ops.c:248 diff --git a/src/nvim/po/cs.cp1250.po b/src/nvim/po/cs.cp1250.po index 4826303f14..1e62034317 100644 --- a/src/nvim/po/cs.cp1250.po +++ b/src/nvim/po/cs.cp1250.po @@ -1633,7 +1633,7 @@ msgid "E494: Use w or w>>" msgstr "Pouijte w i w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Pkaz nen tto verzi bohuel implementovn" #: ../ex_docmd.c:3752 @@ -2137,7 +2137,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre automatick pkazy nesm mnit aktuln buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: tu ze standardnho vstupu...\n" #. Re-opening the original file failed! @@ -2803,7 +2803,7 @@ msgid "E477: No ! allowed" msgstr "! nen povoleno" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Nelze pout GUI: nebylo zapnuto pi pekladu programu" #: ../globals.h:1036 @@ -4533,7 +4533,7 @@ msgstr "" #: ../normal.c:7053 #, fuzzy -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "zadejte :q<Enter> pro ukonen programu" #: ../ops.c:248 diff --git a/src/nvim/po/cs.po b/src/nvim/po/cs.po index 93ec04e6b8..dd7016fedb 100644 --- a/src/nvim/po/cs.po +++ b/src/nvim/po/cs.po @@ -1633,7 +1633,7 @@ msgid "E494: Use w or w>>" msgstr "Pouijte w i w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Pkaz nen tto verzi bohuel implementovn" #: ../ex_docmd.c:3752 @@ -2137,7 +2137,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre automatick pkazy nesm mnit aktuln buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: tu ze standardnho vstupu...\n" #. Re-opening the original file failed! @@ -2803,7 +2803,7 @@ msgid "E477: No ! allowed" msgstr "! nen povoleno" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Nelze pout GUI: nebylo zapnuto pi pekladu programu" #: ../globals.h:1036 @@ -4533,7 +4533,7 @@ msgstr "" #: ../normal.c:7053 #, fuzzy -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "zadejte :q<Enter> pro ukonen programu" #: ../ops.c:248 diff --git a/src/nvim/po/de.po b/src/nvim/po/de.po index ed696eeb13..4950533a21 100644 --- a/src/nvim/po/de.po +++ b/src/nvim/po/de.po @@ -1040,7 +1040,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Verwenden Sie w oder w>>" #: ../ex_docmd.c:3319 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Der Befehl ist in dieser Version nicht implementiert" #: ../ex_docmd.c:3612 @@ -1523,7 +1523,7 @@ msgstr "" "E201: *ReadPre-Autokommandos drfen den aktuellen Puffer nicht wechseln" #: ../fileio.c:720 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lese von stdin...\n" #. Re-opening the original file failed! @@ -2176,7 +2176,7 @@ msgid "E477: No ! allowed" msgstr "E477: Kein ! erlaubt" #: ../globals.h:1034 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: GUI kann nicht benutzt werden: wurde zum Zeitpunkt des bersetzens " "nicht eingeschaltet." @@ -3899,7 +3899,7 @@ msgid "E663: At end of changelist" msgstr "E663: Am Ende der Liste der nderungen" #: ../normal.c:6950 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Bitte :quit<Enter> eingeben um Vim zu verlassen" #: ../ops.c:229 diff --git a/src/nvim/po/en_GB.po b/src/nvim/po/en_GB.po index a246029bf0..b4b38e11e3 100644 --- a/src/nvim/po/en_GB.po +++ b/src/nvim/po/en_GB.po @@ -1562,7 +1562,7 @@ msgid "E494: Use w or w>>" msgstr "" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "" #: ../ex_docmd.c:3752 @@ -2030,7 +2030,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "" #. Re-opening the original file failed! @@ -2663,7 +2663,7 @@ msgid "E477: No ! allowed" msgstr "" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" #: ../globals.h:1036 @@ -4267,7 +4267,7 @@ msgid "E663: At end of changelist" msgstr "" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "" #: ../ops.c:248 diff --git a/src/nvim/po/eo.po b/src/nvim/po/eo.po index 555eb3637e..8215b31e65 100644 --- a/src/nvim/po/eo.po +++ b/src/nvim/po/eo.po @@ -1587,7 +1587,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Uzu w aŭ w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Bedaŭrinde, tiu komando ne haveblas en tiu versio" #: ../ex_docmd.c:3752 @@ -2068,7 +2068,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: La aŭtokomandoj *ReadPre ne rajtas ŝanĝi la aktualan bufron" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Legado el stdin...\n" #. Re-opening the original file failed! @@ -2709,7 +2709,7 @@ msgid "E477: No ! allowed" msgstr "E477: Neniu ! permesebla" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Grafika interfaco ne uzeblas: Malŝaltita dum kompilado" #: ../globals.h:1036 @@ -4411,7 +4411,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ĉe fino de ŝanĝlisto" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Tajpu \":quit<Enenklavo>\" por eliri el Vim" #: ../ops.c:248 diff --git a/src/nvim/po/es.po b/src/nvim/po/es.po index 4673893476..1a5ef991dc 100644 --- a/src/nvim/po/es.po +++ b/src/nvim/po/es.po @@ -1612,7 +1612,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Use \"w\" o \"w>>\"" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Lo siento, esa orden no está disponible en esta versión" #: ../ex_docmd.c:3752 @@ -2112,7 +2112,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Las auto-órdenes \"*ReadPre\" no deben cambiar el búfer en uso" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leyendo la entrada estándar...\n" # Re-opening the original file failed! @@ -2787,7 +2787,7 @@ msgid "E477: No ! allowed" msgstr "E477: \"!\" no está permitido" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: No se puede usar la interfaz gráfica de usuario: No se activó al " "compilar" @@ -4527,7 +4527,7 @@ msgid "E663: At end of changelist" msgstr "E663: Al final de la lista de cambios" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Escriba \":quit<intro>\" para salir de Vim" #: ../ops.c:248 diff --git a/src/nvim/po/fi.po b/src/nvim/po/fi.po index 565f0fec89..d4082135aa 100644 --- a/src/nvim/po/fi.po +++ b/src/nvim/po/fi.po @@ -1596,7 +1596,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Kyt w:t tai w>>:aa" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Komento ei ole kytettviss tss versiossa" #: ../ex_docmd.c:3752 @@ -2073,7 +2073,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre-autocommand-komennot eivt saa muuttaa puskuria" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Luetaan vakiosytteest...\n" #. Re-opening the original file failed! @@ -2730,7 +2730,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ei sallittu" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUIta ei voi kytt, koska sit ei knnetty mukaan" #: ../globals.h:1036 @@ -4424,7 +4424,7 @@ msgid "E663: At end of changelist" msgstr "E663: Muutoslistan lopussa" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Komento :quit<Enter> lopettaa Vimin" #: ../ops.c:248 diff --git a/src/nvim/po/fr.po b/src/nvim/po/fr.po index 4f410fb039..9b2d44ce7d 100644 --- a/src/nvim/po/fr.po +++ b/src/nvim/po/fr.po @@ -1766,7 +1766,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Utilisez w ou w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Dsol, cette commande n'est pas disponible dans cette version" #: ../ex_docmd.c:3752 @@ -2252,7 +2252,7 @@ msgstr "" "courant" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim : Lecture de stdin...\n" #. Re-opening the original file failed! @@ -2909,7 +2909,7 @@ msgid "E477: No ! allowed" msgstr "E477: Le ! n'est pas autoris" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: L'interface graphique n'a pas t compile dans cette version" #: ../globals.h:1036 @@ -4616,7 +4616,7 @@ msgid "E663: At end of changelist" msgstr "E663: la fin de la liste des modifications" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "tapez :q<Entre> pour quitter Vim" #: ../ops.c:248 diff --git a/src/nvim/po/ga.po b/src/nvim/po/ga.po index 34770267b8..f7117c6e86 100644 --- a/src/nvim/po/ga.po +++ b/src/nvim/po/ga.po @@ -1589,7 +1589,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Bain sid as w n w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: T brn orm, nl an t-ord ar fil sa leagan seo" #: ../ex_docmd.c:3752 @@ -2073,7 +2073,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: N cheadatear d'uathorduithe *ReadPre an maoln reatha a athr" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Ag lamh n ionchur caighdenach...\n" #. Re-opening the original file failed! @@ -2725,7 +2725,7 @@ msgid "E477: No ! allowed" msgstr "E477: N cheadatear !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: N fidir an GUI a sid: Nor cumasaodh ag am tiomsaithe" #: ../globals.h:1036 @@ -4438,7 +4438,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ag deireadh liosta na n-athruithe" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Clscrobh :quit<Enter> chun Vim a scor" # ouch - English -ed ? diff --git a/src/nvim/po/it.po b/src/nvim/po/it.po index c7f77aad5b..7fe61c45bc 100644 --- a/src/nvim/po/it.po +++ b/src/nvim/po/it.po @@ -1581,7 +1581,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Usa w oppure w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Spiacente, comando non disponibile in questa versione" #: ../ex_docmd.c:3752 @@ -2064,7 +2064,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Gli autocomandi *ReadPre non devono modificare il buffer in uso" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leggo da 'stdin'...\n" #. Re-opening the original file failed! @@ -2714,7 +2714,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! non consentito" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI non utilizzabile: Non abilitata in compilazione" #: ../globals.h:1036 @@ -4409,7 +4409,7 @@ msgid "E663: At end of changelist" msgstr "E663: Alla fine della lista modifiche" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Batti :quit<Invio> per uscire da Vim" #: ../ops.c:248 diff --git a/src/nvim/po/ja.euc-jp.po b/src/nvim/po/ja.euc-jp.po index cb1b8dab24..d3061d3c5a 100644 --- a/src/nvim/po/ja.euc-jp.po +++ b/src/nvim/po/ja.euc-jp.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w ⤷ w>> ѤƤ" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ΥСǤϤΥޥɤѤǤޤ, ʤ" #: ../ex_docmd.c:3752 @@ -2050,7 +2050,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommand ϸߤΥХåեѤޤ" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ɸϤɹ...\n" #. Re-opening the original file failed! @@ -2689,7 +2689,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ϵĤƤޤ" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUIϻԲǽǤ: ѥ̵ˤƤޤ" #: ../globals.h:1036 @@ -4375,7 +4375,7 @@ msgid "E663: At end of changelist" msgstr "E663: ѹꥹȤ" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Vimλˤ :quit<Enter> ϤƤ" #: ../ops.c:248 diff --git a/src/nvim/po/ja.po b/src/nvim/po/ja.po index 606553f5ca..6bdfcb426f 100644 --- a/src/nvim/po/ja.po +++ b/src/nvim/po/ja.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w もしくは w>> を使用してください" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: このバージョンではこのコマンドは利用できません, ごめんなさい" #: ../ex_docmd.c:3752 @@ -2050,7 +2050,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommand は現在のバッファを変えられません" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: 標準入力から読込中...\n" #. Re-opening the original file failed! @@ -2689,7 +2689,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! は許可されていません" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUIは使用不可能です: コンパイル時に無効にされています" #: ../globals.h:1036 @@ -4375,7 +4375,7 @@ msgid "E663: At end of changelist" msgstr "E663: 変更リストの末尾" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Vimを終了するには :quit<Enter> と入力してください" #: ../ops.c:248 diff --git a/src/nvim/po/ja.sjis.po b/src/nvim/po/ja.sjis.po index 4b1073f708..7dac89e172 100644 --- a/src/nvim/po/ja.sjis.po +++ b/src/nvim/po/ja.sjis.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w w>> gpĂ" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ̃o[Wł͂̃R}h͗pł܂, ߂Ȃ" #: ../ex_docmd.c:3752 @@ -2050,7 +2050,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommand ݂͌̃obt@ς܂" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: W͂Ǎ...\n" #. Re-opening the original file failed! @@ -2689,7 +2689,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ͋Ă܂" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI͎gps\\ł: RpCɖɂĂ܂" #: ../globals.h:1036 @@ -4375,7 +4375,7 @@ msgid "E663: At end of changelist" msgstr "E663: ύXXg̖" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "VimIɂ :quit<Enter> Ɠ͂Ă" #: ../ops.c:248 diff --git a/src/nvim/po/ko.UTF-8.po b/src/nvim/po/ko.UTF-8.po index 8b43e1ceed..149286eda8 100644 --- a/src/nvim/po/ko.UTF-8.po +++ b/src/nvim/po/ko.UTF-8.po @@ -1577,7 +1577,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w나 w>>를 사용하십시오" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: 미안합니다, 그 명령은 현재 판에서 사용할 수 없습니다" #: ../ex_docmd.c:3752 @@ -2049,7 +2049,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre 자동명령은 현재 버퍼를 바꾸면 안 됩니다" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "빔: 표준입력에서 읽는 중...\n" #. Re-opening the original file failed! @@ -2687,7 +2687,7 @@ msgid "E477: No ! allowed" msgstr "E477: !은 허용되지 않습니다" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI는 사용할 수 없습니다: 컴파일 때 포함되지 않았습니다" #: ../globals.h:1036 @@ -4373,7 +4373,7 @@ msgid "E663: At end of changelist" msgstr "" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "VIM을 마치려면 :quit<Enter> 입력" #: ../ops.c:248 diff --git a/src/nvim/po/ko.po b/src/nvim/po/ko.po index a8965b682c..b6aaf37bbb 100644 --- a/src/nvim/po/ko.po +++ b/src/nvim/po/ko.po @@ -1577,7 +1577,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w w>> Ͻʽÿ" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ̾մϴ, ǿ ϴ" #: ../ex_docmd.c:3752 @@ -2049,7 +2049,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre ڵ ۸ ٲٸ ˴ϴ" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr ": ǥԷ¿ д ...\n" #. Re-opening the original file failed! @@ -2687,7 +2687,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ʽϴ" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI ϴ: Ե ʾҽϴ" #: ../globals.h:1036 @@ -4373,7 +4373,7 @@ msgid "E663: At end of changelist" msgstr "" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "VIM ġ :quit<Enter> Է" #: ../ops.c:248 diff --git a/src/nvim/po/nb.po b/src/nvim/po/nb.po index b9bac7b692..ce635e098c 100644 --- a/src/nvim/po/nb.po +++ b/src/nvim/po/nb.po @@ -1605,7 +1605,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Bruk w eller w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Kommandoen er ikke tilgjengelig i denne versjonen" #: ../ex_docmd.c:3752 @@ -2092,7 +2092,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: \"*ReadPre\"-autokommandoer m ikke forandre nvrende buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leser fra stdin...\n" #. Re-opening the original file failed! @@ -2738,7 +2738,7 @@ msgid "E477: No ! allowed" msgstr "E477: Ingen ! tillatt" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan ikke brukes: Ikke sltt p under kompilering" #: ../globals.h:1036 @@ -4428,7 +4428,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ved slutten av forandringsliste" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Skriv :quit<Enter> for avslutte Vim" #: ../ops.c:248 diff --git a/src/nvim/po/nl.po b/src/nvim/po/nl.po index aa7fe9cf4a..ea609c0f69 100644 --- a/src/nvim/po/nl.po +++ b/src/nvim/po/nl.po @@ -1589,7 +1589,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w of w>> gebruiken" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Helaas, in deze versie is de opdracht niet beschikbaar" #: ../ex_docmd.c:3752 @@ -2072,7 +2072,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommands mogen huidige buffer niet wijzigen" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: lezen van standaardinvoer...\n" #. Re-opening the original file failed! @@ -2724,7 +2724,7 @@ msgid "E477: No ! allowed" msgstr "" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" #: ../globals.h:1036 @@ -4424,7 +4424,7 @@ msgid "E663: At end of changelist" msgstr "E663: einde van wijzigingslijst" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Typ :quit<Enter> om Vim te verlaten" #: ../ops.c:248 diff --git a/src/nvim/po/no.po b/src/nvim/po/no.po index b9bac7b692..ce635e098c 100644 --- a/src/nvim/po/no.po +++ b/src/nvim/po/no.po @@ -1605,7 +1605,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Bruk w eller w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Kommandoen er ikke tilgjengelig i denne versjonen" #: ../ex_docmd.c:3752 @@ -2092,7 +2092,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: \"*ReadPre\"-autokommandoer m ikke forandre nvrende buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leser fra stdin...\n" #. Re-opening the original file failed! @@ -2738,7 +2738,7 @@ msgid "E477: No ! allowed" msgstr "E477: Ingen ! tillatt" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan ikke brukes: Ikke sltt p under kompilering" #: ../globals.h:1036 @@ -4428,7 +4428,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ved slutten av forandringsliste" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Skriv :quit<Enter> for avslutte Vim" #: ../ops.c:248 diff --git a/src/nvim/po/pl.UTF-8.po b/src/nvim/po/pl.UTF-8.po index 6f2d33d8ba..68cb9e72d5 100644 --- a/src/nvim/po/pl.UTF-8.po +++ b/src/nvim/po/pl.UTF-8.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Stosuj w lub w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Przykro mi, ale ta komenda nie jest dostępna w tej wersji" #: ../ex_docmd.c:3752 @@ -2052,7 +2052,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Autokomendy *ReadPre nie mogą zmieniać bieżącego bufora" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Wczytywanie ze stdin...\n" #. Re-opening the original file failed! @@ -2697,7 +2697,7 @@ msgid "E477: No ! allowed" msgstr "E477: Niedozwolone !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI nie może być użyte: Nie włączono podczas kompilacji" #: ../globals.h:1036 @@ -4392,7 +4392,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na końcu listy zmian" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "wprowadź :quit<Enter> zakończenie programu" #: ../ops.c:248 diff --git a/src/nvim/po/pl.cp1250.po b/src/nvim/po/pl.cp1250.po index c598ff385f..3fcdbfb87d 100644 --- a/src/nvim/po/pl.cp1250.po +++ b/src/nvim/po/pl.cp1250.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Stosuj w lub w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Przykro mi, ale ta komenda nie jest dostpna w tej wersji" #: ../ex_docmd.c:3752 @@ -2052,7 +2052,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Autokomendy *ReadPre nie mog zmienia biecego bufora" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Wczytywanie ze stdin...\n" #. Re-opening the original file failed! @@ -2697,7 +2697,7 @@ msgid "E477: No ! allowed" msgstr "E477: Niedozwolone !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI nie moe by uyte: Nie wczono podczas kompilacji" #: ../globals.h:1036 @@ -4392,7 +4392,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na kocu listy zmian" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "wprowad :quit<Enter> zakoczenie programu" #: ../ops.c:248 diff --git a/src/nvim/po/pl.po b/src/nvim/po/pl.po index 253d8b31ab..2a2d12daac 100644 --- a/src/nvim/po/pl.po +++ b/src/nvim/po/pl.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Stosuj w lub w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Przykro mi, ale ta komenda nie jest dostpna w tej wersji" #: ../ex_docmd.c:3752 @@ -2052,7 +2052,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Autokomendy *ReadPre nie mog zmienia biecego bufora" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Wczytywanie ze stdin...\n" #. Re-opening the original file failed! @@ -2697,7 +2697,7 @@ msgid "E477: No ! allowed" msgstr "E477: Niedozwolone !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI nie moe by uyte: Nie wczono podczas kompilacji" #: ../globals.h:1036 @@ -4392,7 +4392,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na kocu listy zmian" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "wprowad :quit<Enter> zakoczenie programu" #: ../ops.c:248 diff --git a/src/nvim/po/pt_BR.po b/src/nvim/po/pt_BR.po index b39ae155c8..60c11d4b5a 100644 --- a/src/nvim/po/pt_BR.po +++ b/src/nvim/po/pt_BR.po @@ -2517,7 +2517,7 @@ msgid "E477: No ! allowed" msgstr "E477: '!' no permitido" #: ../globals.h:1034 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: Interface grfica no pode ser usada, no foi ativada na compilao" @@ -2825,7 +2825,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Os autocomandos *ReadPre no devem alterar o buffer atual" #: ../fileio.c:720 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lendo da entrada padro...\n" #. Re-opening the original file failed! @@ -3558,7 +3558,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Use w ou w>>" #: ../ex_docmd.c:3319 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Desculpe, esse comando no est disponvel nesta verso" #: ../ex_docmd.c:3616 @@ -4423,7 +4423,7 @@ msgid "E663: At end of changelist" msgstr "E663: No final da lista de modificaes" #: ../normal.c:6950 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Digite :quit<Enter> para sair do Vim" #: ../hardcopy.c:296 diff --git a/src/nvim/po/ru.cp1251.po b/src/nvim/po/ru.cp1251.po index 4dd4cec235..29e8c83ee6 100644 --- a/src/nvim/po/ru.cp1251.po +++ b/src/nvim/po/ru.cp1251.po @@ -1580,7 +1580,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: , " #: ../ex_docmd.c:3752 @@ -2060,7 +2060,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre " #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: stdin...\n" #. Re-opening the original file failed! @@ -2717,7 +2717,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! " #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: " "" @@ -4435,7 +4435,7 @@ msgid "E663: At end of changelist" msgstr "E663: " #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr " :quit<Enter> Vim" #: ../ops.c:248 diff --git a/src/nvim/po/ru.po b/src/nvim/po/ru.po index 5bdbc33801..c8146e8c47 100644 --- a/src/nvim/po/ru.po +++ b/src/nvim/po/ru.po @@ -1581,7 +1581,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Используйте w или w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Извините, эта команда недоступна в данной версии" #: ../ex_docmd.c:3752 @@ -2058,7 +2058,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Автокоманды *ReadPre не должны изменять активный буфер" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Чтение из стандартного потока ввода stdin...\n" #. Re-opening the original file failed! @@ -2715,7 +2715,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! не допускается" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: Возможность использования графического интерфейса выключена при " "компиляции" @@ -4433,7 +4433,7 @@ msgid "E663: At end of changelist" msgstr "E663: В конце списка изменений" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Введите :quit<Enter> для выхода из Vim" #: ../ops.c:248 diff --git a/src/nvim/po/sk.cp1250.po b/src/nvim/po/sk.cp1250.po index 97db400252..e3b7508cdc 100644 --- a/src/nvim/po/sk.cp1250.po +++ b/src/nvim/po/sk.cp1250.po @@ -1595,7 +1595,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Pouite w alebo w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: utujem, ale tento prkaz nie je dostupn v tejto verzii" #: ../ex_docmd.c:3752 @@ -2080,7 +2080,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: automatick prkazy *ReadPre nesm meni aktulny buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: tam zo tandardnho vstupu...\n" #. Re-opening the original file failed! @@ -2728,7 +2728,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! nie je povolen" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Ned sa pou GUI: nebolo zapnut pri preklade programu" #: ../globals.h:1036 @@ -4429,7 +4429,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na konci zoznamu zmien" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Zadajte :quit<Enter> pre ukonenie programu Vim" #: ../ops.c:248 diff --git a/src/nvim/po/sk.po b/src/nvim/po/sk.po index e6f833d52e..53f8a7b911 100644 --- a/src/nvim/po/sk.po +++ b/src/nvim/po/sk.po @@ -1595,7 +1595,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Pouite w alebo w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: utujem, ale tento prkaz nie je dostupn v tejto verzii" #: ../ex_docmd.c:3752 @@ -2080,7 +2080,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: automatick prkazy *ReadPre nesm meni aktulny buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: tam zo tandardnho vstupu...\n" #. Re-opening the original file failed! @@ -2728,7 +2728,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! nie je povolen" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Ned sa pou GUI: nebolo zapnut pri preklade programu" #: ../globals.h:1036 @@ -4429,7 +4429,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na konci zoznamu zmien" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Zadajte :quit<Enter> pre ukonenie programu Vim" #: ../ops.c:248 diff --git a/src/nvim/po/sv.po b/src/nvim/po/sv.po index 4ba06c3d45..eedaecd1e7 100644 --- a/src/nvim/po/sv.po +++ b/src/nvim/po/sv.po @@ -419,7 +419,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autokommandon fr inte ndra nuvarande buffert" #: ../fileio.c:720 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lser frn standard in...\n" #. Re-opening the original file failed! @@ -922,7 +922,7 @@ msgid "E663: At end of changelist" msgstr "E663: Vid slutet av ndringslista" #: ../normal.c:6950 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "skriv :q<Enter> fr att avsluta Vim " #: ../ex_cmds2.c:163 @@ -4781,7 +4781,7 @@ msgid "E477: No ! allowed" msgstr "E477: Inget ! tilltet" #: ../globals.h:1019 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan inte anvndas: Inte aktiverat vid kompilering" #: ../globals.h:1020 @@ -5380,7 +5380,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Anvnd w eller w>>" #: ../ex_docmd.c:3318 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Tyvrr, kommandot r inte tillgngligt i den hr versionen" #: ../ex_docmd.c:3611 diff --git a/src/nvim/po/uk.cp1251.po b/src/nvim/po/uk.cp1251.po index 1c14606740..2c6f3423ae 100644 --- a/src/nvim/po/uk.cp1251.po +++ b/src/nvim/po/uk.cp1251.po @@ -1602,7 +1602,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: , " #: ../ex_docmd.c:3752 @@ -2099,7 +2099,7 @@ msgstr "E201: *ReadPre " # msgstr "E201: " #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: stdin...\n" #. Re-opening the original file failed! @@ -2766,7 +2766,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! " #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI: " # msgstr "E25: " @@ -4514,7 +4514,7 @@ msgid "E663: At end of changelist" msgstr "E663: ʳ " #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr " :quit<Enter> Vim" #: ../ops.c:248 diff --git a/src/nvim/po/uk.po b/src/nvim/po/uk.po index 4471747ff2..eaa3a5bfa9 100644 --- a/src/nvim/po/uk.po +++ b/src/nvim/po/uk.po @@ -1602,7 +1602,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Спробуйте w або w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Вибачте, цієї команди немає у цій версії" #: ../ex_docmd.c:3752 @@ -2099,7 +2099,7 @@ msgstr "E201: Автокоманди *ReadPre не повинні змінюва # msgstr "E201: " #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Читається з stdin...\n" #. Re-opening the original file failed! @@ -2766,7 +2766,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! не дозволено" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Не можна використати GUI: Не ввімкнено під час компіляції" # msgstr "E25: " @@ -4514,7 +4514,7 @@ msgid "E663: At end of changelist" msgstr "E663: Кінець списку змін" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Уведіть :quit<Enter> щоб вийти з Vim" #: ../ops.c:248 diff --git a/src/nvim/po/vi.po b/src/nvim/po/vi.po index 7b6e5865f5..a720510426 100644 --- a/src/nvim/po/vi.po +++ b/src/nvim/po/vi.po @@ -1608,7 +1608,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Hãy sử dụng w hoặc w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Xin lỗi, câu lệnh này không có trong phiên bản này" #: ../ex_docmd.c:3752 @@ -2099,7 +2099,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Câu lệnh tự động *ReadPre không được thay đổi bộ đệm hoạt động" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Đọc từ đầu vào tiêu chuẩn stdin...\n" #. Re-opening the original file failed! @@ -2759,7 +2759,7 @@ msgid "E477: No ! allowed" msgstr "E477: Không cho phép !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Không sử dụng được giao diện đồ họa vì không chọn khi biên dịch" #: ../globals.h:1036 @@ -4466,7 +4466,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ở cuối danh sách những thay đổi" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Gõ :quit<Enter> để thoát khỏi Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_CN.UTF-8.po b/src/nvim/po/zh_CN.UTF-8.po index f4c7c4a471..82b895d9d6 100644 --- a/src/nvim/po/zh_CN.UTF-8.po +++ b/src/nvim/po/zh_CN.UTF-8.po @@ -1595,7 +1595,7 @@ msgid "E494: Use w or w>>" msgstr "E494: 请使用 w 或 w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: 抱歉,命令在此版本中不可用" #: ../ex_docmd.c:3752 @@ -2078,7 +2078,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre 自动命令不允许改变当前缓冲区" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: 从标准输入读取...\n" #. Re-opening the original file failed! @@ -2714,7 +2714,7 @@ msgid "E477: No ! allowed" msgstr "E477: 不能使用 \"!\"" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: 无法使用图形界面: 编译时没有启用" #: ../globals.h:1036 @@ -4416,7 +4416,7 @@ msgid "E663: At end of changelist" msgstr "E663: 已在改变列表的末尾处" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "输入 :quit<Enter> 退出 Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_CN.cp936.po b/src/nvim/po/zh_CN.cp936.po index a7ac34726c..cf66010c71 100644 --- a/src/nvim/po/zh_CN.cp936.po +++ b/src/nvim/po/zh_CN.cp936.po @@ -1596,7 +1596,7 @@ msgid "E494: Use w or w>>" msgstr "E494: ʹ w w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Ǹڴ˰汾в" #: ../ex_docmd.c:3752 @@ -2079,7 +2079,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre Զı䵱ǰ" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ӱȡ...\n" #. Re-opening the original file failed! @@ -2715,7 +2715,7 @@ msgid "E477: No ! allowed" msgstr "E477: ʹ \"!\"" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: ʹͼν: ʱû" #: ../globals.h:1036 @@ -4417,7 +4417,7 @@ msgid "E663: At end of changelist" msgstr "E663: ڸıбĩβ" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr " :quit<Enter> ˳ Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_CN.po b/src/nvim/po/zh_CN.po index aec9929fd9..254ebbce6b 100644 --- a/src/nvim/po/zh_CN.po +++ b/src/nvim/po/zh_CN.po @@ -1596,7 +1596,7 @@ msgid "E494: Use w or w>>" msgstr "E494: ʹ w w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Ǹڴ˰汾в" #: ../ex_docmd.c:3752 @@ -2079,7 +2079,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre Զı䵱ǰ" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ӱȡ...\n" #. Re-opening the original file failed! @@ -2715,7 +2715,7 @@ msgid "E477: No ! allowed" msgstr "E477: ʹ \"!\"" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: ʹͼν: ʱû" #: ../globals.h:1036 @@ -4417,7 +4417,7 @@ msgid "E663: At end of changelist" msgstr "E663: ڸıбĩβ" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr " :quit<Enter> ˳ Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_TW.UTF-8.po b/src/nvim/po/zh_TW.UTF-8.po index 321ca1c321..627389d8bf 100644 --- a/src/nvim/po/zh_TW.UTF-8.po +++ b/src/nvim/po/zh_TW.UTF-8.po @@ -1638,7 +1638,7 @@ msgid "E494: Use w or w>>" msgstr "E494: 請使用 w 或 w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: 抱歉, 本命令在此版本中沒有實作" #: ../ex_docmd.c:3752 @@ -2122,7 +2122,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *Filter* Autocommand 不可以更改緩衝區的內容" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: 從標準輸入讀取...\n" #. Re-opening the original file failed! @@ -2765,7 +2765,7 @@ msgid "E477: No ! allowed" msgstr "E477: 不可使用 '!'" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: 因為編譯時沒有加入圖型界面的程式碼,所以無法使用圖型界面" #: ../globals.h:1036 @@ -4460,7 +4460,7 @@ msgid "E663: At end of changelist" msgstr "E663: 已在變更列表的結尾" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "要離開 Vim 請輸入 :quit<Enter> " #: ../ops.c:248 diff --git a/src/nvim/po/zh_TW.po b/src/nvim/po/zh_TW.po index 3ef5cba071..9a7e6bf488 100644 --- a/src/nvim/po/zh_TW.po +++ b/src/nvim/po/zh_TW.po @@ -1630,7 +1630,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Шϥ w w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: p, RObS@" #: ../ex_docmd.c:3752 @@ -2114,7 +2114,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *Filter* Autocommand iHwİϪe" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: qзǿJŪ...\n" #. Re-opening the original file failed! @@ -2757,7 +2757,7 @@ msgid "E477: No ! allowed" msgstr "E477: iϥ '!'" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: ]sĶɨS[Jϫɭ{XAҥHLkϥιϫɭ" #: ../globals.h:1036 @@ -4452,7 +4452,7 @@ msgid "E663: At end of changelist" msgstr "E663: wbܧC" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "n} Vim пJ :quit<Enter> " #: ../ops.c:248 diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 1ea12d6862..10012a9775 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -2,6 +2,7 @@ /// /// Popup menu (PUM) // +#include <assert.h> #include <inttypes.h> #include <stdbool.h> @@ -17,6 +18,7 @@ #include "nvim/screen.h" #include "nvim/search.h" #include "nvim/strings.h" +#include "nvim/memory.h" #include "nvim/window.h" #include "nvim/edit.h" @@ -101,7 +103,7 @@ redo: } if ((p_ph > 0) && (pum_height > p_ph)) { - pum_height = p_ph; + pum_height = (int)p_ph; } // Put the pum below "row" if possible. If there are few lines decide on @@ -126,8 +128,8 @@ redo: } if ((p_ph > 0) && (pum_height > p_ph)) { - pum_row += pum_height - p_ph; - pum_height = p_ph; + pum_row += pum_height - (int)p_ph; + pum_height = (int)p_ph; } } else { // pum below "row" @@ -148,7 +150,7 @@ redo: } if ((p_ph > 0) && (pum_height > p_ph)) { - pum_height = p_ph; + pum_height = (int)p_ph; } } @@ -219,7 +221,9 @@ redo: if (curwin->w_p_rl) { pum_width = pum_col - pum_scrollbar + 1; } else { - pum_width = Columns - pum_col - pum_scrollbar; + assert(Columns - pum_col - pum_scrollbar >= INT_MIN + && Columns - pum_col - pum_scrollbar <= INT_MAX); + pum_width = (int)(Columns - pum_col - pum_scrollbar); } if ((pum_width > max_width + kind_width + extra_width + 1) @@ -233,11 +237,13 @@ redo: } else if (Columns < def_width) { // not enough room, will use what we have if (curwin->w_p_rl) { - pum_col = Columns - 1; + assert(Columns - 1 >= INT_MIN); + pum_col = (int)(Columns - 1); } else { pum_col = 0; } - pum_width = Columns - 1; + assert(Columns - 1 >= INT_MIN); + pum_width = (int)(Columns - 1); } else { if (max_width > PUM_DEF_WIDTH) { // truncate @@ -247,7 +253,8 @@ redo: if (curwin->w_p_rl) { pum_col = max_width - 1; } else { - pum_col = Columns - max_width; + assert(Columns - max_width >= INT_MIN && Columns - max_width <= INT_MAX); + pum_col = (int)(Columns - max_width); } pum_width = max_width - pum_scrollbar; } @@ -345,7 +352,7 @@ void pum_redraw(void) // Display the text that fits or comes before a Tab. // First convert it to printable characters. char_u *st; - int saved = *p; + char_u saved = *p; *p = NUL; st = transstr(s); @@ -371,12 +378,12 @@ void pum_redraw(void) } } screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, attr); - free(rt_start); - free(st); + xfree(rt_start); + xfree(st); col -= width; } else { screen_puts_len(st, (int)STRLEN(st), row, col, attr); - free(st); + xfree(st); col += width; } @@ -535,7 +542,7 @@ static int pum_set_selected(int n, int repeat) g_do_tagpreview = 3; if ((p_pvh > 0) && (p_pvh < g_do_tagpreview)) { - g_do_tagpreview = p_pvh; + g_do_tagpreview = (int)p_pvh; } RedrawingDisabled++; resized = prepare_tagpreview(false); diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 8e55cced78..7e83132a25 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -784,15 +784,15 @@ qf_init_ok: for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) { fmt_first = fmt_ptr->next; vim_regfree(fmt_ptr->prog); - free(fmt_ptr); + xfree(fmt_ptr); } qf_clean_dir_stack(&dir_stack); qf_clean_dir_stack(&file_stack); qf_init_end: - free(namebuf); - free(errmsg); - free(pattern); - free(fmtstr); + xfree(namebuf); + xfree(errmsg); + xfree(pattern); + xfree(fmtstr); qf_update_buffer(qi); @@ -855,7 +855,7 @@ static void ll_free_all(qf_info_T **pqi) /* No references to this location list */ for (i = 0; i < qi->qf_listcount; ++i) qf_free(qi, i); - free(qi); + xfree(qi); } } @@ -1091,7 +1091,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname) * directory change. */ if (!os_file_exists(ptr)) { - free(ptr); + xfree(ptr); directory = qf_guess_filepath(fname); if (directory) ptr = concat_fnames(directory, fname, TRUE); @@ -1100,7 +1100,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname) } /* Use concatenated directory name and file name */ fnum = buflist_add(ptr, 0); - free(ptr); + xfree(ptr); return fnum; } return buflist_add(fname, 0); @@ -1134,7 +1134,7 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) ds_new = (*stackptr)->next; (*stackptr)->dirname = NULL; while (ds_new) { - free((*stackptr)->dirname); + xfree((*stackptr)->dirname); (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, TRUE); if (os_isdir((*stackptr)->dirname)) @@ -1147,13 +1147,13 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) while ((*stackptr)->next != ds_new) { ds_ptr = (*stackptr)->next; (*stackptr)->next = (*stackptr)->next->next; - free(ds_ptr->dirname); - free(ds_ptr); + xfree(ds_ptr->dirname); + xfree(ds_ptr); } /* Nothing found -> it must be on top level */ if (ds_new == NULL) { - free((*stackptr)->dirname); + xfree((*stackptr)->dirname); (*stackptr)->dirname = vim_strsave(dirbuf); } } @@ -1163,7 +1163,7 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) else { ds_ptr = *stackptr; *stackptr = (*stackptr)->next; - free(ds_ptr); + xfree(ds_ptr); return NULL; } } @@ -1184,8 +1184,8 @@ static char_u *qf_pop_dir(struct dir_stack_T **stackptr) if (*stackptr != NULL) { ds_ptr = *stackptr; *stackptr = (*stackptr)->next; - free(ds_ptr->dirname); - free(ds_ptr); + xfree(ds_ptr->dirname); + xfree(ds_ptr); } /* return NEW top element as current dir or NULL if stack is empty*/ @@ -1201,8 +1201,8 @@ static void qf_clean_dir_stack(struct dir_stack_T **stackptr) while ((ds_ptr = *stackptr) != NULL) { *stackptr = (*stackptr)->next; - free(ds_ptr->dirname); - free(ds_ptr); + xfree(ds_ptr->dirname); + xfree(ds_ptr); } } @@ -1239,7 +1239,7 @@ static char_u *qf_guess_filepath(char_u *filename) ds_ptr = dir_stack->next; fullname = NULL; while (ds_ptr) { - free(fullname); + xfree(fullname); fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); if (os_file_exists(fullname)) @@ -1248,14 +1248,14 @@ static char_u *qf_guess_filepath(char_u *filename) ds_ptr = ds_ptr->next; } - free(fullname); + xfree(fullname); /* clean up all dirs we already left */ while (dir_stack->next != ds_ptr) { ds_tmp = dir_stack->next; dir_stack->next = dir_stack->next->next; - free(ds_tmp->dirname); - free(ds_tmp); + xfree(ds_tmp->dirname); + xfree(ds_tmp); } return ds_ptr==NULL ? NULL : ds_ptr->dirname; @@ -1876,10 +1876,10 @@ static void qf_free(qf_info_T *qi, int idx) while (qi->qf_lists[idx].qf_count) { qfp = qi->qf_lists[idx].qf_start->qf_next; if (qi->qf_lists[idx].qf_title != NULL && !stop) { - free(qi->qf_lists[idx].qf_start->qf_text); + xfree(qi->qf_lists[idx].qf_start->qf_text); stop = (qi->qf_lists[idx].qf_start == qfp); - free(qi->qf_lists[idx].qf_start->qf_pattern); - free(qi->qf_lists[idx].qf_start); + xfree(qi->qf_lists[idx].qf_start->qf_pattern); + xfree(qi->qf_lists[idx].qf_start); if (stop) /* Somehow qf_count may have an incorrect value, set it to 1 * to avoid crashing when it's wrong. @@ -1889,7 +1889,7 @@ static void qf_free(qf_info_T *qi, int idx) qi->qf_lists[idx].qf_start = qfp; --qi->qf_lists[idx].qf_count; } - free(qi->qf_lists[idx].qf_title); + xfree(qi->qf_lists[idx].qf_title); qi->qf_lists[idx].qf_title = NULL; qi->qf_lists[idx].qf_index = 0; } @@ -2526,8 +2526,8 @@ void ex_make(exarg_T *eap) qf_jump(qi, 0, 0, FALSE); /* display first error */ os_remove((char *)fname); - free(fname); - free(cmd); + xfree(fname); + xfree(cmd); } /* @@ -2573,7 +2573,7 @@ static char_u *get_mef_name(void) if (!file_or_link_found) { break; } - free(name); + xfree(name); } return name; } @@ -2834,7 +2834,7 @@ void ex_vimgrep(exarg_T *eap) msg_outtrans(fname); else { msg_outtrans(p); - free(p); + xfree(p); } msg_clr_eos(); msg_didout = FALSE; /* overwrite this message */ @@ -3021,9 +3021,9 @@ void ex_vimgrep(exarg_T *eap) } theend: - free(dirname_now); - free(dirname_start); - free(target_dir); + xfree(dirname_now); + xfree(dirname_start); + xfree(target_dir); vim_regfree(regmatch.regprog); } @@ -3091,7 +3091,7 @@ static void restore_start_dir(char_u *dirname_start) ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; ex_cd(&ea); } - free(dirname_now); + xfree(dirname_now); } /* @@ -3356,10 +3356,10 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) type == NULL ? NUL : *type, valid); - free(filename); - free(pattern); - free(text); - free(type); + xfree(filename); + xfree(pattern); + xfree(text); + xfree(type); if (status == FAIL) { retval = FAIL; @@ -3599,12 +3599,12 @@ void ex_helpgrep(exarg_T *eap) ) == FAIL) { got_int = TRUE; if (line != IObuff) - free(line); + xfree(line); break; } } if (line != IObuff) - free(line); + xfree(line); ++lnum; line_breakcheck(); } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index d5e963c2f8..a260860e17 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1265,7 +1265,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) regcode = r->program; regc(REGMAGIC); if (reg(REG_NOPAREN, &flags) == NULL || reg_toolong) { - free(r); + xfree(r); if (reg_toolong) EMSG_RET_NULL(_("E339: Pattern too long")); return NULL; @@ -1349,7 +1349,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) */ static void bt_regfree(regprog_T *prog) { - free(prog); + xfree(prog); } /* @@ -3236,8 +3236,8 @@ void free_regexp_stuff(void) { ga_clear(®stack); ga_clear(&backpos); - free(reg_tofree); - free(reg_prev_sub); + xfree(reg_tofree); + xfree(reg_prev_sub); } #endif @@ -3509,7 +3509,7 @@ theend: /* Free "reg_tofree" when it's a bit big. * Free regstack and backpos if they are bigger than their initial size. */ if (reg_tofreelen > 400) { - free(reg_tofree); + xfree(reg_tofree); reg_tofree = NULL; } if (regstack.ga_maxlen > REGSTACK_INITIAL) @@ -3551,8 +3551,8 @@ void unref_extmatch(reg_extmatch_T *em) if (em != NULL && --em->refcnt <= 0) { for (i = 0; i < NSUBEXP; ++i) - free(em->matches[i]); - free(em); + xfree(em->matches[i]); + xfree(em); } } @@ -5642,7 +5642,7 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e len = (int)STRLEN(regline); if (reg_tofree == NULL || len >= (int)reg_tofreelen) { len += 50; /* get some extra */ - free(reg_tofree); + xfree(reg_tofree); reg_tofree = xmalloc(len); reg_tofreelen = len; } @@ -6382,7 +6382,7 @@ char_u *regtilde(char_u *source, int magic) STRCPY(tmpsub + len + prevlen, p + 1); if (newsub != source) /* already allocated newsub */ - free(newsub); + xfree(newsub); newsub = tmpsub; p = newsub + len + prevlen; } else if (magic) @@ -6398,7 +6398,7 @@ char_u *regtilde(char_u *source, int magic) } } - free(reg_prev_sub); + xfree(reg_prev_sub); if (newsub != source) /* newsub was allocated, just keep it */ reg_prev_sub = newsub; else /* no ~ found, need to save newsub */ @@ -6494,14 +6494,14 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in if (eval_result != NULL) { STRCPY(dest, eval_result); dst += STRLEN(eval_result); - free(eval_result); + xfree(eval_result); eval_result = NULL; } } else { win_T *save_reg_win; int save_ireg_ic; - free(eval_result); + xfree(eval_result); /* The expression may contain substitute(), which calls us * recursively. Make sure submatch() gets the text from the first @@ -6542,7 +6542,7 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in if (had_backslash && backslash) { /* Backslashes will be consumed, need to double them. */ s = vim_strsave_escaped(eval_result, (char_u *)"\\"); - free(eval_result); + xfree(eval_result); eval_result = s; } @@ -7073,7 +7073,7 @@ static int vim_regexec_both(regmatch_T *rmp, char_u *line, colnr_T col, bool nl) result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); } - free(pat); + xfree(pat); p_re = save_p_re; } @@ -7127,7 +7127,7 @@ long vim_regexec_multi( tm); } - free(pat); + xfree(pat); p_re = save_p_re; } diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 1de167c40f..56e488fbd4 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -2886,7 +2886,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size) if (stackp < stack) \ { \ st_error(postfix, end, p); \ - free(stack); \ + xfree(stack); \ return NULL; \ } @@ -3317,13 +3317,13 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size) e = POP(); if (stackp != stack) { - free(stack); + xfree(stack); EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA)," "too many states left on stack")); } if (istate >= nstate) { - free(stack); + xfree(stack); EMSG_RET_NULL(_("E876: (NFA regexp) " "Not enough space to store the whole NFA ")); } @@ -3337,7 +3337,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size) ret = e.start; theend: - free(stack); + xfree(stack); return ret; #undef POP1 @@ -4195,7 +4195,7 @@ addstate_here ( memmove(&(newl[listidx + count]), &(l->t[listidx + 1]), sizeof(nfa_thread_T) * (l->n - count - listidx - 1)); - free(l->t); + xfree(l->t); l->t = newl; } else { /* make space for new states, then move them from the @@ -6033,9 +6033,9 @@ nextchar: theend: /* Free memory */ - free(list[0].t); - free(list[1].t); - free(listids); + xfree(list[0].t); + xfree(list[1].t); + xfree(listids); #undef ADD_STATE_IF_MATCH #ifdef NFA_REGEXP_DEBUG_LOG fclose(debug); @@ -6340,13 +6340,13 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags) nfa_regengine.expr = NULL; out: - free(post_start); + xfree(post_start); post_start = post_ptr = post_end = NULL; state_ptr = NULL; return (regprog_T *)prog; fail: - free(prog); + xfree(prog); prog = NULL; #ifdef REGEXP_DEBUG nfa_postfix_dump(expr, FAIL); @@ -6361,9 +6361,9 @@ fail: static void nfa_regfree(regprog_T *prog) { if (prog != NULL) { - free(((nfa_regprog_T *)prog)->match_text); - free(((nfa_regprog_T *)prog)->pattern); - free(prog); + xfree(((nfa_regprog_T *)prog)->match_text); + xfree(((nfa_regprog_T *)prog)->pattern); + xfree(prog); } } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index c32603afb0..acd8e925e0 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1905,7 +1905,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T } if (text != buf) - free(text); + xfree(text); /* * 6. set highlighting for the Visual area an other text. @@ -3015,7 +3015,7 @@ win_line ( --n_extra; } else { if (p_extra_free != NULL) { - free(p_extra_free); + xfree(p_extra_free); p_extra_free = NULL; } /* @@ -4700,7 +4700,7 @@ win_redr_status_matches ( } win_redraw_last_status(topframe); - free(buf); + xfree(buf); } /* @@ -4915,7 +4915,7 @@ get_keymap_str ( sprintf((char *)buf, "<%s>", p); else buf[0] = NUL; - free(s); + xfree(s); } return buf[0] != NUL; } @@ -5021,14 +5021,14 @@ win_redr_custom ( width = build_stl_str_hl(ewp, buf, sizeof(buf), stl, use_sandbox, fillchar, maxwidth, hltab, tabtab); - free(stl); + xfree(stl); ewp->w_p_crb = p_crb_save; /* Make all characters printable. */ p = transstr(buf); len = STRLCPY(buf, p, sizeof(buf)); len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1; - free(p); + xfree(p); /* fill up with "fillchar" */ while (width < maxwidth && len < (int)sizeof(buf) - 1) { @@ -5999,23 +5999,23 @@ retry: * and over again. */ done_outofmem_msg = TRUE; } - free(new_ScreenLines); + xfree(new_ScreenLines); new_ScreenLines = NULL; - free(new_ScreenLinesUC); + xfree(new_ScreenLinesUC); new_ScreenLinesUC = NULL; for (i = 0; i < p_mco; ++i) { - free(new_ScreenLinesC[i]); + xfree(new_ScreenLinesC[i]); new_ScreenLinesC[i] = NULL; } - free(new_ScreenLines2); + xfree(new_ScreenLines2); new_ScreenLines2 = NULL; - free(new_ScreenAttrs); + xfree(new_ScreenAttrs); new_ScreenAttrs = NULL; - free(new_LineOffset); + xfree(new_LineOffset); new_LineOffset = NULL; - free(new_LineWraps); + xfree(new_LineWraps); new_LineWraps = NULL; - free(new_TabPageIdxs); + xfree(new_TabPageIdxs); new_TabPageIdxs = NULL; } else { done_outofmem_msg = FALSE; @@ -6126,15 +6126,15 @@ void free_screenlines(void) { int i; - free(ScreenLinesUC); + xfree(ScreenLinesUC); for (i = 0; i < Screen_mco; ++i) - free(ScreenLinesC[i]); - free(ScreenLines2); - free(ScreenLines); - free(ScreenAttrs); - free(LineOffset); - free(LineWraps); - free(TabPageIdxs); + xfree(ScreenLinesC[i]); + xfree(ScreenLines2); + xfree(ScreenLines); + xfree(ScreenAttrs); + xfree(LineOffset); + xfree(LineWraps); + xfree(TabPageIdxs); } void screenclear(void) diff --git a/src/nvim/search.c b/src/nvim/search.c index f62aeabd72..f015c233c8 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -179,7 +179,7 @@ search_regcomp ( add_to_history(HIST_SEARCH, pat, TRUE, NUL); if (mr_pattern_alloced) { - free(mr_pattern); + xfree(mr_pattern); mr_pattern_alloced = FALSE; } @@ -249,7 +249,7 @@ char_u *reverse_text(char_u *s) FUNC_ATTR_NONNULL_RET void save_re_pat(int idx, char_u *pat, int magic) { if (spats[idx].pat != pat) { - free(spats[idx].pat); + xfree(spats[idx].pat); spats[idx].pat = vim_strsave(pat); spats[idx].magic = magic; spats[idx].no_scs = no_smartcase; @@ -284,10 +284,10 @@ void save_search_patterns(void) void restore_search_patterns(void) { if (--save_level == 0) { - free(spats[0].pat); + xfree(spats[0].pat); spats[0] = saved_spats[0]; set_vv_searchforward(); - free(spats[1].pat); + xfree(spats[1].pat); spats[1] = saved_spats[1]; last_idx = saved_last_idx; SET_NO_HLSEARCH(saved_no_hlsearch); @@ -297,11 +297,11 @@ void restore_search_patterns(void) #if defined(EXITFREE) void free_search_patterns(void) { - free(spats[0].pat); - free(spats[1].pat); + xfree(spats[0].pat); + xfree(spats[1].pat); if (mr_pattern_alloced) { - free(mr_pattern); + xfree(mr_pattern); mr_pattern_alloced = FALSE; mr_pattern = NULL; } @@ -377,7 +377,7 @@ void reset_search_dir(void) */ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) { - free(spats[idx].pat); + xfree(spats[idx].pat); /* An empty string means that nothing should be matched. */ if (*s == NUL) spats[idx].pat = NULL; @@ -393,7 +393,7 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) if (setlast) last_idx = idx; if (save_level) { - free(saved_spats[idx].pat); + xfree(saved_spats[idx].pat); saved_spats[idx] = spats[0]; if (spats[idx].pat == NULL) saved_spats[idx].pat = NULL; @@ -1075,17 +1075,17 @@ int do_search( * left, but do reverse the text. */ if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { char_u *r = reverse_text(trunc != NULL ? trunc : msgbuf); - free(trunc); + xfree(trunc); trunc = r; } if (trunc != NULL) { msg_outtrans(trunc); - free(trunc); + xfree(trunc); } else msg_outtrans(msgbuf); msg_clr_eos(); msg_check(); - free(msgbuf); + xfree(msgbuf); gotocmdline(FALSE); ui_flush(); @@ -1203,7 +1203,7 @@ int do_search( end_do_search: if ((options & SEARCH_KEEP) || cmdmod.keeppatterns) spats[0].off = old_off; - free(strcopy); + xfree(strcopy); return retval; } @@ -3246,8 +3246,8 @@ again: r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"", 0, NULL, (linenr_T)0, 0L); - free(spat); - free(epat); + xfree(spat); + xfree(epat); if (r < 1 || lt(curwin->w_cursor, old_end)) { /* Can't find other end or it's before the previous end. Could be a @@ -4006,7 +4006,7 @@ find_pattern_in_path ( /* ignore case according to p_ic, p_scs and pat */ regmatch.rm_ic = ignorecase(pat); regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); - free(pat); + xfree(pat); if (regmatch.regprog == NULL) goto fpip_end; } @@ -4070,7 +4070,7 @@ find_pattern_in_path ( prev_fname = NULL; } } - free(new_fname); + xfree(new_fname); new_fname = NULL; already_searched = TRUE; break; @@ -4173,17 +4173,17 @@ find_pattern_in_path ( bigger[i + max_path_depth] = files[i]; old_files += max_path_depth; max_path_depth *= 2; - free(files); + xfree(files); files = bigger; } if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r")) == NULL) - free(new_fname); + xfree(new_fname); else { if (++depth == old_files) { // Something wrong. We will forget one of our already visited files // now. - free(files[old_files].name); + xfree(files[old_files].name); ++old_files; } files[depth].name = curr_fname = new_fname; @@ -4491,11 +4491,11 @@ exit_matched: /* Close any files that are still open. */ for (i = 0; i <= depth; i++) { fclose(files[i].fp); - free(files[i].name); + xfree(files[i].name); } for (i = old_files; i < max_path_depth; i++) - free(files[i].name); - free(files); + xfree(files[i].name); + xfree(files); if (type == CHECK_PATH) { if (!did_show) { @@ -4518,7 +4518,7 @@ exit_matched: msg_end(); fpip_end: - free(file_line); + xfree(file_line); vim_regfree(regmatch.regprog); vim_regfree(incl_regmatch.regprog); vim_regfree(def_regmatch.regprog); @@ -4629,7 +4629,7 @@ int read_viminfo_search_pattern(vir_T *virp, int force) if (force || spats[idx].pat == NULL) { val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), TRUE); set_last_search_pat(val, idx, magic, setlast); - free(val); + xfree(val); spats[idx].no_scs = no_scs; spats[idx].off.line = off_line; spats[idx].off.end = off_end; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6708ad2aa7..7b38b540cb 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2097,7 +2097,7 @@ spell_move_to ( len = (int)STRLEN(line); if (buflen < len + MAXWLEN + 2) { - free(buf); + xfree(buf); buflen = len + MAXWLEN + 2; buf = xmalloc(buflen); } @@ -2172,7 +2172,7 @@ spell_move_to ( if (dir == FORWARD) { // No need to search further. wp->w_cursor = found_pos; - free(buf); + xfree(buf); if (attrp != NULL) *attrp = attr; return len; @@ -2195,7 +2195,7 @@ spell_move_to ( if (dir == BACKWARD && found_pos.lnum != 0) { // Use the last match in the line (before the cursor). wp->w_cursor = found_pos; - free(buf); + xfree(buf); return found_len; } @@ -2259,7 +2259,7 @@ spell_move_to ( line_breakcheck(); } - free(buf); + xfree(buf); return 0; } @@ -2376,26 +2376,26 @@ static slang_T *slang_alloc(char_u *lang) // Free the contents of an slang_T and the structure itself. static void slang_free(slang_T *lp) { - free(lp->sl_name); - free(lp->sl_fname); + xfree(lp->sl_name); + xfree(lp->sl_fname); slang_clear(lp); - free(lp); + xfree(lp); } /// Frees a salitem_T static void free_salitem(salitem_T *smp) { - free(smp->sm_lead); + xfree(smp->sm_lead); // Don't free sm_oneof and sm_rules, they point into sm_lead. - free(smp->sm_to); - free(smp->sm_lead_w); - free(smp->sm_oneof_w); - free(smp->sm_to_w); + xfree(smp->sm_to); + xfree(smp->sm_lead_w); + xfree(smp->sm_oneof_w); + xfree(smp->sm_to_w); } /// Frees a fromto_T static void free_fromto(fromto_T *ftp) { - free(ftp->ft_from); - free(ftp->ft_to); + xfree(ftp->ft_from); + xfree(ftp->ft_to); } // Clear an slang_T so that the file can be reloaded. @@ -2403,18 +2403,18 @@ static void slang_clear(slang_T *lp) { garray_T *gap; - free(lp->sl_fbyts); + xfree(lp->sl_fbyts); lp->sl_fbyts = NULL; - free(lp->sl_kbyts); + xfree(lp->sl_kbyts); lp->sl_kbyts = NULL; - free(lp->sl_pbyts); + xfree(lp->sl_pbyts); lp->sl_pbyts = NULL; - free(lp->sl_fidxs); + xfree(lp->sl_fidxs); lp->sl_fidxs = NULL; - free(lp->sl_kidxs); + xfree(lp->sl_kidxs); lp->sl_kidxs = NULL; - free(lp->sl_pidxs); + xfree(lp->sl_pidxs); lp->sl_pidxs = NULL; GA_DEEP_CLEAR(&lp->sl_rep, fromto_T, free_fromto); @@ -2433,25 +2433,25 @@ static void slang_clear(slang_T *lp) vim_regfree(lp->sl_prefprog[i]); } lp->sl_prefixcnt = 0; - free(lp->sl_prefprog); + xfree(lp->sl_prefprog); lp->sl_prefprog = NULL; - free(lp->sl_info); + xfree(lp->sl_info); lp->sl_info = NULL; - free(lp->sl_midword); + xfree(lp->sl_midword); lp->sl_midword = NULL; vim_regfree(lp->sl_compprog); - free(lp->sl_comprules); - free(lp->sl_compstartflags); - free(lp->sl_compallflags); + xfree(lp->sl_comprules); + xfree(lp->sl_compstartflags); + xfree(lp->sl_compallflags); lp->sl_compprog = NULL; lp->sl_comprules = NULL; lp->sl_compstartflags = NULL; lp->sl_compallflags = NULL; - free(lp->sl_syllable); + xfree(lp->sl_syllable); lp->sl_syllable = NULL; ga_clear(&lp->sl_syl_items); @@ -2474,9 +2474,9 @@ static void slang_clear(slang_T *lp) // Clear the info from the .sug file in "lp". static void slang_clear_sug(slang_T *lp) { - free(lp->sl_sbyts); + xfree(lp->sl_sbyts); lp->sl_sbyts = NULL; - free(lp->sl_sidxs); + xfree(lp->sl_sidxs); lp->sl_sidxs = NULL; close_spellbuf(lp->sl_sugbuf); lp->sl_sugbuf = NULL; @@ -2642,7 +2642,7 @@ spell_load_file ( if (p == NULL) goto endFAIL; set_map_str(lp, p); - free(p); + xfree(p); break; case SN_WORDS: @@ -2799,7 +2799,7 @@ static int read_charflags_section(FILE *fd) // <folcharslen> <folchars> fol = read_cnt_string(fd, 2, &follen); if (follen < 0) { - free(flags); + xfree(flags); return follen; } @@ -2807,8 +2807,8 @@ static int read_charflags_section(FILE *fd) if (flags != NULL && fol != NULL) set_spell_charflags(flags, flagslen, fol); - free(flags); - free(fol); + xfree(flags); + xfree(fol); // When <charflagslen> is zero then <fcharlen> must also be zero. if ((flags == NULL) != (fol == NULL)) @@ -2878,7 +2878,7 @@ static int read_rep_section(FILE *fd, garray_T *gap, short *first) return SP_FORMERROR; ftp->ft_to = read_cnt_string(fd, 1, &c); if (c <= 0) { - free(ftp->ft_from); + xfree(ftp->ft_from); if (c < 0) return c; return SP_FORMERROR; @@ -2973,7 +2973,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) // <saltolen> <salto> smp->sm_to = read_cnt_string(fd, 1, &ccnt); if (ccnt < 0) { - free(smp->sm_lead); + xfree(smp->sm_lead); return ccnt; } @@ -3136,7 +3136,7 @@ static int read_sofo_section(FILE *fd, slang_T *slang) // <sofotolen> <sofoto> to = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { - free(from); + xfree(from); return cnt; } @@ -3148,8 +3148,8 @@ static int read_sofo_section(FILE *fd, slang_T *slang) else res = 0; - free(from); - free(to); + xfree(from); + xfree(to); return res; } @@ -3250,7 +3250,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) while (todo-- > 0) { c = getc(fd); // <compflags> if (c == EOF) { - free(pat); + xfree(pat); return SP_TRUNCERROR; } @@ -3281,7 +3281,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Copy flag to "sl_comprules", unless we run into a wildcard. if (crp != NULL) { if (c == '?' || c == '+' || c == '*') { - free(slang->sl_comprules); + xfree(slang->sl_comprules); slang->sl_comprules = NULL; crp = NULL; } else @@ -3311,7 +3311,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *crp = NUL; slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT); - free(pat); + xfree(pat); if (slang->sl_compprog == NULL) return SP_FORMERROR; @@ -3961,7 +3961,7 @@ char_u *did_set_spelllang(win_T *wp) } theend: - free(spl_copy); + xfree(spl_copy); recursive = false; redraw_win_later(wp, NOT_VALID); return ret_msg; @@ -3971,7 +3971,7 @@ theend: static void clear_midword(win_T *wp) { memset(wp->w_s->b_spell_ismw, 0, 256); - free(wp->w_s->b_spell_ismw_mb); + xfree(wp->w_s->b_spell_ismw_mb); wp->w_s->b_spell_ismw_mb = NULL; } @@ -4000,7 +4000,7 @@ static void use_midword(slang_T *lp, win_T *wp) // Append multi-byte chars to "b_spell_ismw_mb". n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); - free(wp->w_s->b_spell_ismw_mb); + xfree(wp->w_s->b_spell_ismw_mb); wp->w_s->b_spell_ismw_mb = bp; STRLCPY(bp + n, p, l + 1); } @@ -4124,7 +4124,7 @@ void spell_delete_wordlist(void) os_remove((char *)int_wordlist); int_wordlist_spl(fname); os_remove((char *)fname); - free(int_wordlist); + xfree(int_wordlist); int_wordlist = NULL; } } @@ -4147,9 +4147,9 @@ void spell_free_all(void) spell_delete_wordlist(); - free(repl_to); + xfree(repl_to); repl_to = NULL; - free(repl_from); + xfree(repl_from); repl_from = NULL; } @@ -4392,7 +4392,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) continue; // Convert from "SET" to 'encoding' when needed. - free(pc); + xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { @@ -5005,9 +5005,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) (void)set_spell_chartab(fol, low, upp); } - free(fol); - free(low); - free(upp); + xfree(fol); + xfree(low); + xfree(upp); } // Use compound specifications of the .aff file for the spell info. @@ -5070,7 +5070,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) spin->si_midword = midword; } - free(pc); + xfree(pc); fclose(fd); return aff; } @@ -5344,7 +5344,7 @@ static void spell_free_aff(afffile_T *aff) affheader_T *ah; affentry_T *ae; - free(aff->af_enc); + xfree(aff->af_enc); // All this trouble to free the "ae_prog" items... for (ht = &aff->af_pref;; ht = &aff->af_suff) { @@ -5461,7 +5461,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Skip non-ASCII words when "spin->si_ascii" is true. if (spin->si_ascii && has_non_ascii(w)) { ++non_ascii; - free(pc); + xfree(pc); continue; } @@ -5483,7 +5483,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) dw = getroom_save(spin, w); if (dw == NULL) { retval = FAIL; - free(pc); + xfree(pc); break; } @@ -5542,7 +5542,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) retval = FAIL; } - free(pc); + xfree(pc); } if (duplicate > 0) @@ -5938,7 +5938,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) rline[l] = NUL; // Convert from "/encoding={encoding}" to 'encoding' when needed. - free(pc); + xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { @@ -5974,7 +5974,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) p_enc) == FAIL) smsg((char_u *)_("Conversion in %s not supported: from %s to %s"), fname, line, p_enc); - free(enc); + xfree(enc); spin->si_conv.vc_fail = true; } continue; @@ -6054,7 +6054,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) did_word = true; } - free(pc); + xfree(pc); fclose(fd); if (spin->si_ascii && non_ascii > 0) { @@ -6123,7 +6123,7 @@ static void free_blocks(sblock_T *bl) while (bl != NULL) { next = bl->sb_next; - free(bl); + xfree(bl); bl = next; } } @@ -7167,7 +7167,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) sug_write(spin, fname); theend: - free(fname); + xfree(fname); if (free_slang) slang_free(slang); free_blocks(spin->si_blocks); @@ -7514,7 +7514,7 @@ static void close_spellbuf(buf_T *buf) { if (buf != NULL) { ml_close(buf, TRUE); - free(buf); + xfree(buf); } } @@ -7737,8 +7737,8 @@ mkspell ( } theend: - free(fname); - free(wfname); + xfree(fname); + xfree(wfname); } // Display a message for spell file processing when 'verbose' is set or using @@ -7812,7 +7812,7 @@ spell_add_word ( break; if (*spf == NUL) { EMSGN(_("E765: 'spellfile' does not have %" PRId64 " entries"), idx); - free(fnamebuf); + xfree(fnamebuf); return; } } @@ -7823,7 +7823,7 @@ spell_add_word ( buf = NULL; if (buf != NULL && bufIsChanged(buf)) { EMSG(_(e_bufloaded)); - free(fnamebuf); + xfree(fnamebuf); return; } @@ -7908,7 +7908,7 @@ spell_add_word ( redraw_all_later(SOME_VALID); } - free(fnamebuf); + xfree(fnamebuf); } // Initialize 'spellfile' for the current buffer. @@ -7977,7 +7977,7 @@ static void init_spellfile(void) aspath = false; } - free(buf); + xfree(buf); } } @@ -8464,9 +8464,9 @@ void spell_suggest(int count) smsg((char_u *)_("Sorry, only %" PRId64 " suggestions"), (int64_t)sug.su_ga.ga_len); } else { - free(repl_from); + xfree(repl_from); repl_from = NULL; - free(repl_to); + xfree(repl_to); repl_to = NULL; // When 'rightleft' is set the list is drawn right-left. @@ -8638,7 +8638,7 @@ static bool check_need_cap(linenr_T lnum, colnr_T col) } } - free(line_copy); + xfree(line_copy); return need_cap; } @@ -8696,7 +8696,7 @@ void ex_spellrepall(exarg_T *eap) p_ws = save_ws; curwin->w_cursor = pos; - free(frompat); + xfree(frompat); if (sub_nsubs == 0) EMSG2(_("E753: Not found: %s"), repl_from); @@ -8849,7 +8849,7 @@ spell_find_suggest ( } } - free(sps_copy); + xfree(sps_copy); if (do_combine) // Combine the two list of suggestions. This must be done last, @@ -9181,7 +9181,7 @@ static void tree_count_words(char_u *byts, idx_T *idxs) // Free the info put in "*su" by spell_find_suggest(). static void spell_find_cleanup(suginfo_T *su) { -# define FREE_SUG_WORD(sug) free(sug->st_word) +# define FREE_SUG_WORD(sug) xfree(sug->st_word) // Free the suggestions. GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD); @@ -10866,7 +10866,7 @@ static void score_combine(suginfo_T *su) if (j == ga.ga_len) stp[ga.ga_len++] = SUG(*gap, i); else - free(p); + xfree(p); } } } @@ -10877,7 +10877,7 @@ static void score_combine(suginfo_T *su) // Truncate the list to the number of suggestions that will be displayed. if (ga.ga_len > su->su_maxcount) { for (int i = su->su_maxcount; i < ga.ga_len; ++i) { - free(stp[i].st_word); + xfree(stp[i].st_word); } ga.ga_len = su->su_maxcount; } @@ -11004,7 +11004,7 @@ static void suggest_try_soundalike_finish(void) todo = (int)slang->sl_sounddone.ht_used; for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) { - free(HI2SFT(hi)); + xfree(HI2SFT(hi)); --todo; } @@ -11328,7 +11328,7 @@ static void set_map_str(slang_T *lp, char_u *map) // This should have been checked when generating the .spl // file. EMSG(_("E783: duplicate char in MAP entry")); - free(b); + xfree(b); } } else lp->sl_map_array[c] = headc; @@ -11511,7 +11511,7 @@ check_suggestions ( (void)spell_check(curwin, longword, &attr, NULL, false); if (attr != HLF_COUNT) { // Remove this entry. - free(stp[i].st_word); + xfree(stp[i].st_word); --gap->ga_len; if (i < gap->ga_len) memmove(stp + i, stp + i + 1, @@ -11608,7 +11608,7 @@ cleanup_suggestions ( // Truncate the list to the number of suggestions that will be displayed. if (gap->ga_len > keep) { for (int i = keep; i < gap->ga_len; ++i) { - free(stp[i].st_word); + xfree(stp[i].st_word); } gap->ga_len = keep; return stp[keep - 1].st_score; @@ -12548,7 +12548,7 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) } i = CNT(badlen - 1, goodlen - 1); - free(cnt); + xfree(cnt); return i; } @@ -12906,7 +12906,7 @@ void ex_spelldump(exarg_T *eap) // enable spelling locally in the new window set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL); - free(spl); + xfree(spl); if (!bufempty() || !buf_valid(curbuf)) return; diff --git a/src/nvim/strings.c b/src/nvim/strings.c index dd10184d38..4e70f48860 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -269,7 +269,7 @@ char_u *strup_save(const char_u *orig) memcpy(s, res, (size_t)(p - res)); STRCPY(s + (p - res) + newl, p + l); p = s + (p - res); - free(res); + xfree(res); res = s; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 20bfbc8db4..8c32e5f06a 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -959,7 +959,7 @@ static void syn_stack_free_block(synblock_T *block) if (block->b_sst_array != NULL) { for (p = block->b_sst_first; p != NULL; p = p->sst_next) clear_syn_state(p); - free(block->b_sst_array); + xfree(block->b_sst_array); block->b_sst_array = NULL; block->b_sst_len = 0; } @@ -1044,7 +1044,7 @@ static void syn_stack_alloc(void) to->sst_next = to + 1; (sstp + len - 1)->sst_next = NULL; - free(syn_block->b_sst_array); + xfree(syn_block->b_sst_array); syn_block->b_sst_array = sstp; syn_block->b_sst_len = len; } @@ -3054,7 +3054,7 @@ void syntax_clear(synblock_T *block) vim_regfree(block->b_syn_linecont_prog); block->b_syn_linecont_prog = NULL; - free(block->b_syn_linecont_pat); + xfree(block->b_syn_linecont_pat); block->b_syn_linecont_pat = NULL; block->b_syn_folditems = 0; @@ -3073,7 +3073,7 @@ void reset_synblock(win_T *wp) { if (wp->w_s != &wp->w_buffer->b_s) { syntax_clear(wp->w_s); - free(wp->w_s); + xfree(wp->w_s); wp->w_s = &wp->w_buffer->b_s; } } @@ -3097,7 +3097,7 @@ static void syntax_sync_clear(void) vim_regfree(curwin->w_s->b_syn_linecont_prog); curwin->w_s->b_syn_linecont_prog = NULL; - free(curwin->w_s->b_syn_linecont_pat); + xfree(curwin->w_s->b_syn_linecont_pat); curwin->w_s->b_syn_linecont_pat = NULL; syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ @@ -3125,13 +3125,13 @@ static void syn_remove_pattern(synblock_T *block, int idx) */ static void syn_clear_pattern(synblock_T *block, int i) { - free(SYN_ITEMS(block)[i].sp_pattern); + xfree(SYN_ITEMS(block)[i].sp_pattern); vim_regfree(SYN_ITEMS(block)[i].sp_prog); /* Only free sp_cont_list and sp_next_list of first start pattern */ if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) { - free(SYN_ITEMS(block)[i].sp_cont_list); - free(SYN_ITEMS(block)[i].sp_next_list); - free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); + xfree(SYN_ITEMS(block)[i].sp_cont_list); + xfree(SYN_ITEMS(block)[i].sp_next_list); + xfree(SYN_ITEMS(block)[i].sp_syn.cont_in_list); } } @@ -3140,9 +3140,9 @@ static void syn_clear_pattern(synblock_T *block, int i) */ static void syn_clear_cluster(synblock_T *block, int i) { - free(SYN_CLSTR(block)[i].scl_name); - free(SYN_CLSTR(block)[i].scl_name_u); - free(SYN_CLSTR(block)[i].scl_list); + xfree(SYN_CLSTR(block)[i].scl_name); + xfree(SYN_CLSTR(block)[i].scl_name_u); + xfree(SYN_CLSTR(block)[i].scl_list); } /* @@ -3198,7 +3198,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) */ short scl_id = id - SYNID_CLUSTER; - free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); + xfree(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; } } else { @@ -3760,9 +3760,9 @@ static void syn_clear_keyword(int id, hashtab_T *ht) hi->hi_key = KE2HIKEY(kp_next); } else kp_prev->ke_next = kp_next; - free(kp->next_list); - free(kp->k_syn.cont_in_list); - free(kp); + xfree(kp->next_list); + xfree(kp->k_syn.cont_in_list); + xfree(kp); kp = kp_next; } else { kp_prev = kp; @@ -3789,9 +3789,9 @@ static void clear_keywtab(hashtab_T *ht) --todo; for (kp = HI2KE(hi); kp != NULL; kp = kp_next) { kp_next = kp->ke_next; - free(kp->next_list); - free(kp->k_syn.cont_in_list); - free(kp); + xfree(kp->next_list); + xfree(kp->k_syn.cont_in_list); + xfree(kp); } } } @@ -4011,12 +4011,12 @@ get_syn_options ( } if (i < 0) { EMSG2(_("E394: Didn't find region item for %s"), gname); - free(gname); + xfree(gname); return NULL; } } - free(gname); + xfree(gname); arg = skipwhite(arg); } else if (flagtab[fidx].flags == HL_FOLD && foldmethodIsSyntax(curwin)) @@ -4208,9 +4208,9 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) } } - free(keyword_copy); - free(syn_opt_arg.cont_in_list); - free(syn_opt_arg.next_list); + xfree(keyword_copy); + xfree(syn_opt_arg.cont_in_list); + xfree(syn_opt_arg.next_list); } if (rest != NULL) @@ -4311,10 +4311,10 @@ syn_cmd_match ( * Something failed, free the allocated memory. */ vim_regfree(item.sp_prog); - free(item.sp_pattern); - free(syn_opt_arg.cont_list); - free(syn_opt_arg.cont_in_list); - free(syn_opt_arg.next_list); + xfree(item.sp_pattern); + xfree(syn_opt_arg.cont_list); + xfree(syn_opt_arg.cont_in_list); + xfree(syn_opt_arg.next_list); if (rest == NULL) EMSG2(_(e_invarg2), arg); @@ -4388,7 +4388,7 @@ syn_cmd_region ( key_end = rest; while (*key_end && !vim_iswhite(*key_end) && *key_end != '=') ++key_end; - free(key); + xfree(key); key = vim_strnsave_up(rest, (int)(key_end - rest)); if (STRCMP(key, "MATCHGROUP") == 0) item = ITEM_MATCHGROUP; @@ -4456,7 +4456,7 @@ syn_cmd_region ( ++pat_count; } } - free(key); + xfree(key); if (illegal || not_enough) rest = NULL; @@ -4530,17 +4530,17 @@ syn_cmd_region ( for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) { if (!success) { vim_regfree(ppp->pp_synp->sp_prog); - free(ppp->pp_synp->sp_pattern); + xfree(ppp->pp_synp->sp_pattern); } - free(ppp->pp_synp); + xfree(ppp->pp_synp); ppp_next = ppp->pp_next; - free(ppp); + xfree(ppp); } if (!success) { - free(syn_opt_arg.cont_list); - free(syn_opt_arg.cont_in_list); - free(syn_opt_arg.next_list); + xfree(syn_opt_arg.cont_list); + xfree(syn_opt_arg.cont_in_list); + xfree(syn_opt_arg.next_list); if (not_enough) EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); else if (illegal || rest == NULL) @@ -4580,11 +4580,11 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op) return; if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) { if (list_op == CLUSTER_REPLACE) - free(*clstr1); + xfree(*clstr1); if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) *clstr1 = *clstr2; else - free(*clstr2); + xfree(*clstr2); return; } @@ -4668,8 +4668,8 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op) /* * Finally, put the new list in place. */ - free(*clstr1); - free(*clstr2); + xfree(*clstr1); + xfree(*clstr2); *clstr1 = clstr; } @@ -4688,7 +4688,7 @@ static int syn_scl_name2id(char_u *name) break; } } - free(name_u); + xfree(name_u); return i < 0 ? 0 : i + SYNID_CLUSTER; } @@ -4699,7 +4699,7 @@ static int syn_scl_namen2id(char_u *linep, int len) { char_u *name = vim_strnsave(linep, len); int id = syn_scl_name2id(name); - free(name); + xfree(name); return id; } @@ -4721,7 +4721,7 @@ static int syn_check_cluster(char_u *pp, int len) if (id == 0) /* doesn't exist yet */ id = syn_add_cluster(name); else - free(name); + xfree(name); return id; } @@ -4743,7 +4743,7 @@ static int syn_add_cluster(char_u *name) int len = curwin->w_s->b_syn_clusters.ga_len; if (len >= MAX_CLUSTER_ID) { EMSG((char_u *)_("E848: Too many syntax clusters")); - free(name); + xfree(name); return 0; } @@ -4945,7 +4945,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) while (!ends_excmd(*arg_start)) { arg_end = skiptowhite(arg_start); next_arg = skipwhite(arg_end); - free(key); + xfree(key); key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); if (STRCMP(key, "CCOMMENT") == 0) { if (!eap->skip) @@ -5013,7 +5013,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) syn_clear_time(&curwin->w_s->b_syn_linecont_time); if (curwin->w_s->b_syn_linecont_prog == NULL) { - free(curwin->w_s->b_syn_linecont_pat); + xfree(curwin->w_s->b_syn_linecont_pat); curwin->w_s->b_syn_linecont_pat = NULL; finished = TRUE; break; @@ -5035,7 +5035,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } arg_start = next_arg; } - free(key); + xfree(key); if (illegal) EMSG2(_("E404: Illegal arguments: %s"), arg_start); else if (!finished) { @@ -5109,13 +5109,13 @@ get_id_list ( if (TOUPPER_ASC(**arg) != 'C') { EMSG2(_("E407: %s not allowed here"), name + 1); failed = TRUE; - free(name); + xfree(name); break; } if (count != 0) { EMSG2(_("E408: %s must be first in contains list"), name + 1); failed = TRUE; - free(name); + xfree(name); break; } if (name[1] == 'A') @@ -5142,7 +5142,7 @@ get_id_list ( regmatch.regprog = vim_regcomp(name, RE_MAGIC); if (regmatch.regprog == NULL) { failed = TRUE; - free(name); + xfree(name); break; } @@ -5156,7 +5156,7 @@ get_id_list ( * "contains=a.*b,axb". * Go back to first round */ if (count >= total_count) { - free(retval); + xfree(retval); round = 1; } else retval[count] = i + 1; @@ -5168,7 +5168,7 @@ get_id_list ( vim_regfree(regmatch.regprog); } } - free(name); + xfree(name); if (id == 0) { EMSG2(_("E409: Unknown group name: %s"), p); failed = TRUE; @@ -5178,7 +5178,7 @@ get_id_list ( if (round == 2) { /* Got more items than expected, go back to first round */ if (count >= total_count) { - free(retval); + xfree(retval); round = 1; } else retval[count] = id; @@ -5201,14 +5201,14 @@ get_id_list ( *arg = p; if (failed || retval == NULL) { - free(retval); + xfree(retval); return FAIL; } if (*list == NULL) *list = retval; else - free(retval); /* list already found, don't overwrite it */ + xfree(retval); /* list already found, don't overwrite it */ return OK; } @@ -5387,7 +5387,7 @@ void ex_syntax(exarg_T *eap) break; } } - free(subcmd_name); + xfree(subcmd_name); if (eap->skip) --emsg_skip; } @@ -5427,7 +5427,7 @@ void ex_ownsyntax(exarg_T *eap) do_unlet((char_u *)"b:current_syntax", TRUE); else { set_internal_string_var((char_u *)"b:current_syntax", old_value); - free(old_value); + xfree(old_value); } } @@ -5751,183 +5751,94 @@ static void syntime_report(void) * Highlighting stuff * **************************************/ -/* - * The default highlight groups. These are compiled-in for fast startup and - * they still work when the runtime files can't be found. - * When making changes here, also change runtime/colors/default.vim! - * The #ifdefs are needed to reduce the amount of static data. Helps to make - * the 16 bit DOS (museum) version compile. - */ -# define CENT(a, b) b -static char *(highlight_init_both[]) = -{ - CENT( - "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", - "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), - CENT("IncSearch term=reverse cterm=reverse", - "IncSearch term=reverse cterm=reverse gui=reverse"), - CENT("ModeMsg term=bold cterm=bold", - "ModeMsg term=bold cterm=bold gui=bold"), - CENT("NonText term=bold ctermfg=Blue", - "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), - CENT("StatusLine term=reverse,bold cterm=reverse,bold", - "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), - CENT("StatusLineNC term=reverse cterm=reverse", - "StatusLineNC term=reverse cterm=reverse gui=reverse"), +// The default highlight groups. These are compiled-in for fast startup and +// they still work when the runtime files can't be found. +// +// When making changes here, also change runtime/colors/default.vim! + +static char *highlight_init_both[] = +{ + "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey", + "DiffText cterm=bold ctermbg=Red gui=bold guibg=Red", + "ErrorMsg ctermbg=DarkRed ctermfg=White guibg=Red guifg=White", + "IncSearch cterm=reverse gui=reverse", + "ModeMsg cterm=bold gui=bold", + "NonText ctermfg=Blue gui=bold guifg=Blue", + "PmenuSbar ctermbg=Grey guibg=Grey", + "StatusLine cterm=reverse,bold gui=reverse,bold", + "StatusLineNC cterm=reverse gui=reverse", + "TabLineFill cterm=reverse gui=reverse", + "TabLineSel cterm=bold gui=bold", + "TermCursor cterm=reverse gui=reverse", + "VertSplit cterm=reverse gui=reverse", + "WildMenu ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black", "default link EndOfBuffer NonText", - CENT("VertSplit term=reverse cterm=reverse", - "VertSplit term=reverse cterm=reverse gui=reverse"), - CENT("DiffText term=reverse cterm=bold ctermbg=Red", - "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), - CENT("PmenuSbar ctermbg=Grey", - "PmenuSbar ctermbg=Grey guibg=Grey"), - CENT("TabLineSel term=bold cterm=bold", - "TabLineSel term=bold cterm=bold gui=bold"), - CENT("TabLineFill term=reverse cterm=reverse", - "TabLineFill term=reverse cterm=reverse gui=reverse"), NULL }; -static char *(highlight_init_light[]) = -{ - CENT("Directory term=bold ctermfg=DarkBlue", - "Directory term=bold ctermfg=DarkBlue guifg=Blue"), - CENT("LineNr term=underline ctermfg=Brown", - "LineNr term=underline ctermfg=Brown guifg=Brown"), - CENT("CursorLineNr term=bold ctermfg=Brown", - "CursorLineNr term=bold ctermfg=Brown gui=bold guifg=Brown"), - CENT("MoreMsg term=bold ctermfg=DarkGreen", - "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), - CENT("Question term=standout ctermfg=DarkGreen", - "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), - CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", - "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), - CENT("SpellBad term=reverse ctermbg=LightRed", - "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), - CENT("SpellCap term=reverse ctermbg=LightBlue", - "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), - CENT("SpellRare term=reverse ctermbg=LightMagenta", - "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), - CENT("SpellLocal term=underline ctermbg=Cyan", - "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), - CENT("PmenuThumb ctermbg=Black", - "PmenuThumb ctermbg=Black guibg=Black"), - CENT("Pmenu ctermbg=LightMagenta ctermfg=Black", - "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta"), - CENT("PmenuSel ctermbg=LightGrey ctermfg=Black", - "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey"), - CENT("SpecialKey term=bold ctermfg=DarkBlue", - "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), - CENT("Title term=bold ctermfg=DarkMagenta", - "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), - CENT("WarningMsg term=standout ctermfg=DarkRed", - "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), - CENT( - "WildMenu term=standout ctermbg=Yellow ctermfg=Black", - "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), - CENT( - "Folded term=standout ctermbg=Grey ctermfg=DarkBlue", - "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), - CENT( - "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", - "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), - CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", - "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), - CENT("Visual term=reverse", - "Visual term=reverse guibg=LightGrey"), - CENT("DiffAdd term=bold ctermbg=LightBlue", - "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), - CENT("DiffChange term=bold ctermbg=LightMagenta", - "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), - CENT( - "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", - "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), - CENT( - "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", - "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), - CENT("CursorColumn term=reverse ctermbg=LightGrey", - "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), - CENT("CursorLine term=underline cterm=underline", - "CursorLine term=underline cterm=underline guibg=Grey90"), - CENT("ColorColumn term=reverse ctermbg=LightRed", - "ColorColumn term=reverse ctermbg=LightRed guibg=LightRed"), - CENT( - "Conceal ctermbg=DarkGrey ctermfg=LightGrey", - "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), - CENT("MatchParen term=reverse ctermbg=Cyan", - "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), +static char *highlight_init_light[] = +{ + "ColorColumn ctermbg=LightRed guibg=LightRed", + "CursorColumn ctermbg=LightGrey guibg=Grey90", + "CursorLine cterm=underline guibg=Grey90", + "CursorLineNr ctermfg=Brown gui=bold guifg=Brown", + "DiffAdd ctermbg=LightBlue guibg=LightBlue", + "DiffChange ctermbg=LightMagenta guibg=LightMagenta", + "DiffDelete ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan", + "Directory ctermfg=DarkBlue guifg=Blue", + "FoldColumn ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue", + "Folded ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue", + "LineNr ctermfg=Brown guifg=Brown", + "MatchParen ctermbg=Cyan guibg=Cyan", + "MoreMsg ctermfg=DarkGreen gui=bold guifg=SeaGreen", + "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta", + "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey", + "PmenuThumb ctermbg=Black guibg=Black", + "Question ctermfg=DarkGreen gui=bold guifg=SeaGreen", + "Search ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE", + "SignColumn ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue", + "SpecialKey ctermfg=DarkBlue guifg=Blue", + "SpellBad ctermbg=LightRed guisp=Red gui=undercurl", + "SpellCap ctermbg=LightBlue guisp=Blue gui=undercurl", + "SpellLocal ctermbg=Cyan guisp=DarkCyan gui=undercurl", + "SpellRare ctermbg=LightMagenta guisp=Magenta gui=undercurl", + "TabLine cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey", + "Title ctermfg=DarkMagenta gui=bold guifg=Magenta", + "Visual guibg=LightGrey", + "WarningMsg ctermfg=DarkRed guifg=Red", NULL }; -static char *(highlight_init_dark[]) = -{ - CENT("Directory term=bold ctermfg=LightCyan", - "Directory term=bold ctermfg=LightCyan guifg=Cyan"), - CENT("LineNr term=underline ctermfg=Yellow", - "LineNr term=underline ctermfg=Yellow guifg=Yellow"), - CENT("CursorLineNr term=bold ctermfg=Yellow", - "CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow"), - CENT("MoreMsg term=bold ctermfg=LightGreen", - "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), - CENT("Question term=standout ctermfg=LightGreen", - "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), - CENT( - "Search term=reverse ctermbg=Yellow ctermfg=Black", - "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), - CENT("SpecialKey term=bold ctermfg=LightBlue", - "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), - CENT("SpellBad term=reverse ctermbg=Red", - "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), - CENT("SpellCap term=reverse ctermbg=Blue", - "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), - CENT("SpellRare term=reverse ctermbg=Magenta", - "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), - CENT("SpellLocal term=underline ctermbg=Cyan", - "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), - CENT("PmenuThumb ctermbg=White", - "PmenuThumb ctermbg=White guibg=White"), - CENT("Pmenu ctermbg=Magenta ctermfg=Black", - "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta"), - CENT("PmenuSel ctermbg=Black ctermfg=DarkGrey", - "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey"), - CENT("Title term=bold ctermfg=LightMagenta", - "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), - CENT("WarningMsg term=standout ctermfg=LightRed", - "WarningMsg term=standout ctermfg=LightRed guifg=Red"), - CENT( - "WildMenu term=standout ctermbg=Yellow ctermfg=Black", - "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), - CENT( - "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", - "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), - CENT( - "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", - "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), - CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", - "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), - CENT("Visual term=reverse", - "Visual term=reverse guibg=DarkGrey"), - CENT("DiffAdd term=bold ctermbg=DarkBlue", - "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), - CENT("DiffChange term=bold ctermbg=DarkMagenta", - "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), - CENT( - "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", - "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), - CENT( - "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", - "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), - CENT("CursorColumn term=reverse ctermbg=DarkGrey", - "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), - CENT("CursorLine term=underline cterm=underline", - "CursorLine term=underline cterm=underline guibg=Grey40"), - CENT("ColorColumn term=reverse ctermbg=DarkRed", - "ColorColumn term=reverse ctermbg=DarkRed guibg=DarkRed"), - CENT("MatchParen term=reverse ctermbg=DarkCyan", - "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), - CENT( - "Conceal ctermbg=DarkGrey ctermfg=LightGrey", - "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), +static char *highlight_init_dark[] = +{ + "ColorColumn ctermbg=DarkRed guibg=DarkRed", + "CursorColumn ctermbg=DarkGrey guibg=Grey40", + "CursorLine cterm=underline guibg=Grey40", + "CursorLineNr ctermfg=Yellow gui=bold guifg=Yellow", + "DiffAdd ctermbg=DarkBlue guibg=DarkBlue", + "DiffChange ctermbg=DarkMagenta guibg=DarkMagenta", + "DiffDelete ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan", + "Directory ctermfg=LightCyan guifg=Cyan", + "FoldColumn ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan", + "Folded ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan", + "LineNr ctermfg=Yellow guifg=Yellow", + "MatchParen ctermbg=DarkCyan guibg=DarkCyan", + "MoreMsg ctermfg=LightGreen gui=bold guifg=SeaGreen", + "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta", + "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey", + "PmenuThumb ctermbg=White guibg=White", + "Question ctermfg=LightGreen gui=bold guifg=Green", + "Search ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black", + "SignColumn ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan", + "SpecialKey ctermfg=LightBlue guifg=Cyan", + "SpellBad ctermbg=Red guisp=Red gui=undercurl", + "SpellCap ctermbg=Blue guisp=Blue gui=undercurl", + "SpellLocal ctermbg=Cyan guisp=Cyan gui=undercurl", + "SpellRare ctermbg=Magenta guisp=Magenta gui=undercurl", + "TabLine cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey", + "Title ctermfg=LightMagenta gui=bold guifg=Magenta", + "Visual guibg=DarkGrey", + "WarningMsg ctermfg=LightRed guifg=Red", NULL }; @@ -5951,7 +5862,7 @@ init_highlight ( // p invalid, so copy it. char_u *copy_p = vim_strsave(p); bool okay = load_colors(copy_p); - free(copy_p); + xfree(copy_p); if (okay) { return; } @@ -6032,7 +5943,7 @@ int load_colors(char_u *name) buf = xmalloc(STRLEN(name) + 12); sprintf((char *)buf, "colors/%s.vim", name); retval = source_runtime(buf, FALSE); - free(buf); + xfree(buf); apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); recursive = FALSE; @@ -6234,7 +6145,7 @@ do_highlight ( */ while (*linep && !vim_iswhite(*linep) && *linep != '=') ++linep; - free(key); + xfree(key); key = vim_strnsave_up(key_start, (int)(linep - key_start)); linep = skipwhite(linep); @@ -6278,7 +6189,7 @@ do_highlight ( error = TRUE; break; } - free(arg); + xfree(arg); arg = vim_strnsave(arg_start, (int)(linep - arg_start)); if (*linep == '\'') @@ -6483,7 +6394,7 @@ do_highlight ( if (!init) HL_TABLE()[idx].sg_set |= SG_GUI; - free(HL_TABLE()[idx].sg_rgb_fg_name); + xfree(HL_TABLE()[idx].sg_rgb_fg_name); if (STRCMP(arg, "NONE")) { HL_TABLE()[idx].sg_rgb_fg_name = (uint8_t *)xstrdup((char *)arg); HL_TABLE()[idx].sg_rgb_fg = name_to_color(arg); @@ -6501,7 +6412,7 @@ do_highlight ( if (!init) HL_TABLE()[idx].sg_set |= SG_GUI; - free(HL_TABLE()[idx].sg_rgb_bg_name); + xfree(HL_TABLE()[idx].sg_rgb_bg_name); if (STRCMP(arg, "NONE") != 0) { HL_TABLE()[idx].sg_rgb_bg_name = (uint8_t *)xstrdup((char *)arg); HL_TABLE()[idx].sg_rgb_bg = name_to_color(arg); @@ -6551,8 +6462,8 @@ do_highlight ( HL_TABLE()[idx].sg_scriptID = current_SID; redraw_all_later(NOT_VALID); } - free(key); - free(arg); + xfree(key); + xfree(arg); /* Only call highlight_changed() once, after sourcing a syntax file */ need_highlight_changed = TRUE; @@ -6563,8 +6474,8 @@ void free_highlight(void) { for (int i = 0; i < highlight_ga.ga_len; ++i) { highlight_clear(i); - free(HL_TABLE()[i].sg_name); - free(HL_TABLE()[i].sg_name_u); + xfree(HL_TABLE()[i].sg_name); + xfree(HL_TABLE()[i].sg_name_u); } ga_clear(&highlight_ga); } @@ -6611,9 +6522,9 @@ static void highlight_clear(int idx) HL_TABLE()[idx].sg_gui = 0; HL_TABLE()[idx].sg_rgb_fg = -1; HL_TABLE()[idx].sg_rgb_bg = -1; - free(HL_TABLE()[idx].sg_rgb_fg_name); + xfree(HL_TABLE()[idx].sg_rgb_fg_name); HL_TABLE()[idx].sg_rgb_fg_name = NULL; - free(HL_TABLE()[idx].sg_rgb_bg_name); + xfree(HL_TABLE()[idx].sg_rgb_bg_name); HL_TABLE()[idx].sg_rgb_bg_name = NULL; /* Clear the script ID only when there is no link, since that is not * cleared. */ @@ -7048,7 +6959,7 @@ int syn_namen2id(char_u *linep, int len) { char_u *name = vim_strnsave(linep, len); int id = syn_name2id(name); - free(name); + xfree(name); return id; } @@ -7070,7 +6981,7 @@ int syn_check_group(char_u *pp, int len) if (id == 0) /* doesn't exist yet */ id = syn_add_group(name); else - free(name); + xfree(name); return id; } @@ -7087,7 +6998,7 @@ static int syn_add_group(char_u *name) for (p = name; *p != NUL; ++p) { if (!vim_isprintc(*p)) { EMSG(_("E669: Unprintable character in group name")); - free(name); + xfree(name); return 0; } else if (!ASCII_ISALNUM(*p) && *p != '_') { /* This is an error, but since there previously was no check only @@ -7108,7 +7019,7 @@ static int syn_add_group(char_u *name) if (highlight_ga.ga_len >= MAX_HL_ID) { EMSG(_("E849: Too many highlight and syntax groups")); - free(name); + xfree(name); return 0; } @@ -7128,8 +7039,8 @@ static int syn_add_group(char_u *name) static void syn_unadd_group(void) { --highlight_ga.ga_len; - free(HL_TABLE()[highlight_ga.ga_len].sg_name); - free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); + xfree(HL_TABLE()[highlight_ga.ga_len].sg_name); + xfree(HL_TABLE()[highlight_ga.ga_len].sg_name_u); } /* diff --git a/src/nvim/tag.c b/src/nvim/tag.c index d84f5f0208..b9abf3552c 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -246,7 +246,7 @@ do_tag ( cur_match = ptag_entry.cur_match; cur_fnum = ptag_entry.cur_fnum; } else { - free(ptag_entry.tagname); + xfree(ptag_entry.tagname); ptag_entry.tagname = vim_strsave(tag); } } else { @@ -255,12 +255,12 @@ do_tag ( * stack entries above it. */ while (tagstackidx < tagstacklen) - free(tagstack[--tagstacklen].tagname); + xfree(tagstack[--tagstacklen].tagname); /* if the tagstack is full: remove oldest entry */ if (++tagstacklen > TAGSTACKSIZE) { tagstacklen = TAGSTACKSIZE; - free(tagstack[0].tagname); + xfree(tagstack[0].tagname); for (i = 1; i < tagstacklen; ++i) tagstack[i - 1] = tagstack[i]; --tagstackidx; @@ -450,7 +450,7 @@ do_tag ( || (cur_match >= num_matches && max_num_matches != MAXCOL) || other_name) { if (other_name) { - free(tagmatchname); + xfree(tagmatchname); tagmatchname = vim_strsave(name); } @@ -569,7 +569,7 @@ do_tag ( * it and put "..." in the middle */ p = tag_full_fname(&tagp); msg_puts_long_attr(p, hl_attr(HLF_D)); - free(p); + xfree(p); if (msg_col > 0) msg_putchar('\n'); @@ -709,7 +709,7 @@ do_tag ( /* Save the tag file name */ p = tag_full_fname(&tagp); STRLCPY(fname, p, MAXPATHL + 1); - free(p); + xfree(p); /* * Get the line number or the search pattern used to locate @@ -804,8 +804,8 @@ do_tag ( set_errorlist(curwin, list, ' ', IObuff); list_free(list, TRUE); - free(fname); - free(cmd); + xfree(fname); + xfree(cmd); cur_match = 0; /* Jump to the first tag */ } @@ -941,7 +941,7 @@ end_do_tag: */ void tag_freematch(void) { - free(tagmatchname); + xfree(tagmatchname); tagmatchname = NULL; } @@ -983,7 +983,7 @@ void do_tags(exarg_T *eap) msg_outtrans(IObuff); msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum ? hl_attr(HLF_D) : 0); - free(name); + xfree(name); } ui_flush(); /* show one line at a time */ } @@ -1411,12 +1411,12 @@ line_read_in: /* Copy or swap lbuf and conv_line. */ len = (int)STRLEN(conv_line) + 1; if (len > lbuf_size) { - free(lbuf); + xfree(lbuf); lbuf = conv_line; lbuf_size = len; } else { STRCPY(lbuf, conv_line); - free(conv_line); + xfree(conv_line); } } } @@ -1873,7 +1873,7 @@ parse_line: [ga_match[mtt].ga_len++] = mfp; ++match_count; } else - free(mfp); + xfree(mfp); } } } @@ -1932,9 +1932,9 @@ parse_line: } findtag_end: - free(lbuf); + xfree(lbuf); vim_regfree(orgpat.regmatch.regprog); - free(tag_fname); + xfree(tag_fname); /* * Move the matches from the ga_match[] arrays into one list of @@ -1952,7 +1952,7 @@ findtag_end: for (int i = 0; i < ga_match[mtt].ga_len; ++i) { mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i]; if (matches == NULL) - free(mfp); + xfree(mfp); else { /* To avoid allocating memory again we turn the struct * match_found into a string. For help the priority was not @@ -1969,7 +1969,7 @@ findtag_end: *num_matches = match_count; curbuf->b_help = help_save; - free(saved_pat); + xfree(saved_pat); return retval; } @@ -1993,7 +1993,7 @@ void free_tag_stuff(void) tag_freematch(); if (ptag_entry.tagname) { - free(ptag_entry.tagname); + xfree(ptag_entry.tagname); ptag_entry.tagname = NULL; } } @@ -2102,7 +2102,7 @@ get_tagfname ( } STRCPY(buf, fname); - free(fname); + xfree(fname); return OK; } @@ -2111,7 +2111,7 @@ get_tagfname ( */ void tagname_free(tagname_T *tnp) { - free(tnp->tn_tags); + xfree(tnp->tn_tags); vim_findfile_cleanup(tnp->tn_search_ctx); tnp->tn_search_ctx = NULL; ga_clear_strings(&tag_fnames); @@ -2362,7 +2362,7 @@ jumpto_tag ( && !has_autocmd(EVENT_BUFREADCMD, fname, NULL) ) { retval = NOTAGFILE; - free(nofile_fname); + xfree(nofile_fname); nofile_fname = vim_strsave(fname); goto erret; } @@ -2565,9 +2565,9 @@ erret: g_do_tagpreview = 0; /* For next time */ if (tagp.fname_end != NULL) *tagp.fname_end = csave; - free(pbuf); - free(tofree_fname); - free(full_fname); + xfree(pbuf); + xfree(tofree_fname); + xfree(full_fname); return retval; } @@ -2611,7 +2611,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) } else retval = vim_strsave(fname); - free(expanded_fname); + xfree(expanded_fname); return retval; } @@ -2635,7 +2635,7 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname, } fullname = expand_tag_fname(fname, tag_fname, TRUE); retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles); - free(fullname); + xfree(fullname); *fname_end = c; } @@ -2761,7 +2761,7 @@ add_tag_field ( } buf[len] = NUL; retval = dict_add_nr_str(dict, field_name, 0L, buf); - free(buf); + xfree(buf); return retval; } @@ -2808,7 +2808,7 @@ int get_tags(list_T *list, char_u *pat) || dict_add_nr_str(dict, "static", is_static, NULL) == FAIL) ret = FAIL; - free(full_fname); + xfree(full_fname); if (tp.command_end != NULL) { for (p = tp.command_end + 3; @@ -2848,9 +2848,9 @@ int get_tags(list_T *list, char_u *pat) } } - free(matches[i]); + xfree(matches[i]); } - free(matches); + xfree(matches); } return ret; } diff --git a/src/nvim/tempfile.c b/src/nvim/tempfile.c index 0750be0ab9..1b51b226db 100644 --- a/src/nvim/tempfile.c +++ b/src/nvim/tempfile.c @@ -77,7 +77,7 @@ void vim_deltempdir(void) path_tail(NameBuff)[-1] = NUL; os_rmdir((char *)NameBuff); - free(vim_tempdir); + xfree(vim_tempdir); vim_tempdir = NULL; } } @@ -109,7 +109,7 @@ static bool vim_settempdir(char_u *tempdir) vim_FullName(tempdir, buf, MAXPATHL, false); add_pathsep(buf); vim_tempdir = vim_strsave(buf); - free(buf); + xfree(buf); return true; } diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index daba7b943f..8ee47b2642 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -130,8 +130,6 @@ struct terminal { // the default values are used to obtain the color numbers passed to cterm // colors RgbValue colors[256]; - // attributes for focused/unfocused cursor cells - int focused_cursor_attr_id, unfocused_cursor_attr_id; }; static VTermScreenCallbacks vterm_screen_callbacks = { @@ -245,7 +243,7 @@ Terminal *terminal_open(TerminalOptions opts) char *name = get_config_string(rv, var); if (name) { color_val = name_to_color((uint8_t *)name); - free(name); + xfree(name); if (color_val != -1) { rv->colors[i] = color_val; @@ -260,41 +258,6 @@ Terminal *terminal_open(TerminalOptions opts) } } - // Configure cursor highlighting when focused/unfocused - char *group = get_config_string(rv, "terminal_focused_cursor_highlight"); - if (group) { - int group_id = syn_name2id((uint8_t *)group); - free(group); - - if (group_id) { - rv->focused_cursor_attr_id = syn_id2attr(group_id); - } - } - if (!rv->focused_cursor_attr_id) { - rv->focused_cursor_attr_id = get_attr_entry(&(attrentry_T) { - .rgb_ae_attr = HL_INVERSE, .rgb_fg_color = -1, .rgb_bg_color = -1, - .cterm_ae_attr = HL_INVERSE, .cterm_fg_color = 0, .cterm_bg_color = 0 - }); - } - - group = get_config_string(rv, "terminal_unfocused_cursor_highlight"); - if (group) { - int group_id = syn_name2id((uint8_t *)group); - free(group); - - if (group_id) { - rv->unfocused_cursor_attr_id = syn_id2attr(group_id); - } - } - if (!rv->unfocused_cursor_attr_id) { - int yellow_rgb = RGB(0xfc, 0xe9, 0x4f); - int yellow_term = 12; - rv->unfocused_cursor_attr_id = get_attr_entry(&(attrentry_T) { - .rgb_ae_attr = 0, .rgb_fg_color = -1, .rgb_bg_color = yellow_rgb, - .cterm_ae_attr = 0, .cterm_fg_color = 0, .cterm_bg_color = yellow_term, - }); - } - return rv; } @@ -307,9 +270,12 @@ void terminal_close(Terminal *term, char *msg) term->forward_mouse = false; term->closed = true; if (!msg || exiting) { - // If no msg was given, this was called by close_buffer(buffer.c) so we - // should not wait for the user to press a key. Also cannot wait if - // `exiting == true` + // If no msg was given, this was called by close_buffer(buffer.c). Or if + // exiting, we must inform the buffer the terminal no longer exists so that + // close_buffer() doesn't call this again. + term->buf->terminal = NULL; + term->buf = NULL; + // We should not wait for the user to press a key. term->opts.close_cb(term->opts.data); } else { terminal_receive(term, msg, strlen(msg)); @@ -338,7 +304,7 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) // terminal in the current tab. FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (!wp->w_closing && wp->w_buffer == term->buf) { - width = (uint16_t)MIN(width, (uint16_t)wp->w_width); + width = (uint16_t)MIN(width, (uint16_t)(wp->w_width - win_col_off(wp))); height = (uint16_t)MIN(height, (uint16_t)wp->w_height); } } @@ -353,8 +319,14 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) invalidate_terminal(term, -1, -1); } -void terminal_enter(Terminal *term, bool process_deferred) +void terminal_enter(bool process_deferred) { + Terminal *term = curbuf->terminal; + assert(term && "should only be called when curbuf has a terminal"); + + // Ensure the terminal is properly sized. + terminal_resize(term, 0, 0); + checkpcmark(); setpcmark(); int save_state = State; @@ -373,7 +345,9 @@ void terminal_enter(Terminal *term, bool process_deferred) int c; bool close = false; - for (;;) { + bool got_bs = false; // True if the last input was <C-\> + + while (term->buf == curbuf) { if (process_deferred) { event_enable_deferred(); } @@ -385,14 +359,6 @@ void terminal_enter(Terminal *term, bool process_deferred) } switch (c) { - case Ctrl_BSL: - c = safe_vgetc(); - if (c == Ctrl_N) { - goto end; - } - terminal_send_key(term, c); - break; - case K_LEFTMOUSE: case K_LEFTDRAG: case K_LEFTRELEASE: @@ -413,12 +379,23 @@ void terminal_enter(Terminal *term, bool process_deferred) event_process(); break; + case Ctrl_N: + if (got_bs) { + goto end; + } + // FALLTHROUGH + default: + if (c == Ctrl_BSL && !got_bs) { + got_bs = true; + break; + } if (term->closed) { close = true; goto end; } + got_bs = false; terminal_send_key(term, c); } } @@ -431,7 +408,7 @@ end: invalidate_terminal(term, term->cursor.row, term->cursor.row + 1); mapped_ctrl_c = save_mapped_ctrl_c; unshowmode(true); - redraw(false); + redraw(term->buf != curbuf); ui_busy_stop(); if (close) { term->opts.close_cb(term->opts.data); @@ -441,15 +418,17 @@ end: void terminal_destroy(Terminal *term) { - term->buf->terminal = NULL; + if (term->buf) { + term->buf->terminal = NULL; + } term->buf = NULL; pmap_del(ptr_t)(invalidated_terminals, term); for (size_t i = 0 ; i < term->sb_current; i++) { - free(term->sb_buffer[i]); + xfree(term->sb_buffer[i]); } - free(term->sb_buffer); + xfree(term->sb_buffer); vterm_free(term->vt); - free(term); + xfree(term); } void terminal_send(Terminal *term, char *data, size_t size) @@ -540,7 +519,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, if (term->cursor.visible && term->cursor.row == row && term->cursor.col == col) { attr_id = hl_combine_attr(attr_id, is_focused(term) && wp == curwin ? - term->focused_cursor_attr_id : term->unfocused_cursor_attr_id); + hl_attr(HLF_TERM) : hl_attr(HLF_TERMNC)); } term_attrs[col] = attr_id; @@ -624,7 +603,7 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data) // Recycle old row if it's the right size sbrow = term->sb_buffer[term->sb_current - 1]; } else { - free(term->sb_buffer[term->sb_current - 1]); + xfree(term->sb_buffer[term->sb_current - 1]); } memmove(term->sb_buffer + 1, term->sb_buffer, @@ -685,7 +664,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data) cells[col].chars[0] = 0; cells[col].width = 1; } - free(sbrow); + xfree(sbrow); pmap_put(ptr_t)(invalidated_terminals, term, NULL); return 1; @@ -783,11 +762,11 @@ static bool send_mouse_event(Terminal *term, int c) bool drag = false; switch (c) { - case K_LEFTDRAG: drag = true; + case K_LEFTDRAG: drag = true; // FALLTHROUGH case K_LEFTMOUSE: button = 1; break; - case K_MIDDLEDRAG: drag = true; + case K_MIDDLEDRAG: drag = true; // FALLTHROUGH case K_MIDDLEMOUSE: button = 2; break; - case K_RIGHTDRAG: drag = true; + case K_RIGHTDRAG: drag = true; // FALLTHROUGH case K_RIGHTMOUSE: button = 3; break; case K_MOUSEDOWN: button = 4; break; case K_MOUSEUP: button = 5; break; @@ -916,12 +895,16 @@ static void on_refresh(Event event) } Terminal *term; void *stub; (void)(stub); - // dont process autocommands while updating terminal buffers. JobActivity can - // be used act on terminal output. + // don't process autocommands while updating terminal buffers block_autocmds(); map_foreach(invalidated_terminals, term, stub, { - if (!term->buf) { + // TODO(SplinterOfChaos): Find the condition that makes term->buf invalid. + bool valid = true; + if (!term->buf || !(valid = buf_valid(term->buf))) { // destroyed by `close_buffer`. Dont do anything else + if (!valid) { + term->buf = NULL; + } continue; } bool pending_resize = term->pending_resize; @@ -1018,6 +1001,11 @@ static void refresh_screen(Terminal *term) static void redraw(bool restore_cursor) { + Terminal *term = curbuf->terminal; + if (!term) { + restore_cursor = true; + } + int save_row, save_col; if (restore_cursor) { // save the current row/col to restore after updating screen when not @@ -1040,14 +1028,13 @@ static void redraw(bool restore_cursor) showruler(false); - Terminal *term = curbuf->terminal; if (term && is_focused(term)) { curwin->w_wrow = term->cursor.row; curwin->w_wcol = term->cursor.col + win_col_off(curwin); setcursor(); } else if (restore_cursor) { ui_cursor_goto(save_row, save_col); - } else { + } else if (term) { // exiting terminal focus, put the window cursor in a valid position int height, width; vterm_get_size(term->vt, &height, &width); @@ -1099,28 +1086,30 @@ static bool is_focused(Terminal *term) do { \ Error err; \ o = dict_get_value(t->buf->b_vars, cstr_as_string(k), &err); \ - if (obj.type == kObjectTypeNil) { \ + if (o.type == kObjectTypeNil) { \ o = dict_get_value(&globvardict, cstr_as_string(k), &err); \ } \ } while (0) static char *get_config_string(Terminal *term, char *key) { - Object obj = OBJECT_INIT; + Object obj; GET_CONFIG_VALUE(term, key, obj); if (obj.type == kObjectTypeString) { return obj.data.string.data; } + api_free_object(obj); return NULL; } static int get_config_int(Terminal *term, char *key) { - Object obj = OBJECT_INIT; + Object obj; GET_CONFIG_VALUE(term, key, obj); if (obj.type == kObjectTypeInteger) { return (int)obj.data.integer; } + api_free_object(obj); return 0; } diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index c323f10a4f..0a7c16e2cb 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -16,18 +16,18 @@ SCRIPTS := test_autoformat_join.out \ test24.out \ test26.out test27.out test29.out test30.out \ test31.out test32.out test34.out \ - test36.out test37.out test38.out test39.out test40.out \ - test42.out test43.out test44.out test45.out \ + test36.out test37.out test39.out test40.out \ + test42.out test43.out test45.out \ test46.out test47.out test48.out test49.out \ test52.out test53.out test55.out \ test57.out test58.out test59.out test60.out \ test61.out test62.out test63.out test64.out test65.out \ test68.out test69.out \ test71.out test73.out test74.out \ - test76.out test78.out test79.out test80.out \ + test76.out test79.out test80.out \ test82.out test83.out \ test86.out test87.out test88.out \ - test96.out test99.out \ + test96.out \ test_listlbr.out \ test_breakindent.out diff --git a/src/nvim/testdir/test38.in b/src/nvim/testdir/test38.in deleted file mode 100644 index 3e0236251b..0000000000 --- a/src/nvim/testdir/test38.in +++ /dev/null @@ -1,35 +0,0 @@ - -Test Virtual replace mode. - -STARTTEST -:so small.vim -:" make sure that backspace works, no matter what termcap is used -:set t_kD=x7f t_kb=x08 -ggdGa -abcdefghi -jk lmn - opq rst -uvwxyz -gg:set ai -:set bs=2 -gR0 1 -A -BCDEFGHIJ - KL -MNO -PQRG:ka -o0 -abcdefghi -jk lmn - opq rst -uvwxyz -'ajgR0 1 -A -BCDEFGHIJ - KL -MNO -PQR:$ -iab cdefghi jkl0gRAB......CDEFGHI.Jo: -iabcdefghijklmnopqrst0gRAB IJKLMNO QR:wq! test.out -ENDTEST - diff --git a/src/nvim/testdir/test38.ok b/src/nvim/testdir/test38.ok deleted file mode 100644 index e10209667b..0000000000 --- a/src/nvim/testdir/test38.ok +++ /dev/null @@ -1,13 +0,0 @@ - 1 - A - BCDEFGHIJ - KL - MNO - PQR - 1 -abcdefghi -jk lmn - opq rst -uvwxyz -AB......CDEFGHI.Jkl -AB IJKLMNO QRst diff --git a/src/nvim/testdir/test44.in b/src/nvim/testdir/test44.in deleted file mode 100644 index 7b1a13488f..0000000000 --- a/src/nvim/testdir/test44.in +++ /dev/null @@ -1,74 +0,0 @@ -Tests for regexp with multi-byte encoding and various magic settings. -Test matchstr() with a count and multi-byte chars. -See test99 for exactly the same test with re=2. - -STARTTEST -:so mbyte.vim -:set encoding=utf-8 termencoding=latin1 -:set re=1 -/^1 -/a*b\{2}c\+/e -x/\Md\*e\{2}f\+/e -x:set nomagic -/g\*h\{2}i\+/e -x/\mj*k\{2}l\+/e -x/\vm*n{2}o+/e -x/\V^aa$ -x:set magic -/\v(a)(b)\2\1\1/e -x/\V[ab]\(\[xy]\)\1 -x:" Now search for multi-byte without composing char -/ม -x:" Now search for multi-byte with composing char -/ม่ -x:" find word by change of word class -/ち\<カヨ\>は -x:" Test \%u, [\u] and friends -/\%u20ac -x/[\u4f7f\u5929]\+ -x/\%U12345678 -x/[\U1234abcd\u1234\uabcd] -x/\%d21879b -x/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* [[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* [[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* [[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e -x/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* [[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* [[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* [[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e -x:" Test backwards search from a multi-byte char -/x -x?. -x:let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g' -:@w -:?^1?,$w! test.out -:e! test.out -G:put =matchstr(\"אבגד\", \".\", 0, 2) " ב -:put =matchstr(\"אבגד\", \"..\", 0, 2) " בג -:put =matchstr(\"אבגד\", \".\", 0, 0) " א -:put =matchstr(\"אבגד\", \".\", 4, -1) " ג -:new -:$put =['dog(a', 'cat('] -/(/e+ -"ayn:bd! -:$put ='' -G"ap -:w! -:qa! -ENDTEST - -1 a aa abb abbccc -2 d dd dee deefff -3 g gg ghh ghhiii -4 j jj jkk jkklll -5 m mm mnn mnnooo -6 x ^aa$ x -7 (a)(b) abbaa -8 axx [ab]xx -9 หม่x อมx -a อมx หม่x -b ちカヨは -c x ¬€x -d 天使x -e y -f z -g a啷bb -h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐẔ -i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ -j 0123❤x -k combinations diff --git a/src/nvim/testdir/test44.ok b/src/nvim/testdir/test44.ok deleted file mode 100644 index d9a1206cc2..0000000000 --- a/src/nvim/testdir/test44.ok +++ /dev/null @@ -1,26 +0,0 @@ -1 a aa abb abbcc -2 d dd dee deeff -3 g gg ghh ghhii -4 j jj jkk jkkll -5 m mm mnn mnnoo -6 x aa$ x -7 (a)(b) abba -8 axx ab]xx -9 หม่x อx -a อมx หx -b カヨは -c x ¬x -d 使x -e y -f z -g abb -h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐ -i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑ -j 012❤ -k œ̄ṣ́m̥̄ᾱ̆́ -ב -בג -א -ג -a -cat( diff --git a/src/nvim/testdir/test78.in b/src/nvim/testdir/test78.in deleted file mode 100644 index cb0e51edd5..0000000000 --- a/src/nvim/testdir/test78.in +++ /dev/null @@ -1,46 +0,0 @@ -Inserts 10000 lines with text to fill the swap file with two levels of pointer -blocks. Then recovers from the swap file and checks all text is restored. - -We need about 10000 lines of 100 characters to get two levels of pointer -blocks. - -STARTTEST -:so small.vim -:set fileformat=unix undolevels=-1 -:e! Xtest -ggdG -:let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789" -:let i = 1 -:let linecount = 10000 -:while i <= linecount | call append(i - 1, i . text) | let i += 1 | endwhile -:preserve -:" get the name of the swap file -:redir => swapname -:swapname -:redir END -:let swapname = substitute(swapname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') -:" make a copy of the swap file in Xswap -:set bin -:exe 'sp ' . swapname -:w! Xswap -:echo swapname -:set nobin -:new -:only! -:bwipe! Xtest -:call rename('Xswap', swapname) -:recover Xtest -:call delete(swapname) -:new -:call append(0, 'recovery start') -:wincmd w -:let linedollar = line('$') -:if linedollar < linecount | exe 'wincmd w' | call append(line('$'), "expected " . linecount . " lines but found only " . linedollar) | exe 'wincmd w' | let linecount = linedollar | endif -:let i = 1 -:while i <= linecount | if getline(i) != i . text | exe 'wincmd w' | call append(line('$'), i . ' differs') | exe 'wincmd w' | endif | let i += 1 | endwhile -:q! -:call append(line('$'), 'recovery end') -:w! test.out -:qa! -ENDTEST - diff --git a/src/nvim/testdir/test78.ok b/src/nvim/testdir/test78.ok deleted file mode 100644 index 6c3ecefe3c..0000000000 --- a/src/nvim/testdir/test78.ok +++ /dev/null @@ -1,3 +0,0 @@ -recovery start - -recovery end diff --git a/src/nvim/testdir/test99.in b/src/nvim/testdir/test99.in deleted file mode 100644 index 32bc68cce4..0000000000 --- a/src/nvim/testdir/test99.in +++ /dev/null @@ -1,68 +0,0 @@ -Tests for regexp with multi-byte encoding and various magic settings. -Test matchstr() with a count and multi-byte chars. -See test44 for exactly the same test with re=1. - -STARTTEST -:so mbyte.vim -:set encoding=utf-8 termencoding=latin1 -:set re=2 -/^1 -/a*b\{2}c\+/e -x/\Md\*e\{2}f\+/e -x:set nomagic -/g\*h\{2}i\+/e -x/\mj*k\{2}l\+/e -x/\vm*n{2}o+/e -x/\V^aa$ -x:set magic -/\v(a)(b)\2\1\1/e -x/\V[ab]\(\[xy]\)\1 -x:" Now search for multi-byte without composing char -/ม -x:" Now search for multi-byte with composing char -/ม่ -x:" find word by change of word class -/ち\<カヨ\>は -x:" Test \%u, [\u] and friends -/\%u20ac -x/[\u4f7f\u5929]\+ -x/\%U12345678 -x/[\U1234abcd\u1234\uabcd] -x/\%d21879b -x/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* [[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* [[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* [[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e -x/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* [[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* [[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* [[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e -x:" Test backwards search from a multi-byte char -/x -x?. -x:let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g' -:@w -:?^1?,$w! test.out -:e! test.out -G:put =matchstr(\"אבגד\", \".\", 0, 2) " ב -:put =matchstr(\"אבגד\", \"..\", 0, 2) " בג -:put =matchstr(\"אבגד\", \".\", 0, 0) " א -:put =matchstr(\"אבגד\", \".\", 4, -1) " ג -:w! -:qa! -ENDTEST - -1 a aa abb abbccc -2 d dd dee deefff -3 g gg ghh ghhiii -4 j jj jkk jkklll -5 m mm mnn mnnooo -6 x ^aa$ x -7 (a)(b) abbaa -8 axx [ab]xx -9 หม่x อมx -a อมx หม่x -b ちカヨは -c x ¬€x -d 天使x -e y -f z -g a啷bb -h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐẔ -i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ -j 0123❤x -k combinations diff --git a/src/nvim/testdir/test99.ok b/src/nvim/testdir/test99.ok deleted file mode 100644 index 0bd0b8ab73..0000000000 --- a/src/nvim/testdir/test99.ok +++ /dev/null @@ -1,24 +0,0 @@ -1 a aa abb abbcc -2 d dd dee deeff -3 g gg ghh ghhii -4 j jj jkk jkkll -5 m mm mnn mnnoo -6 x aa$ x -7 (a)(b) abba -8 axx ab]xx -9 หม่x อx -a อมx หx -b カヨは -c x ¬x -d 使x -e y -f z -g abb -h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐ -i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑ -j 012❤ -k œ̄ṣ́m̥̄ᾱ̆́ -ב -בג -א -ג diff --git a/src/nvim/tui/term_input.inl b/src/nvim/tui/term_input.inl index c1ccc863de..ccc47080b8 100644 --- a/src/nvim/tui/term_input.inl +++ b/src/nvim/tui/term_input.inl @@ -296,5 +296,5 @@ static void term_input_destroy(TermInput *input) uv_close((uv_handle_t *)&input->timer_handle, NULL); termkey_destroy(input->tk); event_poll(0); // Run once to remove references to input/timer handles - free(input); + xfree(input); } diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 6d23c2cf74..763a7c0e6d 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -190,12 +190,12 @@ static void tui_stop(UI *ui) if (uv_loop_close(data->write_loop)) { abort(); } - free(data->write_loop); + xfree(data->write_loop); unibi_destroy(data->ut); destroy_screen(data); - free(data); + xfree(data); ui_detach(ui); - free(ui); + xfree(ui); } static void try_resize(Event ev) @@ -851,8 +851,8 @@ static void destroy_screen(TUIData *data) { if (data->screen) { for (int i = 0; i < data->old_height; i++) { - free(data->screen[i]); + xfree(data->screen[i]); } - free(data->screen); + xfree(data->screen); } } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 601c3af741..d8cf8aa7b7 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -686,11 +686,11 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading) (!reading || os_file_exists(undo_file_name))) { break; } - free(undo_file_name); + xfree(undo_file_name); undo_file_name = NULL; } - free(munged_name); + xfree(munged_name); return undo_file_name; } @@ -710,146 +710,162 @@ static void u_free_uhp(u_header_T *uhp) u_freeentry(uep, uep->ue_size); uep = nuep; } - free(uhp); + xfree(uhp); } -static int serialize_header(FILE *fp, buf_T *buf, char_u *hash) +/// Writes the header. +/// @returns false in case of an error. +static bool serialize_header(bufinfo_T *bi, char_u *hash) + FUNC_ATTR_NONNULL_ALL { - /* Start writing, first the magic marker and undo info version. */ - if (fwrite(UF_START_MAGIC, UF_START_MAGIC_LEN, 1, fp) != 1) - return FAIL; + buf_T *buf = bi->bi_buf; + FILE *fp = bi->bi_fp; - put_bytes(fp, UF_VERSION, 2); - - /* Write a hash of the buffer text, so that we can verify it is still the - * same when reading the buffer text. */ - if (fwrite(hash, UNDO_HASH_SIZE, 1, fp) != 1) - return FAIL; - - /* buffer-specific data */ - put_bytes(fp, (uintmax_t)buf->b_ml.ml_line_count, 4); - size_t len = buf->b_u_line_ptr ? STRLEN(buf->b_u_line_ptr) : 0; - put_bytes(fp, len, 4); - if (len > 0 && fwrite(buf->b_u_line_ptr, len, 1, fp) != 1) - return FAIL; - put_bytes(fp, (uintmax_t)buf->b_u_line_lnum, 4); - put_bytes(fp, (uintmax_t)buf->b_u_line_colnr, 4); - - /* Undo structures header data */ - put_header_ptr(fp, buf->b_u_oldhead); - put_header_ptr(fp, buf->b_u_newhead); - put_header_ptr(fp, buf->b_u_curhead); - - put_bytes(fp, (uintmax_t)buf->b_u_numhead, 4); - put_bytes(fp, (uintmax_t)buf->b_u_seq_last, 4); - put_bytes(fp, (uintmax_t)buf->b_u_seq_cur, 4); - put_time(fp, buf->b_u_time_cur); + // Start writing, first the magic marker and undo info version. + if (fwrite(UF_START_MAGIC, UF_START_MAGIC_LEN, 1, fp) != 1) { + return false; + } - /* Optional fields. */ - putc(4, fp); - putc(UF_LAST_SAVE_NR, fp); - put_bytes(fp, (uintmax_t)buf->b_u_save_nr_last, 4); + undo_write_bytes(bi, UF_VERSION, 2); - putc(0, fp); /* end marker */ + // Write a hash of the buffer text, so that we can verify it is + // still the same when reading the buffer text. + if (!undo_write(bi, hash, UNDO_HASH_SIZE)) { + return false; + } - return OK; + // Write buffer-specific data. + undo_write_bytes(bi, (uintmax_t)buf->b_ml.ml_line_count, 4); + size_t len = buf->b_u_line_ptr ? STRLEN(buf->b_u_line_ptr) : 0; + undo_write_bytes(bi, len, 4); + if (len > 0 && !undo_write(bi, buf->b_u_line_ptr, len)) { + return false; + } + undo_write_bytes(bi, (uintmax_t)buf->b_u_line_lnum, 4); + undo_write_bytes(bi, (uintmax_t)buf->b_u_line_colnr, 4); + + // Write undo structures header data. + put_header_ptr(bi, buf->b_u_oldhead); + put_header_ptr(bi, buf->b_u_newhead); + put_header_ptr(bi, buf->b_u_curhead); + + undo_write_bytes(bi, (uintmax_t)buf->b_u_numhead, 4); + undo_write_bytes(bi, (uintmax_t)buf->b_u_seq_last, 4); + undo_write_bytes(bi, (uintmax_t)buf->b_u_seq_cur, 4); + uint8_t time_buf[8]; + time_to_bytes(buf->b_u_time_cur, time_buf); + undo_write(bi, time_buf, sizeof(time_buf)); + + // Write optional fields. + undo_write_bytes(bi, 4, 1); + undo_write_bytes(bi, UF_LAST_SAVE_NR, 1); + undo_write_bytes(bi, (uintmax_t)buf->b_u_save_nr_last, 4); + + // Write end marker. + undo_write_bytes(bi, 0, 1); + + return true; } -static int serialize_uhp(FILE *fp, buf_T *buf, u_header_T *uhp) +static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp) { - if (put_bytes(fp, UF_HEADER_MAGIC, 2) == FAIL) - return FAIL; - - put_header_ptr(fp, uhp->uh_next.ptr); - put_header_ptr(fp, uhp->uh_prev.ptr); - put_header_ptr(fp, uhp->uh_alt_next.ptr); - put_header_ptr(fp, uhp->uh_alt_prev.ptr); - put_bytes(fp, (uintmax_t)uhp->uh_seq, 4); - serialize_pos(uhp->uh_cursor, fp); - put_bytes(fp, (uintmax_t)uhp->uh_cursor_vcol, 4); - put_bytes(fp, (uintmax_t)uhp->uh_flags, 2); - /* Assume NMARKS will stay the same. */ - for (size_t i = 0; i < NMARKS; ++i) - serialize_pos(uhp->uh_namedm[i], fp); - serialize_visualinfo(&uhp->uh_visual, fp); - put_time(fp, uhp->uh_time); - - /* Optional fields. */ - putc(4, fp); - putc(UHP_SAVE_NR, fp); - put_bytes(fp, (uintmax_t)uhp->uh_save_nr, 4); - - putc(0, fp); /* end marker */ - - /* Write all the entries. */ + if (!undo_write_bytes(bi, (uintmax_t)UF_HEADER_MAGIC, 2)) { + return false; + } + + put_header_ptr(bi, uhp->uh_next.ptr); + put_header_ptr(bi, uhp->uh_prev.ptr); + put_header_ptr(bi, uhp->uh_alt_next.ptr); + put_header_ptr(bi, uhp->uh_alt_prev.ptr); + undo_write_bytes(bi, (uintmax_t)uhp->uh_seq, 4); + serialize_pos(bi, uhp->uh_cursor); + undo_write_bytes(bi, (uintmax_t)uhp->uh_cursor_vcol, 4); + undo_write_bytes(bi, (uintmax_t)uhp->uh_flags, 2); + // Assume NMARKS will stay the same. + for (size_t i = 0; i < (size_t)NMARKS; i++) { + serialize_pos(bi, uhp->uh_namedm[i]); + } + serialize_visualinfo(bi, &uhp->uh_visual); + uint8_t time_buf[8]; + time_to_bytes(uhp->uh_time, time_buf); + undo_write(bi, time_buf, sizeof(time_buf)); + + // Write optional fields. + undo_write_bytes(bi, 4, 1); + undo_write_bytes(bi, UHP_SAVE_NR, 1); + undo_write_bytes(bi, (uintmax_t)uhp->uh_save_nr, 4); + + // Write end marker. + undo_write_bytes(bi, 0, 1); + + // Write all the entries. for (u_entry_T *uep = uhp->uh_entry; uep; uep = uep->ue_next) { - put_bytes(fp, UF_ENTRY_MAGIC, 2); - if (serialize_uep(fp, buf, uep) == FAIL) - return FAIL; + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_MAGIC, 2); + if (!serialize_uep(bi, uep)) { + return false; + } } - put_bytes(fp, UF_ENTRY_END_MAGIC, 2); - return OK; + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_END_MAGIC, 2); + return true; } -static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name) +static u_header_T *unserialize_uhp(bufinfo_T *bi, char_u *file_name) { - u_header_T *uhp; - int i; - u_entry_T *uep, *last_uep; - int c; - int error; - - uhp = xmalloc(sizeof(u_header_T)); + u_header_T *uhp = xmalloc(sizeof(u_header_T)); memset(uhp, 0, sizeof(u_header_T)); #ifdef U_DEBUG uhp->uh_magic = UH_MAGIC; #endif - uhp->uh_next.seq = get4c(fp); - uhp->uh_prev.seq = get4c(fp); - uhp->uh_alt_next.seq = get4c(fp); - uhp->uh_alt_prev.seq = get4c(fp); - uhp->uh_seq = get4c(fp); + uhp->uh_next.seq = undo_read_4c(bi); + uhp->uh_prev.seq = undo_read_4c(bi); + uhp->uh_alt_next.seq = undo_read_4c(bi); + uhp->uh_alt_prev.seq = undo_read_4c(bi); + uhp->uh_seq = undo_read_4c(bi); if (uhp->uh_seq <= 0) { corruption_error("uh_seq", file_name); - free(uhp); + xfree(uhp); return NULL; } - unserialize_pos(&uhp->uh_cursor, fp); - uhp->uh_cursor_vcol = get4c(fp); - uhp->uh_flags = get2c(fp); - for (i = 0; i < NMARKS; ++i) - unserialize_pos(&uhp->uh_namedm[i], fp); - unserialize_visualinfo(&uhp->uh_visual, fp); - uhp->uh_time = get8ctime(fp); + unserialize_pos(bi, &uhp->uh_cursor); + uhp->uh_cursor_vcol = undo_read_4c(bi); + uhp->uh_flags = undo_read_2c(bi); + for (size_t i = 0; i < (size_t)NMARKS; i++) { + unserialize_pos(bi, &uhp->uh_namedm[i]); + } + unserialize_visualinfo(bi, &uhp->uh_visual); + uhp->uh_time = undo_read_time(bi); - /* Optional fields. */ + // Unserialize optional fields. for (;; ) { - int len = getc(fp); - int what; + int len = undo_read_byte(bi); - if (len == 0) + if (len == 0) { break; - what = getc(fp); + } + int what = undo_read_byte(bi); switch (what) { case UHP_SAVE_NR: - uhp->uh_save_nr = get4c(fp); + uhp->uh_save_nr = undo_read_4c(bi); break; default: - /* field not supported, skip */ - while (--len >= 0) - (void)getc(fp); + // Field not supported, skip it. + while (--len >= 0) { + (void)undo_read_byte(bi); + } } } - /* Unserialize the uep list. */ - last_uep = NULL; - while ((c = get2c(fp)) == UF_ENTRY_MAGIC) { - error = FALSE; - uep = unserialize_uep(fp, &error, file_name); - if (last_uep == NULL) + // Unserialize the uep list. + u_entry_T *last_uep = NULL; + int c; + while ((c = undo_read_2c(bi)) == UF_ENTRY_MAGIC) { + bool error = false; + u_entry_T *uep = unserialize_uep(bi, &error, file_name); + if (last_uep == NULL) { uhp->uh_entry = uep; - else + } else { last_uep->ue_next = uep; + } last_uep = uep; if (uep == NULL || error) { u_free_uhp(uhp); @@ -865,59 +881,60 @@ static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name) return uhp; } -/* - * Serialize "uep" to "fp". - */ -static int serialize_uep(FILE *fp, buf_T *buf, u_entry_T *uep) +/// Serializes "uep". +/// +/// @returns false in case of an error. +static bool serialize_uep(bufinfo_T *bi, u_entry_T *uep) { - put_bytes(fp, (uintmax_t)uep->ue_top, 4); - put_bytes(fp, (uintmax_t)uep->ue_bot, 4); - put_bytes(fp, (uintmax_t)uep->ue_lcount, 4); - put_bytes(fp, (uintmax_t)uep->ue_size, 4); - for (size_t i = 0; i < (size_t)uep->ue_size; ++i) { + undo_write_bytes(bi, (uintmax_t)uep->ue_top, 4); + undo_write_bytes(bi, (uintmax_t)uep->ue_bot, 4); + undo_write_bytes(bi, (uintmax_t)uep->ue_lcount, 4); + undo_write_bytes(bi, (uintmax_t)uep->ue_size, 4); + + for (size_t i = 0; i < (size_t)uep->ue_size; i++) { size_t len = STRLEN(uep->ue_array[i]); - if (put_bytes(fp, len, 4) == FAIL) - return FAIL; - if (len > 0 && fwrite(uep->ue_array[i], len, 1, fp) != 1) - return FAIL; + if (!undo_write_bytes(bi, len, 4)) { + return false; + } + if (len > 0 && !undo_write(bi, uep->ue_array[i], len)) { + return false; + } } - return OK; + return true; } -static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name) +static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error, char_u *file_name) { - int i; - u_entry_T *uep; - char_u **array; - char_u *line; - int line_len; - - uep = xmalloc(sizeof(u_entry_T)); + u_entry_T *uep = xmalloc(sizeof(u_entry_T)); memset(uep, 0, sizeof(u_entry_T)); #ifdef U_DEBUG uep->ue_magic = UE_MAGIC; #endif - uep->ue_top = get4c(fp); - uep->ue_bot = get4c(fp); - uep->ue_lcount = get4c(fp); - uep->ue_size = get4c(fp); + uep->ue_top = undo_read_4c(bi); + uep->ue_bot = undo_read_4c(bi); + uep->ue_lcount = undo_read_4c(bi); + uep->ue_size = undo_read_4c(bi); + + char_u **array; if (uep->ue_size > 0) { array = xmalloc(sizeof(char_u *) * (size_t)uep->ue_size); memset(array, 0, sizeof(char_u *) * (size_t)uep->ue_size); - } else + } else { array = NULL; + } uep->ue_array = array; - for (i = 0; i < uep->ue_size; ++i) { - line_len = get4c(fp); - if (line_len >= 0) - line = READ_STRING(fp, line_len); - else { + for (size_t i = 0; i < (size_t)uep->ue_size; i++) { + int line_len = undo_read_4c(bi); + char_u *line; + if (line_len >= 0) { + line = undo_read_string(bi, (size_t)line_len); + } else { line = NULL; corruption_error("line length", file_name); } if (line == NULL) { - *error = TRUE; + *error = true; return uep; } array[i] = line; @@ -925,61 +942,47 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name) return uep; } -/* - * Serialize "pos" to "fp". - */ -static void serialize_pos(pos_T pos, FILE *fp) +/// Serializes "pos". +static void serialize_pos(bufinfo_T *bi, pos_T pos) { - put_bytes(fp, (uintmax_t)pos.lnum, 4); - put_bytes(fp, (uintmax_t)pos.col, 4); - put_bytes(fp, (uintmax_t)pos.coladd, 4); + undo_write_bytes(bi, (uintmax_t)pos.lnum, 4); + undo_write_bytes(bi, (uintmax_t)pos.col, 4); + undo_write_bytes(bi, (uintmax_t)pos.coladd, 4); } -/* - * Unserialize the pos_T at the current position in fp. - */ -static void unserialize_pos(pos_T *pos, FILE *fp) +/// Unserializes the pos_T at the current position. +static void unserialize_pos(bufinfo_T *bi, pos_T *pos) { - pos->lnum = get4c(fp); - if (pos->lnum < 0) + pos->lnum = undo_read_4c(bi); + if (pos->lnum < 0) { pos->lnum = 0; - pos->col = get4c(fp); - if (pos->col < 0) + } + pos->col = undo_read_4c(bi); + if (pos->col < 0) { pos->col = 0; - pos->coladd = get4c(fp); - if (pos->coladd < 0) + } + pos->coladd = undo_read_4c(bi); + if (pos->coladd < 0) { pos->coladd = 0; + } } -/* - * Serialize "info" to "fp". - */ -static void serialize_visualinfo(visualinfo_T *info, FILE *fp) +/// Serializes "info". +static void serialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) { - serialize_pos(info->vi_start, fp); - serialize_pos(info->vi_end, fp); - put_bytes(fp, (uintmax_t)info->vi_mode, 4); - put_bytes(fp, (uintmax_t)info->vi_curswant, 4); + serialize_pos(bi, info->vi_start); + serialize_pos(bi, info->vi_end); + undo_write_bytes(bi, (uintmax_t)info->vi_mode, 4); + undo_write_bytes(bi, (uintmax_t)info->vi_curswant, 4); } -/* - * Unserialize the visualinfo_T at the current position in fp. - */ -static void unserialize_visualinfo(visualinfo_T *info, FILE *fp) +/// Unserializes the visualinfo_T at the current position. +static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) { - unserialize_pos(&info->vi_start, fp); - unserialize_pos(&info->vi_end, fp); - info->vi_mode = get4c(fp); - info->vi_curswant = get4c(fp); -} - -/* - * Write the pointer to an undo header. Instead of writing the pointer itself - * we use the sequence number of the header. This is converted back to - * pointers when reading. */ -static void put_header_ptr(FILE *fp, u_header_T *uhp) -{ - put_bytes(fp, (uintmax_t)(uhp != NULL ? uhp->uh_seq : 0), 4); + unserialize_pos(bi, &info->vi_start); + unserialize_pos(bi, &info->vi_end); + info->vi_mode = undo_read_4c(bi); + info->vi_curswant = undo_read_4c(bi); } /* @@ -1003,6 +1006,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) FILE *fp = NULL; int perm; bool write_ok = false; + bufinfo_T bi; if (name == NULL) { file_name = u_get_undo_file_name(buf->b_ffname, FALSE); @@ -1134,8 +1138,11 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) /* * Write the header. */ - if (serialize_header(fp, buf, hash) == FAIL) + bi.bi_buf = buf; + bi.bi_fp = fp; + if (!serialize_header(&bi, hash)) { goto write_error; + } /* * Iteratively serialize UHPs and their UEPs from the top down. @@ -1149,8 +1156,9 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) #ifdef U_DEBUG ++headers_written; #endif - if (serialize_uhp(fp, buf, uhp) == FAIL) + if (!serialize_uhp(&bi, uhp)) { goto write_error; + } } /* Now walk through the tree - algorithm from undo_time(). */ @@ -1168,8 +1176,9 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) uhp = uhp->uh_next.ptr; } - if (put_bytes(fp, UF_HEADER_END_MAGIC, 2) == OK) + if (undo_write_bytes(&bi, (uintmax_t)UF_HEADER_END_MAGIC, 2)) { write_ok = true; + } #ifdef U_DEBUG if (headers_written != buf->b_u_numhead) { EMSGN("Written %" PRId64 " headers, ...", headers_written); @@ -1195,50 +1204,30 @@ write_error: theend: if (file_name != name) - free(file_name); + xfree(file_name); } -/* - * Load the undo tree from an undo file. - * If "name" is not NULL use it as the undo file name. This also means being - * a bit more verbose. - * Otherwise use curbuf->b_ffname to generate the undo file name. - * "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. - */ +/// Loads the undo tree from an undo file. +/// If "name" is not NULL use it as the undo file name. This also means being +/// a bit more verbose. +/// Otherwise use curbuf->b_ffname to generate the undo file name. +/// "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) + FUNC_ATTR_NONNULL_ARG(2) { - char_u *file_name; - FILE *fp; - long version, str_len; - char_u *line_ptr = NULL; - linenr_T line_lnum; - colnr_T line_colnr; - linenr_T line_count; - int num_head = 0; - long old_header_seq, new_header_seq, cur_header_seq; - long seq_last, seq_cur; - long last_save_nr = 0; - short old_idx = -1, new_idx = -1, cur_idx = -1; - long num_read_uhps = 0; - time_t seq_time; - int i, j; - int c; - u_header_T *uhp; - u_header_T **uhp_table = NULL; - char_u read_hash[UNDO_HASH_SIZE]; - char_u magic_buf[UF_START_MAGIC_LEN]; -#ifdef U_DEBUG - int *uhp_table_used; -#endif + u_header_T **uhp_table = NULL; + char_u *line_ptr = NULL; + char_u *file_name; if (name == NULL) { file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE); - if (file_name == NULL) + if (file_name == NULL) { return; + } #ifdef UNIX - /* For safety we only read an undo file if the owner is equal to the - * owner of the text file or equal to the current user. */ + // For safety we only read an undo file if the owner is equal to the + // owner of the text file or equal to the current user. FileInfo file_info_orig; FileInfo file_info_undo; if (os_fileinfo((char *)orig_name, &file_info_orig) @@ -1254,8 +1243,9 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) return; } #endif - } else + } else { file_name = name; + } if (p_verbose > 0) { verbose_enter(); @@ -1263,103 +1253,120 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) verbose_leave(); } - fp = mch_fopen((char *)file_name, "r"); + FILE *fp = mch_fopen((char *)file_name, "r"); if (fp == NULL) { - if (name != NULL || p_verbose > 0) + if (name != NULL || p_verbose > 0) { EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name); + } goto error; } - /* - * Read the undo file header. - */ + bufinfo_T bi; + bi.bi_buf = curbuf; + bi.bi_fp = fp; + + // Read the undo file header. + char_u magic_buf[UF_START_MAGIC_LEN]; if (fread(magic_buf, UF_START_MAGIC_LEN, 1, fp) != 1 || memcmp(magic_buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) { EMSG2(_("E823: Not an undo file: %s"), file_name); goto error; } - version = get2c(fp); + int version = get2c(fp); if (version != UF_VERSION) { EMSG2(_("E824: Incompatible undo file: %s"), file_name); goto error; } - if (fread(read_hash, UNDO_HASH_SIZE, 1, fp) != 1) { + char_u read_hash[UNDO_HASH_SIZE]; + if (!undo_read(&bi, read_hash, UNDO_HASH_SIZE)) { corruption_error("hash", file_name); goto error; } - line_count = (linenr_T)get4c(fp); + linenr_T line_count = (linenr_T)undo_read_4c(&bi); if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 || line_count != curbuf->b_ml.ml_line_count) { if (p_verbose > 0 || name != NULL) { - if (name == NULL) + if (name == NULL) { verbose_enter(); + } give_warning((char_u *) _("File contents changed, cannot use undo info"), true); - if (name == NULL) + if (name == NULL) { verbose_leave(); + } } goto error; } - /* Read undo data for "U" command. */ - str_len = get4c(fp); - if (str_len < 0) + // Read undo data for "U" command. + int str_len = undo_read_4c(&bi); + if (str_len < 0) { goto error; - if (str_len > 0) - line_ptr = READ_STRING(fp, str_len); - line_lnum = (linenr_T)get4c(fp); - line_colnr = (colnr_T)get4c(fp); + } + + if (str_len > 0) { + line_ptr = undo_read_string(&bi, (size_t)str_len); + } + linenr_T line_lnum = (linenr_T)undo_read_4c(&bi); + colnr_T line_colnr = (colnr_T)undo_read_4c(&bi); if (line_lnum < 0 || line_colnr < 0) { corruption_error("line lnum/col", file_name); goto error; } - /* Begin general undo data */ - old_header_seq = get4c(fp); - new_header_seq = get4c(fp); - cur_header_seq = get4c(fp); - num_head = get4c(fp); - seq_last = get4c(fp); - seq_cur = get4c(fp); - seq_time = get8ctime(fp); + // Begin general undo data + int old_header_seq = undo_read_4c(&bi); + int new_header_seq = undo_read_4c(&bi); + int cur_header_seq = undo_read_4c(&bi); + int num_head = undo_read_4c(&bi); + int seq_last = undo_read_4c(&bi); + int seq_cur = undo_read_4c(&bi); + time_t seq_time = undo_read_time(&bi); - /* Optional header fields. */ + // Optional header fields. + long last_save_nr = 0; for (;; ) { - int len = getc(fp); - int what; + int len = undo_read_byte(&bi); - if (len == 0 || len == EOF) + if (len == 0 || len == EOF) { break; - what = getc(fp); + } + int what = undo_read_byte(&bi); switch (what) { - case UF_LAST_SAVE_NR: - last_save_nr = get4c(fp); - break; - default: - /* field not supported, skip */ - while (--len >= 0) - (void)getc(fp); + case UF_LAST_SAVE_NR: + last_save_nr = undo_read_4c(&bi); + break; + + default: + // field not supported, skip + while (--len >= 0) { + (void)undo_read_byte(&bi); + } } } - /* uhp_table will store the freshly created undo headers we allocate - * until we insert them into curbuf. The table remains sorted by the - * sequence numbers of the headers. - * When there are no headers uhp_table is NULL. */ + // uhp_table will store the freshly created undo headers we allocate + // until we insert them into curbuf. The table remains sorted by the + // sequence numbers of the headers. + // When there are no headers uhp_table is NULL. if (num_head > 0) { uhp_table = xmalloc((size_t)num_head * sizeof(u_header_T *)); } - while ((c = get2c(fp)) == UF_HEADER_MAGIC) { + long num_read_uhps = 0; + + int c; + while ((c = undo_read_2c(&bi)) == UF_HEADER_MAGIC) { if (num_read_uhps >= num_head) { corruption_error("num_head too small", file_name); goto error; } - uhp = unserialize_uhp(fp, file_name); - if (uhp == NULL) + u_header_T *uhp = unserialize_uhp(&bi, file_name); + if (uhp == NULL) { goto error; + } uhp_table[num_read_uhps++] = uhp; } @@ -1374,54 +1381,61 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) #ifdef U_DEBUG size_t amount = num_head * sizeof(int) + 1; - uhp_table_used = xmalloc(amount); + int *uhp_table_used = xmalloc(amount); memset(uhp_table_used, 0, amount); # define SET_FLAG(j) ++ uhp_table_used[j] #else # define SET_FLAG(j) #endif - /* We have put all of the headers into a table. Now we iterate through the - * table and swizzle each sequence number we have stored in uh_*_seq into - * a pointer corresponding to the header with that sequence number. */ - for (i = 0; i < num_head; i++) { - uhp = uhp_table[i]; - if (uhp == NULL) + // We have put all of the headers into a table. Now we iterate through the + // table and swizzle each sequence number we have stored in uh_*_seq into + // a pointer corresponding to the header with that sequence number. + short old_idx = -1, new_idx = -1, cur_idx = -1; + for (int i = 0; i < num_head; i++) { + u_header_T *uhp = uhp_table[i]; + if (uhp == NULL) { continue; - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && i != j && uhp_table[i]->uh_seq == uhp_table[j]->uh_seq) { corruption_error("duplicate uh_seq", file_name); goto error; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_next.seq) { uhp->uh_next.ptr = uhp_table[j]; SET_FLAG(j); break; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_prev.seq) { uhp->uh_prev.ptr = uhp_table[j]; SET_FLAG(j); break; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_alt_next.seq) { uhp->uh_alt_next.ptr = uhp_table[j]; SET_FLAG(j); break; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_alt_prev.seq) { uhp->uh_alt_prev.ptr = uhp_table[j]; SET_FLAG(j); break; } + } if (old_header_seq > 0 && old_idx < 0 && uhp->uh_seq == old_header_seq) { assert(i <= SHRT_MAX); old_idx = (short)i; @@ -1439,8 +1453,8 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) } } - /* Now that we have read the undo info successfully, free the current undo - * info and use the info from the file. */ + // Now that we have read the undo info successfully, free the current undo + // info and use the info from the file. u_blockfree(curbuf); curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx]; curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx]; @@ -1456,38 +1470,120 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) curbuf->b_u_save_nr_cur = last_save_nr; curbuf->b_u_synced = true; - free(uhp_table); + xfree(uhp_table); #ifdef U_DEBUG - for (i = 0; i < num_head; ++i) - if (uhp_table_used[i] == 0) + for (int i = 0; i < num_head; i++) { + if (uhp_table_used[i] == 0) { EMSGN("uhp_table entry %" PRId64 " not used, leaking memory", i); - free(uhp_table_used); + } + } + xfree(uhp_table_used); u_check(TRUE); #endif - if (name != NULL) + if (name != NULL) { smsg((char_u *)_("Finished reading undo file %s"), file_name); + } goto theend; error: - free(line_ptr); + xfree(line_ptr); if (uhp_table != NULL) { - for (i = 0; i < num_read_uhps; i++) - if (uhp_table[i] != NULL) + for (long i = 0; i < num_read_uhps; i++) + if (uhp_table[i] != NULL) { u_free_uhp(uhp_table[i]); - free(uhp_table); + } + xfree(uhp_table); } theend: - if (fp != NULL) + if (fp != NULL) { fclose(fp); - if (file_name != name) - free(file_name); - return; + } + if (file_name != name) { + xfree(file_name); + } +} + +/// Writes a sequence of bytes to the undo file. +/// +/// @returns false in case of an error. +static bool undo_write(bufinfo_T *bi, uint8_t *ptr, size_t len) + FUNC_ATTR_NONNULL_ARG(1) +{ + return fwrite(ptr, len, 1, bi->bi_fp) == 1; +} + +/// Writes a number, most significant bit first, in "len" bytes. +/// +/// Must match with undo_read_?c() functions. +/// +/// @returns false in case of an error. +static bool undo_write_bytes(bufinfo_T *bi, uintmax_t nr, size_t len) +{ + assert(len > 0); + uint8_t buf[8]; + for (size_t i = len - 1, bufi = 0; bufi < len; i--, bufi++) { + buf[bufi] = (uint8_t)(nr >> (i * 8)); + } + return undo_write(bi, buf, len); +} + +/// Writes the pointer to an undo header. +/// +/// Instead of writing the pointer itself, we use the sequence +/// number of the header. This is converted back to pointers +/// when reading. +static void put_header_ptr(bufinfo_T *bi, u_header_T *uhp) +{ + assert(uhp == NULL || uhp->uh_seq >= 0); + undo_write_bytes(bi, (uint64_t)(uhp != NULL ? uhp->uh_seq : 0), 4); +} + +static int undo_read_4c(bufinfo_T *bi) +{ + return get4c(bi->bi_fp); } +static int undo_read_2c(bufinfo_T *bi) +{ + return get2c(bi->bi_fp); +} +static int undo_read_byte(bufinfo_T *bi) +{ + return getc(bi->bi_fp); +} + +static time_t undo_read_time(bufinfo_T *bi) +{ + return get8ctime(bi->bi_fp); +} + +/// Reads "buffer[size]" from the undo file. +/// +/// @returns false in case of an error. +static bool undo_read(bufinfo_T *bi, uint8_t *buffer, size_t size) + FUNC_ATTR_NONNULL_ARG(1) +{ + return fread(buffer, size, 1, bi->bi_fp) == 1; +} + +/// Reads a string of length "len" from "bi->bi_fd" and appends a zero to it. +/// +/// @param len can be zero to allocate an empty line. +/// +/// @returns a pointer to allocated memory or NULL in case of an error. +static uint8_t *undo_read_string(bufinfo_T *bi, size_t len) +{ + uint8_t *ptr = xmallocz(len); + if (len > 0 && !undo_read(bi, ptr, len)) { + xfree(ptr); + return NULL; + } + return ptr; +} /* * If 'cpoptions' contains 'u': Undo the previous undo or redo (vi compatible). @@ -2011,9 +2107,9 @@ static void u_undoredo(int undo) ml_replace((linenr_T)1, uep->ue_array[i], TRUE); else ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE); - free(uep->ue_array[i]); + xfree(uep->ue_array[i]); } - free((char_u *)uep->ue_array); + xfree((char_u *)uep->ue_array); } /* adjust marks */ @@ -2572,7 +2668,7 @@ u_freeentries ( #ifdef U_DEBUG uhp->uh_magic = 0; #endif - free((char_u *)uhp); + xfree((char_u *)uhp); --buf->b_u_numhead; } @@ -2582,12 +2678,12 @@ u_freeentries ( static void u_freeentry(u_entry_T *uep, long n) { while (n > 0) - free(uep->ue_array[--n]); - free((char_u *)uep->ue_array); + xfree(uep->ue_array[--n]); + xfree((char_u *)uep->ue_array); #ifdef U_DEBUG uep->ue_magic = 0; #endif - free((char_u *)uep); + xfree((char_u *)uep); } /* @@ -2627,7 +2723,7 @@ void u_saveline(linenr_T lnum) void u_clearline(void) { if (curbuf->b_u_line_ptr != NULL) { - free(curbuf->b_u_line_ptr); + xfree(curbuf->b_u_line_ptr); curbuf->b_u_line_ptr = NULL; curbuf->b_u_line_lnum = 0; } @@ -2660,7 +2756,7 @@ void u_undoline(void) oldp = u_save_line(curbuf->b_u_line_lnum); ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE); changed_bytes(curbuf->b_u_line_lnum, 0); - free(curbuf->b_u_line_ptr); + xfree(curbuf->b_u_line_ptr); curbuf->b_u_line_ptr = oldp; t = curbuf->b_u_line_colnr; @@ -2684,7 +2780,7 @@ void u_blockfree(buf_T *buf) u_freeheader(buf, buf->b_u_oldhead, NULL); assert(buf->b_u_oldhead != previous_oldhead); } - free(buf->b_u_line_ptr); + xfree(buf->b_u_line_ptr); } /* diff --git a/src/nvim/undo_defs.h b/src/nvim/undo_defs.h index 2579f13b93..610adb4367 100644 --- a/src/nvim/undo_defs.h +++ b/src/nvim/undo_defs.h @@ -4,6 +4,7 @@ #include <time.h> // for time_t #include "nvim/pos.h" +#include "nvim/buffer_defs.h" /* Structure to store info about the Visual area. */ typedef struct { @@ -67,4 +68,10 @@ struct u_header { #define UH_CHANGED 0x01 /* b_changed flag before undo/after redo */ #define UH_EMPTYBUF 0x02 /* buffer was empty */ +/// Structure passed around between undofile functions. +typedef struct { + buf_T *bi_buf; + FILE *bi_fp; +} bufinfo_T; + #endif // NVIM_UNDO_DEFS_H diff --git a/src/nvim/version.c b/src/nvim/version.c index 1a5eb523fa..49f374bce4 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -915,13 +915,13 @@ void list_version(void) if (*default_vim_dir != NUL) { version_msg(_(" fall-back for $VIM: \"")); - version_msg((char *)default_vim_dir); + version_msg(default_vim_dir); version_msg("\"\n"); } if (*default_vimruntime_dir != NUL) { version_msg(_(" f-b for $VIMRUNTIME: \"")); - version_msg((char *)default_vimruntime_dir); + version_msg(default_vimruntime_dir); version_msg("\"\n"); } #endif // ifdef HAVE_PATHDEF diff --git a/src/nvim/window.c b/src/nvim/window.c index 9f07f2bddc..caa7ecc041 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -401,7 +401,7 @@ wingotofile: beginline(BL_SOL | BL_FIX); } } - free(ptr); + xfree(ptr); } break; @@ -1766,7 +1766,7 @@ static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_c } buf_T *old_curbuf = curbuf; - Terminal *term = win->w_buffer->terminal; + Terminal *term = win->w_buffer ? win->w_buffer->terminal : NULL; if (term) { // Don't free terminal buffers free_buf = false; @@ -2065,7 +2065,7 @@ win_free_mem ( /* Remove the window and its frame from the tree of frames. */ frp = win->w_frame; wp = winframe_remove(win, dirp, tp); - free(frp); + xfree(frp); win_free(win, tp); /* When deleting the current window of another tab page select a new @@ -2209,7 +2209,7 @@ winframe_remove ( if (frp2->fr_win != NULL) frp2->fr_win->w_frame = frp2->fr_parent; frp = frp2->fr_parent; - free(frp2); + xfree(frp2); frp2 = frp->fr_parent; if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) { @@ -2230,7 +2230,7 @@ winframe_remove ( break; } } - free(frp); + xfree(frp); } } @@ -2914,7 +2914,7 @@ void free_tabpage(tabpage_T *tp) - free(tp); + xfree(tp); } /* @@ -2934,7 +2934,7 @@ int win_new_tabpage(int after) /* Remember the current windows in this Tab page. */ if (leave_tabpage(curbuf, TRUE) == FAIL) { - free(newtp); + xfree(newtp); return FAIL; } curtab = newtp; @@ -3528,7 +3528,7 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri /* Window doesn't have a local directory and we are not in the global * directory: Change to the global directory. */ ignored = os_chdir((char *)globaldir); - free(globaldir); + xfree(globaldir); globaldir = NULL; shorten_fnames(TRUE); } @@ -3702,9 +3702,9 @@ win_free ( win_free_lsize(wp); for (i = 0; i < wp->w_tagstacklen; ++i) - free(wp->w_tagstack[i].tagname); + xfree(wp->w_tagstack[i].tagname); - free(wp->w_localdir); + xfree(wp->w_localdir); /* Remove the window from the b_wininfo lists, it may happen that the * freed memory is re-used for another window. */ @@ -3721,7 +3721,7 @@ win_free ( qf_free_all(wp); - free(wp->w_p_cc_cols); + xfree(wp->w_p_cc_cols); if (wp != aucmd_win) win_remove(wp, tp); @@ -3729,7 +3729,7 @@ win_free ( wp->w_next = au_pending_free_win; au_pending_free_win = wp; } else { - free(wp); + xfree(wp); } unblock_autocmds(); @@ -3839,7 +3839,7 @@ void win_free_lsize(win_T *wp) { // TODO: why would wp be NULL here? if (wp != NULL) { - free(wp->w_lines); + xfree(wp->w_lines); wp->w_lines = NULL; } } @@ -5136,7 +5136,7 @@ static void clear_snapshot_rec(frame_T *fr) if (fr != NULL) { clear_snapshot_rec(fr->fr_next); clear_snapshot_rec(fr->fr_child); - free(fr); + xfree(fr); } } @@ -5472,7 +5472,7 @@ int match_add(win_T *wp, char_u *grp, char_u *pat, int prio, int id, list_T *pos return id; fail: - free(m); + xfree(m); return -1; } @@ -5507,7 +5507,7 @@ int match_delete(win_T *wp, int id, int perr) else prev->next = cur->next; vim_regfree(cur->match.regprog); - free(cur->pattern); + xfree(cur->pattern); if (cur->pos.toplnum != 0) { if (wp->w_buffer->b_mod_set) { if (wp->w_buffer->b_mod_top > cur->pos.toplnum) { @@ -5524,7 +5524,7 @@ int match_delete(win_T *wp, int id, int perr) } rtype = VALID; } - free(cur); + xfree(cur); redraw_later(rtype); return 0; } @@ -5539,8 +5539,8 @@ void clear_matches(win_T *wp) while (wp->w_match_head != NULL) { m = wp->w_match_head->next; vim_regfree(wp->w_match_head->match.regprog); - free(wp->w_match_head->pattern); - free(wp->w_match_head); + xfree(wp->w_match_head->pattern); + xfree(wp->w_match_head); wp->w_match_head = m; } redraw_later(SOME_VALID); diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index a37c41294b..34669c5f29 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -3,8 +3,8 @@ -- be running. local helpers = require('test.functional.helpers') local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval -local eq, run, stop = helpers.eq, helpers.run, helpers.stop - +local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop +local nvim_prog = helpers.nvim_prog describe('server -> client', function() @@ -115,4 +115,44 @@ describe('server -> client', function() eq(expected, notified) end) end) + + describe('when the client is a recursive vim instance', function() + before_each(function() + nvim('command', "let vim = rpcstart('"..nvim_prog.."', ['--embed'])") + neq(0, eval('vim')) + end) + + after_each(function() nvim('command', 'call rpcstop(vim)') end) + + it('can send/recieve notifications and make requests', function() + nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") + + -- Wait for the notification to complete. + nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") + + eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')")) + end) + + it('can communicate buffers, tabpages, and windows', function() + eq({3}, eval("rpcrequest(vim, 'vim_get_tabpages')")) + eq({1}, eval("rpcrequest(vim, 'vim_get_windows')")) + + local buf = eval("rpcrequest(vim, 'vim_get_buffers')")[1] + eq(2, buf) + + eval("rpcnotify(vim, 'buffer_set_line', "..buf..", 0, 'SOME TEXT')") + nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait + + eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', "..buf..", 0)")) + + -- Call get_line_slice(buf, range [0,0], includes start, includes end) + eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_line_slice', "..buf..", 0, 0, 1, 1)")) + end) + + it('returns an error if the request failed', function() + local status, err = pcall(eval, "rpcrequest(vim, 'does-not-exist')") + eq(false, status) + eq(true, string.match(err, ': (.*)') == 'Failed to evaluate expression') + end) + end) end) diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index e7ca183a0e..c5d8f57008 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -55,6 +55,12 @@ local function basic_register_test(noblock) , stuff and some more some textsome some text, stuff and some more]]) + -- deleting a line does update "" + feed('ggdd""P') + expect([[ + , stuff and some more + some textsome some text, stuff and some more]]) + feed('ggw<c-v>jwyggP') if noblock then expect([[ @@ -72,6 +78,7 @@ end describe('the unnamed register', function() before_each(clear) it('works without provider', function() + eq('"', eval('v:register')) basic_register_test() end) end) @@ -227,6 +234,13 @@ describe('clipboard usage', function() a line]]) end) + it('supports v:register and getreg() without parameters', function() + eq('*', eval('v:register')) + execute("let g:test_clip['*'] = [['some block',''], 'b']") + eq('some block', eval('getreg()')) + eq('\02210', eval('getregtype()')) + end) + end) it('supports :put', function() diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua new file mode 100644 index 0000000000..d4c9477133 --- /dev/null +++ b/test/functional/ex_cmds/recover_spec.lua @@ -0,0 +1,71 @@ +-- Tests for :recover + +local helpers = require('test.functional.helpers') +local execute, eq, clear, eval, feed, expect, source = + helpers.execute, helpers.eq, helpers.clear, helpers.eval, helpers.feed, + helpers.expect, helpers.source + +describe(':recover', function() + before_each(clear) + + it('fails if given a non-existent swapfile', function() + local swapname = 'bogus-swapfile' + execute('recover '..swapname) -- This should not segfault. #2117 + eq('E305: No swap file found for '..swapname, eval('v:errmsg')) + end) + +end) + +describe(':preserve', function() + local swapdir = lfs.currentdir()..'/testdir_recover_spec' + before_each(function() + clear() + os.remove(swapdir) + lfs.mkdir(swapdir) + end) + after_each(function() + os.remove(swapdir) + end) + + it("saves to custom 'directory' and (R)ecovers (issue #1836)", function() + local testfile = 'testfile_recover_spec' + local init = [[ + set swapfile fileformat=unix undolevels=-1 + set directory^=]]..swapdir..[[// + ]] + + source(init) + execute('set swapfile fileformat=unix undolevels=-1') + -- Put swapdir at the start of the 'directory' list. #1836 + execute('set directory^='..swapdir..'//') + execute('edit '..testfile) + feed('isometext<esc>') + execute('preserve') + source('redir => g:swapname | swapname | redir END') + + local swappath1 = eval('g:swapname') + + --TODO(justinmk): this is an ugly hack to force `helpers` to support + --multiple sessions. + local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '--embed'}) + helpers.set_session(nvim2) + + source(init) + + -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. + execute('autocmd SwapExists * let v:swapchoice = "r"') + execute('silent edit '..testfile) + source('redir => g:swapname | swapname | redir END') + + local swappath2 = eval('g:swapname') + + -- swapfile from session 1 should end in .swp + assert(testfile..'.swp' == string.match(swappath1, '[^%%]+$')) + + -- swapfile from session 2 should end in .swo + assert(testfile..'.swo' == string.match(swappath2, '[^%%]+$')) + + expect('sometext') + end) + +end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 393b42dda5..27c94c34a8 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -18,6 +18,10 @@ if nvim_dir == nvim_prog then nvim_dir = "." end +-- Nvim "Unit Under Test" http://en.wikipedia.org/wiki/Device_under_test +local NvimUUT = {} +NvimUUT.__index = NvimUUT + local prepend_argv if os.getenv('VALGRIND') then @@ -49,6 +53,10 @@ end local session, loop_running, loop_stopped, last_error +local function set_session(s) + session = s +end + local function request(method, ...) local status, rv = session:request(method, ...) if not status then @@ -305,5 +313,6 @@ return { curwin = curwin, curtab = curtab, curbuf_contents = curbuf_contents, - wait = wait + wait = wait, + set_session = set_session } diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua index c517ae4c1b..df989b3ef9 100644 --- a/test/functional/job/job_spec.lua +++ b/test/functional/job/job_spec.lua @@ -61,7 +61,6 @@ describe('jobs', function() file:write("abc\0def\n") file:close() - -- v:job_data preserves NULs. nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)") eq({'notification', 'stdout', {0, {'abc\ndef', ''}}}, next_msg()) eq({'notification', 'exit', {0, 0}}, next_msg()) @@ -249,6 +248,52 @@ describe('jobs', function() eq({'notification', 'wait', {{-2}}}, next_msg()) end) + it('can be called recursively', function() + source([[ + let g:opts = {} + let g:counter = 0 + function g:opts.on_stdout(id, msg) + if self.state == 0 + if self.counter < 10 + call Run() + endif + let self.state = 1 + call jobsend(a:id, "line1\n") + elseif self.state == 1 + let self.state = 2 + call jobsend(a:id, "line2\n") + elseif self.state == 2 + let self.state = 3 + call jobsend(a:id, "line3\n") + else + call rpcnotify(g:channel, 'w', printf('job %d closed', self.counter)) + call jobclose(a:id, 'stdin') + endif + endfunction + function g:opts.on_exit() + call rpcnotify(g:channel, 'w', printf('job %d exited', self.counter)) + endfunction + function Run() + let g:counter += 1 + let j = copy(g:opts) + let j.state = 0 + let j.counter = g:counter + call jobwait([ + \ jobstart([&sh, '-c', 'echo ready; cat -'], j), + \ ]) + endfunction + ]]) + execute('call Run()') + local r + for i = 10, 1, -1 do + r = next_msg() + eq('job '..i..' closed', r[3][1]) + r = next_msg() + eq('job '..i..' exited', r[3][1]) + end + eq(10, nvim('eval', 'g:counter')) + end) + describe('with timeout argument', function() it('will return -1 if the wait timed out', function() source([[ @@ -292,7 +337,7 @@ describe('jobs', function() data[i] = data[i]:gsub('\n', '\000') end rv = table.concat(data, '\n') - rv = rv:gsub('\r\n$', '') + rv = rv:gsub('\r\n$', ''):gsub('^\r\n', '') if rv ~= '' then break end diff --git a/test/functional/legacy/038_virtual_replace_spec.lua b/test/functional/legacy/038_virtual_replace_spec.lua new file mode 100644 index 0000000000..239ffa47e6 --- /dev/null +++ b/test/functional/legacy/038_virtual_replace_spec.lua @@ -0,0 +1,58 @@ +-- Test Virtual replace mode. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('Virtual replace mode', function() + setup(clear) + + it('is working', function() + -- Make sure that backspace works, no matter what termcap is used. + execute('set t_kD=x7f t_kb=x08') + feed('ggdGa<cr>') + feed('abcdefghi<cr>') + feed('jk<tab>lmn<cr>') + feed('<Space><Space><Space><Space>opq<tab>rst<cr>') + feed('<C-d>uvwxyz<cr>') + feed('<esc>gg') + execute('set ai') + execute('set bs=2') + feed('gR0<C-d> 1<cr>') + feed('A<cr>') + feed('BCDEFGHIJ<cr>') + feed('<tab>KL<cr>') + feed('MNO<cr>') + feed('PQR<esc>G') + execute('ka') + feed('o0<C-d><cr>') + feed('abcdefghi<cr>') + feed('jk<tab>lmn<cr>') + feed('<Space><Space><Space><Space>opq<tab>rst<cr>') + feed('<C-d>uvwxyz<cr>') + feed([[<esc>'ajgR0<C-d> 1<cr>]]) + feed('A<cr>') + feed('BCDEFGHIJ<cr>') + feed('<tab>KL<cr>') + feed('MNO<cr>') + feed('PQR<C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><esc>:$<cr>') + feed('iab<tab>cdefghi<tab>jkl<esc>0gRAB......CDEFGHI.J<esc>o<esc>:<cr>') + feed('iabcdefghijklmnopqrst<esc>0gRAB<tab>IJKLMNO<tab>QR<esc>') + + -- Assert buffer contents. + expect([=[ + 1 + A + BCDEFGHIJ + KL + MNO + PQR + 1 + abcdefghi + jk lmn + opq rst + uvwxyz + AB......CDEFGHI.Jkl + AB IJKLMNO QRst]=]) + end) +end) diff --git a/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua new file mode 100644 index 0000000000..de628b0b52 --- /dev/null +++ b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua @@ -0,0 +1,147 @@ +-- Tests for regexp with multi-byte encoding and various magic settings. +-- Test matchstr() with a count and multi-byte chars. +-- +-- This test contains both "test44" and "test99" from the old test suite. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +-- Runs the test protocol with the given 'regexpengine' setting. In the old test +-- suite the test protocol was duplicated in test44 and test99, the only +-- difference being the 'regexpengine' setting. We've extracted it here. +local function run_test_with_regexpengine(regexpengine) + insert([[ + 1 a aa abb abbccc + 2 d dd dee deefff + 3 g gg ghh ghhiii + 4 j jj jkk jkklll + 5 m mm mnn mnnooo + 6 x ^aa$ x + 7 (a)(b) abbaa + 8 axx [ab]xx + 9 หม่x อมx + a อมx หม่x + b ちカヨは + c x ¬€x + d 天使x + e y + f z + g a啷bb + h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐẔ + i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ + j 0123❤x + k combinations]]) + + execute('set encoding=utf-8 termencoding=latin1') + execute('set re=' .. regexpengine) + + -- Lines 1-8. Exercise regexp search with various magic settings. On each + -- line the character on which the cursor is expected to land is deleted. + feed('/^1<cr>') + feed([[/a*b\{2}c\+/e<cr>x]]) + feed([[/\Md\*e\{2}f\+/e<cr>x]]) + execute('set nomagic') + feed([[/g\*h\{2}i\+/e<cr>x]]) + feed([[/\mj*k\{2}l\+/e<cr>x]]) + feed([[/\vm*n{2}o+/e<cr>x]]) + feed([[/\V^aa$<cr>x]]) + execute('set magic') + feed([[/\v(a)(b)\2\1\1/e<cr>x]]) + feed([[/\V[ab]\(\[xy]\)\1<cr>x]]) + + -- Line 9. Search for multi-byte character without combining character. + feed('/ม<cr>x') + + -- Line a. Search for multi-byte character with combining character. + feed('/ม่<cr>x') + + -- Line b. Find word by change of word class. + -- (The "<" character in this test step seemed to confuse our "feed" test + -- helper, which is why we've resorted to "execute" here.) + execute([[/ち\<カヨ\>は]]) + feed('x') + + -- Lines c-i. Test \%u, [\u], and friends. + feed([[/\%u20ac<cr>x]]) + feed([[/[\u4f7f\u5929]\+<cr>x]]) + feed([[/\%U12345678<cr>x]]) + feed([[/[\U1234abcd\u1234\uabcd]<cr>x]]) + feed([[/\%d21879b<cr>x]]) + feed('/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* ' .. + '[[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* ' .. + '[[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* ' .. + '[[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e<cr>x') + feed('/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* ' .. + '[[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* ' .. + '[[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* ' .. + '[[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e<cr>x') + + -- Line j. Test backwards search from a multi-byte character. + feed('/x<cr>x') + feed('?.<cr>x') + + -- Line k. Test substitution with combining characters by executing register + -- contents. + execute([[let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g']]) + execute('@w') + + -- Additional tests. Test matchstr() with multi-byte characters. + feed('G') + execute([[put =matchstr(\"אבגד\", \".\", 0, 2)]]) -- ב + execute([[put =matchstr(\"אבגד\", \"..\", 0, 2)]]) -- בג + execute([[put =matchstr(\"אבגד\", \".\", 0, 0)]]) -- א + execute([[put =matchstr(\"אבגד\", \".\", 4, -1)]]) -- ג + + -- Test that a search with "/e" offset wraps around at the end of the buffer. + execute('new') + execute([[$put =['dog(a', 'cat('] ]]) + feed('/(/e+<cr>') + feed('"ayn') + execute('bd!') + execute([[$put ='']]) + feed('G"ap') + + -- Assert buffer contents. + expect([[ + 1 a aa abb abbcc + 2 d dd dee deeff + 3 g gg ghh ghhii + 4 j jj jkk jkkll + 5 m mm mnn mnnoo + 6 x aa$ x + 7 (a)(b) abba + 8 axx ab]xx + 9 หม่x อx + a อมx หx + b カヨは + c x ¬x + d 使x + e y + f z + g abb + h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐ + i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑ + j 012❤ + k œ̄ṣ́m̥̄ᾱ̆́ + ב + בג + א + ג + a + cat(]]) +end + +describe('multi-byte regexp search with magic settings', function() + before_each(clear) + + it('is working with regexpengine=1', function() + -- The old test44. + run_test_with_regexpengine(1) + end) + + it('is working with regexpengine=2', function() + -- The old test99. + run_test_with_regexpengine(2) + end) +end) diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua index 3d0375312d..620df97aac 100644 --- a/test/functional/legacy/051_highlight_spec.lua +++ b/test/functional/legacy/051_highlight_spec.lua @@ -24,10 +24,10 @@ describe(':highlight', function() guifg=Blue | EndOfBuffer xxx links to NonText| | + TermCursor xxx cterm=reverse | + gui=reverse | + TermCursorNC xxx cleared | NonText xxx ctermfg=12 | - gui=bold | - guifg=Blue | - Directory xxx ctermfg=4 | -- More --^ | ]]) feed('q') diff --git a/test/functional/legacy/078_swapfile_recover_spec.lua b/test/functional/legacy/078_swapfile_recover_spec.lua new file mode 100644 index 0000000000..e250c91441 --- /dev/null +++ b/test/functional/legacy/078_swapfile_recover_spec.lua @@ -0,0 +1,80 @@ +-- Inserts 10000 lines with text to fill the swap file with two levels of +-- pointer blocks. Then recovers from the swap file and checks all text is +-- restored. We need about 10000 lines of 100 characters to get two levels of +-- pointer blocks. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect, source = helpers.clear, helpers.execute, helpers.expect, helpers.source +local eval = helpers.eval + +describe('78', function() + setup(clear) + teardown(function() + os.remove(".Xtest.swp") + os.remove(".Xtest.swo") + end) + + it('is working', function() + source([=[ + set swapfile fileformat=unix undolevels=-1 + e! Xtest + let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789" + let i = 1 + let linecount = 10000 + while i <= linecount | call append(i - 1, i . text) | let i += 1 | endwhile + preserve + + " Get the name of the swap file, and clean up the :redir capture. + redir => g:swapname | swapname | redir END + let g:swapname = substitute(g:swapname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', 'g') + let g:swapname = fnameescape(g:swapname) + + " Make a copy of the swap file in Xswap + set bin + exe 'sp ' . g:swapname + w! Xswap + + set nobin + new + only! + bwipe! Xtest + call rename('Xswap', g:swapname) + + "TODO(jkeyes): without 'silent', this hangs the test " at message: + " 'Recovery completed. You should check if everything is OK.' + silent recover Xtest + + call delete(g:swapname) + new + call append(0, 'recovery start') + wincmd w + + let g:linedollar = line('$') + if g:linedollar < linecount + wincmd w + call append(line('$'), "expected " . linecount + \ . " lines but found only " . g:linedollar) + wincmd w + let linecount = g:linedollar + endif + + let i = 1 + while i <= linecount + if getline(i) != i . text + exe 'wincmd w' + call append(line('$'), i . ' differs') + exe 'wincmd w' + endif + let i += 1 + endwhile + q! + call append(line('$'), 'recovery end') + ]=]) + + expect([[ + recovery start + + recovery end]]) + end) +end) diff --git a/test/functional/server/server_spec.lua b/test/functional/server/server_spec.lua new file mode 100644 index 0000000000..5dd8197d52 --- /dev/null +++ b/test/functional/server/server_spec.lua @@ -0,0 +1,42 @@ + +local helpers = require('test.functional.helpers') +local nvim, eq, neq, ok, eval + = helpers.nvim, helpers.eq, helpers.neq, helpers.ok, helpers.eval +local clear = helpers.clear + +describe('server*() functions', function() + before_each(clear) + + it('set $NVIM_LISTEN_ADDRESS on first serverstart()', function() + -- Ensure the listen address is unset. + nvim('command', 'let $NVIM_LISTEN_ADDRESS = ""') + nvim('command', 'let s = serverstart()') + eq(1, eval('$NVIM_LISTEN_ADDRESS == s')) + nvim('command', 'call serverstop(s)') + eq(0, eval('$NVIM_LISTEN_ADDRESS == s')) + end) + + it('let the user retrieve the list of servers', function() + -- There should already be at least one server. + local n = eval('len(serverlist())') + + -- Add a few + local servs = {'should-not-exist', 'another-one-that-shouldnt'} + for _, s in ipairs(servs) do + eq(s, eval('serverstart("'..s..'")')) + end + + local new_servs = eval('serverlist()') + + -- Exactly #servs servers should be added. + eq(n + #servs, #new_servs) + -- The new servers should be at the end of the list. + for i = 1, #servs do + eq(servs[i], new_servs[i + n]) + nvim('command', 'call serverstop("'..servs[i]..'")') + end + -- After calling serverstop() on the new servers, they should no longer be + -- in the list. + eq(n, eval('len(serverlist())')) + end) +end) diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua index c9ae92048c..922770ad42 100644 --- a/test/functional/shell/viml_system_spec.lua +++ b/test/functional/shell/viml_system_spec.lua @@ -110,7 +110,7 @@ describe('system()', function() ~ | ~ | ~ | - Type :quit<Enter> to exit Vim | + Type :quit<Enter> to exit Nvim | ]]) end) end) @@ -276,7 +276,7 @@ describe('systemlist()', function() ~ | ~ | ~ | - Type :quit<Enter> to exit Vim | + Type :quit<Enter> to exit Nvim | ]]) end) end) diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 857679c4b3..ffdfec4428 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -2,7 +2,9 @@ local helpers = require('test.functional.helpers') local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim -local wait, execute, eq = helpers.wait, helpers.execute, helpers.eq +local wait = helpers.wait +local eval, execute, source = helpers.eval, helpers.execute, helpers.source +local eq, neq = helpers.eq, helpers.neq describe('terminal buffer', function() @@ -155,5 +157,44 @@ describe('terminal buffer', function() :bnext | ]]) end) + + it('handles loss of focus gracefully', function() + -- Temporarily change the statusline to avoid printing the file name, which + -- varies be where the test is run. + nvim('set_option', 'statusline', '==========') + execute('set laststatus=0') + + -- Save the buffer number of the terminal for later testing. + local tbuf = eval('bufnr("%")') + + source([[ + function! SplitWindow() + new + call feedkeys("iabc\<Esc>") + endfunction + + startinsert + call jobstart(['sh', '-c', 'exit'], {'on_exit': function("SplitWindow")}) + call feedkeys("\<C-\>", 't') " vim will expect <C-n>, but be exited out of + " the terminal before it can be entered. + ]]) + + -- We should be in a new buffer now. + screen:expect([[ + ab^c | + ~ | + ========== | + rows: 2, cols: 50 | + {2: } | + {1:========== }| + | + ]]) + + neq(tbuf, eval('bufnr("%")')) + execute('quit!') -- Should exit the new window, not the terminal. + eq(tbuf, eval('bufnr("%")')) + + execute('set laststatus=1') -- Restore laststatus to the default. + end) end) diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index 3e3f9cbf4f..cecb33de7c 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -129,10 +129,8 @@ describe('cursor with customized highlighting', function() before_each(function() clear() - nvim('set_var', 'terminal_focused_cursor_highlight', 'CursorFocused') - nvim('set_var', 'terminal_unfocused_cursor_highlight', 'CursorUnfocused') - nvim('command', 'highlight CursorFocused ctermfg=45 ctermbg=46') - nvim('command', 'highlight CursorUnfocused ctermfg=55 ctermbg=56') + nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE') + nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE') screen = Screen.new(50, 7) screen:set_default_attr_ids({ [1] = {foreground = 45, background = 46}, diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 631dc579d3..1bc6057a0b 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -34,6 +34,8 @@ local function disable_mouse() feed_termcode('[?1002l') end local function screen_setup(extra_height) + nvim('command', 'highlight TermCursor cterm=reverse') + nvim('command', 'highlight TermCursorNC ctermbg=11') nvim('set_var', 'terminal_scrollback_buffer_size', 10) if not extra_height then extra_height = 0 end local screen = Screen.new(50, 7 + extra_height) diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index b8f6214f8f..4def4dd7f8 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -50,6 +50,20 @@ describe('terminal mouse', function() ]]) end) + it('will exit focus after <C-\\>, then scrolled', function() + feed('<C-\\>') + feed('<MouseDown><0,0>') + screen:expect([[ + line23 | + line24 | + line25 | + line26 | + line27 | + ^line28 | + | + ]]) + end) + describe('with mouse events enabled by the program', function() before_each(function() thelpers.enable_mouse() diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua index 5896f5ddd4..9d936c2564 100644 --- a/test/unit/os/env_spec.lua +++ b/test/unit/os/env_spec.lua @@ -3,6 +3,7 @@ local helpers = require('test.unit.helpers') local cimport = helpers.cimport local internalize = helpers.internalize local eq = helpers.eq +local neq = helpers.neq local ffi = helpers.ffi local lib = helpers.lib local cstr = helpers.cstr @@ -21,6 +22,10 @@ describe('env function', function() return env.os_setenv((to_cstr(name)), (to_cstr(value)), override) end + function os_unsetenv(name, value, override) + return env.os_unsetenv((to_cstr(name))) + end + function os_getenv(name) local rval = env.os_getenv((to_cstr(name))) if rval ~= NULL then @@ -68,6 +73,18 @@ describe('env function', function() end) end) + describe('os_unsetenv', function() + it('unsets environment variable', function() + local name = 'TEST_UNSETENV' + local value = 'TESTVALUE' + os_setenv(name, value, 1) + os_unsetenv(name) + neq(os_getenv(name), value) + -- Depending on the platform the var might be unset or set as '' + assert.True(os_getenv(name) == nil or os_getenv(name) == '') + end) + end) + describe('os_getenvname_at_index', function() it('returns names of environment variables', function() local test_name = 'NEOVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1N' diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 13546a6183..261d797624 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -425,19 +425,18 @@ describe('more path function', function() return ffi.string(c_file) end + before_each(function() lfs.mkdir('CamelCase') end) + after_each(function() lfs.rmdir('CamelCase') end) + if ffi.os == 'Windows' or ffi.os == 'OSX' then it('Corrects the case of file names in Mac and Windows', function() - lfs.mkdir('CamelCase') eq('CamelCase', fix_case('camelcase')) eq('CamelCase', fix_case('cAMELcASE')) - lfs.rmdir('CamelCase') end) else it('does nothing on Linux', function() - lfs.mkdir('CamelCase') eq('camelcase', fix_case('camelcase')) eq('cAMELcASE', fix_case('cAMELcASE')) - lfs.mkdir('CamelCase') end) end end) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 60a53ace8f..fde367bc72 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -13,6 +13,7 @@ set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads") option(USE_BUNDLED "Use bundled dependencies." ON) +option(USE_BUNDLED_JEMALLOC "Use the bundled jemalloc." ${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}) @@ -73,6 +74,8 @@ set(LIBTERMKEY_SHA256 21846369081e6c9a0b615f4b3889c4cb809321c5ccc6e6c1640eb138f1 set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/1b745d29d45623aa8d22a7b9288c7b0e331c7088.tar.gz) set(LIBVTERM_SHA256 3fc75908256c0d158d6c2a32d39f34e86bfd26364f5404b7d9c03bb70cdc3611) +set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/archive/3.6.0.tar.gz) +set(JEMALLOC_SHA256 68175f729423305dc8573cb093025a8db525e1956583c7c5924416a9abaaacb6) if(USE_BUNDLED_UNIBILIUM) include(BuildUnibilium) @@ -102,6 +105,10 @@ if(USE_BUNDLED_LUAROCKS) include(BuildLuarocks) endif() +if(USE_BUNDLED_JEMALLOC) + include(BuildJeMalloc) +endif() + add_custom_target(third-party ALL COMMAND ${CMAKE_COMMAND} -E touch .third-party DEPENDS ${THIRD_PARTY_DEPS}) diff --git a/third-party/cmake/BuildJeMalloc.cmake b/third-party/cmake/BuildJeMalloc.cmake new file mode 100644 index 0000000000..ceb7de41e9 --- /dev/null +++ b/third-party/cmake/BuildJeMalloc.cmake @@ -0,0 +1,19 @@ +ExternalProject_Add(jemalloc + PREFIX ${DEPS_BUILD_DIR} + URL ${JEMALLOC_URL} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/jemalloc + DOWNLOAD_COMMAND ${CMAKE_COMMAND} + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/jemalloc + -DURL=${JEMALLOC_URL} + -DEXPECTED_SHA256=${JEMALLOC_SHA256} + -DTARGET=jemalloc + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND sh ${DEPS_BUILD_DIR}/src/jemalloc/autogen.sh && + ${DEPS_BUILD_DIR}/src/jemalloc/configure --with-jemalloc-prefix=je_ + --enable-cc-silence CC=${DEPS_C_COMPILER} --prefix=${DEPS_INSTALL_DIR} + BUILD_COMMAND "" + INSTALL_COMMAND ${MAKE_PRG} install_include install_lib) + +list(APPEND THIRD_PARTY_DEPS jemalloc) diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake index baa3425918..fabceac3d8 100644 --- a/third-party/cmake/BuildLuarocks.cmake +++ b/third-party/cmake/BuildLuarocks.cmake @@ -56,9 +56,10 @@ add_custom_target(stable-busted-deps add_custom_command(OUTPUT ${DEPS_BIN_DIR}/busted COMMAND ${DEPS_BIN_DIR}/luarocks - ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/master/busted-scm-0.rockspec CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER} - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/utfTerminalDetailed.lua - ${DEPS_INSTALL_DIR}/share/lua/5.1/busted/outputHandlers + ## Drop back to: + ## https://raw.githubusercontent.com/Olivine-Labs/busted/master/busted-scm-0.rockspec + ## once the spec file is fixed in busted. + ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/f803173cc136f7370f7416254eaf3bada01b04a9/busted-scm-0.rockspec CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER} DEPENDS stable-busted-deps) add_custom_target(busted DEPENDS ${DEPS_BIN_DIR}/busted) diff --git a/third-party/utfTerminalDetailed.lua b/third-party/utfTerminalDetailed.lua deleted file mode 100644 index 5a52dfa958..0000000000 --- a/third-party/utfTerminalDetailed.lua +++ /dev/null @@ -1,27 +0,0 @@ --- busted output handler that immediately prints file and test names before --- tests are executed. It simplifies identifying which tests are --- hanging/crashing -if package.config:sub(1,1) == '\\' and not os.getenv("ANSICON") then - -- Disable colors on Windows. - colors = setmetatable({}, {__index = function() return function(s) return s end end}) -else - colors = require 'term.colors' -end - -return function(options, busted) - local handler = require 'busted.outputHandlers.utfTerminal'(options, busted) - - handler.fileStart = function(name) - io.write('\n' .. colors.cyan(name) .. ':') - end - - handler.testStart = function(element, parent, status, debug) - io.write('\n ' .. handler.getFullName(element) .. ' ... ') - io.flush() - end - - busted.subscribe({ 'file', 'start' }, handler.fileStart) - busted.subscribe({ 'test', 'start' }, handler.testStart) - - return handler -end |