diff options
166 files changed, 3396 insertions, 7221 deletions
| diff --git a/CMakeLists.txt b/CMakeLists.txt index abb2bdf248..b44acd4b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ if(TRAVIS_CI_BUILD)    add_definitions(-Werror)  endif() +add_definitions(-DINCLUDE_GENERATED_DECLARATIONS) +  add_definitions(-DHAVE_CONFIG_H)  if(CMAKE_BUILD_TYPE MATCHES Debug)    # cmake automatically appends -g to the compiler flags diff --git a/scripts/finddeclarations.pl b/scripts/finddeclarations.pl new file mode 100755 index 0000000000..1b1a57b9b7 --- /dev/null +++ b/scripts/finddeclarations.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +if ($ARGV[0] eq '--help') { +  print << "EOF"; +Usage: + +  $0 definitions.c +EOF +  exit; +} + +my ($cfname, $sfname, $gfname, $cpp) = @ARGV; + +my $F; + +open $F, "<", $cfname; + +my $text = join "", <$F>; + +close $F; + +my $s = qr/(?>\s*)/aso; +my $w = qr/(?>\w+)/aso; +my $argname = qr/$w(?:\[(?>\w+)\])?/aso; +my $type_regex = qr/(?:$w$s\**$s)+/aso; +my $arg_regex = qr/(?:$type_regex$s$argname)/aso; + +while ($text =~ / +    (?<=\n)         # Definition starts at the start of line +    $type_regex     # Return type +    $s$w            # Function name +    $s\($s +    (?: +       $arg_regex(?:$s,$s$arg_regex)*+ +       ($s,$s\.\.\.)?                   # varargs function +      |void +    )? +    $s\) +    (?:$s FUNC_ATTR_$w(?:\((?>[^)]*)\))?)*+ # Optional attributes +    (?=$s;)         # Ending semicolon +  /axsogp) { +  my $match = "${^MATCH}"; +  my $s = "${^PREMATCH}"; +  $s =~ s/[^\n]++//g; +  my $line = 1 + length $s; +  print "${cfname}:${line}: $match\n"; +} diff --git a/scripts/gendeclarations.lua b/scripts/gendeclarations.lua new file mode 100755 index 0000000000..311ed8b527 --- /dev/null +++ b/scripts/gendeclarations.lua @@ -0,0 +1,232 @@ +#!/usr/bin/lua + +local fname = arg[1] +local static_fname = arg[2] +local non_static_fname = arg[3] +local cpp = arg[4] + +cpp = cpp:gsub(' %-DINCLUDE_GENERATED_DECLARATIONS ', ' ') + +local lpeg = require('lpeg') + +local fold = function (func, ...) +  local result = nil +  for i, v in ipairs({...}) do +    if result == nil then +      result = v +    else +      result = func(result, v) +    end +  end +  return result +end + +local folder = function (func) +  return function (...) +    return fold(func, ...) +  end +end + +local lit = lpeg.P +local set = function(...) +  return lpeg.S(fold(function (a, b) return a .. b end, ...)) +end +local any_character = lpeg.P(1) +local rng = function(s, e) return lpeg.R(s .. e) end +local concat = folder(function (a, b) return a * b end) +local branch = folder(function (a, b) return a + b end) +local one_or_more = function(v) return v ^ 1 end +local two_or_more = function(v) return v ^ 2 end +local any_amount = function(v) return v ^ 0 end +local one_or_no = function(v) return v ^ -1 end +local look_behind = lpeg.B +local look_ahead = function(v) return #v end +local neg_look_ahead = function(v) return -v end +local neg_look_behind = function(v) return -look_behind(v) end + +local w = branch( +  rng('a', 'z'), +  rng('A', 'Z'), +  lit('_') +) +local aw = branch( +  w, +  rng('0', '9') +) +local s = set(' ', '\n', '\t') +local raw_word = concat(w, any_amount(aw)) +local right_word = concat( +  raw_word, +  neg_look_ahead(aw) +) +local word = concat( +  neg_look_behind(aw), +  right_word +) +local spaces = any_amount(branch( +  s, +  -- Comments are really handled by preprocessor, so the following is not needed +  concat( +    lit('/*'), +    any_amount(concat( +      neg_look_ahead(lit('*/')), +      any_character +    )), +    lit('*/') +  ), +  concat( +    lit('//'), +    any_amount(concat( +      neg_look_ahead(lit('\n')), +      any_character +    )), +    lit('\n') +  ) +)) +local typ_part = concat( +  word, +  any_amount(concat( +    spaces, +    lit('*') +  )), +  spaces +) +local typ = one_or_more(typ_part) +local typ_id = two_or_more(typ_part) +local arg = typ_id         -- argument name is swallowed by typ +local pattern = concat( +  typ_id,                  -- return type with function name +  spaces, +  lit('('), +  spaces, +  one_or_no(branch(        -- function arguments +    concat( +      arg,                 -- first argument, does not require comma +      any_amount(concat(   -- following arguments, start with a comma +        spaces, +        lit(','), +        spaces, +        arg, +        any_amount(concat( +          lit('['), +          spaces, +          any_amount(aw), +          spaces, +          lit(']') +        )) +      )), +      one_or_no(concat( +        spaces, +        lit(','), +        spaces, +        lit('...') +      )) +    ), +    lit('void')            -- also accepts just void +  )), +  spaces, +  lit(')'), +  any_amount(concat(       -- optional attributes +    spaces, +    lit('FUNC_ATTR_'), +    any_amount(aw), +    one_or_no(concat(      -- attribute argument +      spaces, +      lit('('), +      any_amount(concat( +        neg_look_ahead(lit(')')), +        any_character +      )), +      lit(')') +    )) +  )), +  look_ahead(concat(       -- definition must be followed by "{" +    spaces, +    lit('{') +  )) +) + +if fname == '--help' then +  print'Usage:' +  print() +  print'  gendeclarations.lua definitions.c static.h non-static.h "cc -E …"' +  os.exit() +end + +local pipe = io.popen(cpp .. ' -DDO_NOT_DEFINE_EMPTY_ATTRIBUTES ' .. fname, 'r') +local text = pipe:read('*a') +if not pipe:close() then +  os.exit(2) +end + +local header = [[ +#ifndef DEFINE_FUNC_ATTRIBUTES +# define DEFINE_FUNC_ATTRIBUTES +#endif +#include "nvim/func_attr.h" +#undef DEFINE_FUNC_ATTRIBUTES +]] + +local footer = [[ +#include "nvim/func_attr.h" +]] + +local non_static = header +local static = header + +local filepattern = '^# %d+ "[^"]-/?([^"/]+)"' +local curfile + +init = 0 +curfile = nil +neededfile = fname:match('[^/]+$') +while init ~= nil do +  init = text:find('\n', init) +  if init == nil then +    break +  end +  init = init + 1 +  if text:sub(init, init) == '#' then +    file = text:match(filepattern, init) +    if file ~= nil then +      curfile = file +    end +  elseif curfile == neededfile then +    s = init +    e = pattern:match(text, init) +    if e ~= nil then +      local declaration = text:sub(s, e - 1) +      -- Comments are really handled by preprocessor, so the following is not  +      -- needed +      declaration = declaration:gsub('/%*.-%*/', '') +      declaration = declaration:gsub('//.-\n', '\n') + +      declaration = declaration:gsub('\n', ' ') +      declaration = declaration:gsub('%s+', ' ') +      declaration = declaration:gsub(' ?%( ?', '(') +      declaration = declaration:gsub(' ?%) ?', ')') +      declaration = declaration:gsub(' ?, ?', ', ') +      declaration = declaration:gsub(' ?(%*+) ?', ' %1') +      declaration = declaration:gsub(' ?(FUNC_ATTR_)', ' %1') +      declaration = declaration:gsub(' $', '') +      declaration = declaration .. ';\n' +      if text:sub(s, s + 5) == 'static' then +        static = static .. declaration +      else +        non_static = non_static .. declaration +      end +    end +  end +end + +non_static = non_static .. footer +static = static .. footer + +local F +F = io.open(static_fname, 'w') +F:write(static) +F:close() + +F = io.open(non_static_fname, 'w') +F:write(non_static) +F:close() diff --git a/scripts/movedocs.pl b/scripts/movedocs.pl new file mode 100755 index 0000000000..923c633f13 --- /dev/null +++ b/scripts/movedocs.pl @@ -0,0 +1,180 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +if ($ARGV[0] eq '--help') { +  print << "EOF"; +Usage: + +  $0 file.h file.c + +Removes documentation attached to function declarations in file.h and adds them  +to function definitions found in file.c. + +  $0 file.c + +Moves documentation attached to function declaration present in the same file as  +the definition. +EOF +  exit 0; +} + +my $hfile = shift @ARGV; +my @cfiles = @ARGV; + +my %docs = (); +my $F; + +sub write_lines { +  my $file = shift; +  my @lines = @_; + +  my $F; + +  open $F, '>', $file; +  print $F (join "", @lines); +  close $F; +} + +if (@cfiles) { +  open $F, '<', $hfile +    or die "Failed to open $hfile."; + +  my @hlines = (); + +  my $lastdoc = ''; + +  while (<$F>) { +    if (/^\/\/\/?/) { +      $lastdoc .= $_; +    } elsif (/^\S.*?(\w+)\(.*(?:,|\);?|FUNC_ATTR_\w+;?)$/) { +      die "Documentation for $1 was already defined" if (defined $docs{$1}); +      if ($lastdoc ne '') { +        $docs{$1} = $lastdoc; +        $lastdoc = ''; +      } +      push @hlines, $_; +    } elsif ($lastdoc ne '') { +      push @hlines, $lastdoc; +      $lastdoc = ''; +      push @hlines, $_; +    } else { +      push @hlines, $_; +    } +  } + +  close $F; + +  my %clines_hash = (); + +  for my $cfile (@cfiles) { +    open $F, '<', $cfile +      or die "Failed to open $cfile."; + +    my @clines = (); + +    while (<$F>) { +      if (/^\S.*?(\w+)\(.*[,)]$/ and defined $docs{$1}) { +        push @clines, $docs{$1}; +        delete $docs{$1}; +      } elsif (/^(?!static\s)\S.*?(\w+)\(.*[,)]$/ and not defined $docs{$1}) { +        print STDERR "Documentation not defined for $1\n"; +      } +      push @clines, $_; +    } + +    close $F; + +    $clines_hash{$cfile} = \@clines; +  } + +  while (my ($func, $value) = each %docs) { +    die "Function not found: $func\n"; +  } + +  write_lines($hfile, @hlines); +  while (my ($cfile, $clines) = each %clines_hash) { +    write_lines($cfile, @$clines); +  } +} else { +  open $F, '<', $hfile; + +  my @lines; + +  my $lastdoc = ''; +  my $defstart = ''; +  my $funcname; + +  sub clear_lastdoc { +    if ($lastdoc ne '') { +      push @lines, $lastdoc; +      $lastdoc = ''; +    } +  } + +  sub record_lastdoc { +    my $funcname = shift; +    if ($lastdoc ne '') { +      $docs{$funcname} = $lastdoc; +      $lastdoc = ''; +    } +  } + +  sub add_doc { +    my $funcname = shift; +    if (defined $docs{$funcname}) { +      push @lines, $docs{$funcname}; +      delete $docs{$funcname}; +    } +  } + +  sub clear_defstart { +    push @lines, $defstart; +    $defstart = ''; +  } + +  while (<$F>) { +    if (/\/\*/ .. /\*\// and not /\/\*.*?\*\//) { +      push @lines, $_; +    } elsif (/^\/\/\/?/) { +      $lastdoc .= $_; +    } elsif (/^\S.*?(\w+)\(.*(?:,|(\);?))$/) { +      if (not $2) { +        $defstart .= $_; +        $funcname = $1; +      } elsif ($2 eq ');') { +        record_lastdoc $1; +        push @lines, $_; +      } elsif ($2 eq ')') { +        clear_lastdoc; +        add_doc $1; +        push @lines, $_; +      } +    } elsif ($defstart ne '') { +      $defstart .= $_; +      if (/[{}]/) { +        clear_lastdoc; +        clear_defstart; +      } elsif (/\);$/) { +        record_lastdoc $funcname; +        clear_defstart; +      } elsif (/\)$/) { +        clear_lastdoc; +        add_doc $funcname; +        clear_defstart; +      } +    } else { +      clear_lastdoc; +      push @lines, $_; +    } +  } + +  close $F; + +  while (my ($func, $value) = each %docs) { +    die "Function not found: $func\n"; +  } + +  write_lines($hfile, @lines); +} diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua index 8d7bb8ea59..c8a09c8e96 100644 --- a/scripts/msgpack-gen.lua +++ b/scripts/msgpack-gen.lua @@ -94,7 +94,9 @@ output:write([[  ]])  for i = 1, #headers do -  output:write('\n#include "nvim/'..headers[i]..'"') +  if headers[i]:sub(-12) ~= '.generated.h' then +    output:write('\n#include "nvim/'..headers[i]..'"') +  end  end  output:write([[ diff --git a/scripts/stripdecls.py b/scripts/stripdecls.py new file mode 100755 index 0000000000..34be2a1578 --- /dev/null +++ b/scripts/stripdecls.py @@ -0,0 +1,141 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8: + +from __future__ import print_function, unicode_literals, division + +from clang.cindex import Index, CursorKind +from collections import namedtuple, OrderedDict, defaultdict +import sys +import os + + +DECL_KINDS = { +  CursorKind.FUNCTION_DECL, +} + + +Strip = namedtuple('Strip', 'start_line start_column end_line end_column') + + +def main(progname, cfname, only_static, move_all): +  only_static = False + +  cfname = os.path.abspath(os.path.normpath(cfname)) + +  hfname1 = os.path.splitext(cfname)[0] + os.extsep + 'h' +  hfname2 = os.path.splitext(cfname)[0] + '_defs' + os.extsep + 'h' + +  files_to_modify = (cfname, hfname1, hfname2) + +  index = Index.create() +  src_dirname = os.path.join(os.path.dirname(__file__), '..', 'src') +  src_dirname = os.path.abspath(os.path.normpath(src_dirname)) +  relname = os.path.join(src_dirname, 'nvim') +  unit = index.parse(cfname, args=('-I' + src_dirname, +                                   '-DUNIX', +                                   '-DEXITFREE', +                                   '-DFEAT_USR_CMDS', +                                   '-DFEAT_CMDL_COMPL', +                                   '-DFEAT_COMPL_FUNC', +                                   '-DPROTO', +                                   '-DUSE_MCH_ERRMSG')) +  cursor = unit.cursor + +  tostrip = defaultdict(OrderedDict) +  definitions = set() + +  for child in cursor.get_children(): +    if not (child.location and child.location.file): +      continue +    fname = os.path.abspath(os.path.normpath(child.location.file.name)) +    if fname not in files_to_modify: +      continue +    if child.kind not in DECL_KINDS: +      continue +    if only_static and next(child.get_tokens()).spelling == 'static': +      continue + +    if child.is_definition() and fname == cfname: +      definitions.add(child.spelling) +    else: +      stripdict = tostrip[fname] +      assert(child.spelling not in stripdict) +      stripdict[child.spelling] = Strip( +        child.extent.start.line, +        child.extent.start.column, +        child.extent.end.line, +        child.extent.end.column, +      ) + +  for (fname, stripdict) in tostrip.items(): +    if not move_all: +      for name in set(stripdict) - definitions: +        stripdict.pop(name) + +    if not stripdict: +      continue + +    if fname.endswith('.h'): +      is_h_file = True +      include_line = next(reversed(stripdict.values())).start_line + 1 +    else: +      is_h_file = False +      include_line = next(iter(stripdict.values())).start_line + +    lines = None +    generated_existed = os.path.exists(fname + '.generated.h') +    with open(fname, 'rb') as F: +      lines = list(F) + +    stripped = [] + +    for name, position in reversed(stripdict.items()): +      sl = slice(position.start_line - 1, position.end_line) +      if is_h_file: +        include_line -= sl.stop - sl.start +      stripped += lines[sl] +      lines[sl] = () + +    if not generated_existed: +      lines[include_line:include_line] = [ +        '#ifdef INCLUDE_GENERATED_DECLARATIONS\n', +        '# include "{0}.generated.h"\n'.format(os.path.relpath(fname, relname)), +        '#endif\n', +      ] + +    with open(fname, 'wb') as F: +      F.writelines(lines) + + +if __name__ == '__main__': +  progname = sys.argv[0] +  args = sys.argv[1:] +  if not args or '--help' in args: +    print('Usage:') +    print('') +    print('  {0} [--static [--all]] file.c...'.format(progname)) +    print('') +    print('Stripts all declarations from file.c, file.h and file_defs.h.') +    print('If --static argument is given then only static declarations are') +    print('stripped. Declarations are stripped only if corresponding') +    print('definition is found unless --all argument was given.') +    print('') +    print('Note: it is assumed that static declarations starts with "static"') +    print('      keyword.') +    sys.exit(0 if args else 1) + +  if args[0] == '--static': +    only_static = True +    args = args[1:] +  else: +    only_static = False + +  if args[0] == '--all': +    move_all = True +    args = args[1:] +  else: +    move_all = False + +  for cfname in args: +    print('Processing {0}'.format(cfname)) +    main(progname, cfname, only_static, move_all) diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index e956328061..dd5989f96f 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -5,16 +5,20 @@ set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua)  file(GLOB API_HEADERS api/*.h)  set(MSGPACK_RPC_HEADER ${PROJECT_SOURCE_DIR}/src/nvim/os/msgpack_rpc.h)  set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c) +set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua) +set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include) -file(MAKE_DIRECTORY ${GENERATED_DIR}) +include_directories(${GENERATED_DIR}) +include_directories(${GENERATED_INCLUDES_DIR}) -add_custom_command(OUTPUT ${MSGPACK_DISPATCH} -  COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_HEADERS} ${MSGPACK_DISPATCH} -  DEPENDS -    ${API_HEADERS} -    ${MSGPACK_RPC_HEADER} -    ${DISPATCH_GENERATOR} -    ) +file(MAKE_DIRECTORY ${GENERATED_DIR}) +file(MAKE_DIRECTORY ${GENERATED_DIR}/os) +file(MAKE_DIRECTORY ${GENERATED_DIR}/api) +file(MAKE_DIRECTORY ${GENERATED_DIR}/api/private) +file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}) +file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/os) +file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/api) +file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/api/private)  file( GLOB NEOVIM_SOURCES *.c ) @@ -26,8 +30,6 @@ foreach(sfile ${NEOVIM_SOURCES})  endforeach()  list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove}) -list(APPEND NEOVIM_SOURCES "${PROJECT_BINARY_DIR}/config/auto/pathdef.c") -list(APPEND NEOVIM_SOURCES "${MSGPACK_DISPATCH}")  file( GLOB OS_SOURCES os/*.c )  file( GLOB API_SOURCES api/*.c ) @@ -78,6 +80,57 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")    endif()  endif() +get_directory_property(gen_cdefs COMPILE_DEFINITIONS) +foreach(gen_cdef ${gen_cdefs}) +  set(gen_cflags "${gen_cflags} -D${gen_cdef}") +endforeach() + +get_directory_property(gen_includes INCLUDE_DIRECTORIES) +foreach(gen_include ${gen_includes}) +  set(gen_cflags "${gen_cflags} -I${gen_include}") +endforeach() +set(gen_cflags "${gen_cflags} ${CMAKE_C_FLAGS}") + +foreach(sfile ${NEOVIM_SOURCES} +              "${PROJECT_SOURCE_DIR}/src/nvim/regexp_nfa.c" +              ${OS_SOURCES} +              ${API_SOURCES} +              ${API_PRIV_SOURCES}) +  get_filename_component(full_d ${sfile} PATH) +  file(RELATIVE_PATH d "${PROJECT_SOURCE_DIR}/src/nvim" "${full_d}") +  get_filename_component(f ${sfile} NAME) +  get_filename_component(r ${sfile} NAME_WE) +  if(NOT ${d} EQUAL ".") +    set(f "${d}/${f}") +    set(r "${d}/${r}") +  endif() +  set(gf1 "${GENERATED_DIR}/${r}.c.generated.h") +  set(gf2 "${GENERATED_INCLUDES_DIR}/${r}.h.generated.h") +  add_custom_command( +    OUTPUT "${gf1}" "${gf2}" +    COMMAND "${LUA_PRG}" "${HEADER_GENERATOR}" +                             "${sfile}" "${gf1}" "${gf2}" +                             "${CMAKE_C_COMPILER} ${gen_cflags} -E" +    DEPENDS "${HEADER_GENERATOR}" "${sfile}" +    ) +  list(APPEND NEOVIM_GENERATED_SOURCES "${gf1}") +  list(APPEND NEOVIM_GENERATED_SOURCES "${gf2}") +  if(${d} MATCHES "^api$" AND NOT ${f} MATCHES "^api/helpers.c$") +    list(APPEND API_HEADERS ${gf2}) +  endif() +endforeach() + +add_custom_command(OUTPUT ${MSGPACK_DISPATCH} +  COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_HEADERS} ${MSGPACK_DISPATCH} +  DEPENDS +    ${API_HEADERS} +    ${MSGPACK_RPC_HEADER} +    ${DISPATCH_GENERATOR} +    ) + +list(APPEND NEOVIM_SOURCES "${PROJECT_BINARY_DIR}/config/auto/pathdef.c") +list(APPEND NEOVIM_SOURCES "${MSGPACK_DISPATCH}") +  # Our dependencies come first.  if (LibIntl_FOUND) @@ -106,14 +159,14 @@ list(APPEND NVIM_LINK_LIBRARIES      ${CMAKE_THREAD_LIBS_INIT})  if(NOT DEFINED ENV{SKIP_EXEC}) -  add_executable(nvim ${NEOVIM_SOURCES} ${OS_SOURCES} ${API_SOURCES} -    ${API_PRIV_SOURCES}) +  add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} +    ${OS_SOURCES} ${API_SOURCES} ${API_PRIV_SOURCES})    target_link_libraries(nvim ${NVIM_LINK_LIBRARIES})    install(TARGETS nvim RUNTIME DESTINATION bin)  endif()  if(NOT DEFINED ENV{SKIP_UNITTEST}) -  add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_SOURCES} -    ${OS_SOURCES} ${API_SOURCES} ${API_PRIV_SOURCES}) +  add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES} +    ${NEOVIM_SOURCES} ${OS_SOURCES} ${API_SOURCES} ${API_PRIV_SOURCES})    target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES})  endif() diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 1637374459..0fe05e69b0 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -20,27 +20,15 @@  #include "nvim/window.h"  #include "nvim/undo.h" -// Find a window that contains "buf" and switch to it. -// If there is no such window, use the current window and change "curbuf". -// Caller must initialize save_curbuf to NULL. -// restore_win_for_buf() MUST be called later! -static void switch_to_win_for_buf(buf_T *buf, -                                  win_T **save_curwinp, -                                  tabpage_T **save_curtabp, -                                  buf_T **save_curbufp); - -static void restore_win_for_buf(win_T *save_curwin, -                                tabpage_T *save_curtab, -                                buf_T *save_curbuf); - -// Check if deleting lines made the cursor position invalid. -// Changed the lines from "lo" to "hi" and added "extra" lines (negative if -// deleted). -static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra); - -// Normalizes 0-based indexes to buffer line numbers -static int64_t normalize_index(buf_T *buf, int64_t index); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/buffer.c.generated.h" +#endif + +/// Gets the buffer line count +/// +/// @param buffer The buffer handle +/// @param[out] err Details of an error that may have occurred +/// @return The line count  Integer buffer_get_length(Buffer buffer, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -52,6 +40,12 @@ Integer buffer_get_length(Buffer buffer, Error *err)    return buf->b_ml.ml_line_count;  } +/// Gets a buffer line +/// +/// @param buffer The buffer handle +/// @param index The line index +/// @param[out] err Details of an error that may have occurred +/// @return The line string  String buffer_get_line(Buffer buffer, Integer index, Error *err)  {    String rv = {.size = 0}; @@ -66,18 +60,38 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)    return rv;  } +/// Sets a buffer line +/// +/// @param buffer The buffer handle +/// @param index The line index +/// @param line The new line. +/// @param[out] err Details of an error that may have occurred  void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)  {    StringArray array = {.items = &line, .size = 1};    buffer_set_slice(buffer, index, index, true, true, array, err);  } +/// Deletes a buffer line +/// +/// @param buffer The buffer handle +/// @param index The line index +/// @param[out] err Details of an error that may have occurred  void buffer_del_line(Buffer buffer, Integer index, Error *err)  {    StringArray array = ARRAY_DICT_INIT;    buffer_set_slice(buffer, index, index, true, true, array, err);  } +/// Retrieves a line range from the buffer +/// +/// @param buffer The buffer handle +/// @param start The first line index +/// @param end The last line index +/// @param include_start True if the slice includes the `start` parameter +/// @param include_end True if the slice includes the `end` parameter +/// @param[out] err Details of an error that may have occurred +/// @return An array of lines  StringArray buffer_get_slice(Buffer buffer,                               Integer start,                               Integer end, @@ -128,6 +142,16 @@ end:    return rv;  } +/// Replaces a line range on the buffer +/// +/// @param buffer The buffer handle +/// @param start The first line index +/// @param end The last line index +/// @param include_start True if the slice includes the `start` parameter +/// @param include_end True if the slice includes the `end` parameter +/// @param lines An array of lines to use as replacement(A 0-length array +///        will simply delete the line range) +/// @param[out] err Details of an error that may have occurred  void buffer_set_slice(Buffer buffer,                        Integer start,                        Integer end, @@ -251,6 +275,12 @@ end:    try_end(err);  } +/// Gets a buffer variable +/// +/// @param buffer The buffer handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value  Object buffer_get_var(Buffer buffer, String name, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -262,6 +292,13 @@ Object buffer_get_var(Buffer buffer, String name, Error *err)    return dict_get_value(buf->b_vars, name, err);  } +/// Sets a buffer variable. Passing 'nil' as value deletes the variable. +/// +/// @param buffer The buffer handle +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +/// @return The old value  Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -273,6 +310,12 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)    return dict_set_value(buf->b_vars, name, value, err);  } +/// Gets a buffer option value +/// +/// @param buffer The buffer handle +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return The option value  Object buffer_get_option(Buffer buffer, String name, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -284,6 +327,13 @@ Object buffer_get_option(Buffer buffer, String name, Error *err)    return get_option_from(buf, SREQ_BUF, name, err);  } +/// Sets a buffer option value. Passing 'nil' as value deletes the option(only +/// works if there's a global fallback) +/// +/// @param buffer The buffer handle +/// @param name The option name +/// @param value The option value +/// @param[out] err Details of an error that may have occurred  void buffer_set_option(Buffer buffer, String name, Object value, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -295,6 +345,11 @@ void buffer_set_option(Buffer buffer, String name, Object value, Error *err)    set_option_to(buf, SREQ_BUF, name, value, err);  } +/// Gets the buffer number +/// +/// @param buffer The buffer handle +/// @param[out] err Details of an error that may have occurred +/// @return The buffer number  Integer buffer_get_number(Buffer buffer, Error *err)  {    Integer rv = 0; @@ -307,6 +362,11 @@ Integer buffer_get_number(Buffer buffer, Error *err)    return buf->b_fnum;  } +/// Gets the full file name for the buffer +/// +/// @param buffer The buffer handle +/// @param[out] err Details of an error that may have occurred +/// @return The buffer name  String buffer_get_name(Buffer buffer, Error *err)  {    String rv = STRING_INIT; @@ -319,6 +379,11 @@ String buffer_get_name(Buffer buffer, Error *err)    return cstr_to_string((char *)buf->b_ffname);  } +/// Sets the full file name for a buffer +/// +/// @param buffer The buffer handle +/// @param name The buffer name +/// @param[out] err Details of an error that may have occurred  void buffer_set_name(Buffer buffer, String name, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -347,17 +412,34 @@ void buffer_set_name(Buffer buffer, String name, Error *err)    }  } +/// Checks if a buffer is valid +/// +/// @param buffer The buffer handle +/// @return true if the buffer is valid, false otherwise  Boolean buffer_is_valid(Buffer buffer)  {    Error stub = {.set = false};    return find_buffer(buffer, &stub) != NULL;  } +/// Inserts a sequence of lines to a buffer at a certain index +/// +/// @param buffer The buffer handle +/// @param lnum Insert the lines after `lnum`. If negative, it will append +///        to the end of the buffer. +/// @param lines An array of lines +/// @param[out] err Details of an error that may have occurred  void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err)  {    buffer_set_slice(buffer, lnum, lnum, false, true, lines, err);  } +/// Return a tuple (row,col) representing the position of the named mark +/// +/// @param buffer The buffer handle +/// @param name The mark's name +/// @param[out] err Details of an error that may have occurred +/// @return The (row, col) tuple  Position buffer_get_mark(Buffer buffer, String name, Error *err)  {    Position rv = POSITION_INIT; @@ -395,6 +477,10 @@ Position buffer_get_mark(Buffer buffer, String name, Error *err)    return rv;  } +// Find a window that contains "buf" and switch to it. +// If there is no such window, use the current window and change "curbuf". +// Caller must initialize save_curbuf to NULL. +// restore_win_for_buf() MUST be called later!  static void switch_to_win_for_buf(buf_T *buf,                                    win_T **save_curwinp,                                    tabpage_T **save_curtabp, @@ -419,6 +505,9 @@ static void restore_win_for_buf(win_T *save_curwin,    }  } +// Check if deleting lines made the cursor position invalid. +// Changed the lines from "lo" to "hi" and added "extra" lines (negative if +// deleted).  static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)  {    if (curwin->w_cursor.lnum >= lo) { @@ -438,6 +527,7 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)    invalidate_botline();  } +// Normalizes 0-based indexes to buffer line numbers  static int64_t normalize_index(buf_T *buf, int64_t index)  {    // Fix if < 0 diff --git a/src/nvim/api/buffer.h b/src/nvim/api/buffer.h index 52a3b7cdb3..0262ea000e 100644 --- a/src/nvim/api/buffer.h +++ b/src/nvim/api/buffer.h @@ -6,147 +6,7 @@  #include "nvim/api/private/defs.h" -/// Gets the buffer line count -/// -/// @param buffer The buffer handle -/// @param[out] err Details of an error that may have occurred -/// @return The line count -Integer buffer_get_length(Buffer buffer, Error *err); - -/// Gets a buffer line -/// -/// @param buffer The buffer handle -/// @param index The line index -/// @param[out] err Details of an error that may have occurred -/// @return The line string -String buffer_get_line(Buffer buffer, Integer index, Error *err); - -/// Sets a buffer line -/// -/// @param buffer The buffer handle -/// @param index The line index -/// @param line The new line. -/// @param[out] err Details of an error that may have occurred -void buffer_set_line(Buffer buffer, Integer index, String line, Error *err); - -/// Deletes a buffer line -/// -/// @param buffer The buffer handle -/// @param index The line index -/// @param[out] err Details of an error that may have occurred -void buffer_del_line(Buffer buffer, Integer index, Error *err); - -/// Retrieves a line range from the buffer -/// -/// @param buffer The buffer handle -/// @param start The first line index -/// @param end The last line index -/// @param include_start True if the slice includes the `start` parameter -/// @param include_end True if the slice includes the `end` parameter -/// @param[out] err Details of an error that may have occurred -/// @return An array of lines -StringArray buffer_get_slice(Buffer buffer, -                             Integer start, -                             Integer end, -                             Boolean include_start, -                             Boolean include_end, -                             Error *err); - -/// Replaces a line range on the buffer -/// -/// @param buffer The buffer handle -/// @param start The first line index -/// @param end The last line index -/// @param include_start True if the slice includes the `start` parameter -/// @param include_end True if the slice includes the `end` parameter -/// @param lines An array of lines to use as replacement(A 0-length array -///        will simply delete the line range) -/// @param[out] err Details of an error that may have occurred -void buffer_set_slice(Buffer buffer, -                      Integer start, -                      Integer end, -                      Boolean include_start, -                      Boolean include_end, -                      StringArray replacement, -                      Error *err); - -/// Gets a buffer variable -/// -/// @param buffer The buffer handle -/// @param name The variable name -/// @param[out] err Details of an error that may have occurred -/// @return The variable value -Object buffer_get_var(Buffer buffer, String name, Error *err); - -/// Sets a buffer variable. Passing 'nil' as value deletes the variable. -/// -/// @param buffer The buffer handle -/// @param name The variable name -/// @param value The variable value -/// @param[out] err Details of an error that may have occurred -/// @return The old value -Object buffer_set_var(Buffer buffer, String name, Object value, Error *err); - -/// Gets a buffer option value -/// -/// @param buffer The buffer handle -/// @param name The option name -/// @param[out] err Details of an error that may have occurred -/// @return The option value -Object buffer_get_option(Buffer buffer, String name, Error *err); - -/// Sets a buffer option value. Passing 'nil' as value deletes the option(only -/// works if there's a global fallback) -/// -/// @param buffer The buffer handle -/// @param name The option name -/// @param value The option value -/// @param[out] err Details of an error that may have occurred -void buffer_set_option(Buffer buffer, String name, Object value, Error *err); - -/// Gets the buffer number -/// -/// @param buffer The buffer handle -/// @param[out] err Details of an error that may have occurred -/// @return The buffer number -Integer buffer_get_number(Buffer buffer, Error *err); - -/// Gets the full file name for the buffer -/// -/// @param buffer The buffer handle -/// @param[out] err Details of an error that may have occurred -/// @return The buffer name -String buffer_get_name(Buffer buffer, Error *err); - -/// Sets the full file name for a buffer -/// -/// @param buffer The buffer handle -/// @param name The buffer name -/// @param[out] err Details of an error that may have occurred -void buffer_set_name(Buffer buffer, String name, Error *err); - -/// Checks if a buffer is valid -/// -/// @param buffer The buffer handle -/// @return true if the buffer is valid, false otherwise -Boolean buffer_is_valid(Buffer buffer); - -/// Inserts a sequence of lines to a buffer at a certain index -/// -/// @param buffer The buffer handle -/// @param lnum Insert the lines after `lnum`. If negative, it will append -///        to the end of the buffer. -/// @param lines An array of lines -/// @param[out] err Details of an error that may have occurred -void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err); - -/// Return a tuple (row,col) representing the position of the named mark -/// -/// @param buffer The buffer handle -/// @param name The mark's name -/// @param[out] err Details of an error that may have occurred -/// @return The (row, col) tuple -Position buffer_get_mark(Buffer buffer, String name, Error *err); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/buffer.h.generated.h" +#endif  #endif  // NVIM_API_BUFFER_H - diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index c9bc849af0..11de50455b 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -15,35 +15,21 @@  #include "nvim/option.h"  #include "nvim/option_defs.h" -/// Recursion helper for the `vim_to_object`. This uses a pointer table -/// to avoid infinite recursion due to cyclic references -/// -/// @param obj The source object -/// @param lookup Lookup table containing pointers to all processed objects -/// @return The converted value -static Object vim_to_object_rec(typval_T *obj, PMap(ptr_t) *lookup); - -static bool object_to_vim(Object obj, typval_T *tv, Error *err); - -static void set_option_value_for(char *key, -                                 int numval, -                                 char *stringval, -                                 int opt_flags, -                                 int opt_type, -                                 void *from, -                                 Error *err); - -static void set_option_value_err(char *key, -                                 int numval, -                                 char *stringval, -                                 int opt_flags, -                                 Error *err); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/private/helpers.c.generated.h" +#endif +/// Start block that may cause vimscript exceptions  void try_start()  {    ++trylevel;  } +/// End try block, set the error message if any and return true if an error +/// occurred. +/// +/// @param err Pointer to the stack-allocated error object +/// @return true if an error occurred  bool try_end(Error *err)  {    --trylevel; @@ -81,6 +67,11 @@ bool try_end(Error *err)    return err->set;  } +/// Recursively expands a vimscript value in a dict +/// +/// @param dict The vimscript dict +/// @param key The key +/// @param[out] err Details of an error that may have occurred  Object dict_get_value(dict_T *dict, String key, Error *err)  {    Object rv = OBJECT_INIT; @@ -101,6 +92,14 @@ Object dict_get_value(dict_T *dict, String key, Error *err)    return rv;  } +/// Set a value in a dict. Objects are recursively expanded into their +/// vimscript equivalents. Passing 'nil' as value deletes the key. +/// +/// @param dict The vimscript dict +/// @param key The key +/// @param value The new value +/// @param[out] err Details of an error that may have occurred +/// @return the old value, if any  Object dict_set_value(dict_T *dict, String key, Object value, Error *err)  {    Object rv = OBJECT_INIT; @@ -164,6 +163,14 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err)    return rv;  } +/// Gets the value of a global or local(buffer, window) option. +/// +/// @param from If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer +///        to the window or buffer. +/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF` +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return the option value  Object get_option_from(void *from, int type, String name, Error *err)  {    Object rv = OBJECT_INIT; @@ -207,6 +214,13 @@ Object get_option_from(void *from, int type, String name, Error *err)    return rv;  } +/// Sets the value of a global or local(buffer, window) option. +/// +/// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer +///        to the window or buffer. +/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF` +/// @param name The option name +/// @param[out] err Details of an error that may have occurred  void set_option_to(void *to, int type, String name, Object value, Error *err)  {    if (name.size == 0) { @@ -274,6 +288,11 @@ cleanup:    free(key);  } +/// Convert a vim object to an `Object` instance, recursively expanding +/// Arrays/Dictionaries. +/// +/// @param obj The source object +/// @return The converted value  Object vim_to_object(typval_T *obj)  {    Object rv; @@ -285,6 +304,11 @@ Object vim_to_object(typval_T *obj)    return rv;  } +/// Finds the pointer for a window number +/// +/// @param window the window number +/// @param[out] err Details of an error that may have occurred +/// @return the window pointer  buf_T *find_buffer(Buffer buffer, Error *err)  {    buf_T *rv = handle_get_buffer(buffer); @@ -296,6 +320,11 @@ buf_T *find_buffer(Buffer buffer, Error *err)    return rv;  } +/// Finds the pointer for a window number +/// +/// @param window the window number +/// @param[out] err Details of an error that may have occurred +/// @return the window pointer  win_T * find_window(Window window, Error *err)  {    win_T *rv = handle_get_window(window); @@ -307,6 +336,11 @@ win_T * find_window(Window window, Error *err)    return rv;  } +/// Finds the pointer for a tabpage number +/// +/// @param tabpage the tabpage number +/// @param[out] err Details of an error that may have occurred +/// @return the tabpage pointer  tabpage_T * find_tab(Tabpage tabpage, Error *err)  {    tabpage_T *rv = handle_get_tabpage(tabpage); @@ -318,6 +352,11 @@ tabpage_T * find_tab(Tabpage tabpage, Error *err)    return rv;  } +/// Copies a C string into a String (binary safe string, characters + length) +/// +/// @param str the C string to copy +/// @return the resulting String, if the input string was NULL, then an +///         empty String is returned  String cstr_to_string(const char *str) {      if (str == NULL) {          return (String) STRING_INIT; @@ -422,6 +461,12 @@ static bool object_to_vim(Object obj, typval_T *tv, Error *err)    return true;  } +/// Recursion helper for the `vim_to_object`. This uses a pointer table +/// to avoid infinite recursion due to cyclic references +/// +/// @param obj The source object +/// @param lookup Lookup table containing pointers to all processed objects +/// @return The converted value  static Object vim_to_object_rec(typval_T *obj, PMap(ptr_t) *lookup)  {    Object rv = OBJECT_INIT; diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 04b128d3f1..68ab4ff614 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -13,86 +13,7 @@      err->set = true;                               \    } while (0) -/// Start block that may cause vimscript exceptions -void try_start(void); - -/// End try block, set the error message if any and return true if an error -/// occurred. -/// -/// @param err Pointer to the stack-allocated error object -/// @return true if an error occurred -bool try_end(Error *err); - -/// Recursively expands a vimscript value in a dict -/// -/// @param dict The vimscript dict -/// @param key The key -/// @param[out] err Details of an error that may have occurred -Object dict_get_value(dict_T *dict, String key, Error *err); - -/// Set a value in a dict. Objects are recursively expanded into their -/// vimscript equivalents. Passing 'nil' as value deletes the key. -/// -/// @param dict The vimscript dict -/// @param key The key -/// @param value The new value -/// @param[out] err Details of an error that may have occurred -/// @return the old value, if any -Object dict_set_value(dict_T *dict, String key, Object value, Error *err); - -/// Gets the value of a global or local(buffer, window) option. -/// -/// @param from If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer -///        to the window or buffer. -/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF` -/// @param name The option name -/// @param[out] err Details of an error that may have occurred -/// @return the option value -Object get_option_from(void *from, int type, String name, Error *err); - -/// Sets the value of a global or local(buffer, window) option. -/// -/// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer -///        to the window or buffer. -/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF` -/// @param name The option name -/// @param[out] err Details of an error that may have occurred -void set_option_to(void *to, int type, String name, Object value, Error *err); - -/// Convert a vim object to an `Object` instance, recursively expanding -/// Arrays/Dictionaries. -/// -/// @param obj The source object -/// @return The converted value -Object vim_to_object(typval_T *obj); - -/// Finds the pointer for a window number -/// -/// @param window the window number -/// @param[out] err Details of an error that may have occurred -/// @return the window pointer -buf_T *find_buffer(Buffer buffer, Error *err); - -/// Finds the pointer for a window number -/// -/// @param window the window number -/// @param[out] err Details of an error that may have occurred -/// @return the window pointer -win_T * find_window(Window window, Error *err); - -/// Finds the pointer for a tabpage number -/// -/// @param tabpage the tabpage number -/// @param[out] err Details of an error that may have occurred -/// @return the tabpage pointer -tabpage_T * find_tab(Tabpage tabpage, Error *err); - -/// Copies a C string into a String (binary safe string, characters + length) -/// -/// @param str the C string to copy -/// @return the resulting String, if the input string was NULL, then an -///         empty String is returned -String cstr_to_string(const char *str); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/private/helpers.h.generated.h" +#endif  #endif  // NVIM_API_PRIVATE_HELPERS_H - diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index ce52466d12..8d92b01cf9 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -8,6 +8,11 @@  #include "nvim/api/private/helpers.h"  #include "nvim/memory.h" +/// Gets the number of windows in a tabpage +/// +/// @param tabpage The tabpage +/// @param[out] err Details of an error that may have occurred +/// @return The number of windows in `tabpage`  WindowArray tabpage_get_windows(Tabpage tabpage, Error *err)  {    WindowArray rv = ARRAY_DICT_INIT; @@ -40,6 +45,12 @@ WindowArray tabpage_get_windows(Tabpage tabpage, Error *err)    return rv;  } +/// Gets a tabpage variable +/// +/// @param tabpage The tab page handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value  Object tabpage_get_var(Tabpage tabpage, String name, Error *err)  {    tabpage_T *tab = find_tab(tabpage, err); @@ -51,6 +62,13 @@ Object tabpage_get_var(Tabpage tabpage, String name, Error *err)    return dict_get_value(tab->tp_vars, name, err);  } +/// Sets a tabpage variable. Passing 'nil' as value deletes the variable. +/// +/// @param tabpage handle +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +/// @return The tab page handle  Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)  {    tabpage_T *tab = find_tab(tabpage, err); @@ -62,6 +80,11 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)    return dict_set_value(tab->tp_vars, name, value, err);  } +/// Gets the current window in a tab page +/// +/// @param tabpage The tab page handle +/// @param[out] err Details of an error that may have occurred +/// @return The Window handle  Window tabpage_get_window(Tabpage tabpage, Error *err)  {    Window rv = 0; @@ -87,6 +110,10 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)    }  } +/// Checks if a tab page is valid +/// +/// @param tabpage The tab page handle +/// @return true if the tab page is valid, false otherwise  Boolean tabpage_is_valid(Tabpage tabpage)  {    Error stub = {.set = false}; diff --git a/src/nvim/api/tabpage.h b/src/nvim/api/tabpage.h index dddcecbdbd..b24a9795e5 100644 --- a/src/nvim/api/tabpage.h +++ b/src/nvim/api/tabpage.h @@ -6,42 +6,7 @@  #include "nvim/api/private/defs.h" -/// Gets the number of windows in a tabpage -/// -/// @param tabpage The tabpage -/// @param[out] err Details of an error that may have occurred -/// @return The number of windows in `tabpage` -WindowArray tabpage_get_windows(Tabpage tabpage, Error *err); - -/// Gets a tabpage variable -/// -/// @param tabpage The tab page handle -/// @param name The variable name -/// @param[out] err Details of an error that may have occurred -/// @return The variable value -Object tabpage_get_var(Tabpage tabpage, String name, Error *err); - -/// Sets a tabpage variable. Passing 'nil' as value deletes the variable. -/// -/// @param tabpage handle -/// @param name The variable name -/// @param value The variable value -/// @param[out] err Details of an error that may have occurred -/// @return The tab page handle -Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err); - -/// Gets the current window in a tab page -/// -/// @param tabpage The tab page handle -/// @param[out] err Details of an error that may have occurred -/// @return The Window handle -Window tabpage_get_window(Tabpage tabpage, Error *err); - -/// Checks if a tab page is valid -/// -/// @param tabpage The tab page handle -/// @return true if the tab page is valid, false otherwise -Boolean tabpage_is_valid(Tabpage tabpage); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/tabpage.h.generated.h" +#endif  #endif  // NVIM_API_TABPAGE_H - diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 39e2c32d6d..59f4721da2 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -22,20 +22,22 @@  #define LINE_BUFFER_SIZE 4096 -/// Writes a message to vim output or error buffer. The string is split -/// and flushed after each newline. Incomplete lines are kept for writing -/// later. -/// -/// @param message The message to write -/// @param to_err True if it should be treated as an error message(use -///        `emsg` instead of `msg` to print each line) -static void write_msg(String message, bool to_err); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/vim.c.generated.h" +#endif +/// Send keys to vim input buffer, simulating user input. +/// +/// @param str The keys to send  void vim_push_keys(String str)  {    abort();  } +/// Executes an ex-mode command str +/// +/// @param str The command str +/// @param[out] err Details of an error that may have occurred  void vim_command(String str, Error *err)  {    // We still use 0-terminated strings, so we must convert. @@ -48,6 +50,13 @@ void vim_command(String str, Error *err)    try_end(err);  } +/// Evaluates the expression str using the vim internal expression +/// evaluator (see |expression|). +/// Dictionaries and lists are recursively expanded. +/// +/// @param str The expression str +/// @param[out] err Details of an error that may have occurred +/// @return The expanded object  Object vim_eval(String str, Error *err)  {    Object rv; @@ -67,6 +76,12 @@ Object vim_eval(String str, Error *err)    return rv;  } +/// Calculates the number of display cells `str` occupies, tab is counted as +/// one cell. +/// +/// @param str Some text +/// @param[out] err Details of an error that may have occurred +/// @return The number of cells  Integer vim_strwidth(String str, Error *err)  {    if (str.size > INT_MAX) { @@ -80,6 +95,9 @@ Integer vim_strwidth(String str, Error *err)    return rv;  } +/// Returns a list of paths contained in 'runtimepath' +/// +/// @return The list of paths  StringArray vim_list_runtime_paths(void)  {    StringArray rv = ARRAY_DICT_INIT; @@ -117,6 +135,10 @@ StringArray vim_list_runtime_paths(void)    return rv;  } +/// Changes vim working directory +/// +/// @param dir The new working directory +/// @param[out] err Details of an error that may have occurred  void vim_change_directory(String dir, Error *err)  {    if (dir.size >= MAXPATHL) { @@ -141,56 +163,102 @@ void vim_change_directory(String dir, Error *err)    try_end(err);  } +/// Return the current line +/// +/// @param[out] err Details of an error that may have occurred +/// @return The current line string  String vim_get_current_line(Error *err)  {    return buffer_get_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);  } +/// Sets the current line +/// +/// @param line The line contents +/// @param[out] err Details of an error that may have occurred  void vim_set_current_line(String line, Error *err)  {    buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err);  } +/// Delete the current line +/// +/// @param[out] err Details of an error that may have occurred  void vim_del_current_line(Error *err)  {    buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);  } +/// Gets a global variable +/// +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value  Object vim_get_var(String name, Error *err)  {    return dict_get_value(&globvardict, name, err);  } +/// Sets a global variable. Passing 'nil' as value deletes the variable. +/// +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +/// @return the old value if any  Object vim_set_var(String name, Object value, Error *err)  {    return dict_set_value(&globvardict, name, value, err);  } +/// Gets a vim variable +/// +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value  Object vim_get_vvar(String name, Error *err)  {    return dict_get_value(&vimvardict, name, err);  } +/// Get an option value string +/// +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return The option value  Object vim_get_option(String name, Error *err)  {    return get_option_from(NULL, SREQ_GLOBAL, name, err);  } +/// Sets an option value +/// +/// @param name The option name +/// @param value The new option value +/// @param[out] err Details of an error that may have occurred  void vim_set_option(String name, Object value, Error *err)  {    set_option_to(NULL, SREQ_GLOBAL, name, value, err);  } +/// Write a message to vim output buffer +/// +/// @param str The message  void vim_out_write(String str)  {    write_msg(str, false);  } +/// Write a message to vim error buffer +/// +/// @param str The message  void vim_err_write(String str)  {    write_msg(str, true);  } +/// Gets the current list of buffer handles +/// +/// @return The number of buffers  BufferArray vim_get_buffers(void)  {    BufferArray rv = ARRAY_DICT_INIT; @@ -213,11 +281,18 @@ BufferArray vim_get_buffers(void)    return rv;  } +/// Return the current buffer +/// +/// @reqturn The buffer handle  Buffer vim_get_current_buffer(void)  {    return curbuf->handle;  } +/// Sets the current buffer +/// +/// @param id The buffer handle +/// @param[out] err Details of an error that may have occurred  void vim_set_current_buffer(Buffer buffer, Error *err)  {    buf_T *buf = find_buffer(buffer, err); @@ -241,6 +316,9 @@ void vim_set_current_buffer(Buffer buffer, Error *err)    try_end(err);  } +/// Gets the current list of window handles +/// +/// @return The number of windows  WindowArray vim_get_windows(void)  {    WindowArray rv = ARRAY_DICT_INIT; @@ -261,11 +339,17 @@ WindowArray vim_get_windows(void)    return rv;  } +/// Return the current window +/// +/// @return The window handle  Window vim_get_current_window(void)  {    return curwin->handle;  } +/// Sets the current window +/// +/// @param handle The window handle  void vim_set_current_window(Window window, Error *err)  {    win_T *win = find_window(window, err); @@ -288,6 +372,9 @@ void vim_set_current_window(Window window, Error *err)    try_end(err);  } +/// Gets the current list of tabpage handles +/// +/// @return The number of tab pages  TabpageArray vim_get_tabpages(void)  {    TabpageArray rv = ARRAY_DICT_INIT; @@ -310,11 +397,18 @@ TabpageArray vim_get_tabpages(void)    return rv;  } +/// Return the current tab page +/// +/// @return The tab page handle  Tabpage vim_get_current_tabpage(void)  {    return curtab->handle;  } +/// Sets the current tab page +/// +/// @param handle The tab page handle +/// @param[out] err Details of an error that may have occurred  void vim_set_current_tabpage(Tabpage tabpage, Error *err)  {    tabpage_T *tp = find_tab(tabpage, err); @@ -328,6 +422,10 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err)    try_end(err);  } +/// Subscribes to event broadcasts +/// +/// @param channel_id The channel id(passed automatically by the dispatcher) +/// @param event The event type string  void vim_subscribe(uint64_t channel_id, String event)  {    size_t length = (event.size < EVENT_MAXLEN ? event.size : EVENT_MAXLEN); @@ -337,6 +435,10 @@ void vim_subscribe(uint64_t channel_id, String event)    channel_subscribe(channel_id, e);  } +/// Unsubscribes to event broadcasts +/// +/// @param channel_id The channel id(passed automatically by the dispatcher) +/// @param event The event type string  void vim_unsubscribe(uint64_t channel_id, String event)  {    size_t length = (event.size < EVENT_MAXLEN ? event.size : EVENT_MAXLEN); @@ -346,6 +448,13 @@ void vim_unsubscribe(uint64_t channel_id, String event)    channel_unsubscribe(channel_id, e);  } +/// Writes a message to vim output or error buffer. The string is split +/// and flushed after each newline. Incomplete lines are kept for writing +/// later. +/// +/// @param message The message to write +/// @param to_err True if it should be treated as an error message(use +///        `emsg` instead of `msg` to print each line)  static void write_msg(String message, bool to_err)  {    static int pos = 0; diff --git a/src/nvim/api/vim.h b/src/nvim/api/vim.h index 4d1ac9023e..f15edb8548 100644 --- a/src/nvim/api/vim.h +++ b/src/nvim/api/vim.h @@ -6,166 +6,7 @@  #include "nvim/api/private/defs.h" -/// Send keys to vim input buffer, simulating user input. -/// -/// @param str The keys to send -void vim_push_keys(String str); - -/// Executes an ex-mode command str -/// -/// @param str The command str -/// @param[out] err Details of an error that may have occurred -void vim_command(String str, Error *err); - -/// Evaluates the expression str using the vim internal expression -/// evaluator (see |expression|). -/// Dictionaries and lists are recursively expanded. -/// -/// @param str The expression str -/// @param[out] err Details of an error that may have occurred -/// @return The expanded object -Object vim_eval(String str, Error *err); - -/// Calculates the number of display cells `str` occupies, tab is counted as -/// one cell. -/// -/// @param str Some text -/// @param[out] err Details of an error that may have occurred -/// @return The number of cells -Integer vim_strwidth(String str, Error *err); - -/// Returns a list of paths contained in 'runtimepath' -/// -/// @return The list of paths -StringArray vim_list_runtime_paths(void); - -/// Changes vim working directory -/// -/// @param dir The new working directory -/// @param[out] err Details of an error that may have occurred -void vim_change_directory(String dir, Error *err); - -/// Return the current line -/// -/// @param[out] err Details of an error that may have occurred -/// @return The current line string -String vim_get_current_line(Error *err); - -/// Delete the current line -/// -/// @param[out] err Details of an error that may have occurred -void vim_del_current_line(Error *err); - -/// Sets the current line -/// -/// @param line The line contents -/// @param[out] err Details of an error that may have occurred -void vim_set_current_line(String line, Error *err); - -/// Gets a global variable -/// -/// @param name The variable name -/// @param[out] err Details of an error that may have occurred -/// @return The variable value -Object vim_get_var(String name, Error *err); - -/// Sets a global variable. Passing 'nil' as value deletes the variable. -/// -/// @param name The variable name -/// @param value The variable value -/// @param[out] err Details of an error that may have occurred -/// @return the old value if any -Object vim_set_var(String name, Object value, Error *err); - -/// Gets a vim variable -/// -/// @param name The variable name -/// @param[out] err Details of an error that may have occurred -/// @return The variable value -Object vim_get_vvar(String name, Error *err); - -/// Get an option value string -/// -/// @param name The option name -/// @param[out] err Details of an error that may have occurred -/// @return The option value -Object vim_get_option(String name, Error *err); - -/// Sets an option value -/// -/// @param name The option name -/// @param value The new option value -/// @param[out] err Details of an error that may have occurred -void vim_set_option(String name, Object value, Error *err); - -/// Write a message to vim output buffer -/// -/// @param str The message -void vim_out_write(String str); - -/// Write a message to vim error buffer -/// -/// @param str The message -void vim_err_write(String str); - -/// Gets the current list of buffer handles -/// -/// @return The number of buffers -BufferArray vim_get_buffers(void); - -/// Return the current buffer -/// -/// @reqturn The buffer handle -Buffer vim_get_current_buffer(void); - -/// Sets the current buffer -/// -/// @param id The buffer handle -/// @param[out] err Details of an error that may have occurred -void vim_set_current_buffer(Buffer buffer, Error *err); - -/// Gets the current list of window handles -/// -/// @return The number of windows -WindowArray vim_get_windows(void); - -/// Return the current window -/// -/// @return The window handle -Window vim_get_current_window(void); - -/// Sets the current window -/// -/// @param handle The window handle -void vim_set_current_window(Window window, Error *err); - -/// Gets the current list of tabpage handles -/// -/// @return The number of tab pages -TabpageArray vim_get_tabpages(void); - -/// Return the current tab page -/// -/// @return The tab page handle -Tabpage vim_get_current_tabpage(void); - -/// Sets the current tab page -/// -/// @param handle The tab page handle -/// @param[out] err Details of an error that may have occurred -void vim_set_current_tabpage(Tabpage tabpage, Error *err); - -/// Subscribes to event broadcasts -/// -/// @param channel_id The channel id(passed automatically by the dispatcher) -/// @param event The event type string -void vim_subscribe(uint64_t channel_id, String event); - -/// Unsubscribes to event broadcasts -/// -/// @param channel_id The channel id(passed automatically by the dispatcher) -/// @param event The event type string -void vim_unsubscribe(uint64_t channel_id, String event); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/vim.h.generated.h" +#endif  #endif  // NVIM_API_VIM_H - diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index fd13557e3b..2b81afdb0c 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -12,6 +12,11 @@  #include "nvim/misc2.h" +/// Gets the current buffer in a window +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The buffer handle  Buffer window_get_buffer(Window window, Error *err)  {    win_T *win = find_window(window, err); @@ -23,6 +28,11 @@ Buffer window_get_buffer(Window window, Error *err)    return win->w_buffer->handle;  } +/// Gets the cursor position in the window +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return the (row, col) tuple  Position window_get_cursor(Window window, Error *err)  {    Position rv = {.row = 0, .col = 0}; @@ -36,6 +46,11 @@ Position window_get_cursor(Window window, Error *err)    return rv;  } +/// Sets the cursor position in the window +/// +/// @param window The window handle +/// @param pos the (row, col) tuple representing the new position +/// @param[out] err Details of an error that may have occurred  void window_set_cursor(Window window, Position pos, Error *err)  {    win_T *win = find_window(window, err); @@ -67,6 +82,11 @@ void window_set_cursor(Window window, Position pos, Error *err)    update_screen(VALID);  } +/// Gets the window height +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return the height in rows  Integer window_get_height(Window window, Error *err)  {    win_T *win = find_window(window, err); @@ -78,6 +98,12 @@ Integer window_get_height(Window window, Error *err)    return win->w_height;  } +/// Sets the window height. This will only succeed if the screen is split +/// horizontally. +/// +/// @param window The window handle +/// @param height the new height in rows +/// @param[out] err Details of an error that may have occurred  void window_set_height(Window window, Integer height, Error *err)  {    win_T *win = find_window(window, err); @@ -99,6 +125,11 @@ void window_set_height(Window window, Integer height, Error *err)    try_end(err);  } +/// Gets the window width +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return the width in columns  Integer window_get_width(Window window, Error *err)  {    win_T *win = find_window(window, err); @@ -110,6 +141,12 @@ Integer window_get_width(Window window, Error *err)    return win->w_width;  } +/// Sets the window width. This will only succeed if the screen is split +/// vertically. +/// +/// @param window The window handle +/// @param width the new width in columns +/// @param[out] err Details of an error that may have occurred  void window_set_width(Window window, Integer width, Error *err)  {    win_T *win = find_window(window, err); @@ -131,6 +168,12 @@ void window_set_width(Window window, Integer width, Error *err)    try_end(err);  } +/// Gets a window variable +/// +/// @param window The window handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value  Object window_get_var(Window window, String name, Error *err)  {    win_T *win = find_window(window, err); @@ -142,6 +185,13 @@ Object window_get_var(Window window, String name, Error *err)    return dict_get_value(win->w_vars, name, err);  } +/// Sets a window variable. Passing 'nil' as value deletes the variable. +/// +/// @param window The window handle +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +/// @return The old value  Object window_set_var(Window window, String name, Object value, Error *err)  {    win_T *win = find_window(window, err); @@ -153,6 +203,12 @@ Object window_set_var(Window window, String name, Object value, Error *err)    return dict_set_value(win->w_vars, name, value, err);  } +/// Gets a window option value +/// +/// @param window The window handle +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return The option value  Object window_get_option(Window window, String name, Error *err)  {    win_T *win = find_window(window, err); @@ -164,6 +220,13 @@ Object window_get_option(Window window, String name, Error *err)    return get_option_from(win, SREQ_WIN, name, err);  } +/// Sets a window option value. Passing 'nil' as value deletes the option(only +/// works if there's a global fallback) +/// +/// @param window The window handle +/// @param name The option name +/// @param value The option value +/// @param[out] err Details of an error that may have occurred  void window_set_option(Window window, String name, Object value, Error *err)  {    win_T *win = find_window(window, err); @@ -175,6 +238,11 @@ void window_set_option(Window window, String name, Object value, Error *err)    set_option_to(win, SREQ_WIN, name, value, err);  } +/// Gets the window position in display cells. First position is zero. +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The (row, col) tuple with the window position  Position window_get_position(Window window, Error *err)  {    Position rv; @@ -188,6 +256,11 @@ Position window_get_position(Window window, Error *err)    return rv;  } +/// Gets the window tab page +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The tab page that contains the window  Tabpage window_get_tabpage(Window window, Error *err)  {    Tabpage rv = 0; @@ -200,6 +273,10 @@ Tabpage window_get_tabpage(Window window, Error *err)    return rv;  } +/// Checks if a window is valid +/// +/// @param window The window handle +/// @return true if the window is valid, false otherwise  Boolean window_is_valid(Window window)  {    Error stub = {.set = false}; diff --git a/src/nvim/api/window.h b/src/nvim/api/window.h index 4c036ff5d7..3a8cde18e2 100644 --- a/src/nvim/api/window.h +++ b/src/nvim/api/window.h @@ -6,110 +6,7 @@  #include "nvim/api/private/defs.h" -/// Gets the current buffer in a window -/// -/// @param window The window handle -/// @param[out] err Details of an error that may have occurred -/// @return The buffer handle -Buffer window_get_buffer(Window window, Error *err); - -/// Gets the cursor position in the window -/// -/// @param window The window handle -/// @param[out] err Details of an error that may have occurred -/// @return the (row, col) tuple -Position window_get_cursor(Window window, Error *err); - -/// Sets the cursor position in the window -/// -/// @param window The window handle -/// @param pos the (row, col) tuple representing the new position -/// @param[out] err Details of an error that may have occurred -void window_set_cursor(Window window, Position pos, Error *err); - -/// Gets the window height -/// -/// @param window The window handle -/// @param[out] err Details of an error that may have occurred -/// @return the height in rows -Integer window_get_height(Window window, Error *err); - -/// Sets the window height. This will only succeed if the screen is split -/// horizontally. -/// -/// @param window The window handle -/// @param height the new height in rows -/// @param[out] err Details of an error that may have occurred -void window_set_height(Window window, Integer height, Error *err); - -/// Gets the window width -/// -/// @param window The window handle -/// @param[out] err Details of an error that may have occurred -/// @return the width in columns -Integer window_get_width(Window window, Error *err); - -/// Sets the window width. This will only succeed if the screen is split -/// vertically. -/// -/// @param window The window handle -/// @param width the new width in columns -/// @param[out] err Details of an error that may have occurred -void window_set_width(Window window, Integer width, Error *err); - -/// Gets a window variable -/// -/// @param window The window handle -/// @param name The variable name -/// @param[out] err Details of an error that may have occurred -/// @return The variable value -Object window_get_var(Window window, String name, Error *err); - -/// Sets a window variable. Passing 'nil' as value deletes the variable. -/// -/// @param window The window handle -/// @param name The variable name -/// @param value The variable value -/// @param[out] err Details of an error that may have occurred -/// @return The old value -Object window_set_var(Window window, String name, Object value, Error *err); - -/// Gets a window option value -/// -/// @param window The window handle -/// @param name The option name -/// @param[out] err Details of an error that may have occurred -/// @return The option value -Object window_get_option(Window window, String name, Error *err); - -/// Sets a window option value. Passing 'nil' as value deletes the option(only -/// works if there's a global fallback) -/// -/// @param window The window handle -/// @param name The option name -/// @param value The option value -/// @param[out] err Details of an error that may have occurred -void window_set_option(Window window, String name, Object value, Error *err); - -/// Gets the window position in display cells. First position is zero. -/// -/// @param window The window handle -/// @param[out] err Details of an error that may have occurred -/// @return The (row, col) tuple with the window position -Position window_get_position(Window window, Error *err); - -/// Gets the window tab page -/// -/// @param window The window handle -/// @param[out] err Details of an error that may have occurred -/// @return The tab page that contains the window -Tabpage window_get_tabpage(Window window, Error *err); - -/// Checks if a window is valid -/// -/// @param window The window handle -/// @return true if the window is valid, false otherwise -Boolean window_is_valid(Window window); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/window.h.generated.h" +#endif  #endif  // NVIM_API_WINDOW_H - diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c index 192c3c5afe..53bb481e92 100644 --- a/src/nvim/arabic.c +++ b/src/nvim/arabic.c @@ -240,26 +240,10 @@  #define a_BYTE_ORDER_MARK               0xfeff -static int A_is_a(int cur_c); -static int A_is_s(int cur_c); -static int A_is_f(int cur_c); -static int chg_c_a2s(int cur_c); -static int chg_c_a2i(int cur_c); -static int chg_c_a2m(int cur_c); -static int chg_c_a2f(int cur_c); -static int chg_c_i2m(int cur_c); -static int chg_c_f2m(int cur_c); -static int chg_c_laa2i(int hid_c); -static int chg_c_laa2f(int hid_c); -static int half_shape(int c); -static int A_firstc_laa(int c1, int c); -static int A_is_harakat(int c); -static int A_is_iso(int c); -static int A_is_formb(int c); -static int A_is_ok(int c); -static int A_is_valid(int c); -static int A_is_special(int c); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "arabic.c.generated.h" +#endif  // Returns True if c is an ISO-8859-6 shaped ARABIC letter (user entered).  static int A_is_a(int cur_c)  { diff --git a/src/nvim/arabic.h b/src/nvim/arabic.h index 829a10e44e..6c4529a93c 100644 --- a/src/nvim/arabic.h +++ b/src/nvim/arabic.h @@ -8,9 +8,7 @@ static inline int arabic_char(int c)      return c >= 0x0621 && c <= 0x0670;  } -int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, -                 int next_c); -int arabic_combine(int one, int two); -int arabic_maycombine(int two); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "arabic.h.generated.h" +#endif  #endif  // NVIM_ARABIC_H diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d3dcb375b2..de2cb64d59 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -73,22 +73,17 @@  // Todo(stefan991): remove this macro  #define INVALID_DEVICE_ID UINT64_MAX -static char_u   *buflist_match(regprog_T *prog, buf_T *buf); -# define HAVE_BUFLIST_MATCH -static char_u   *fname_match(regprog_T *prog, char_u *name); -static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, -                            colnr_T col, int copy_options); -static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer); -static buf_T *buflist_findname_file_info(char_u *ffname, FileInfo *file_info); -static int otherfile_buf(buf_T *buf, char_u *ffname, FileInfo *file_info); -static int buf_same_ino(buf_T *buf, FileInfo *file_info); -static int ti_change(char_u *str, char_u **last); -static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); -static void free_buffer(buf_T *); -static void free_buffer_stuff(buf_T *buf, int free_options); -static void clear_wininfo(buf_T *buf); - -static void insert_sign(buf_T *buf, signlist_T *prev, signlist_T *next, int id, linenr_T lnum, int typenr); +#define HAVE_BUFLIST_MATCH + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "buffer.c.generated.h" +#endif + +#ifdef UNIX +# define dev_T dev_t +#else +# define dev_T unsigned +#endif  static char *msg_loclist = N_("[Location List]");  static char *msg_qflist = N_("[Quickfix List]"); @@ -791,7 +786,6 @@ do_bufdel (  } -static int empty_curbuf(int close_others, int forceit, int action);  /*   * Make the current buffer empty. @@ -2014,7 +2008,6 @@ static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col,    return;  } -static int wininfo_other_tab_diff(wininfo_T *wip);  /*   * Return TRUE when "wip" has 'diff' set and the diff is only for another tab @@ -4016,7 +4009,6 @@ void ex_buffer_all(exarg_T *eap)  } -static int chk_modeline(linenr_T, int);  /*   * do_modelines() - process mode lines for the current file diff --git a/src/nvim/buffer.h b/src/nvim/buffer.h index 3462106aec..e62db843c7 100644 --- a/src/nvim/buffer.h +++ b/src/nvim/buffer.h @@ -1,81 +1,7 @@  #ifndef NVIM_BUFFER_H  #define NVIM_BUFFER_H -/* buffer.c */ -int open_buffer(int read_stdin, exarg_T *eap, int flags); -int buf_valid(buf_T *buf); -void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last); -void buf_clear_file(buf_T *buf); -void buf_freeall(buf_T *buf, int flags); -void goto_buffer(exarg_T *eap, int start, int dir, int count); -void handle_swap_exists(buf_T *old_curbuf); -char_u *do_bufdel(int command, char_u *arg, int addr_count, -                  int start_bnr, int end_bnr, -                  int forceit); -int do_buffer(int action, int start, int dir, int count, int forceit); -void set_curbuf(buf_T *buf, int action); -void enter_buffer(buf_T *buf); -void do_autochdir(void); -buf_T *buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, -                   int flags); -void free_buf_options(buf_T *buf, int free_p_ff); -int buflist_getfile(int n, linenr_T lnum, int options, int forceit); -void buflist_getfpos(void); -buf_T *buflist_findname_exp(char_u *fname); -buf_T *buflist_findname(char_u *ffname); -int buflist_findpat(char_u *pattern, char_u *pattern_end, int unlisted, -                    int diffmode, -                    int curtab_only); -int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, -                   int options); -buf_T *buflist_findnr(int nr); -char_u *buflist_nr2name(int n, int fullname, int helptail); -void get_winopts(buf_T *buf); -pos_T *buflist_findfpos(buf_T *buf); -linenr_T buflist_findlnum(buf_T *buf); -void buflist_list(exarg_T *eap); -int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum); -int setfname(buf_T *buf, char_u *ffname, char_u *sfname, int message); -void buf_set_name(int fnum, char_u *name); -void buf_name_changed(buf_T *buf); -buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum); -char_u *getaltfname(int errmsg); -int buflist_add(char_u *fname, int flags); -void buflist_slash_adjust(void); -void buflist_altfpos(win_T *win); -int otherfile(char_u *ffname); -void buf_setino(buf_T *buf); -void fileinfo(int fullname, int shorthelp, int dont_truncate); -void col_print(char_u *buf, size_t buflen, int col, int vcol); -void maketitle(void); -void resettitle(void); -void free_titles(void); -int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, -                     int use_sandbox, int fillchar, int maxwidth, -                     struct stl_hlrec *hltab, -                     struct stl_hlrec *tabtab); -void get_rel_pos(win_T *wp, char_u *buf, int buflen); -void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname); -char_u *alist_name(aentry_T *aep); -void do_arg_all(int count, int forceit, int keep_tabs); -void ex_buffer_all(exarg_T *eap); -void do_modelines(int flags); -int read_viminfo_bufferlist(vir_T *virp, int writing); -void write_viminfo_bufferlist(FILE *fp); -char_u *buf_spname(buf_T *buf); -int find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp); -void buf_addsign(buf_T *buf, int id, linenr_T lnum, int typenr); -linenr_T buf_change_sign_type(buf_T *buf, int markId, int typenr); -int buf_getsigntype(buf_T *buf, linenr_T lnum, int type); -linenr_T buf_delsign(buf_T *buf, int id); -int buf_findsign(buf_T *buf, int id); -int buf_findsign_id(buf_T *buf, linenr_T lnum); -void buf_delete_signs(buf_T *buf); -void buf_delete_all_signs(void); -void sign_list_placed(buf_T *rbuf); -void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, -                      long amount_after); -void set_buflisted(int on); -int buf_contents_changed(buf_T *buf); -void wipe_buffer(buf_T *buf, int aucmd); -#endif /* NVIM_BUFFER_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "buffer.h.generated.h" +#endif +#endif  // NVIM_BUFFER_H diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 1c979365bf..26ae17510a 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -20,12 +20,11 @@  #include "nvim/os_unix.h"  #include "nvim/strings.h" -static int win_chartabsize(win_T *wp, char_u *p, colnr_T col); -static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, -                                 int *headp); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "charset.c.generated.h" +#endif -static unsigned nr2hex(unsigned c);  static int chartab_initialized = FALSE; diff --git a/src/nvim/charset.h b/src/nvim/charset.h index f273ed4c96..78d6f2a76c 100644 --- a/src/nvim/charset.h +++ b/src/nvim/charset.h @@ -1,66 +1,7 @@  #ifndef NVIM_CHARSET_H  #define NVIM_CHARSET_H -int init_chartab(void); -int buf_init_chartab(buf_T *buf, int global); -void trans_characters(char_u *buf, int bufsize); -char_u *transstr(char_u *s); -char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen); -char_u *transchar(int c); -char_u *transchar_byte(int c); -void transchar_nonprint(char_u *buf, int c); -void transchar_hex(char_u *buf, int c); -int byte2cells(int b); -int char2cells(int c); -int ptr2cells(char_u *p); -int vim_strsize(char_u *s); -int vim_strnsize(char_u *s, int len); -int chartabsize(char_u *p, colnr_T col); -int linetabsize(char_u *s); -int linetabsize_col(int startcol, char_u *s); -int win_linetabsize(win_T *wp, char_u *p, colnr_T len); -int vim_isIDc(int c); -int vim_iswordc(int c); -int vim_iswordc_buf(int c, buf_T *buf); -int vim_iswordp(char_u *p); -int vim_iswordp_buf(char_u *p, buf_T *buf); -int vim_isfilec(int c); -int vim_isfilec_or_wc(int c); -int vim_isprintc(int c); -int vim_isprintc_strict(int c); -int lbr_chartabsize(unsigned char *s, colnr_T col); -int lbr_chartabsize_adv(char_u **s, colnr_T col); -int win_lbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp); -int in_win_border(win_T *wp, colnr_T vcol); -void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, -             colnr_T *end); -colnr_T getvcol_nolist(pos_T *posp); -void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, -              colnr_T *end); -void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, -              colnr_T *right); -char_u *skipwhite(char_u *q); -char_u *skipdigits(char_u *q); -char_u *skiphex(char_u *q); -char_u *skiptodigit(char_u *q); -char_u *skiptohex(char_u *q); -int vim_isdigit(int c); -int vim_isxdigit(int c); -int vim_islower(int c); -int vim_isupper(int c); -int vim_toupper(int c); -int vim_tolower(int c); -char_u *skiptowhite(char_u *p); -char_u *skiptowhite_esc(char_u *p); -long getdigits(char_u **pp); -int vim_isblankline(char_u *lbuf); -void vim_str2nr(char_u *start, int *hexp, int *len, int dooct, -                int dohex, long *nptr, -                unsigned long *unptr); -int hex2nr(int c); -int hexhex2nr(char_u *p); -int rem_backslash(char_u *str); -void backslash_halve(char_u *p); -char_u *backslash_halve_save(char_u *p); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "charset.h.generated.h" +#endif  #endif  // NVIM_CHARSET_H diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 8f8bc60510..5049a51872 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -10,7 +10,9 @@  #include "nvim/screen.h"  #include "nvim/vim.h" -static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "cursor.c.generated.h" +#endif  /*   * Get the screen position of the cursor. diff --git a/src/nvim/cursor_shape.h b/src/nvim/cursor_shape.h index aaed73e025..9ce1b6e0a0 100644 --- a/src/nvim/cursor_shape.h +++ b/src/nvim/cursor_shape.h @@ -47,6 +47,8 @@ typedef struct cursor_entry {    char used_for;                /* SHAPE_MOUSE and/or SHAPE_CURSOR */  } cursorentry_T; -char_u *parse_shape_opt(int what); -#endif /* NVIM_CURSOR_SHAPE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "cursor_shape.h.generated.h" +#endif +#endif  // NVIM_CURSOR_SHAPE_H diff --git a/src/nvim/diff.c b/src/nvim/diff.c index b01a7a934a..b859871f98 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -46,24 +46,10 @@ static int diff_flags = DIFF_FILLER;  // checked yet  static int diff_a_works = MAYBE; -static int diff_buf_idx(buf_T *buf); -static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp); -static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, -                                linenr_T line2, long amount, -                                long amount_after); -static void diff_check_unchanged(tabpage_T *tp, diff_T *dp); -static int diff_check_sanity(tabpage_T *tp, diff_T *dp); -static void diff_redraw(int dofold); -static int diff_write(buf_T *buf, char_u *fname); -static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff); -static int diff_equal_entry(diff_T *dp, int idx1, int idx2); -static int diff_cmp(char_u *s1, char_u *s2); -static void diff_fold_update(diff_T *dp, int skip_idx); -static void diff_read(int idx_orig, int idx_new, char_u *fname); -static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, -                            int idx_new); -static diff_T* diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "diff.c.generated.h" +#endif  #ifndef USE_CR  # define tag_fgets vim_fgets  #endif  // ifndef USE_CR diff --git a/src/nvim/diff.h b/src/nvim/diff.h index f68fd03d46..f6cef1cafd 100644 --- a/src/nvim/diff.h +++ b/src/nvim/diff.h @@ -1,33 +1,7 @@  #ifndef NVIM_DIFF_H  #define NVIM_DIFF_H -void diff_buf_delete(buf_T *buf); -void diff_buf_adjust(win_T *win); -void diff_buf_add(buf_T *buf); -void diff_invalidate(buf_T *buf); -void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, -                      long amount_after); -void ex_diffupdate(exarg_T *eap); -void ex_diffpatch(exarg_T *eap); -void ex_diffsplit(exarg_T *eap); -void ex_diffthis(exarg_T *eap); -void diff_win_options(win_T *wp, int addbuf); -void ex_diffoff(exarg_T *eap); -void diff_clear(tabpage_T *tp); -int diff_check(win_T *wp, linenr_T lnum); -int diff_check_fill(win_T *wp, linenr_T lnum); -void diff_set_topline(win_T *fromwin, win_T *towin); -int diffopt_changed(void); -int diffopt_horizontal(void); -int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp); -int diff_infold(win_T *wp, linenr_T lnum); -void nv_diffgetput(int put); -void ex_diffgetput(exarg_T *eap); -int diff_mode_buf(buf_T *buf); -int diff_move_to(int dir, long count); -linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1, -                                     buf_T *buf2, -                                     linenr_T lnum3); -linenr_T diff_lnum_win(linenr_T lnum, win_T *wp); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "diff.h.generated.h" +#endif  #endif  // NVIM_DIFF_H diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 443640d23d..ee9a2fee5f 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -27,9 +27,10 @@ typedef struct digraph {    result_T result;  } digr_T; -static int getexactdigraph(int char1, int char2, int meta_char); -static void printdigraph(digr_T *dp); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "digraph.c.generated.h" +#endif  // digraphs added by the user  static garray_T user_digraphs = {0, 0, (int)sizeof(digr_T), 10, NULL}; @@ -1721,7 +1722,6 @@ typedef struct {  #define KMAP_MAXLEN 20  // maximum length of "from" or "to" -static void keymap_unload(void);  /// Set up key mapping tables for the 'keymap' option.  /// diff --git a/src/nvim/digraph.h b/src/nvim/digraph.h index afeaa49ec6..b623969e08 100644 --- a/src/nvim/digraph.h +++ b/src/nvim/digraph.h @@ -1,12 +1,7 @@  #ifndef NVIM_DIGRAPH_H  #define NVIM_DIGRAPH_H -int do_digraph(int c); -int get_digraph(int cmdline); -int getdigraph(int char1, int char2, int meta_char); -void putdigraph(char_u *str); -void listdigraphs(void); -char_u *keymap_init(void); -void ex_loadkeymap(exarg_T *eap); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "digraph.h.generated.h" +#endif  #endif  // NVIM_DIGRAPH_H diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 338721d46d..accd346d36 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -175,113 +175,16 @@ static expand_T compl_xp;  static int compl_opt_refresh_always = FALSE; -static void ins_ctrl_x(void); -static int has_compl_option(int dict_opt); -static int ins_compl_accept_char(int c); -static int ins_compl_add(char_u *str, int len, int icase, char_u *fname, -                         char_u **cptext, int cdir, int flags, -                         int adup); -static int ins_compl_equal(compl_T *match, char_u *str, int len); -static void ins_compl_longest_match(compl_T *match); -static void ins_compl_add_matches(int num_matches, char_u **matches, -                                  int icase); -static int ins_compl_make_cyclic(void); -static void ins_compl_upd_pum(void); -static void ins_compl_del_pum(void); -static int pum_wanted(void); -static int pum_enough_matches(void); -static void ins_compl_dictionaries(char_u *dict, char_u *pat, int flags, -                                   int thesaurus); -static void ins_compl_files(int count, char_u **files, int thesaurus, -                            int flags, regmatch_T *regmatch, char_u * -                            buf, -                            int *dir); -static char_u *find_line_end(char_u *ptr); -static void ins_compl_free(void); -static void ins_compl_clear(void); -static int ins_compl_bs(void); -static int ins_compl_need_restart(void); -static void ins_compl_new_leader(void); -static void ins_compl_addleader(int c); -static int ins_compl_len(void); -static void ins_compl_restart(void); -static void ins_compl_set_original_text(char_u *str); -static void ins_compl_addfrommatch(void); -static int ins_compl_prep(int c); -static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg); -static buf_T *ins_compl_next_buf(buf_T *buf, int flag); -static void ins_compl_add_list(list_T *list); -static void ins_compl_add_dict(dict_T *dict); -static int ins_compl_get_exp(pos_T *ini); -static void ins_compl_delete(void); -static void ins_compl_insert(void); -static int ins_compl_next(int allow_get_expansion, int count, -                          int insert_match); -static int ins_compl_key2dir(int c); -static int ins_compl_pum_key(int c); -static int ins_compl_key2count(int c); -static int ins_compl_use_match(int c); -static int ins_complete(int c); -static unsigned quote_meta(char_u *dest, char_u *str, int len); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "edit.c.generated.h" +#endif  #define BACKSPACE_CHAR              1  #define BACKSPACE_WORD              2  #define BACKSPACE_WORD_NOT_SPACE    3  #define BACKSPACE_LINE              4 -static void ins_redraw(int ready); -static void ins_ctrl_v(void); -static void undisplay_dollar(void); -static void insert_special(int, int, int); -static void internal_format(int textwidth, int second_indent, int flags, -                            int format_only, -                            int c); -static void check_auto_format(int); -static void redo_literal(int c); -static void start_arrow(pos_T *end_insert_pos); -static void check_spell_redraw(void); -static void spell_back_to_badword(void);  static int spell_bad_len = 0;   /* length of located bad word */ -static void stop_insert(pos_T *end_insert_pos, int esc, int nomove); -static int echeck_abbr(int); -static int replace_pop(void); -static void replace_join(int off); -static void replace_pop_ins(void); -static void mb_replace_pop_ins(int cc); -static void replace_flush(void); -static void replace_do_bs(int limit_col); -static int del_char_after_col(int limit_col); -static int cindent_on(void); -static void ins_reg(void); -static void ins_ctrl_g(void); -static void ins_ctrl_hat(void); -static int ins_esc(long *count, int cmdchar, int nomove); -static void ins_ctrl_(void); -static int ins_start_select(int c); -static void ins_insert(int replaceState); -static void ins_ctrl_o(void); -static void ins_shift(int c, int lastc); -static void ins_del(void); -static int ins_bs(int c, int mode, int *inserted_space_p); -static void ins_mouse(int c); -static void ins_mousescroll(int dir); -static void ins_left(void); -static void ins_home(int c); -static void ins_end(int c); -static void ins_s_left(void); -static void ins_right(void); -static void ins_s_right(void); -static void ins_up(int startcol); -static void ins_pageup(void); -static void ins_down(int startcol); -static void ins_pagedown(void); -static int ins_tab(void); -static int ins_eol(int c); -static int ins_digraph(void); -static int ins_ctrl_ey(int tc); -static void ins_try_si(int c); -static colnr_T get_nolist_virtcol(void); -static char_u *do_insert_char_pre(int c);  static colnr_T Insstart_textlen;        /* length of line when insert started */  static colnr_T Insstart_blank_vcol;     /* vcol for first inserted blank */ @@ -3341,7 +3244,6 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag)    return buf;  } -static void expand_by_function(int type, char_u *base);  /*   * Execute user defined complete function 'completefunc' or 'omnifunc', and @@ -6472,9 +6374,7 @@ static int cindent_on(void) {   * confused what all the part that handles Control-T is doing that I'm not.   * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.   */ - -void fixthisline(get_the_indent) -int (*get_the_indent)(void); +void fixthisline(IndentGetter get_the_indent)  {    change_indent(INDENT_SET, get_the_indent(), FALSE, 0, TRUE);    if (linewhite(curwin->w_cursor.lnum)) @@ -7259,7 +7159,6 @@ static void ins_del(void)    AppendCharToRedobuff(K_DEL);  } -static void ins_bs_one(colnr_T *vcolp);  /*   * Delete one character for ins_bs(). diff --git a/src/nvim/edit.h b/src/nvim/edit.h index edd42800cc..52b8ae923b 100644 --- a/src/nvim/edit.h +++ b/src/nvim/edit.h @@ -12,47 +12,9 @@  #define CPT_INFO    3   /* "info" */  #define CPT_COUNT   4   /* Number of entries */ -int edit(int cmdchar, int startln, long count); -void edit_putchar(int c, int highlight); -void edit_unputchar(void); -void display_dollar(colnr_T col); -void change_indent(int type, int amount, int round, int replaced, -                   int call_changed_bytes); -void truncate_spaces(char_u *line); -void backspace_until_column(int col); -int vim_is_ctrl_x_key(int c); -int ins_compl_add_infercase(char_u *str, int len, int icase, -                            char_u *fname, int dir, -                            int flags); -void set_completion(colnr_T startcol, list_T *list); -void ins_compl_show_pum(void); -char_u *find_word_start(char_u *ptr); -char_u *find_word_end(char_u *ptr); -int ins_compl_active(void); -int ins_compl_add_tv(typval_T *tv, int dir); -void ins_compl_check_keys(int frequency); -int get_literal(void); -void insertchar(int c, int flags, int second_indent); -void auto_format(int trailblank, int prev_line); -int comp_textwidth(int ff); -int stop_arrow(void); -void set_last_insert(int c); -void free_last_insert(void); -char_u *add_char2buf(int c, char_u *s); -void beginline(int flags); -int oneright(void); -int oneleft(void); -int cursor_up(long n, int upd_topline); -int cursor_down(long n, int upd_topline); -int stuff_inserted(int c, long count, int no_esc); -char_u *get_last_insert(void); -char_u *get_last_insert_save(void); -void replace_push(int c); -int replace_push_mb(char_u *p); -void fixthisline(int (*get_the_indent)(void)); -void fix_indent(void); -int in_cinkeys(int keytyped, int when, int line_is_empty); -int hkmap(int c); -int ins_copychar(linenr_T lnum); +typedef int (*IndentGetter)(void); -#endif /* NVIM_EDIT_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "edit.h.generated.h" +#endif +#endif  // NVIM_EDIT_H diff --git a/src/nvim/eval.c b/src/nvim/eval.c index db57f73a1f..85361b50f4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -305,6 +305,14 @@ typedef struct {    dictitem_T  *fd_di;           /* Dictionary item used */  } funcdict_T; +/* + * enum used by var_flavour() + */ +typedef enum { +  VAR_FLAVOUR_DEFAULT,          /* doesn't start with uppercase */ +  VAR_FLAVOUR_SESSION,          /* starts with uppercase, some lower */ +  VAR_FLAVOUR_VIMINFO           /* all uppercase */ +} var_flavour_T;  /*   * Array to hold the value of v: variables. @@ -404,459 +412,13 @@ static struct vimvar {  static dictitem_T vimvars_var;                  /* variable used for v: */  #define vimvarht  vimvardict.dv_hashtab -static void on_job_stdout(RStream *rstream, void *data, bool eof); -static void on_job_stderr(RStream *rstream, void *data, bool eof); -static void on_job_exit(Job *job, void *data); -static void on_job_data(RStream *rstream, void *data, bool eof, char *type); -static void apply_job_autocmds(Job *job, char *name, char *type, char *str); -static void prepare_vimvar(int idx, typval_T *save_tv); -static void restore_vimvar(int idx, typval_T *save_tv); -static int ex_let_vars(char_u *arg, typval_T *tv, int copy, -                       int semicolon, int var_count, -                       char_u *nextchars); -static char_u *skip_var_list(char_u *arg, int *var_count, -                                     int *semicolon); -static char_u *skip_var_one(char_u *arg); -static void list_hashtable_vars(hashtab_T *ht, char_u *prefix, -                                        int empty, -                                        int *first); -static void list_glob_vars(int *first); -static void list_buf_vars(int *first); -static void list_win_vars(int *first); -static void list_tab_vars(int *first); -static void list_vim_vars(int *first); -static void list_script_vars(int *first); -static void list_func_vars(int *first); -static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); -static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, -                          char_u *endchars, char_u *op); -static int check_changedtick(char_u *arg); -static char_u *get_lval(char_u *name, typval_T *rettv, lval_T *lp, -                        int unlet, int skip, int flags, -                        int fne_flags); -static void clear_lval(lval_T *lp); -static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, -                         int copy, -                         char_u *op); -static int tv_op(typval_T *tv1, typval_T *tv2, char_u  *op); -static void list_fix_watch(list_T *l, listitem_T *item); -static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep); -static int do_unlet_var(lval_T *lp, char_u *name_end, int forceit); -static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock); -static void item_lock(typval_T *tv, int deep, int lock); -static int tv_islocked(typval_T *tv); - -static int eval0(char_u *arg,  typval_T *rettv, char_u **nextcmd, -                 int evaluate); -static int eval1(char_u **arg, typval_T *rettv, int evaluate); -static int eval2(char_u **arg, typval_T *rettv, int evaluate); -static int eval3(char_u **arg, typval_T *rettv, int evaluate); -static int eval4(char_u **arg, typval_T *rettv, int evaluate); -static int eval5(char_u **arg, typval_T *rettv, int evaluate); -static int eval6(char_u **arg, typval_T *rettv, int evaluate, -                 int want_string); -static int eval7(char_u **arg, typval_T *rettv, int evaluate, -                 int want_string); - -static int eval_index(char_u **arg, typval_T *rettv, int evaluate, -                      int verbose); -static int get_option_tv(char_u **arg, typval_T *rettv, int evaluate); -static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate); -static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate); -static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate); -static void rettv_list_alloc(typval_T *rettv); -static long list_len(list_T *l); -static int list_equal(list_T *l1, list_T *l2, int ic, int recursive); -static int dict_equal(dict_T *d1, dict_T *d2, int ic, int recursive); -static int tv_equal(typval_T *tv1, typval_T *tv2, int ic, int recursive); -static long list_find_nr(list_T *l, long idx, int *errorp); -static long list_idx_of_item(list_T *l, listitem_T *item); -static void list_append_number(list_T *l, varnumber_T n); -static int list_extend(list_T   *l1, list_T *l2, listitem_T *bef); -static int list_concat(list_T *l1, list_T *l2, typval_T *tv); -static list_T *list_copy(list_T *orig, int deep, int copyID); -static char_u *list2string(typval_T *tv, int copyID); -static int list_join_inner(garray_T *gap, list_T *l, char_u *sep, -                           int echo_style, int copyID, -                           garray_T *join_gap); -static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo, -                     int copyID); -static int free_unref_items(int copyID); -static int rettv_dict_alloc(typval_T *rettv); -static dictitem_T *dictitem_copy(dictitem_T *org); -static void dictitem_remove(dict_T *dict, dictitem_T *item); -static dict_T *dict_copy(dict_T *orig, int deep, int copyID); -static long dict_len(dict_T *d); -static char_u *dict2string(typval_T *tv, int copyID); -static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate); -static char_u *echo_string(typval_T *tv, char_u **tofree, -                           char_u *numbuf, -                           int copyID); -static char_u *tv2string(typval_T *tv, char_u **tofree, char_u *numbuf, -                         int copyID); -static char_u *string_quote(char_u *str, int function); -static int string2float(char_u *text, float_T *value); -static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate); -static int find_internal_func(char_u *name); -static char_u *deref_func_name(char_u *name, int *lenp, int no_autoload); -static int get_func_tv(char_u *name, int len, typval_T *rettv, -                       char_u **arg, linenr_T firstline, linenr_T lastline, -                       int *doesrange, int evaluate, -                       dict_T *selfdict); -static int call_func(char_u *funcname, int len, typval_T *rettv, -                     int argcount, typval_T *argvars, -                     linenr_T firstline, linenr_T lastline, -                     int *doesrange, int evaluate, -                     dict_T *selfdict); -static void emsg_funcname(char *ermsg, char_u *name); -static int non_zero_arg(typval_T *argvars); - -static void f_abs(typval_T *argvars, typval_T *rettv); -static void f_acos(typval_T *argvars, typval_T *rettv); -static void f_add(typval_T *argvars, typval_T *rettv); -static void f_and(typval_T *argvars, typval_T *rettv); -static void f_append(typval_T *argvars, typval_T *rettv); -static void f_argc(typval_T *argvars, typval_T *rettv); -static void f_argidx(typval_T *argvars, typval_T *rettv); -static void f_argv(typval_T *argvars, typval_T *rettv); -static void f_asin(typval_T *argvars, typval_T *rettv); -static void f_atan(typval_T *argvars, typval_T *rettv); -static void f_atan2(typval_T *argvars, typval_T *rettv); -static void f_browse(typval_T *argvars, typval_T *rettv); -static void f_browsedir(typval_T *argvars, typval_T *rettv); -static void f_bufexists(typval_T *argvars, typval_T *rettv); -static void f_buflisted(typval_T *argvars, typval_T *rettv); -static void f_bufloaded(typval_T *argvars, typval_T *rettv); -static void f_bufname(typval_T *argvars, typval_T *rettv); -static void f_bufnr(typval_T *argvars, typval_T *rettv); -static void f_bufwinnr(typval_T *argvars, typval_T *rettv); -static void f_byte2line(typval_T *argvars, typval_T *rettv); -static void byteidx(typval_T *argvars, typval_T *rettv, int comp); -static void f_byteidx(typval_T *argvars, typval_T *rettv); -static void f_byteidxcomp(typval_T *argvars, typval_T *rettv); -static void f_call(typval_T *argvars, typval_T *rettv); -static void f_ceil(typval_T *argvars, typval_T *rettv); -static void f_changenr(typval_T *argvars, typval_T *rettv); -static void f_char2nr(typval_T *argvars, typval_T *rettv); -static void f_cindent(typval_T *argvars, typval_T *rettv); -static void f_clearmatches(typval_T *argvars, typval_T *rettv); -static void f_col(typval_T *argvars, typval_T *rettv); -static void f_complete(typval_T *argvars, typval_T *rettv); -static void f_complete_add(typval_T *argvars, typval_T *rettv); -static void f_complete_check(typval_T *argvars, typval_T *rettv); -static void f_confirm(typval_T *argvars, typval_T *rettv); -static void f_copy(typval_T *argvars, typval_T *rettv); -static void f_cos(typval_T *argvars, typval_T *rettv); -static void f_cosh(typval_T *argvars, typval_T *rettv); -static void f_count(typval_T *argvars, typval_T *rettv); -static void f_cscope_connection(typval_T *argvars, typval_T *rettv); -static void f_cursor(typval_T *argsvars, typval_T *rettv); -static void f_deepcopy(typval_T *argvars, typval_T *rettv); -static void f_delete(typval_T *argvars, typval_T *rettv); -static void f_did_filetype(typval_T *argvars, typval_T *rettv); -static void f_diff_filler(typval_T *argvars, typval_T *rettv); -static void f_diff_hlID(typval_T *argvars, typval_T *rettv); -static void f_empty(typval_T *argvars, typval_T *rettv); -static void f_escape(typval_T *argvars, typval_T *rettv); -static void f_eval(typval_T *argvars, typval_T *rettv); -static void f_eventhandler(typval_T *argvars, typval_T *rettv); -static void f_executable(typval_T *argvars, typval_T *rettv); -static void f_exists(typval_T *argvars, typval_T *rettv); -static void f_exp(typval_T *argvars, typval_T *rettv); -static void f_expand(typval_T *argvars, typval_T *rettv); -static void f_extend(typval_T *argvars, typval_T *rettv); -static void f_feedkeys(typval_T *argvars, typval_T *rettv); -static void f_filereadable(typval_T *argvars, typval_T *rettv); -static void f_filewritable(typval_T *argvars, typval_T *rettv); -static void f_filter(typval_T *argvars, typval_T *rettv); -static void f_finddir(typval_T *argvars, typval_T *rettv); -static void f_findfile(typval_T *argvars, typval_T *rettv); -static void f_float2nr(typval_T *argvars, typval_T *rettv); -static void f_floor(typval_T *argvars, typval_T *rettv); -static void f_fmod(typval_T *argvars, typval_T *rettv); -static void f_fnameescape(typval_T *argvars, typval_T *rettv); -static void f_fnamemodify(typval_T *argvars, typval_T *rettv); -static void f_foldclosed(typval_T *argvars, typval_T *rettv); -static void f_foldclosedend(typval_T *argvars, typval_T *rettv); -static void f_foldlevel(typval_T *argvars, typval_T *rettv); -static void f_foldtext(typval_T *argvars, typval_T *rettv); -static void f_foldtextresult(typval_T *argvars, typval_T *rettv); -static void f_foreground(typval_T *argvars, typval_T *rettv); -static void f_function(typval_T *argvars, typval_T *rettv); -static void f_garbagecollect(typval_T *argvars, typval_T *rettv); -static void f_get(typval_T *argvars, typval_T *rettv); -static void f_getbufline(typval_T *argvars, typval_T *rettv); -static void f_getbufvar(typval_T *argvars, typval_T *rettv); -static void f_getchar(typval_T *argvars, typval_T *rettv); -static void f_getcharmod(typval_T *argvars, typval_T *rettv); -static void f_getcmdline(typval_T *argvars, typval_T *rettv); -static void f_getcmdpos(typval_T *argvars, typval_T *rettv); -static void f_getcmdtype(typval_T *argvars, typval_T *rettv); -static void f_getcwd(typval_T *argvars, typval_T *rettv); -static void f_getfontname(typval_T *argvars, typval_T *rettv); -static void f_getfperm(typval_T *argvars, typval_T *rettv); -static void f_getfsize(typval_T *argvars, typval_T *rettv); -static void f_getftime(typval_T *argvars, typval_T *rettv); -static void f_getftype(typval_T *argvars, typval_T *rettv); -static void f_getline(typval_T *argvars, typval_T *rettv); -static void f_getmatches(typval_T *argvars, typval_T *rettv); -static void f_getpid(typval_T *argvars, typval_T *rettv); -static void f_getpos(typval_T *argvars, typval_T *rettv); -static void f_getqflist(typval_T *argvars, typval_T *rettv); -static void f_getreg(typval_T *argvars, typval_T *rettv); -static void f_getregtype(typval_T *argvars, typval_T *rettv); -static void f_gettabvar(typval_T *argvars, typval_T *rettv); -static void f_gettabwinvar(typval_T *argvars, typval_T *rettv); -static void f_getwinposx(typval_T *argvars, typval_T *rettv); -static void f_getwinposy(typval_T *argvars, typval_T *rettv); -static void f_getwinvar(typval_T *argvars, typval_T *rettv); -static void f_glob(typval_T *argvars, typval_T *rettv); -static void f_globpath(typval_T *argvars, typval_T *rettv); -static void f_has(typval_T *argvars, typval_T *rettv); -static void f_has_key(typval_T *argvars, typval_T *rettv); -static void f_haslocaldir(typval_T *argvars, typval_T *rettv); -static void f_hasmapto(typval_T *argvars, typval_T *rettv); -static void f_histadd(typval_T *argvars, typval_T *rettv); -static void f_histdel(typval_T *argvars, typval_T *rettv); -static void f_histget(typval_T *argvars, typval_T *rettv); -static void f_histnr(typval_T *argvars, typval_T *rettv); -static void f_hlID(typval_T *argvars, typval_T *rettv); -static void f_hlexists(typval_T *argvars, typval_T *rettv); -static void f_hostname(typval_T *argvars, typval_T *rettv); -static void f_iconv(typval_T *argvars, typval_T *rettv); -static void f_indent(typval_T *argvars, typval_T *rettv); -static void f_index(typval_T *argvars, typval_T *rettv); -static void f_input(typval_T *argvars, typval_T *rettv); -static void f_inputdialog(typval_T *argvars, typval_T *rettv); -static void f_inputlist(typval_T *argvars, typval_T *rettv); -static void f_inputrestore(typval_T *argvars, typval_T *rettv); -static void f_inputsave(typval_T *argvars, typval_T *rettv); -static void f_inputsecret(typval_T *argvars, typval_T *rettv); -static void f_insert(typval_T *argvars, typval_T *rettv); -static void f_invert(typval_T *argvars, typval_T *rettv); -static void f_isdirectory(typval_T *argvars, typval_T *rettv); -static void f_islocked(typval_T *argvars, typval_T *rettv); -static void f_items(typval_T *argvars, typval_T *rettv); -static void f_job_start(typval_T *argvars, typval_T *rettv); -static void f_job_stop(typval_T *argvars, typval_T *rettv); -static void f_job_write(typval_T *argvars, typval_T *rettv); -static void f_join(typval_T *argvars, typval_T *rettv); -static void f_keys(typval_T *argvars, typval_T *rettv); -static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv); -static void f_len(typval_T *argvars, typval_T *rettv); -static void f_libcall(typval_T *argvars, typval_T *rettv); -static void f_libcallnr(typval_T *argvars, typval_T *rettv); -static void f_line(typval_T *argvars, typval_T *rettv); -static void f_line2byte(typval_T *argvars, typval_T *rettv); -static void f_lispindent(typval_T *argvars, typval_T *rettv); -static void f_localtime(typval_T *argvars, typval_T *rettv); -static void f_log(typval_T *argvars, typval_T *rettv); -static void f_log10(typval_T *argvars, typval_T *rettv); -static void f_map(typval_T *argvars, typval_T *rettv); -static void f_maparg(typval_T *argvars, typval_T *rettv); -static void f_mapcheck(typval_T *argvars, typval_T *rettv); -static void f_match(typval_T *argvars, typval_T *rettv); -static void f_matchadd(typval_T *argvars, typval_T *rettv); -static void f_matcharg(typval_T *argvars, typval_T *rettv); -static void f_matchdelete(typval_T *argvars, typval_T *rettv); -static void f_matchend(typval_T *argvars, typval_T *rettv); -static void f_matchlist(typval_T *argvars, typval_T *rettv); -static void f_matchstr(typval_T *argvars, typval_T *rettv); -static void f_max(typval_T *argvars, typval_T *rettv); -static void f_min(typval_T *argvars, typval_T *rettv); -static void f_mkdir(typval_T *argvars, typval_T *rettv); -static void f_mode(typval_T *argvars, typval_T *rettv); -static void f_nextnonblank(typval_T *argvars, typval_T *rettv); -static void f_nr2char(typval_T *argvars, typval_T *rettv); -static void f_or(typval_T *argvars, typval_T *rettv); -static void f_pathshorten(typval_T *argvars, typval_T *rettv); -static void f_pow(typval_T *argvars, typval_T *rettv); -static void f_prevnonblank(typval_T *argvars, typval_T *rettv); -static void f_printf(typval_T *argvars, typval_T *rettv); -static void f_pumvisible(typval_T *argvars, typval_T *rettv); -static void f_range(typval_T *argvars, typval_T *rettv); -static void f_readfile(typval_T *argvars, typval_T *rettv); -static void f_reltime(typval_T *argvars, typval_T *rettv); -static void f_reltimestr(typval_T *argvars, typval_T *rettv); -static void f_remove(typval_T *argvars, typval_T *rettv); -static void f_rename(typval_T *argvars, typval_T *rettv); -static void f_repeat(typval_T *argvars, typval_T *rettv); -static void f_resolve(typval_T *argvars, typval_T *rettv); -static void f_reverse(typval_T *argvars, typval_T *rettv); -static void f_round(typval_T *argvars, typval_T *rettv); -static void f_screenattr(typval_T *argvars, typval_T *rettv); -static void f_screenchar(typval_T *argvars, typval_T *rettv); -static void f_screencol(typval_T *argvars, typval_T *rettv); -static void f_screenrow(typval_T *argvars, typval_T *rettv); -static void f_search(typval_T *argvars, typval_T *rettv); -static void f_searchdecl(typval_T *argvars, typval_T *rettv); -static void f_searchpair(typval_T *argvars, typval_T *rettv); -static void f_searchpairpos(typval_T *argvars, typval_T *rettv); -static void f_searchpos(typval_T *argvars, typval_T *rettv); -static void f_send_event(typval_T *argvars, typval_T *rettv); -static void f_setbufvar(typval_T *argvars, typval_T *rettv); -static void f_setcmdpos(typval_T *argvars, typval_T *rettv); -static void f_setline(typval_T *argvars, typval_T *rettv); -static void f_setloclist(typval_T *argvars, typval_T *rettv); -static void f_setmatches(typval_T *argvars, typval_T *rettv); -static void f_setpos(typval_T *argvars, typval_T *rettv); -static void f_setqflist(typval_T *argvars, typval_T *rettv); -static void f_setreg(typval_T *argvars, typval_T *rettv); -static void f_settabvar(typval_T *argvars, typval_T *rettv); -static void f_settabwinvar(typval_T *argvars, typval_T *rettv); -static void f_setwinvar(typval_T *argvars, typval_T *rettv); -static void f_shellescape(typval_T *argvars, typval_T *rettv); -static void f_shiftwidth(typval_T *argvars, typval_T *rettv); -static void f_simplify(typval_T *argvars, typval_T *rettv); -static void f_sin(typval_T *argvars, typval_T *rettv); -static void f_sinh(typval_T *argvars, typval_T *rettv); -static void f_sort(typval_T *argvars, typval_T *rettv); -static void f_soundfold(typval_T *argvars, typval_T *rettv); -static void f_spellbadword(typval_T *argvars, typval_T *rettv); -static void f_spellsuggest(typval_T *argvars, typval_T *rettv); -static void f_split(typval_T *argvars, typval_T *rettv); -static void f_sqrt(typval_T *argvars, typval_T *rettv); -static void f_str2float(typval_T *argvars, typval_T *rettv); -static void f_str2nr(typval_T *argvars, typval_T *rettv); -static void f_strchars(typval_T *argvars, typval_T *rettv); -static void f_strftime(typval_T *argvars, typval_T *rettv); -static void f_stridx(typval_T *argvars, typval_T *rettv); -static void f_string(typval_T *argvars, typval_T *rettv); -static void f_strlen(typval_T *argvars, typval_T *rettv); -static void f_strpart(typval_T *argvars, typval_T *rettv); -static void f_strridx(typval_T *argvars, typval_T *rettv); -static void f_strtrans(typval_T *argvars, typval_T *rettv); -static void f_strdisplaywidth(typval_T *argvars, typval_T *rettv); -static void f_strwidth(typval_T *argvars, typval_T *rettv); -static void f_submatch(typval_T *argvars, typval_T *rettv); -static void f_substitute(typval_T *argvars, typval_T *rettv); -static void f_synID(typval_T *argvars, typval_T *rettv); -static void f_synIDattr(typval_T *argvars, typval_T *rettv); -static void f_synIDtrans(typval_T *argvars, typval_T *rettv); -static void f_synstack(typval_T *argvars, typval_T *rettv); -static void f_synconcealed(typval_T *argvars, typval_T *rettv); -static void f_system(typval_T *argvars, typval_T *rettv); -static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv); -static void f_tabpagenr(typval_T *argvars, typval_T *rettv); -static void f_tabpagewinnr(typval_T *argvars, typval_T *rettv); -static void f_taglist(typval_T *argvars, typval_T *rettv); -static void f_tagfiles(typval_T *argvars, typval_T *rettv); -static void f_tempname(typval_T *argvars, typval_T *rettv); -static void f_test(typval_T *argvars, typval_T *rettv); -static void f_tan(typval_T *argvars, typval_T *rettv); -static void f_tanh(typval_T *argvars, typval_T *rettv); -static void f_tolower(typval_T *argvars, typval_T *rettv); -static void f_toupper(typval_T *argvars, typval_T *rettv); -static void f_tr(typval_T *argvars, typval_T *rettv); -static void f_trunc(typval_T *argvars, typval_T *rettv); -static void f_type(typval_T *argvars, typval_T *rettv); -static void f_undofile(typval_T *argvars, typval_T *rettv); -static void f_undotree(typval_T *argvars, typval_T *rettv); -static void f_uniq(typval_T *argvars, typval_T *rettv); -static void f_values(typval_T *argvars, typval_T *rettv); -static void f_virtcol(typval_T *argvars, typval_T *rettv); -static void f_visualmode(typval_T *argvars, typval_T *rettv); -static void f_wildmenumode(typval_T *argvars, typval_T *rettv); -static void f_winbufnr(typval_T *argvars, typval_T *rettv); -static void f_wincol(typval_T *argvars, typval_T *rettv); -static void f_winheight(typval_T *argvars, typval_T *rettv); -static void f_winline(typval_T *argvars, typval_T *rettv); -static void f_winnr(typval_T *argvars, typval_T *rettv); -static void f_winrestcmd(typval_T *argvars, typval_T *rettv); -static void f_winrestview(typval_T *argvars, typval_T *rettv); -static void f_winsaveview(typval_T *argvars, typval_T *rettv); -static void f_winwidth(typval_T *argvars, typval_T *rettv); -static void f_writefile(typval_T *argvars, typval_T *rettv); -static void f_xor(typval_T *argvars, typval_T *rettv); - -static int list2fpos(typval_T *arg, pos_T *posp, int *fnump); -static pos_T *var2fpos(typval_T *varp, int dollar_lnum, int *fnum); -static int get_env_len(char_u **arg); -static int get_id_len(char_u **arg); -static int get_name_len(char_u **arg, char_u **alias, int evaluate, -                        int verbose); -static char_u *find_name_end(char_u *arg, char_u **expr_start, char_u * -                             *expr_end, -                             int flags); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "eval.c.generated.h" +#endif +  #define FNE_INCL_BR     1       /* find_name_end(): include [] in name */  #define FNE_CHECK_START 2       /* find_name_end(): check name starts with                                     valid character */ -static char_u * -make_expanded_name(char_u *in_start, char_u *expr_start, char_u * -                   expr_end, -                   char_u *in_end); -static int eval_isnamec(int c); -static int eval_isnamec1(int c); -static int get_var_tv(char_u *name, int len, typval_T *rettv, -                      int verbose, -                      int no_autoload); -static int handle_subscript(char_u **arg, typval_T *rettv, int evaluate, -                            int verbose); -static void init_tv(typval_T *varp); -static long get_tv_number(typval_T *varp); -static linenr_T get_tv_lnum(typval_T *argvars); -static linenr_T get_tv_lnum_buf(typval_T *argvars, buf_T *buf); -static char_u *get_tv_string(typval_T *varp); -static char_u *get_tv_string_buf(typval_T *varp, char_u *buf); -static char_u *get_tv_string_buf_chk(typval_T *varp, char_u *buf); -static dictitem_T *find_var(char_u *name, hashtab_T **htp, -                            int no_autoload); -static dictitem_T *find_var_in_ht(hashtab_T *ht, int htname, -                                  char_u *varname, -                                  int no_autoload); -static hashtab_T *find_var_ht(char_u *name, char_u **varname); -static void vars_clear_ext(hashtab_T *ht, int free_val); -static void delete_var(hashtab_T *ht, hashitem_T *hi); -static void list_one_var(dictitem_T *v, char_u *prefix, int *first); -static void list_one_var_a(char_u *prefix, char_u *name, int type, -                           char_u *string, -                           int *first); -static void set_var(char_u *name, typval_T *varp, int copy); -static int var_check_ro(int flags, char_u *name); -static int var_check_fixed(int flags, char_u *name); -static int var_check_func_name(char_u *name, int new_var); -static int valid_varname(char_u *varname); -static int tv_check_lock(int lock, char_u *name); -static int item_copy(typval_T *from, typval_T *to, int deep, int copyID); -static char_u *find_option_end(char_u **arg, int *opt_flags); -static char_u *trans_function_name(char_u **pp, int skip, int flags, -                                   funcdict_T *fd); -static int eval_fname_script(char_u *p); -static int eval_fname_sid(char_u *p); -static void list_func_head(ufunc_T *fp, int indent); -static ufunc_T *find_func(char_u *name); -static int function_exists(char_u *name); -static bool builtin_function(char_u *name, int len); -static void func_do_profile(ufunc_T *fp); -static void prof_sort_list(FILE *fd, ufunc_T **sorttab, int st_len, -                           char *title, -                           int prefer_self); -static void prof_func_line(FILE *fd, int count, proftime_T *total, -                           proftime_T *self, -                           int prefer_self); -static int -prof_total_cmp(const void *s1, const void *s2); -static int -prof_self_cmp(const void *s1, const void *s2); -static int script_autoload(char_u *name, int reload); -static char_u *autoload_name(char_u *name); -static void cat_func_name(char_u *buf, ufunc_T *fp); -static void func_free(ufunc_T *fp); -static void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, -                           typval_T *rettv, linenr_T firstline, -                           linenr_T lastline, -                           dict_T *selfdict); -static int can_free_funccal(funccall_T *fc, int copyID); -static void free_funccal(funccall_T *fc, int free_val); -static void add_nr_var(dict_T *dp, dictitem_T *v, char *name, -                       varnumber_T nr); -static win_T *find_win_by_nr(typval_T *vp, tabpage_T *tp); -static void getwinvar(typval_T *argvars, typval_T *rettv, int off); -static int searchpair_cmn(typval_T *argvars, pos_T *match_pos); -static int search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp); -static void setwinvar(typval_T *argvars, typval_T *rettv, int off); - -  /*   * Initialize the global and v: variables. @@ -1627,8 +1189,8 @@ void restore_funccal(void *vfc)   * counted for the script/function itself.   * Should always be called in pair with prof_child_exit().   */ -void prof_child_enter(tm) -proftime_T *tm;         /* place to store waittime */ +void prof_child_enter(proftime_T *tm /* place to store waittime */ +                      )  {    funccall_T *fc = current_funccal; @@ -1641,8 +1203,8 @@ proftime_T *tm;         /* place to store waittime */   * Take care of time spent in a child.   * Should always be called after prof_child_enter().   */ -void prof_child_exit(tm) -proftime_T *tm;         /* where waittime was stored */ +void prof_child_exit(proftime_T *tm /* where waittime was stored */ +                     )  {    funccall_T *fc = current_funccal; @@ -3406,7 +2968,6 @@ void del_menutrans_vars(void)   * get_user_var_name().   */ -static char_u *cat_prefix_varname(int prefix, char_u *name);  static char_u   *varnamebuf = NULL;  static size_t varnamebuflen = 0; @@ -7416,7 +6977,6 @@ static int non_zero_arg(typval_T *argvars)   * Implementation of the built-in functions   */ -static int get_float_arg(typval_T *argvars, float_T *f);  /*   * Get the float value of "argvars[0]" into "f". @@ -7653,7 +7213,6 @@ static void f_browsedir(typval_T *argvars, typval_T *rettv)    rettv->v_type = VAR_STRING;  } -static buf_T *find_buffer(typval_T *avar);  /*   * Find a buffer by number or exact name. @@ -7711,7 +7270,6 @@ static void f_bufloaded(typval_T *argvars, typval_T *rettv)    rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL);  } -static buf_T *get_buf_tv(typval_T *tv, int curtab_only);  /*   * Get buffer by number or pattern. @@ -8814,8 +8372,6 @@ static void f_filewritable(typval_T *argvars, typval_T *rettv)    rettv->vval.v_number = os_file_is_writable(filename);  } -static void findfilendir(typval_T *argvars, typval_T *rettv, -                                 int find_what);  static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)  { @@ -8873,8 +8429,6 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)      rettv->vval.v_string = fresult;  } -static void filter_map(typval_T *argvars, typval_T *rettv, int map); -static int filter_map_one(typval_T *tv, char_u *expr, int map, int *remp);  /*   * Implementation of map() and filter(). @@ -9120,7 +8674,6 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv)    free(fbuf);  } -static void foldclosed_both(typval_T *argvars, typval_T *rettv, int end);  /*   * "foldclosed()" function @@ -9338,9 +8891,6 @@ static void f_get(typval_T *argvars, typval_T *rettv)      copy_tv(tv, rettv);  } -static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, -                             int retlist, -                             typval_T *rettv);  /*   * Get line or list of lines from buffer "buf" into "rettv". @@ -10542,8 +10092,6 @@ static void f_index(typval_T *argvars, typval_T *rettv)  static int inputsecret_flag = 0; -static void get_user_input(typval_T *argvars, typval_T *rettv, -                           int inputdialog);  /*   * This function is used by f_input() and f_inputdialog() functions. The third @@ -10835,7 +10383,6 @@ static void f_islocked(typval_T *argvars, typval_T *rettv)    clear_lval(&lv);  } -static void dict_list(typval_T *argvars, typval_T *rettv, int what);  /*   * Turn a dict into a list: @@ -11124,7 +10671,6 @@ static void f_len(typval_T *argvars, typval_T *rettv)    }  } -static void libcall_common(typval_T *argvars, typval_T *rettv, int type);  static void libcall_common(typval_T *argvars, typval_T *rettv, int type)  { @@ -11236,7 +10782,6 @@ static void f_localtime(typval_T *argvars, typval_T *rettv)    rettv->vval.v_number = (varnumber_T)time(NULL);  } -static void get_maparg(typval_T *argvars, typval_T *rettv, int exact);  static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)  { @@ -11356,7 +10901,6 @@ static void f_mapcheck(typval_T *argvars, typval_T *rettv)    get_maparg(argvars, rettv, FALSE);  } -static void find_some_match(typval_T *argvars, typval_T *rettv, int start);  static void find_some_match(typval_T *argvars, typval_T *rettv, int type)  { @@ -11608,7 +11152,6 @@ static void f_matchstr(typval_T *argvars, typval_T *rettv)    find_some_match(argvars, rettv, 2);  } -static void max_min(typval_T *argvars, typval_T *rettv, int domax);  static void max_min(typval_T *argvars, typval_T *rettv, int domax)  { @@ -11677,7 +11220,6 @@ static void f_min(typval_T *argvars, typval_T *rettv)    max_min(argvars, rettv, FALSE);  } -static int mkdir_recurse(char_u *dir, int prot);  /*   * Create the directory in which "dir" is located, and higher levels when @@ -12142,7 +11684,6 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)    fclose(fd);  } -static int list2proftime(typval_T *arg, proftime_T *tm);  /*   * Convert a List to proftime_T. @@ -12556,7 +12097,6 @@ static void f_reverse(typval_T *argvars, typval_T *rettv)  #define SP_SUBPAT       0x20        /* return nr of matching sub-pattern */  #define SP_END          0x40        /* leave cursor at end of match */ -static int get_search_arg(typval_T *varp, int *flagsp);  /*   * Get flags for a search function. @@ -13228,9 +12768,6 @@ static void f_setline(typval_T *argvars, typval_T *rettv)      appended_lines_mark(lcount, added);  } -static void set_qf_ll_list(win_T *wp, typval_T *list_arg, -                           typval_T *action_arg, -                           typval_T *rettv);  /*   * Used by "setqflist()" and "setloclist()" functions @@ -13589,16 +13126,11 @@ static void f_sinh(typval_T *argvars, typval_T *rettv)      rettv->vval.v_float = 0.0;  } -static int -item_compare(const void *s1, const void *s2); -static int -item_compare2(const void *s1, const void *s2);  static int item_compare_ic;  static char_u   *item_compare_func;  static dict_T   *item_compare_selfdict;  static int item_compare_func_err; -static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort);  #define ITEM_COMPARE_FAIL 999  /* @@ -14637,7 +14169,6 @@ static void f_tabpagenr(typval_T *argvars, typval_T *rettv)  } -static int get_winnr(tabpage_T *tp, typval_T *argvar);  /*   * Common code for tabpagewinnr() and winnr(). @@ -18088,12 +17619,13 @@ prof_sort_list (  /*   * Print the count and times for one function or function line.   */ -static void prof_func_line(fd, count, total, self, prefer_self) -FILE        *fd; -int count; -proftime_T  *total; -proftime_T  *self; -int prefer_self;                /* when equal print only self time */ +static void prof_func_line( +    FILE        *fd, +    int count, +    proftime_T  *total, +    proftime_T  *self, +    int prefer_self                 /* when equal print only self time */ +    )  {    if (count > 0) {      fprintf(fd, "%5d ", count); @@ -19020,14 +18552,6 @@ int func_has_abort(void *cookie)    return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT;  } -typedef enum { -  VAR_FLAVOUR_DEFAULT,          /* doesn't start with uppercase */ -  VAR_FLAVOUR_SESSION,          /* starts with uppercase, some lower */ -  VAR_FLAVOUR_VIMINFO           /* all uppercase */ -} var_flavour_T; - -static var_flavour_T var_flavour(char_u *varname); -  static var_flavour_T var_flavour(char_u *varname)  {    char_u *p = varname; diff --git a/src/nvim/eval.h b/src/nvim/eval.h index 30177b81e8..7daea8fc71 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -1,152 +1,7 @@  #ifndef NVIM_EVAL_H  #define NVIM_EVAL_H -/* eval.c */ -void eval_init(void); -void eval_clear(void); -char_u *func_name(void *cookie); -linenr_T *func_breakpoint(void *cookie); -int *func_dbg_tick(void *cookie); -int func_level(void *cookie); -int current_func_returned(void); -void set_internal_string_var(char_u *name, char_u *value); -int var_redir_start(char_u *name, int append); -void var_redir_str(char_u *value, int value_len); -void var_redir_stop(void); -int eval_charconvert(char_u *enc_from, char_u *enc_to, char_u * -                     fname_from, -                     char_u *fname_to); -int eval_printexpr(char_u *fname, char_u *args); -void eval_diff(char_u *origfile, char_u *newfile, char_u *outfile); -void eval_patch(char_u *origfile, char_u *difffile, char_u *outfile); -int eval_to_bool(char_u *arg, int *error, char_u **nextcmd, int skip); -char_u *eval_to_string_skip(char_u *arg, char_u **nextcmd, int skip); -int skip_expr(char_u **pp); -char_u *eval_to_string(char_u *arg, char_u **nextcmd, int convert); -char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, -                            int use_sandbox); -int eval_to_number(char_u *expr); -list_T *eval_spell_expr(char_u *badword, char_u *expr); -int get_spellword(list_T *list, char_u **pp); -typval_T *eval_expr(char_u *arg, char_u **nextcmd); -int call_vim_function(char_u *func, int argc, char_u **argv, int safe, -                      int str_arg_only, -                      typval_T *rettv); -long call_func_retnr(char_u *func, int argc, char_u **argv, int safe); -void *call_func_retstr(char_u *func, int argc, char_u **argv, int safe); -void *call_func_retlist(char_u *func, int argc, char_u **argv, int safe); -void *save_funccal(void); -void restore_funccal(void *vfc); -void prof_child_enter(proftime_T *tm); -void prof_child_exit(proftime_T *tm); -int eval_foldexpr(char_u *arg, int *cp); -void ex_let(exarg_T *eap); -void list_add_watch(list_T *l, listwatch_T *lw); -void list_rem_watch(list_T *l, listwatch_T *lwrem); -void *eval_for_line(char_u *arg, int *errp, char_u **nextcmdp, int skip); -int next_for_item(void *fi_void, char_u *arg); -void free_for_info(void *fi_void); -void set_context_for_expression(expand_T *xp, char_u *arg, -                                cmdidx_T cmdidx); -void ex_call(exarg_T *eap); -void ex_unlet(exarg_T *eap); -void ex_lockvar(exarg_T *eap); -int do_unlet(char_u *name, int forceit); -void del_menutrans_vars(void); -char_u *get_user_var_name(expand_T *xp, int idx); -list_T *list_alloc(void); -void list_unref(list_T *l); -void list_free(list_T *l, int recurse); -listitem_T *listitem_alloc(void); -void listitem_free(listitem_T *item); -void listitem_remove(list_T *l, listitem_T *item); -dictitem_T *dict_lookup(hashitem_T *hi); -listitem_T *list_find(list_T *l, long n); -char_u *list_find_str(list_T *l, long idx); -void list_append(list_T *l, listitem_T *item); -void list_append_tv(list_T *l, typval_T *tv); -void list_append_dict(list_T *list, dict_T *dict); -void list_append_string(list_T *l, char_u *str, int len); -int list_insert_tv(list_T *l, typval_T *tv, listitem_T *item); -void list_remove(list_T *l, listitem_T *item, listitem_T *item2); -void list_insert(list_T *l, listitem_T *ni, listitem_T *item); -int garbage_collect(void); -void set_ref_in_ht(hashtab_T *ht, int copyID); -void set_ref_in_list(list_T *l, int copyID); -void set_ref_in_item(typval_T *tv, int copyID); -dict_T *dict_alloc(void); -void dict_unref(dict_T *d); -void dict_free(dict_T *d, int recurse); -dictitem_T *dictitem_alloc(char_u *key); -void dictitem_free(dictitem_T *item); -int dict_add(dict_T *d, dictitem_T *item); -int dict_add_nr_str(dict_T *d, char *key, long nr, char_u *str); -int dict_add_list(dict_T *d, char *key, list_T *list); -dictitem_T *dict_find(dict_T *d, char_u *key, int len); -char_u *get_dict_string(dict_T *d, char_u *key, int save); -long get_dict_number(dict_T *d, char_u *key); -char_u *get_function_name(expand_T *xp, int idx); -char_u *get_expr_name(expand_T *xp, int idx); -int func_call(char_u *name, typval_T *args, dict_T *selfdict, -              typval_T *rettv); -void dict_extend(dict_T *d1, dict_T *d2, char_u *action); -float_T vim_round(float_T f); -long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, -                   char_u *skip, int flags, pos_T *match_pos, -                   linenr_T lnum_stop, -                   long time_limit); -void set_vim_var_nr(int idx, long val); -long get_vim_var_nr(int idx); -char_u *get_vim_var_str(int idx); -list_T *get_vim_var_list(int idx); -void set_vim_var_char(int c); -void set_vcount(long count, long count1, int set_prevcount); -void set_vim_var_string(int idx, char_u *val, int len); -void set_vim_var_list(int idx, list_T *val); -void set_reg_var(int c); -char_u *v_exception(char_u *oldval); -char_u *v_throwpoint(char_u *oldval); -char_u *set_cmdarg(exarg_T *eap, char_u *oldarg); -void free_tv(typval_T *varp); -void clear_tv(typval_T *varp); -long get_tv_number_chk(typval_T *varp, int *denote); -char_u *get_tv_string_chk(typval_T *varp); -char_u *get_var_value(char_u *name); -void new_script_vars(scid_T id); -void init_var_dict(dict_T *dict, dictitem_T *dict_var, int scope); -void unref_var_dict(dict_T *dict); -void vars_clear(hashtab_T *ht); -void copy_tv(typval_T *from, typval_T *to); -void ex_echo(exarg_T *eap); -void ex_echohl(exarg_T *eap); -void ex_execute(exarg_T *eap); -void ex_function(exarg_T *eap); -void free_all_functions(void); -int translated_function_exists(char_u *name); -char_u *get_expanded_name(char_u *name, int check); -void func_dump_profile(FILE *fd); -char_u *get_user_func_name(expand_T *xp, int idx); -void ex_delfunction(exarg_T *eap); -void func_unref(char_u *name); -void func_ref(char_u *name); -void ex_return(exarg_T *eap); -int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv); -void discard_pending_return(void *rettv); -char_u *get_return_cmd(void *rettv); -char_u *get_func_line(int c, void *cookie, int indent); -void func_line_start(void *cookie); -void func_line_exec(void *cookie); -void func_line_end(void *cookie); -int func_has_ended(void *cookie); -int func_has_abort(void *cookie); -int read_viminfo_varlist(vir_T *virp, int writing); -void write_viminfo_varlist(FILE *fp); -int store_session_globals(FILE *fd); -void last_set_msg(scid_T scriptID); -void ex_oldfiles(exarg_T *eap); -int modify_fname(char_u *src, int *usedlen, char_u **fnamep, -                 char_u **bufp, -                 int *fnamelen); -char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, -                      char_u *flags); -#endif /* NVIM_EVAL_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "eval.h.generated.h" +#endif +#endif  // NVIM_EVAL_H diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index de01665286..909e79be6d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -62,19 +62,15 @@  #include "nvim/os/os.h"  #include "nvim/os/shell.h" -static int linelen(int *has_tab); -static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, -                      char_u *cmd, int do_in, -                      int do_out); -static char_u *viminfo_filename(char_u  *); -static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags); -static int viminfo_encoding(vir_T *virp); -static int read_viminfo_up_to_marks(vir_T *virp, int forceit, -                                    int writing); - -static int check_readonly(int *forceit, buf_T *buf); -static void delbuf_msg(char_u *name); -static int help_compare(const void *s1, const void *s2); +/* + * Struct to hold the sign properties. + */ +typedef struct sign sign_T; + + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_cmds.c.generated.h" +#endif  /*   * ":ascii" and "ga". @@ -293,8 +289,6 @@ typedef struct {    long end_col_nr;                      /* ending column number */  } sorti_T; -static int -sort_compare(const void *s1, const void *s2);  static int sort_compare(const void *s1, const void *s2)  { @@ -1407,7 +1401,6 @@ void append_redir(char_u *buf, int buflen, char_u *opt, char_u *fname)  } -static int no_viminfo(void);  static int viminfo_errcnt;  static int no_viminfo(void) @@ -5290,8 +5283,6 @@ void ex_viusage(exarg_T *eap)    do_cmdline_cmd((char_u *)"help normal-index");  } -static void helptags_one(char_u *dir, char_u *ext, char_u *lang, -                         int add_help_tags);  /*   * ":helptags" @@ -5606,11 +5597,6 @@ helptags_one (    fclose(fd_tags);          /* there is no check for an error... */  } -/* - * Struct to hold the sign properties. - */ -typedef struct sign sign_T; -  struct sign  {      sign_T      *sn_next;       /* next sign in list */ @@ -5625,9 +5611,6 @@ struct sign  static sign_T   *first_sign = NULL;  static int      next_sign_typenr = 1; -static int sign_cmd_idx (char_u *begin_cmd, char_u *end_cmd); -static void sign_list_defined (sign_T *sp); -static void sign_undefine (sign_T *sp, sign_T *sp_prev);  static char *cmds[] = {  			"define", @@ -6053,104 +6036,86 @@ void ex_sign(exarg_T *eap)  /*   * List one sign.   */ -    static void -sign_list_defined(sp) -    sign_T	*sp; +static void sign_list_defined(sign_T *sp)  { -    char_u	*p; +  char_u  *p; -    smsg((char_u *)"sign %s", sp->sn_name); -    if (sp->sn_icon != NULL) -    { -	MSG_PUTS(" icon="); -	msg_outtrans(sp->sn_icon); -	MSG_PUTS(_(" (not supported)")); -    } -    if (sp->sn_text != NULL) -    { -	MSG_PUTS(" text="); -	msg_outtrans(sp->sn_text); -    } -    if (sp->sn_line_hl > 0) -    { -	MSG_PUTS(" linehl="); -	p = get_highlight_name(NULL, sp->sn_line_hl - 1); -	if (p == NULL) -	    MSG_PUTS("NONE"); -	else -	    msg_puts(p); -    } -    if (sp->sn_text_hl > 0) -    { -	MSG_PUTS(" texthl="); -	p = get_highlight_name(NULL, sp->sn_text_hl - 1); -	if (p == NULL) -	    MSG_PUTS("NONE"); -	else -	    msg_puts(p); -    } +  smsg((char_u *)"sign %s", sp->sn_name); +  if (sp->sn_icon != NULL) { +    MSG_PUTS(" icon="); +    msg_outtrans(sp->sn_icon); +    MSG_PUTS(_(" (not supported)")); +  } +  if (sp->sn_text != NULL) { +    MSG_PUTS(" text="); +    msg_outtrans(sp->sn_text); +  } +  if (sp->sn_line_hl > 0) { +    MSG_PUTS(" linehl="); +    p = get_highlight_name(NULL, sp->sn_line_hl - 1); +    if (p == NULL) +      MSG_PUTS("NONE"); +    else +      msg_puts(p); +  } +  if (sp->sn_text_hl > 0) { +    MSG_PUTS(" texthl="); +    p = get_highlight_name(NULL, sp->sn_text_hl - 1); +    if (p == NULL) +      MSG_PUTS("NONE"); +    else +      msg_puts(p); +  }  }  /*   * Undefine a sign and free its memory.   */ -    static void -sign_undefine(sp, sp_prev) -    sign_T	*sp; -    sign_T	*sp_prev; +static void sign_undefine(sign_T *sp, sign_T *sp_prev)  { -    free(sp->sn_name); -    free(sp->sn_icon); -    free(sp->sn_text); -    if (sp_prev == NULL) -	first_sign = sp->sn_next; -    else -	sp_prev->sn_next = sp->sn_next; -    free(sp); +  free(sp->sn_name); +  free(sp->sn_icon); +  free(sp->sn_text); +  if (sp_prev == NULL) +    first_sign = sp->sn_next; +  else +    sp_prev->sn_next = sp->sn_next; +  free(sp);  }  /*   * Get highlighting attribute for sign "typenr".   * If "line" is TRUE: line highl, if FALSE: text highl.   */ -    int -sign_get_attr(typenr, line) -    int		typenr; -    int		line; +int sign_get_attr(int typenr, int line)  { -    sign_T	*sp; +  sign_T  *sp; -    for (sp = first_sign; sp != NULL; sp = sp->sn_next) -	if (sp->sn_typenr == typenr) -	{ -	    if (line) -	    { -		if (sp->sn_line_hl > 0) -		    return syn_id2attr(sp->sn_line_hl); -	    } -	    else -	    { -		if (sp->sn_text_hl > 0) -		    return syn_id2attr(sp->sn_text_hl); -	    } -	    break; -	} -    return 0; +  for (sp = first_sign; sp != NULL; sp = sp->sn_next) +    if (sp->sn_typenr == typenr) { +      if (line) { +        if (sp->sn_line_hl > 0) +          return syn_id2attr(sp->sn_line_hl); +      } else { +        if (sp->sn_text_hl > 0) +          return syn_id2attr(sp->sn_text_hl); +      } +      break; +    } +  return 0;  }  /*   * Get text mark for sign "typenr".   * Returns NULL if there isn't one.   */ -    char_u * -sign_get_text(typenr) -    int		typenr; +char_u * sign_get_text(int typenr)  { -    sign_T	*sp; +    sign_T  *sp;      for (sp = first_sign; sp != NULL; sp = sp->sn_next) -	if (sp->sn_typenr == typenr) -	    return sp->sn_text; +      if (sp->sn_typenr == typenr) +        return sp->sn_text;      return NULL;  } @@ -6158,27 +6123,24 @@ sign_get_text(typenr)  /*   * Get the name of a sign by its typenr.   */ -    char_u * -sign_typenr2name(typenr) -    int		typenr; +char_u * sign_typenr2name(int typenr)  { -    sign_T	*sp; +  sign_T  *sp; -    for (sp = first_sign; sp != NULL; sp = sp->sn_next) -	if (sp->sn_typenr == typenr) -	    return sp->sn_name; -    return (char_u *)_("[Deleted]"); +  for (sp = first_sign; sp != NULL; sp = sp->sn_next) +    if (sp->sn_typenr == typenr) +      return sp->sn_name; +  return (char_u *)_("[Deleted]");  }  #if defined(EXITFREE) || defined(PROTO)  /*   * Undefine/free all signs.   */ -    void -free_signs() +void free_signs()  { -    while (first_sign != NULL) -	sign_undefine(first_sign, NULL); +  while (first_sign != NULL) +    sign_undefine(first_sign, NULL);  }  #endif @@ -6240,120 +6202,117 @@ char_u * get_sign_name(expand_T *xp, int idx)  /*   * Handle command line completion for :sign command.   */ -    void -set_context_in_sign_cmd(xp, arg) -    expand_T	*xp; -    char_u	*arg; +void set_context_in_sign_cmd(expand_T *xp, char_u *arg)  { -    char_u	*p; -    char_u	*end_subcmd; -    char_u	*last; -    int		cmd_idx; -    char_u	*begin_subcmd_args; - -    /* Default: expand subcommands. */ -    xp->xp_context = EXPAND_SIGN; -    expand_what = EXP_SUBCMD; -    xp->xp_pattern = arg; - -    end_subcmd = skiptowhite(arg); -    if (*end_subcmd == NUL) -	/* expand subcmd name -	 * :sign {subcmd}<CTRL-D>*/ -	return; +  char_u  *p; +  char_u  *end_subcmd; +  char_u  *last; +  int    cmd_idx; +  char_u  *begin_subcmd_args; + +  /* Default: expand subcommands. */ +  xp->xp_context = EXPAND_SIGN; +  expand_what = EXP_SUBCMD; +  xp->xp_pattern = arg; + +  end_subcmd = skiptowhite(arg); +  if (*end_subcmd == NUL) +    /* expand subcmd name +     * :sign {subcmd}<CTRL-D>*/ +    return; -    cmd_idx = sign_cmd_idx(arg, end_subcmd); +  cmd_idx = sign_cmd_idx(arg, end_subcmd); -    /* :sign {subcmd} {subcmd_args} -     *		      | -     *		      begin_subcmd_args */ -    begin_subcmd_args = skipwhite(end_subcmd); -    p = skiptowhite(begin_subcmd_args); -    if (*p == NUL) +  /* :sign {subcmd} {subcmd_args} +   *          | +   *          begin_subcmd_args */ +  begin_subcmd_args = skipwhite(end_subcmd); +  p = skiptowhite(begin_subcmd_args); +  if (*p == NUL) +  { +    /* +     * Expand first argument of subcmd when possible. +     * For ":jump {id}" and ":unplace {id}", we could +     * possibly expand the ids of all signs already placed. +     */ +    xp->xp_pattern = begin_subcmd_args; +    switch (cmd_idx)      { -	/* -	 * Expand first argument of subcmd when possible. -	 * For ":jump {id}" and ":unplace {id}", we could -	 * possibly expand the ids of all signs already placed. -	 */ -	xp->xp_pattern = begin_subcmd_args; -	switch (cmd_idx) -	{ -	    case SIGNCMD_LIST: -	    case SIGNCMD_UNDEFINE: -		/* :sign list <CTRL-D> -		 * :sign undefine <CTRL-D> */ -		expand_what = EXP_SIGN_NAMES; -		break; -	    default: -		xp->xp_context = EXPAND_NOTHING; -	} -	return; +      case SIGNCMD_LIST: +      case SIGNCMD_UNDEFINE: +        /* :sign list <CTRL-D> +         * :sign undefine <CTRL-D> */ +        expand_what = EXP_SIGN_NAMES; +        break; +      default: +        xp->xp_context = EXPAND_NOTHING;      } +    return; +  } -    /* expand last argument of subcmd */ - -    /* :sign define {name} {args}... -     *		    | -     *		    p */ - -    /* Loop until reaching last argument. */ -    do -    { -	p = skipwhite(p); -	last = p; -	p = skiptowhite(p); -    } while (*p != NUL); - -    p = vim_strchr(last, '='); - -    /* :sign define {name} {args}... {last}= -     *				     |	   | -     *				  last	   p */ -    if (p == NUL) +  /* expand last argument of subcmd */ + +  /* :sign define {name} {args}... +   *        | +   *        p */ + +  /* Loop until reaching last argument. */ +  do +  { +    p = skipwhite(p); +    last = p; +    p = skiptowhite(p); +  } while (*p != NUL); + +  p = vim_strchr(last, '='); + +  /* :sign define {name} {args}... {last}= +   *             |     | +   *          last     p */ +  if (p == NUL) +  { +    /* Expand last argument name (before equal sign). */ +    xp->xp_pattern = last; +    switch (cmd_idx)      { -        /* Expand last argument name (before equal sign). */ -        xp->xp_pattern = last; -        switch (cmd_idx) -        { -            case SIGNCMD_DEFINE: -                expand_what = EXP_DEFINE; -                break; -            case SIGNCMD_PLACE: -                expand_what = EXP_PLACE; -                break; -            case SIGNCMD_JUMP: -            case SIGNCMD_UNPLACE: -                expand_what = EXP_UNPLACE; -                break; -            default: -                xp->xp_context = EXPAND_NOTHING; -        } +      case SIGNCMD_DEFINE: +        expand_what = EXP_DEFINE; +        break; +      case SIGNCMD_PLACE: +        expand_what = EXP_PLACE; +        break; +      case SIGNCMD_JUMP: +      case SIGNCMD_UNPLACE: +        expand_what = EXP_UNPLACE; +        break; +      default: +        xp->xp_context = EXPAND_NOTHING;      } -    else +  } +  else +  { +    /* Expand last argument value (after equal sign). */ +    xp->xp_pattern = p + 1; +    switch (cmd_idx)      { -        /* Expand last argument value (after equal sign). */ -        xp->xp_pattern = p + 1; -        switch (cmd_idx) -        { -            case SIGNCMD_DEFINE: -                if (STRNCMP(last, "texthl", p - last) == 0 || -                        STRNCMP(last, "linehl", p - last) == 0) -                    xp->xp_context = EXPAND_HIGHLIGHT; -                else if (STRNCMP(last, "icon", p - last) == 0) -                    xp->xp_context = EXPAND_FILES; -                else -                    xp->xp_context = EXPAND_NOTHING; -                break; -            case SIGNCMD_PLACE: -                if (STRNCMP(last, "name", p - last) == 0) -                    expand_what = EXP_SIGN_NAMES; -                else -                    xp->xp_context = EXPAND_NOTHING; -                break; -            default: -                xp->xp_context = EXPAND_NOTHING; -        } +      case SIGNCMD_DEFINE: +        if (STRNCMP(last, "texthl", p - last) == 0 || +            STRNCMP(last, "linehl", p - last) == 0) +          xp->xp_context = EXPAND_HIGHLIGHT; +        else if (STRNCMP(last, "icon", p - last) == 0) +          xp->xp_context = EXPAND_FILES; +        else +          xp->xp_context = EXPAND_NOTHING; +        break; +      case SIGNCMD_PLACE: +        if (STRNCMP(last, "name", p - last) == 0) +          expand_what = EXP_SIGN_NAMES; +        else +          xp->xp_context = EXPAND_NOTHING; +        break; +      default: +        xp->xp_context = EXPAND_NOTHING;      } +  }  } diff --git a/src/nvim/ex_cmds.h b/src/nvim/ex_cmds.h index eb96ac475d..7eb92d2c78 100644 --- a/src/nvim/ex_cmds.h +++ b/src/nvim/ex_cmds.h @@ -1,75 +1,7 @@  #ifndef NVIM_EX_CMDS_H  #define NVIM_EX_CMDS_H -/* ex_cmds.c */ -void do_ascii(exarg_T *eap); -void ex_align(exarg_T *eap); -void ex_sort(exarg_T *eap); -void ex_retab(exarg_T *eap); -int do_move(linenr_T line1, linenr_T line2, linenr_T dest); -void ex_copy(linenr_T line1, linenr_T line2, linenr_T n); -void free_prev_shellcmd(void); -void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, -                     int do_out); -void do_shell(char_u *cmd, int flags); -char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp); -void append_redir(char_u *buf, int buflen, char_u *opt, char_u *fname); -int viminfo_error(char *errnum, char *message, char_u *line); -int read_viminfo(char_u *file, int flags); -void write_viminfo(char_u *file, int forceit); -int viminfo_readline(vir_T *virp); -char_u *viminfo_readstring(vir_T *virp, int off, int convert); -void viminfo_writestring(FILE *fd, char_u *p); -void do_fixdel(exarg_T *eap); -void print_line_no_prefix(linenr_T lnum, int use_number, int list); -void print_line(linenr_T lnum, int use_number, int list); -int rename_buffer(char_u *new_fname); -void ex_file(exarg_T *eap); -void ex_update(exarg_T *eap); -void ex_write(exarg_T *eap); -int do_write(exarg_T *eap); -int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u * -                            ffname, -                            int other); -void ex_wnext(exarg_T *eap); -void do_wqall(exarg_T *eap); -int not_writing(void); -int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, -                    linenr_T lnum, -                    int forceit); -int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, -                    linenr_T newlnum, int flags, -                    win_T *oldwin); -void ex_append(exarg_T *eap); -void ex_change(exarg_T *eap); -void ex_z(exarg_T *eap); -int check_restricted(void); -int check_secure(void); -void do_sub(exarg_T *eap); -int do_sub_msg(int count_only); -void ex_global(exarg_T *eap); -void global_exe(char_u *cmd); -int read_viminfo_sub_string(vir_T *virp, int force); -void write_viminfo_sub_string(FILE *fp); -void free_old_sub(void); -int prepare_tagpreview(int undo_sync); -void ex_help(exarg_T *eap); -char_u *check_help_lang(char_u *arg); -int help_heuristic(char_u *matched_string, int offset, int wrong_case); -int find_help_tags(char_u *arg, int *num_matches, char_u ***matches, -                           int keep_lang); -void fix_help_buffer(void); -void ex_exusage(exarg_T *eap); -void ex_viusage(exarg_T *eap); -void ex_helptags(exarg_T *eap); -void ex_sign(exarg_T *eap); -int sign_get_attr(int typenr, int line); -char_u *sign_get_text(int typenr); -void *sign_get_image(int typenr); -char_u *sign_typenr2name(int typenr); -void free_signs(void); -char_u *get_sign_name(expand_T *xp, int idx); -void set_context_in_sign_cmd(expand_T *xp, char_u *arg); -void ex_drop(exarg_T *eap); - -#endif /* NVIM_EX_CMDS_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_cmds.h.generated.h" +#endif +#endif  // NVIM_EX_CMDS_H diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index c37998e26e..02d8f6f9af 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -46,7 +46,6 @@  #include "nvim/os/os.h"  #include "nvim/os/shell.h" -static void cmd_source(char_u *fname, exarg_T *eap);  /* Growarray to store info about already sourced scripts.   * Also store the dev/ino, so that we don't have to stat() each @@ -85,8 +84,33 @@ typedef struct sn_prl_S {    proftime_T sn_prl_self;       /* time spent in a line itself */  } sn_prl_T; +/* + * Structure used to store info for each sourced file. + * It is shared between do_source() and getsourceline(). + * This is required, because it needs to be handed to do_cmdline() and + * sourcing can be done recursively. + */ +struct source_cookie { +  FILE        *fp;              /* opened file for sourcing */ +  char_u      *nextline;        /* if not NULL: line that was read ahead */ +  int finished;                 /* ":finish" used */ +#if defined(USE_CRNL) || defined(USE_CR) +  int fileformat;               /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */ +  int error;                    /* TRUE if LF found after CR-LF */ +#endif +  linenr_T breakpoint;          /* next line with breakpoint or zero */ +  char_u      *fname;           /* name of sourced file */ +  int dbg_tick;                 /* debug_tick when breakpoint was set */ +  int level;                    /* top nesting level of sourced file */ +  vimconv_T conv;               /* type of conversion */ +}; +  #  define PRL_ITEM(si, idx)     (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_cmds2.c.generated.h" +#endif +  static int debug_greedy = FALSE;        /* batch mode debugging: don't save                                             and restore typeahead. */ @@ -389,10 +413,6 @@ static garray_T prof_ga = {0, 0, sizeof(struct debuggy), 4, NULL};  #define DBG_FUNC        1  #define DBG_FILE        2 -static int dbg_parsearg(char_u *arg, garray_T *gap); -static linenr_T debuggy_find(int file,char_u *fname, linenr_T after, -                             garray_T *gap, -                             int *fp);  /*   * Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them @@ -724,8 +744,7 @@ void dbg_breakpoint(char_u *name, linenr_T lnum)  /*   * Store the current time in "tm".   */ -void profile_start(tm) -proftime_T *tm; +void profile_start(proftime_T *tm)  {    gettimeofday(tm, NULL);  } @@ -733,8 +752,7 @@ proftime_T *tm;  /*   * Compute the elapsed time from "tm" till now and store in "tm".   */ -void profile_end(tm) -proftime_T *tm; +void profile_end(proftime_T *tm)  {    proftime_T now; @@ -750,8 +768,7 @@ proftime_T *tm;  /*   * Subtract the time "tm2" from "tm".   */ -void profile_sub(tm, tm2) -proftime_T *tm, *tm2; +void profile_sub(proftime_T *tm, proftime_T *tm2)  {    tm->tv_usec -= tm2->tv_usec;    tm->tv_sec -= tm2->tv_sec; @@ -765,8 +782,7 @@ proftime_T *tm, *tm2;   * Return a string that represents the time in "tm".   * Uses a static buffer!   */ -char * profile_msg(tm) -proftime_T *tm; +char * profile_msg(proftime_T *tm)  {    static char buf[50]; @@ -777,9 +793,7 @@ proftime_T *tm;  /*   * Put the time "msec" past now in "tm".   */ -void profile_setlimit(msec, tm) -long msec; -proftime_T  *tm; +void profile_setlimit(long msec, proftime_T *tm)  {    if (msec <= 0)     /* no limit */      profile_zero(tm); @@ -796,8 +810,7 @@ proftime_T  *tm;  /*   * Return TRUE if the current time is past "tm".   */ -int profile_passed_limit(tm) -proftime_T  *tm; +int profile_passed_limit(proftime_T *tm)  {    proftime_T now; @@ -811,8 +824,7 @@ proftime_T  *tm;  /*   * Set the time in "tm" to zero.   */ -void profile_zero(tm) -proftime_T *tm; +void profile_zero(proftime_T *tm)  {    tm->tv_usec = 0;    tm->tv_sec = 0; @@ -824,10 +836,7 @@ proftime_T *tm;  /*   * Divide the time "tm" by "count" and store in "tm2".   */ -void profile_divide(tm, count, tm2) -proftime_T  *tm; -proftime_T  *tm2; -int count; +void profile_divide(proftime_T *tm, int count, proftime_T *tm2)  {    if (count == 0)      profile_zero(tm2); @@ -842,15 +851,12 @@ int count;  /*   * Functions for profiling.   */ -static void script_do_profile(scriptitem_T *si); -static void script_dump_profile(FILE *fd);  static proftime_T prof_wait_time;  /*   * Add the time "tm2" to "tm".   */ -void profile_add(tm, tm2) -proftime_T *tm, *tm2; +void profile_add(proftime_T *tm, proftime_T *tm2)  {    tm->tv_usec += tm2->tv_usec;    tm->tv_sec += tm2->tv_sec; @@ -863,8 +869,7 @@ proftime_T *tm, *tm2;  /*   * Add the "self" time from the total time and the children's time.   */ -void profile_self(self, total, children) -proftime_T *self, *total, *children; +void profile_self(proftime_T *self, proftime_T *total, proftime_T *children)  {    /* Check that the result won't be negative.  Can happen with recursive     * calls. */ @@ -879,8 +884,7 @@ proftime_T *self, *total, *children;  /*   * Get the current waittime.   */ -void profile_get_wait(tm) -proftime_T *tm; +void profile_get_wait(proftime_T *tm)  {    *tm = prof_wait_time;  } @@ -888,8 +892,7 @@ proftime_T *tm;  /*   * Subtract the passed waittime since "tm" from "tma".   */ -void profile_sub_wait(tm, tma) -proftime_T *tm, *tma; +void profile_sub_wait(proftime_T *tm, proftime_T *tma)  {    proftime_T tm3 = prof_wait_time; @@ -900,8 +903,7 @@ proftime_T *tm, *tma;  /*   * Return TRUE if "tm1" and "tm2" are equal.   */ -int profile_equal(tm1, tm2) -proftime_T *tm1, *tm2; +int profile_equal(proftime_T *tm1, proftime_T *tm2)  {    return tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec;  } @@ -909,8 +911,7 @@ proftime_T *tm1, *tm2;  /*   * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2"   */ -int profile_cmp(tm1, tm2) -const proftime_T *tm1, *tm2; +int profile_cmp(const proftime_T *tm1, const proftime_T *tm2)  {    if (tm1->tv_sec == tm2->tv_sec)      return tm2->tv_usec - tm1->tv_usec; @@ -1055,8 +1056,9 @@ static void script_do_profile(scriptitem_T *si)  /*   * save time when starting to invoke another script or function.   */ -void script_prof_save(tm) -proftime_T  *tm;            /* place to store wait time */ +void script_prof_save( +    proftime_T  *tm             /* place to store wait time */ +    )  {    scriptitem_T    *si; @@ -1071,8 +1073,7 @@ proftime_T  *tm;            /* place to store wait time */  /*   * Count time spent in children after invoking another script or function.   */ -void script_prof_restore(tm) -proftime_T  *tm; +void script_prof_restore(proftime_T *tm)  {    scriptitem_T    *si; @@ -1327,7 +1328,6 @@ int can_abandon(buf_T *buf, int forceit)           || forceit;  } -static void add_bufnum(int *bufnrs, int *bufnump, int nr);  /*   * Add a buffer number to "bufnrs", unless it's already there. @@ -1486,11 +1486,6 @@ int buf_write_all(buf_T *buf, int forceit)   * Code to handle the argument list.   */ -static char_u   *do_one_arg(char_u *str); -static int do_arglist(char_u *str, int what, int after); -static void alist_check_arg_idx(void); -static int editing_arg_idx(win_T *win); -static int alist_add_list(int count, char_u **files, int after);  #define AL_SET  1  #define AL_ADD  2  #define AL_DEL  3 @@ -2202,7 +2197,6 @@ void ex_runtime(exarg_T *eap)    source_runtime(eap->arg, eap->forceit);  } -static void source_callback(char_u *fname, void *cookie);  static void source_callback(char_u *fname, void *cookie)  { @@ -2231,11 +2225,8 @@ int source_runtime(char_u *name, int all)   * passed by reference in this case, setting it to NULL indicates that callback   * has done its job.   */ -int do_in_runtimepath(name, all, callback, cookie) -char_u      *name; -int all; -void        (*callback)(char_u *fname, void *ck); -void        *cookie; +int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, +                      void *cookie)  {    char_u      *rtp;    char_u      *np; @@ -2354,26 +2345,6 @@ static void cmd_source(char_u *fname, exarg_T *eap)  /*   * ":source" and associated commands.   */ -/* - * Structure used to store info for each sourced file. - * It is shared between do_source() and getsourceline(). - * This is required, because it needs to be handed to do_cmdline() and - * sourcing can be done recursively. - */ -struct source_cookie { -  FILE        *fp;              /* opened file for sourcing */ -  char_u      *nextline;        /* if not NULL: line that was read ahead */ -  int finished;                 /* ":finish" used */ -#if defined(USE_CRNL) || defined(USE_CR) -  int fileformat;               /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */ -  int error;                    /* TRUE if LF found after CR-LF */ -#endif -  linenr_T breakpoint;          /* next line with breakpoint or zero */ -  char_u      *fname;           /* name of sourced file */ -  int dbg_tick;                 /* debug_tick when breakpoint was set */ -  int level;                    /* top nesting level of sourced file */ -  vimconv_T conv;               /* type of conversion */ -};  /*   * Return the address holding the next breakpoint line for a source cookie. @@ -2399,12 +2370,9 @@ int source_level(void *cookie)    return ((struct source_cookie *)cookie)->level;  } -static char_u *get_one_sourceline(struct source_cookie *sp);  #if (defined(WIN32) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC)  # define USE_FOPEN_NOINH -static FILE *fopen_noinh_readbin(char *filename); -  /*   * Special function to open a file without handle inheritance.   * When possible the handle is closed on exec(). @@ -3200,9 +3168,7 @@ void do_finish(exarg_T *eap, int reanimate)   * message for missing ":endif".   * Return FALSE when not sourcing a file.   */ -int source_finished(fgetline, cookie) -char_u      *(*fgetline)(int, void *, int); -void        *cookie; +int source_finished(LineGetter fgetline, void *cookie)  {    return getline_equal(fgetline, cookie, getsourceline)           && ((struct source_cookie *)getline_cookie( @@ -3230,7 +3196,6 @@ void ex_checktime(exarg_T *eap)  #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)  # define HAVE_GET_LOCALE_VAL -static char *get_locale_val(int what);  static char *get_locale_val(int what)  { @@ -3278,8 +3243,6 @@ char_u *get_mess_lang(void)  /* Complicated #if; matches with where get_mess_env() is used below. */  #ifdef HAVE_WORKING_LIBINTL -static char_u *get_mess_env(void); -  /*   * Get the language used for messages from the environment.   */ @@ -3440,9 +3403,6 @@ void ex_language(exarg_T *eap)  static char_u   **locales = NULL;       /* Array of all available locales */  static int did_init_locales = FALSE; -static void init_locales(void); -static char_u **find_locales(void); -  /*   * Lazy initialization of all available locales.   */ diff --git a/src/nvim/ex_cmds2.h b/src/nvim/ex_cmds2.h index a99107b237..efc9018dd3 100644 --- a/src/nvim/ex_cmds2.h +++ b/src/nvim/ex_cmds2.h @@ -1,95 +1,11 @@  #ifndef NVIM_EX_CMDS2_H  #define NVIM_EX_CMDS2_H -/* ex_cmds2.c */ -void do_debug(char_u *cmd); -void ex_debug(exarg_T *eap); -void dbg_check_breakpoint(exarg_T *eap); -int dbg_check_skipped(exarg_T *eap); -void ex_breakadd(exarg_T *eap); -void ex_debuggreedy(exarg_T *eap); -void ex_breakdel(exarg_T *eap); -void ex_breaklist(exarg_T *eap); -linenr_T dbg_find_breakpoint(int file, char_u *fname, linenr_T after); -int has_profiling(int file, char_u *fname, int *fp); -void dbg_breakpoint(char_u *name, linenr_T lnum); -void profile_start(proftime_T *tm); -void profile_end(proftime_T *tm); -void profile_sub(proftime_T *tm, proftime_T *tm2); -char *profile_msg(proftime_T *tm); -void profile_setlimit(long msec, proftime_T *tm); -int profile_passed_limit(proftime_T *tm); -void profile_zero(proftime_T *tm); -void profile_divide(proftime_T *tm, int count, proftime_T *tm2); -void profile_add(proftime_T *tm, proftime_T *tm2); -void profile_self(proftime_T *self, proftime_T *total, -                  proftime_T *children); -void profile_get_wait(proftime_T *tm); -void profile_sub_wait(proftime_T *tm, proftime_T *tma); -int profile_equal(proftime_T *tm1, proftime_T *tm2); -int profile_cmp(const proftime_T *tm1, const proftime_T *tm2); -void ex_profile(exarg_T *eap); -char_u *get_profile_name(expand_T *xp, int idx); -void set_context_in_profile_cmd(expand_T *xp, char_u *arg); -void profile_dump(void); -void script_prof_save(proftime_T *tm); -void script_prof_restore(proftime_T *tm); -void prof_inchar_enter(void); -void prof_inchar_exit(void); -int prof_def_func(void); -int autowrite(buf_T *buf, int forceit); -void autowrite_all(void); -int check_changed(buf_T *buf, int flags); -void dialog_changed(buf_T *buf, int checkall); -int can_abandon(buf_T *buf, int forceit); -int check_changed_any(int hidden); -int check_fname(void); -int buf_write_all(buf_T *buf, int forceit); -void get_arglist(garray_T *gap, char_u *str); -int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, -                    int wig); -void check_arg_idx(win_T *win); -void ex_args(exarg_T *eap); -void ex_previous(exarg_T *eap); -void ex_rewind(exarg_T *eap); -void ex_last(exarg_T *eap); -void ex_argument(exarg_T *eap); -void do_argfile(exarg_T *eap, int argn); -void ex_next(exarg_T *eap); -void ex_argedit(exarg_T *eap); -void ex_argadd(exarg_T *eap); -void ex_argdelete(exarg_T *eap); -void ex_listdo(exarg_T *eap); -void ex_compiler(exarg_T *eap); -void ex_runtime(exarg_T *eap); -int source_runtime(char_u *name, int all); -int do_in_runtimepath(char_u *name, int all, -                      void (*callback)(char_u *fname, void *ck), -                      void *cookie); -void ex_options(exarg_T *eap); -void ex_source(exarg_T *eap); -linenr_T *source_breakpoint(void *cookie); -int *source_dbg_tick(void *cookie); -int source_level(void *cookie); -int do_source(char_u *fname, int check_other, int is_vimrc); -void ex_scriptnames(exarg_T *eap); -void scriptnames_slash_adjust(void); -char_u *get_scriptname(scid_T id); -void free_scriptnames(void); -char *fgets_cr(char *s, int n, FILE *stream); -char_u *getsourceline(int c, void *cookie, int indent); -void script_line_start(void); -void script_line_exec(void); -void script_line_end(void); -void ex_scriptencoding(exarg_T *eap); -void ex_finish(exarg_T *eap); -void do_finish(exarg_T *eap, int reanimate); -int source_finished(char_u *(*fgetline)(int, void *, int), void *cookie); -void ex_checktime(exarg_T *eap); -char_u *get_mess_lang(void); -void set_lang_var(void); -void ex_language(exarg_T *eap); -void free_locales(void); -char_u *get_lang_arg(expand_T *xp, int idx); -char_u *get_locales(expand_T *xp, int idx); -#endif /* NVIM_EX_CMDS2_H */ +#include "nvim/ex_docmd.h" + +typedef void (*DoInRuntimepathCB)(char_u *, void *); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_cmds2.h.generated.h" +#endif +#endif  // NVIM_EX_CMDS2_H diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 85cd4cd2fe..ee1c857134 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -5,6 +5,15 @@   * Do ":help credits" in Vim to see a list of people who contributed.   */ +#if (!defined(DO_DECLARE_EXCMD) && !defined(NVIM_EX_CMDS_DEFS_H)) \ +    || (defined(DO_DECLARE_EXCMD) && \ +        !defined(NVIM_EX_CMDS_DEFS_H_DO_DECLARE_EXCMD)) +#ifdef DO_DECLARE_EXCMD +# define NVIM_EX_CMDS_DEFS_H_DO_DECLARE_EXCMD +#else +# define NVIM_EX_CMDS_DEFS_H +#endif +  #include "nvim/normal.h"  /* @@ -1187,3 +1196,4 @@ typedef struct {  } cmdmod_T;  #endif +#endif diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index f17734eb5e..9102ba63bb 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -83,149 +83,61 @@ static garray_T ucmds = {0, 0, sizeof(ucmd_T), 4, NULL};  #define USER_CMD(i) (&((ucmd_T *)(ucmds.ga_data))[i])  #define USER_CMD_GA(gap, i) (&((ucmd_T *)((gap)->ga_data))[i]) -static void do_ucmd(exarg_T *eap); -static void ex_command(exarg_T *eap); -static void ex_delcommand(exarg_T *eap); -static char_u *get_user_command_name(int idx); - - -static char_u   *do_one_cmd(char_u **, int, struct condstack *, -                            char_u *(*fgetline)(int, void *, int), -                            void *cookie); -static void append_command(char_u *cmd); -static char_u   *find_command(exarg_T *eap, int *full); - -static void ex_abbreviate(exarg_T *eap); -static void ex_map(exarg_T *eap); -static void ex_unmap(exarg_T *eap); -static void ex_mapclear(exarg_T *eap); -static void ex_abclear(exarg_T *eap); -static void ex_autocmd(exarg_T *eap); -static void ex_doautocmd(exarg_T *eap); -static void ex_bunload(exarg_T *eap); -static void ex_buffer(exarg_T *eap); -static void ex_bmodified(exarg_T *eap); -static void ex_bnext(exarg_T *eap); -static void ex_bprevious(exarg_T *eap); -static void ex_brewind(exarg_T *eap); -static void ex_blast(exarg_T *eap); -static char_u   *getargcmd(char_u **); -static char_u   *skip_cmd_arg(char_u *p, int rembs); -static int getargopt(exarg_T *eap); - -static int check_more(int, int); -static linenr_T get_address(char_u **, int skip, int to_other_file); -static void get_flags(exarg_T *eap); +/* Struct for storing a line inside a while/for loop */ +typedef struct { +  char_u      *line;            /* command line */ +  linenr_T lnum;                /* sourcing_lnum of the line */ +} wcmd_T; + +/* + * Structure used to store info for line position in a while or for loop. + * This is required, because do_one_cmd() may invoke ex_function(), which + * reads more lines that may come from the while/for loop. + */ +struct loop_cookie { +  garray_T    *lines_gap;               /* growarray with line info */ +  int current_line;                     /* last read line from growarray */ +  int repeating;                        /* TRUE when looping a second time */ +  /* When "repeating" is FALSE use "getline" and "cookie" to get lines */ +  char_u      *(*getline)(int, void *, int); +  void        *cookie; +}; + + +/* Struct to save a few things while debugging.  Used in do_cmdline() only. */ +struct dbg_stuff { +  int trylevel; +  int force_abort; +  except_T    *caught_stack; +  char_u      *vv_exception; +  char_u      *vv_throwpoint; +  int did_emsg; +  int got_int; +  int did_throw; +  int need_rethrow; +  int check_cstack; +  except_T    *current_exception; +}; + + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_docmd.c.generated.h" +#endif +  # define HAVE_EX_SCRIPT_NI -static void ex_script_ni(exarg_T *eap); -static char_u   *invalid_range(exarg_T *eap); -static void correct_range(exarg_T *eap); -static char_u   *replace_makeprg(exarg_T *eap, char_u *p, -                                 char_u **cmdlinep); -static char_u   *repl_cmdline(exarg_T *eap, char_u *src, int srclen, -                              char_u *repl, -                              char_u **cmdlinep); -static void ex_highlight(exarg_T *eap); -static void ex_colorscheme(exarg_T *eap); -static void ex_quit(exarg_T *eap); -static void ex_cquit(exarg_T *eap); -static void ex_quit_all(exarg_T *eap); -static void ex_close(exarg_T *eap); -static void ex_win_close(int forceit, win_T *win, tabpage_T *tp); -static void ex_only(exarg_T *eap); -static void ex_resize(exarg_T *eap); -static void ex_stag(exarg_T *eap); -static void ex_tabclose(exarg_T *eap); -static void ex_tabonly(exarg_T *eap); -static void ex_tabnext(exarg_T *eap); -static void ex_tabmove(exarg_T *eap); -static void ex_tabs(exarg_T *eap); -static void ex_pclose(exarg_T *eap); -static void ex_ptag(exarg_T *eap); -static void ex_pedit(exarg_T *eap); -static void ex_hide(exarg_T *eap); -static void ex_stop(exarg_T *eap); -static void ex_exit(exarg_T *eap); -static void ex_print(exarg_T *eap); -static void ex_goto(exarg_T *eap); -static void ex_preserve(exarg_T *eap); -static void ex_recover(exarg_T *eap); -static void ex_mode(exarg_T *eap); -static void ex_wrongmodifier(exarg_T *eap); -static void ex_find(exarg_T *eap); -static void ex_open(exarg_T *eap); -static void ex_edit(exarg_T *eap);  # define ex_drop                ex_ni  # define ex_gui                 ex_nogui -static void ex_nogui(exarg_T *eap);  # define ex_tearoff             ex_ni  # define ex_popup               ex_ni  # define ex_simalt              ex_ni  # define gui_mch_find_dialog    ex_ni  # define gui_mch_replace_dialog ex_ni  # define ex_helpfind            ex_ni -static void ex_swapname(exarg_T *eap); -static void ex_syncbind(exarg_T *eap); -static void ex_read(exarg_T *eap); -static void ex_pwd(exarg_T *eap); -static void ex_equal(exarg_T *eap); -static void ex_sleep(exarg_T *eap); -static void do_exmap(exarg_T *eap, int isabbrev); -static void ex_winsize(exarg_T *eap); -static void ex_wincmd(exarg_T *eap);  #if defined(FEAT_GUI) || defined(UNIX) || defined(MSWIN) -static void ex_winpos(exarg_T *eap);  #else  # define ex_winpos          ex_ni  #endif -static void ex_operators(exarg_T *eap); -static void ex_put(exarg_T *eap); -static void ex_copymove(exarg_T *eap); -static void ex_submagic(exarg_T *eap); -static void ex_join(exarg_T *eap); -static void ex_at(exarg_T *eap); -static void ex_bang(exarg_T *eap); -static void ex_undo(exarg_T *eap); -static void ex_wundo(exarg_T *eap); -static void ex_rundo(exarg_T *eap); -static void ex_redo(exarg_T *eap); -static void ex_later(exarg_T *eap); -static void ex_redir(exarg_T *eap); -static void ex_redraw(exarg_T *eap); -static void ex_redrawstatus(exarg_T *eap); -static void close_redir(void); -static void ex_mkrc(exarg_T *eap); -static void ex_mark(exarg_T *eap); -static char_u   *uc_fun_cmd(void); -static char_u   *find_ucmd(exarg_T *eap, char_u *p, int *full, -                           expand_T *xp, -                           int *compl); -static void ex_normal(exarg_T *eap); -static void ex_startinsert(exarg_T *eap); -static void ex_stopinsert(exarg_T *eap); -static void ex_checkpath(exarg_T *eap); -static void ex_findpat(exarg_T *eap); -static void ex_psearch(exarg_T *eap); -static void ex_tag(exarg_T *eap); -static void ex_tag_cmd(exarg_T *eap, char_u *name); -static char_u   *arg_all(void); -static int makeopens(FILE *fd, char_u *dirnow); -static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, -                    int current_arg_idx); -static void ex_loadview(exarg_T *eap); -static char_u   *get_view_file(int c);  static int did_lcd;             /* whether ":lcd" was produced for a session */ -static void ex_viminfo(exarg_T *eap); -static void ex_behave(exarg_T *eap); -static void ex_filetype(exarg_T *eap); -static void ex_setfiletype(exarg_T *eap); -static void ex_digraphs(exarg_T *eap); -static void ex_set(exarg_T *eap); -static void ex_nohlsearch(exarg_T *eap); -static void ex_match(exarg_T *eap); -static void ex_fold(exarg_T *eap); -static void ex_foldopen(exarg_T *eap); -static void ex_folddo(exarg_T *eap);  #ifndef HAVE_WORKING_LIBINTL  # define ex_language            ex_ni  #endif @@ -279,49 +191,6 @@ static cmdidx_T cmdidxs[27] =  static char_u dollar_command[2] = {'$', 0}; - -/* Struct for storing a line inside a while/for loop */ -typedef struct { -  char_u      *line;            /* command line */ -  linenr_T lnum;                /* sourcing_lnum of the line */ -} wcmd_T; - -/* - * Structure used to store info for line position in a while or for loop. - * This is required, because do_one_cmd() may invoke ex_function(), which - * reads more lines that may come from the while/for loop. - */ -struct loop_cookie { -  garray_T    *lines_gap;               /* growarray with line info */ -  int current_line;                     /* last read line from growarray */ -  int repeating;                        /* TRUE when looping a second time */ -  /* When "repeating" is FALSE use "getline" and "cookie" to get lines */ -  char_u      *(*getline)(int, void *, int); -  void        *cookie; -}; - -static char_u   *get_loop_line(int c, void *cookie, int indent); -static void store_loop_line(garray_T *gap, char_u *line); -static void free_cmdlines(garray_T *gap); - -/* Struct to save a few things while debugging.  Used in do_cmdline() only. */ -struct dbg_stuff { -  int trylevel; -  int force_abort; -  except_T    *caught_stack; -  char_u      *vv_exception; -  char_u      *vv_throwpoint; -  int did_emsg; -  int got_int; -  int did_throw; -  int need_rethrow; -  int check_cstack; -  except_T    *current_exception; -}; - -static void save_dbg_stuff(struct dbg_stuff *dsp); -static void restore_dbg_stuff(struct dbg_stuff *dsp); -  static void save_dbg_stuff(struct dbg_stuff *dsp)  {    dsp->trylevel       = trylevel;             trylevel = 0; @@ -465,11 +334,9 @@ int do_cmdline_cmd(char_u *cmd)   *   * return FAIL if cmdline could not be executed, OK otherwise   */ -int do_cmdline(cmdline, fgetline, cookie, flags) -char_u      *cmdline; -char_u      *(*fgetline)(int, void *, int); -void        *cookie;                    /* argument for fgetline() */ -int flags; +int do_cmdline(char_u *cmdline, LineGetter fgetline, +               void *cookie, /* argument for fgetline() */ +               int flags)  {    char_u      *next_cmdline;            /* next cmd to execute */    char_u      *cmdline_copy = NULL;     /* copy of cmd line */ @@ -1191,12 +1058,11 @@ static void free_cmdlines(garray_T *gap)   * If "fgetline" is get_loop_line(), return TRUE if the getline it uses equals   * "func".  * Otherwise return TRUE when "fgetline" equals "func".   */ -int getline_equal(fgetline, cookie, func) -char_u      *(*fgetline)(int, void *, int); -void        *cookie;             /* argument for fgetline() */ -char_u      *(*func)(int, void *, int); +int getline_equal(LineGetter fgetline, +                  void *cookie, /* argument for fgetline() */ +                  LineGetter func)  { -  char_u              *(*gp)(int, void *, int); +  LineGetter gp;    struct loop_cookie *cp;    /* When "fgetline" is "get_loop_line()" use the "cookie" to find the @@ -1215,11 +1081,11 @@ char_u      *(*func)(int, void *, int);   * If "fgetline" is get_loop_line(), return the cookie used by the original   * getline function.  Otherwise return "cookie".   */ -void * getline_cookie(fgetline, cookie) -char_u      *(*fgetline)(int, void *, int); -void        *cookie;                    /* argument for fgetline() */ +void * getline_cookie(LineGetter fgetline, +                      void *cookie /* argument for fgetline() */ +                      )  { -  char_u              *(*gp)(int, void *, int); +  LineGetter gp;    struct loop_cookie *cp;    /* When "fgetline" is "get_loop_line()" use the "cookie" to find the @@ -1250,14 +1116,12 @@ void        *cookie;                    /* argument for fgetline() */   *   * This function may be called recursively!   */ -static char_u * do_one_cmd(cmdlinep, sourcing, -    cstack, -    fgetline, cookie) -char_u              **cmdlinep; -int sourcing; -struct condstack    *cstack; -char_u              *(*fgetline)(int, void *, int); -void                *cookie;                    /*argument for fgetline() */ +static char_u * do_one_cmd(char_u **cmdlinep, +                           int sourcing, +                           struct condstack *cstack, +                           LineGetter fgetline, +                           void *cookie /* argument for fgetline() */ +                           )  {    char_u              *p;    linenr_T lnum; @@ -3500,7 +3364,6 @@ static void correct_range(exarg_T *eap)    }  } -static char_u   *skip_grep_pat(exarg_T *eap);  /*   * For a ":vimgrep" or ":vimgrepadd" command return a pointer past the @@ -4263,18 +4126,6 @@ char_u *get_command_name(expand_T *xp, int idx)    return cmdnames[idx].cmd_name;  } -static int uc_add_command(char_u *name, size_t name_len, char_u *rep, -                                  long argt, long def, int flags, int compl, -                                  char_u *compl_arg, -                                  int force); -static void uc_list(char_u *name, size_t name_len); -static int uc_scan_attr(char_u *attr, size_t len, long *argt, long *def, -                        int *flags, int *compl, -                        char_u **compl_arg); -static char_u   *uc_split_args(char_u *arg, size_t *lenp); -static size_t uc_check_code(char_u *code, size_t len, char_u *buf, -                            ucmd_T *cmd, exarg_T *eap, char_u **split_buf, -                            size_t *split_len);  static int uc_add_command(char_u *name, size_t name_len, char_u *rep, long argt, long def, int flags, int compl, char_u *compl_arg, int force)  { @@ -6642,8 +6493,7 @@ static void ex_wincmd(exarg_T *eap)  /*   * ":winpos".   */ -static void ex_winpos(eap) -exarg_T     *eap; +static void ex_winpos(exarg_T *eap)  {    int x, y;    char_u      *arg = eap->arg; @@ -8012,15 +7862,6 @@ char_u *expand_sfile(char_u *arg)    return result;  } -static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin); -static int ses_win_rec(FILE *fd, frame_T *fr); -static frame_T *ses_skipframe(frame_T *fr); -static int ses_do_frame(frame_T *fr); -static int ses_do_win(win_T *wp); -static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, -                       unsigned *flagp); -static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp); -static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp);  /*   * Write openfile commands for the current buffers to an .exrc file. diff --git a/src/nvim/ex_docmd.h b/src/nvim/ex_docmd.h index 963e689e60..7825fcd4fb 100644 --- a/src/nvim/ex_docmd.h +++ b/src/nvim/ex_docmd.h @@ -1,69 +1,9 @@  #ifndef NVIM_EX_DOCMD_H  #define NVIM_EX_DOCMD_H -/* ex_docmd.c */ -void do_exmode(int improved); -int do_cmdline_cmd(char_u *cmd); -int do_cmdline(char_u *cmdline, char_u * -               (*fgetline)(int, void *, int), void *cookie, -               int flags); -int getline_equal(char_u * -                  (*fgetline)(int, void *, int), void *cookie, char_u * -                  (*func)(int, void *, int)); -void *getline_cookie(char_u *(*fgetline)(int, void *, int), void *cookie); -int checkforcmd(char_u **pp, char *cmd, int len); -int modifier_len(char_u *cmd); -int cmd_exists(char_u *name); -char_u *set_one_cmd_context(expand_T *xp, char_u *buff); -char_u *skip_range(char_u *cmd, int *ctx); -void ex_ni(exarg_T *eap); -int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp); -void separate_nextcmd(exarg_T *eap); -int ends_excmd(int c); -char_u *find_nextcmd(char_u *p); -char_u *check_nextcmd(char_u *p); -char_u *get_command_name(expand_T *xp, int idx); -void ex_comclear(exarg_T *eap); -void ex_may_print(exarg_T *eap); -void uc_clear(garray_T *gap); -char_u *get_user_commands(expand_T *xp, int idx); -char_u *get_user_cmd_flags(expand_T *xp, int idx); -char_u *get_user_cmd_nargs(expand_T *xp, int idx); -char_u *get_user_cmd_complete(expand_T *xp, int idx); -int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, -                    char_u **compl_arg); -void not_exiting(void); -void tabpage_close(int forceit); -void tabpage_close_other(tabpage_T *tp, int forceit); -void ex_all(exarg_T *eap); -void alist_clear(alist_T *al); -void alist_init(alist_T *al); -void alist_unlink(alist_T *al); -void alist_new(void); -void alist_expand(int *fnum_list, int fnum_len); -void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, -               int *fnum_list, -               int fnum_len); -void alist_add(alist_T *al, char_u *fname, int set_fnum); -void alist_slash_adjust(void); -void ex_splitview(exarg_T *eap); -void tabpage_new(void); -void do_exedit(exarg_T *eap, win_T *old_curwin); -void free_cd_dir(void); -void post_chdir(int local); -void ex_cd(exarg_T *eap); -void do_sleep(long msec); -int vim_mkdir_emsg(char_u *name, int prot); -FILE *open_exfile(char_u *fname, int forceit, char *mode); -void update_topline_cursor(void); -void exec_normal_cmd(char_u *cmd, int remap, int silent); -int find_cmdline_var(char_u *src, int *usedlen); -char_u *eval_vars(char_u *src, char_u *srcstart, int *usedlen, -                  linenr_T *lnump, char_u **errormsg, -                  int *escaped); -char_u *expand_sfile(char_u *arg); -int put_eol(FILE *fd); -int put_line(FILE *fd, char *s); -void dialog_msg(char_u *buff, char *format, char_u *fname); -char_u *get_behave_arg(expand_T *xp, int idx); -#endif /* NVIM_EX_DOCMD_H */ +typedef char_u *(*LineGetter)(int, void *, int); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_docmd.h.generated.h" +#endif +#endif  // NVIM_EX_DOCMD_H diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 929ff4211f..5122e61c82 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -23,10 +23,10 @@  #include "nvim/strings.h" -static void free_msglist(struct msglist *l); -static int throw_exception(void *, int, char_u *); -static char_u   *get_end_emsg(struct condstack *cstack); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_eval.c.generated.h" +#endif  /*   * Exception handling terms:   * @@ -66,10 +66,6 @@ static char_u   *get_end_emsg(struct condstack *cstack);  # define THROW_ON_INTERRUPT     TRUE  # define THROW_ON_INTERRUPT_TRUE -static void catch_exception(except_T *excp); -static void finish_exception(except_T *excp); -static void discard_exception(except_T *excp, int was_finished); -static void report_pending(int action, int pending, void *value);  /*   * When several errors appear in a row, setting "force_abort" is delayed until diff --git a/src/nvim/ex_eval.h b/src/nvim/ex_eval.h index 6af82d3f3c..7523aff792 100644 --- a/src/nvim/ex_eval.h +++ b/src/nvim/ex_eval.h @@ -118,42 +118,7 @@ struct cleanup_stuff {    except_T *exception;          /* exception value */  }; -/* ex_eval.c */ -int aborting(void); -void update_force_abort(void); -int should_abort(int retcode); -int aborted_in_try(void); -int cause_errthrow(char_u *mesg, int severe, int *ignore); -void free_global_msglist(void); -void do_errthrow(struct condstack *cstack, char_u *cmdname); -int do_intthrow(struct condstack *cstack); -char_u *get_exception_string(void *value, int type, char_u *cmdname, -                             int *should_free); -void discard_current_exception(void); -void report_make_pending(int pending, void *value); -void report_resume_pending(int pending, void *value); -void report_discard_pending(int pending, void *value); -void ex_if(exarg_T *eap); -void ex_endif(exarg_T *eap); -void ex_else(exarg_T *eap); -void ex_while(exarg_T *eap); -void ex_continue(exarg_T *eap); -void ex_break(exarg_T *eap); -void ex_endwhile(exarg_T *eap); -void ex_throw(exarg_T *eap); -void do_throw(struct condstack *cstack); -void ex_try(exarg_T *eap); -void ex_catch(exarg_T *eap); -void ex_finally(exarg_T *eap); -void ex_endtry(exarg_T *eap); -void enter_cleanup(cleanup_T *csp); -void leave_cleanup(cleanup_T *csp); -int cleanup_conditionals(struct condstack *cstack, int searched_cond, -                         int inclusive); -void rewind_conditionals(struct condstack *cstack, int idx, -                         int cond_type, -                         int *cond_level); -void ex_endfunction(exarg_T *eap); -int has_loop_cmd(char_u *p); - -#endif /* NVIM_EX_EVAL_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_eval.h.generated.h" +#endif +#endif  // NVIM_EX_EVAL_H diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 57af0c20e4..abb1bb4f86 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -99,57 +99,26 @@ typedef struct hist_entry {    char_u      *hisstr;          /* actual entry, separator char after the NUL */  } histentry_T; +/* + * Type used by call_user_expand_func + */ +typedef void *(*user_expand_func_T)(char_u *, int, char_u **, int); +  static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};  static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1};       /* lastused entry */  static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0};  /* identifying (unique) number of newest history entry */  static int hislen = 0;                  /* actual length of history tables */ -static int hist_char2type(int c); -static int in_history(int, char_u *, int, int, int); -static int calc_hist_idx(int histype, int num); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_getln.c.generated.h" +#endif  static int cmd_hkmap = 0;       /* Hebrew mapping during command line */  static int cmd_fkmap = 0;       /* Farsi mapping during command line */ -static int cmdline_charsize(int idx); -static void set_cmdspos(void); -static void set_cmdspos_cursor(void); -static void correct_cmdspos(int idx, int cells); -static void alloc_cmdbuff(int len); -static void realloc_cmdbuff(int len); -static void draw_cmdline(int start, int len); -static void save_cmdline(struct cmdline_info *ccp); -static void restore_cmdline(struct cmdline_info *ccp); -static int cmdline_paste(int regname, int literally, int remcr); -static void cmdline_del(int from); -static void redrawcmdprompt(void); -static void cursorcmd(void); -static int ccheck_abbr(int); -static int nextwild(expand_T *xp, int type, int options, int escape); -static void escape_fname(char_u **pp); -static int showmatches(expand_T *xp, int wildmenu); -static void set_expand_context(expand_T *xp); -static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); -static int expand_showtail(expand_T *xp); -static int expand_shellcmd(char_u *filepat, int *num_file, -                           char_u ***file, -                           int flagsarg); -static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, -                               char *dirname[]); -static char_u   *get_history_arg(expand_T *xp, int idx); -static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, -                             int *num_file, -                             char_u ***file); -static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); -static void clear_hist_entry(histentry_T *hisptr); - -static int ex_window(void); - -static int sort_func_compare(const void *s1, const void *s2); -  /*   * getcmdline() - accept a command line starting with firstc.   * @@ -3584,7 +3553,6 @@ expand_cmdline (  /*   * Cleanup matches for help tags: remove "@en" if "en" is the only language.   */ -static void cleanup_help_tags(int num_file, char_u **file);  static void cleanup_help_tags(int num_file, char_u **file)  { @@ -3797,14 +3765,14 @@ ExpandFromContext (   *   * Returns OK when no problems encountered, FAIL for error.   */ -int ExpandGeneric(xp, regmatch, num_file, file, func, escaped) -expand_T    *xp; -regmatch_T  *regmatch; -int         *num_file; -char_u      ***file; -char_u      *((*func)(expand_T *, int)); -/* returns a string from the list */ -int escaped; +int ExpandGeneric( +    expand_T    *xp, +    regmatch_T  *regmatch, +    int         *num_file, +    char_u      ***file, +    CompleteListItemGetter func, /* returns a string from the list */ +    int escaped +    )  {    int i;    int count = 0; @@ -3963,11 +3931,6 @@ expand_shellcmd (    return OK;  } -typedef void *(*user_expand_func_T)(char_u *, int, char_u **, int); -static void * call_user_expand_func(user_expand_func_T user_expand_func, -                                    expand_T *xp, int *num_file, -                                    char_u ***file); -  /*   * Call "user_expand_func()" to invoke a user defined VimL function and return   * the result (either a string or a List). @@ -4483,7 +4446,6 @@ int get_history_idx(int histype)    return history[histype][hisidx[histype]].hisnum;  } -static struct cmdline_info *get_ccline_ptr(void);  /*   * Get pointer to the command line info to use. cmdline_paste() may clear @@ -4871,7 +4833,6 @@ static int viminfo_hisidx[HIST_COUNT] = {0, 0, 0, 0};  static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0};  static int viminfo_add_at_front = FALSE; -static int hist_type2char(int type, int use_question);  /*   * Translate a history type number to the associated character. diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index d2ebb7a82f..6d88e94a78 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -1,66 +1,11 @@  #ifndef NVIM_EX_GETLN_H  #define NVIM_EX_GETLN_H -/* ex_getln.c */ -char_u *getcmdline(int firstc, long count, int indent); -char_u *getcmdline_prompt(int firstc, char_u *prompt, int attr, -                          int xp_context, -                          char_u *xp_arg); -int text_locked(void); -void text_locked_msg(void); -int curbuf_locked(void); -int allbuf_locked(void); -char_u *getexline(int c, void *cookie, int indent); -char_u *getexmodeline(int promptc, void *cookie, int indent); -void free_cmdline_buf(void); -void putcmdline(int c, int shift); -void unputcmdline(void); -void put_on_cmdline(char_u *str, int len, int redraw); -char_u *save_cmdline_alloc(void); -void restore_cmdline_alloc(char_u *p); -void cmdline_paste_str(char_u *s, int literally); -void redrawcmdline(void); -void redrawcmd(void); -void compute_cmdrow(void); -void gotocmdline(int clr); -char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, -                  int mode); -void ExpandInit(expand_T *xp); -void ExpandCleanup(expand_T *xp); -void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u * -                  *files, -                  int options); -char_u *vim_strsave_fnameescape(char_u *fname, int shell); -void tilde_replace(char_u *orig_pat, int num_files, char_u **files); -char_u *sm_gettail(char_u *s); -char_u *addstar(char_u *fname, int len, int context); -void set_cmd_context(expand_T *xp, char_u *str, int len, int col); -int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, -                   char_u ***matches); -int ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, -                  char_u ***file, char_u *((*func)(expand_T *, int)), -                  int escaped); -char_u *globpath(char_u *path, char_u *file, int expand_options); -void init_history(void); -int get_histtype(char_u *name); -void add_to_history(int histype, char_u *new_entry, int in_map, int sep); -int get_history_idx(int histype); -char_u *get_cmdline_str(void); -int get_cmdline_pos(void); -int set_cmdline_pos(int pos); -int get_cmdline_type(void); -char_u *get_history_entry(int histype, int idx); -int clr_history(int histype); -int del_history_entry(int histype, char_u *str); -int del_history_idx(int histype, int idx); -void remove_key_from_history(void); -int get_list_range(char_u **str, int *num1, int *num2); -void ex_history(exarg_T *eap); -void prepare_viminfo_history(int asklen, int writing); -int read_viminfo_history(vir_T *virp, int writing); -void finish_viminfo_history(void); -void write_viminfo_history(FILE *fp, int merge); -void cmd_pchar(int c, int offset); -int cmd_gchar(int offset); -char_u *script_get(exarg_T *eap, char_u *cmd); -#endif /* NVIM_EX_GETLN_H */ +#include "nvim/ex_cmds.h" + +typedef char_u *(*CompleteListItemGetter)(expand_T *, int); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ex_getln.h.generated.h" +#endif +#endif  // NVIM_EX_GETLN_H diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c index 6e532bbe0a..1cb20c71d6 100644 --- a/src/nvim/farsi.c +++ b/src/nvim/farsi.c @@ -54,27 +54,10 @@ const char_u farsi_text_5[] = {    ' ', YE_, _SIN, RE, ALEF_, _FE, '\0'  }; -static int toF_Xor_X_(int c); -static int F_is_TyE(int c); -static int F_is_TyC_TyD(int c); -static int F_is_TyB_TyC_TyD(int src, int offset); -static int toF_TyB(int c); -static void put_curr_and_l_to_X(int c); -static void put_and_redo(int c); -static void chg_c_toX_orX(void); -static void chg_c_to_X_orX_(void); -static void chg_c_to_X_or_X(void); -static void chg_l_to_X_orX_(void); -static void chg_l_toXor_X(void); -static void chg_r_to_Xor_X_(void); -static int toF_leading(int c); -static int toF_Rjoin(int c); -static int canF_Ljoin(int c); -static int canF_Rjoin(int c); -static int F_isterm(int c); -static int toF_ending(int c); -static void lrswapbuf(char_u *buf, int len); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "farsi.c.generated.h" +#endif  /// Convert the given Farsi character into a _X or _X_ type  ///  /// @param c The character to convert. diff --git a/src/nvim/farsi.h b/src/nvim/farsi.h index 779f7053ac..003ea140f2 100644 --- a/src/nvim/farsi.h +++ b/src/nvim/farsi.h @@ -167,17 +167,8 @@ extern const char_u farsi_text_2[];  extern const char_u farsi_text_3[];  extern const char_u farsi_text_5[]; -int toF_TyA(int c); -int fkmap(int c); -void conv_to_pvim(void); -void conv_to_pstd(void); -char_u *lrswap(char_u *ibuf); -char_u *lrFswap(char_u *cmdbuf, int len); -char_u *lrF_sub(char_u *ibuf); -int cmdl_fkmap(int c); -int F_isalpha(int c); -int F_isdigit(int c); -int F_ischar(int c); -void farsi_fkey(cmdarg_T *cap); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "farsi.h.generated.h" +#endif  #endif  // NVIM_FARSI_H diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 0ff02b85bf..4e2a9cb5d9 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -185,20 +185,10 @@ typedef struct ff_search_ctx_T {  } ff_search_ctx_T;  /* locally needed functions */ -static int ff_check_visited(ff_visited_T **, char_u *, char_u *); -static void vim_findfile_free_visited_list -    (ff_visited_list_hdr_T **list_headp); -static void ff_free_visited_list(ff_visited_T *vl); -static ff_visited_list_hdr_T* ff_get_visited_list -    (char_u *, ff_visited_list_hdr_T **list_headp); -static int ff_wc_equal(char_u *s1, char_u *s2); - -static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr); -static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx); -static void ff_clear(ff_search_ctx_T *search_ctx); -static void ff_free_stack_element(ff_stack_T *stack_ptr); -static ff_stack_T *ff_create_stack_element(char_u *, char_u *, int, int); -static int ff_path_in_stoplist(char_u *, int, char_u **); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "file_search.c.generated.h" +#endif  static char_u e_pathtoolong[] = N_("E854: path too long for completion"); diff --git a/src/nvim/file_search.h b/src/nvim/file_search.h index 5957fd1f9f..0b0b03c56a 100644 --- a/src/nvim/file_search.h +++ b/src/nvim/file_search.h @@ -1,23 +1,7 @@  #ifndef NVIM_FILE_SEARCH_H  #define NVIM_FILE_SEARCH_H -void *vim_findfile_init(char_u *path, char_u *filename, char_u * -                                stopdirs, int level, int free_visited, -                                int find_what, void *search_ctx_arg, -                                int tagfile, -                                char_u *rel_fname); -char_u *vim_findfile_stopdir(char_u *buf); -void vim_findfile_cleanup(void *ctx); -char_u *vim_findfile(void *search_ctx_arg); -void vim_findfile_free_visited(void *search_ctx_arg); -char_u *find_file_in_path(char_u *ptr, int len, int options, int first, -                                  char_u *rel_fname); -void free_findfile(void); -char_u *find_directory_in_path(char_u *ptr, int len, int options, -                                       char_u *rel_fname); -char_u *find_file_in_path_option(char_u *ptr, int len, int options, -                                         int first, char_u *path_option, -                                         int find_what, char_u *rel_fname, -                                         char_u *suffixes); - -#endif /* NVIM_FILE_SEARCH_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "file_search.h.generated.h" +#endif +#endif  // NVIM_FILE_SEARCH_H diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 6c42a2bef3..d4faafeed6 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -58,37 +58,89 @@  #define BUFSIZE         8192    /* size of normal write buffer */  #define SMBUFSIZE       256     /* size of emergency write buffer */ -static char_u *next_fenc(char_u **pp); -static char_u *readfile_charconvert(char_u *fname, char_u *fenc, -                                            int *fdp); -static void check_marks_read(void); -#ifdef UNIX -static void set_file_time(char_u *fname, time_t atime, time_t mtime); -#endif -static int set_rw_fname(char_u *fname, char_u *sfname); -static int msg_add_fileformat(int eol_type); -static void msg_add_eol(void); -static int check_mtime(buf_T *buf, FileInfo *file_info); -static int time_differs(long t1, long t2); -static int apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, -                                int force, buf_T *buf, -                                exarg_T *eap); -static int au_find_group(char_u *name); - -# define AUGROUP_DEFAULT    -1      /* default autocmd group */ -# define AUGROUP_ERROR      -2      /* erroneous autocmd group */ -# define AUGROUP_ALL        -3      /* all autocmd groups */ - -# define HAS_BW_FLAGS -# define FIO_LATIN1     0x01    /* convert Latin1 */ -# define FIO_UTF8       0x02    /* convert UTF-8 */ -# define FIO_UCS2       0x04    /* convert UCS-2 */ -# define FIO_UCS4       0x08    /* convert UCS-4 */ -# define FIO_UTF16      0x10    /* convert UTF-16 */ -# define FIO_ENDIAN_L   0x80    /* little endian */ -# define FIO_NOCONVERT  0x2000  /* skip encoding conversion */ -# define FIO_UCSBOM     0x4000  /* check for BOM at start of file */ -# define FIO_ALL        -1      /* allow all formats */ +/* + * The autocommands are stored in a list for each event. + * Autocommands for the same pattern, that are consecutive, are joined + * together, to avoid having to match the pattern too often. + * The result is an array of Autopat lists, which point to AutoCmd lists: + * + * first_autopat[0] --> Autopat.next  -->  Autopat.next -->  NULL + *			Autopat.cmds	   Autopat.cmds + *			    |			 | + *			    V			 V + *			AutoCmd.next	   AutoCmd.next + *			    |			 | + *			    V			 V + *			AutoCmd.next		NULL + *			    | + *			    V + *			   NULL + * + * first_autopat[1] --> Autopat.next  -->  NULL + *			Autopat.cmds + *			    | + *			    V + *			AutoCmd.next + *			    | + *			    V + *			   NULL + *   etc. + * + *   The order of AutoCmds is important, this is the order in which they were + *   defined and will have to be executed. + */ +typedef struct AutoCmd { +  char_u          *cmd;                 /* The command to be executed (NULL +                                           when command has been removed) */ +  char nested;                          /* If autocommands nest here */ +  char last;                            /* last command in list */ +  scid_T scriptID;                      /* script ID where defined */ +  struct AutoCmd  *next;                /* Next AutoCmd in list */ +} AutoCmd; + +typedef struct AutoPat { +  char_u          *pat;                 /* pattern as typed (NULL when pattern +                                           has been removed) */ +  regprog_T       *reg_prog;            /* compiled regprog for pattern */ +  AutoCmd         *cmds;                /* list of commands to do */ +  struct AutoPat  *next;                /* next AutoPat in AutoPat list */ +  int group;                            /* group ID */ +  int patlen;                           /* strlen() of pat */ +  int buflocal_nr;                      /* !=0 for buffer-local AutoPat */ +  char allow_dirs;                      /* Pattern may match whole path */ +  char last;                            /* last pattern for apply_autocmds() */ +} AutoPat; + +/* + * struct used to keep status while executing autocommands for an event. + */ +typedef struct AutoPatCmd { +  AutoPat     *curpat;          /* next AutoPat to examine */ +  AutoCmd     *nextcmd;         /* next AutoCmd to execute */ +  int group;                    /* group being used */ +  char_u      *fname;           /* fname to match with */ +  char_u      *sfname;          /* sfname to match with */ +  char_u      *tail;            /* tail of fname */ +  event_T event;                /* current event */ +  int arg_bufnr;                /* initially equal to <abuf>, set to zero when +                                   buf is deleted */ +  struct AutoPatCmd   *next;    /* chain of active apc-s for auto-invalidation*/ +} AutoPatCmd; + +#define AUGROUP_DEFAULT    -1      /* default autocmd group */ +#define AUGROUP_ERROR      -2      /* erroneous autocmd group */ +#define AUGROUP_ALL        -3      /* all autocmd groups */ + +#define HAS_BW_FLAGS +#define FIO_LATIN1     0x01    /* convert Latin1 */ +#define FIO_UTF8       0x02    /* convert UTF-8 */ +#define FIO_UCS2       0x04    /* convert UCS-2 */ +#define FIO_UCS4       0x08    /* convert UCS-4 */ +#define FIO_UTF16      0x10    /* convert UTF-16 */ +#define FIO_ENDIAN_L   0x80    /* little endian */ +#define FIO_NOCONVERT  0x2000  /* skip encoding conversion */ +#define FIO_UCSBOM     0x4000  /* check for BOM at start of file */ +#define FIO_ALL        -1      /* allow all formats */  /* When converting, a read() or write() may leave some bytes to be converted   * for the next call.  The value is guessed... */ @@ -121,19 +173,14 @@ struct bw_info {  # endif  }; -static int buf_write_bytes(struct bw_info *ip); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "fileio.c.generated.h" +#endif -static linenr_T readfile_linenr(linenr_T linecnt, char_u *p, -                                char_u *endp); -static int ucs2bytes(unsigned c, char_u **pp, int flags); -static int need_conversion(char_u *fenc); -static int get_fio_flags(char_u *ptr); -static char_u *check_for_bom(char_u *p, long size, int *lenp, int flags); -static int make_bom(char_u *buf, char_u *name); -static int move_lines(buf_T *frombuf, buf_T *tobuf); -#ifdef TEMPDIRNAMES -static void vim_settempdir(char_u *tempdir); +#ifdef UNIX  #endif + +  static char *e_auchangedbuf = N_(      "E812: Autocommands changed buffer or buffer name"); @@ -5364,59 +5411,6 @@ void forward_slash(char_u *fname)   */ -/* - * The autocommands are stored in a list for each event. - * Autocommands for the same pattern, that are consecutive, are joined - * together, to avoid having to match the pattern too often. - * The result is an array of Autopat lists, which point to AutoCmd lists: - * - * first_autopat[0] --> Autopat.next  -->  Autopat.next -->  NULL - *			Autopat.cmds	   Autopat.cmds - *			    |			 | - *			    V			 V - *			AutoCmd.next	   AutoCmd.next - *			    |			 | - *			    V			 V - *			AutoCmd.next		NULL - *			    | - *			    V - *			   NULL - * - * first_autopat[1] --> Autopat.next  -->  NULL - *			Autopat.cmds - *			    | - *			    V - *			AutoCmd.next - *			    | - *			    V - *			   NULL - *   etc. - * - *   The order of AutoCmds is important, this is the order in which they were - *   defined and will have to be executed. - */ -typedef struct AutoCmd { -  char_u          *cmd;                 /* The command to be executed (NULL -                                           when command has been removed) */ -  char nested;                          /* If autocommands nest here */ -  char last;                            /* last command in list */ -  scid_T scriptID;                      /* script ID where defined */ -  struct AutoCmd  *next;                /* Next AutoCmd in list */ -} AutoCmd; - -typedef struct AutoPat { -  char_u          *pat;                 /* pattern as typed (NULL when pattern -                                           has been removed) */ -  regprog_T       *reg_prog;            /* compiled regprog for pattern */ -  AutoCmd         *cmds;                /* list of commands to do */ -  struct AutoPat  *next;                /* next AutoPat in AutoPat list */ -  int group;                            /* group ID */ -  int patlen;                           /* strlen() of pat */ -  int buflocal_nr;                      /* !=0 for buffer-local AutoPat */ -  char allow_dirs;                      /* Pattern may match whole path */ -  char last;                            /* last pattern for apply_autocmds() */ -} AutoPat; -  static struct event_name {    char        *name;    /* event name */    event_T event;        /* event number */ @@ -5522,22 +5516,6 @@ static AutoPat *first_autopat[NUM_EVENTS] =    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL  }; -/* - * struct used to keep status while executing autocommands for an event. - */ -typedef struct AutoPatCmd { -  AutoPat     *curpat;          /* next AutoPat to examine */ -  AutoCmd     *nextcmd;         /* next AutoCmd to execute */ -  int group;                    /* group being used */ -  char_u      *fname;           /* fname to match with */ -  char_u      *sfname;          /* sfname to match with */ -  char_u      *tail;            /* tail of fname */ -  event_T event;                /* current event */ -  int arg_bufnr;                /* initially equal to <abuf>, set to zero when -                                   buf is deleted */ -  struct AutoPatCmd   *next;    /* chain of active apc-s for auto-invalidation*/ -} AutoPatCmd; -  static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */  /* @@ -5553,24 +5531,6 @@ static int current_augroup = AUGROUP_DEFAULT;  static int au_need_clean = FALSE;   /* need to delete marked patterns */ -static void show_autocmd(AutoPat *ap, event_T event); -static void au_remove_pat(AutoPat *ap); -static void au_remove_cmds(AutoPat *ap); -static void au_cleanup(void); -static int au_new_group(char_u *name); -static void au_del_group(char_u *name); -static event_T event_name2nr(char_u *start, char_u **end); -static char_u *event_nr2name(event_T event); -static char_u *find_end_event(char_u *arg, int have_group); -static int event_ignored(event_T event); -static int au_get_grouparg(char_u **argp); -static int do_autocmd_event(event_T event, char_u *pat, int nested, -                            char_u *cmd, int forceit, -                            int group); -static int apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, -                                int force, int group, buf_T *buf, -                                exarg_T *eap); -static void auto_next_pat(AutoPatCmd *apc, int stop_at_last);  static event_T last_event; @@ -7803,10 +7763,7 @@ file_pat_to_reg_pat (   * Version of read() that retries when interrupted by EINTR (possibly   * by a SIGWINCH).   */ -long read_eintr(fd, buf, bufsize) -int fd; -void    *buf; -size_t bufsize; +long read_eintr(int fd, void *buf, size_t bufsize)  {    long ret; @@ -7822,10 +7779,7 @@ size_t bufsize;   * Version of write() that retries when interrupted by EINTR (possibly   * by a SIGWINCH).   */ -long write_eintr(fd, buf, bufsize) -int fd; -void    *buf; -size_t bufsize; +long write_eintr(int fd, void *buf, size_t bufsize)  {    long ret = 0;    long wlen; diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h index 137f8506ba..399d93d77c 100644 --- a/src/nvim/fileio.h +++ b/src/nvim/fileio.h @@ -17,76 +17,7 @@ typedef struct {    char_u      *globaldir;       /* saved value of globaldir */  } aco_save_T; -/* fileio.c */ -void filemess(buf_T *buf, char_u *name, char_u *s, int attr); -int readfile(char_u *fname, char_u *sfname, linenr_T from, -             linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, -             int flags); -void prep_exarg(exarg_T *eap, buf_T *buf); -void set_file_options(int set_options, exarg_T *eap); -void set_forced_fenc(exarg_T *eap); -int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, -              linenr_T end, exarg_T *eap, int append, int forceit, -              int reset_changed, -              int filtering); -void msg_add_fname(buf_T *buf, char_u *fname); -void msg_add_lines(int insert_space, long lnum, off_t nchars); -void shorten_fnames(int force); -char_u *modname(char_u *fname, char_u *ext, int prepend_dot); -int vim_fgets(char_u *buf, int size, FILE *fp); -int tag_fgets(char_u *buf, int size, FILE *fp); -int vim_rename(char_u *from, char_u *to); -int check_timestamps(int focus); -int buf_check_timestamp(buf_T *buf, int focus); -void buf_reload(buf_T *buf, int orig_mode); -void buf_store_file_info(buf_T *buf, FileInfo *file_info); -void write_lnum_adjust(linenr_T offset); -void vim_deltempdir(void); -char_u *vim_tempname(int extra_char); -void forward_slash(char_u *fname); -void aubuflocal_remove(buf_T *buf); -int au_has_group(char_u *name); -void do_augroup(char_u *arg, int del_group); -void free_all_autocmds(void); -int check_ei(void); -char_u *au_event_disable(char *what); -void au_event_restore(char_u *old_ei); -void do_autocmd(char_u *arg, int forceit); -int do_doautocmd(char_u *arg, int do_msg); -void ex_doautoall(exarg_T *eap); -int check_nomodeline(char_u **argp); -void aucmd_prepbuf(aco_save_T *aco, buf_T *buf); -void aucmd_restbuf(aco_save_T *aco); -int apply_autocmds(event_T event, char_u *fname, char_u *fname_io, -                   int force, -                   buf_T *buf); -int apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, -                          int force, buf_T *buf, -                          int *retval); -int has_cursorhold(void); -int trigger_cursorhold(void); -int has_cursormoved(void); -int has_cursormovedI(void); -int has_textchanged(void); -int has_textchangedI(void); -int has_insertcharpre(void); -void block_autocmds(void); -void unblock_autocmds(void); -char_u *getnextac(int c, void *cookie, int indent); -int has_autocmd(event_T event, char_u *sfname, buf_T *buf); -char_u *get_augroup_name(expand_T *xp, int idx); -char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd); -char_u *get_event_name(expand_T *xp, int idx); -int autocmd_supported(char_u *name); -int au_exists(char_u *arg); -int match_file_pat(char_u *pattern, regprog_T *prog, char_u *fname, -                   char_u *sfname, char_u *tail, -                   int allow_dirs); -int match_file_list(char_u *list, char_u *sfname, char_u *ffname); -char_u *file_pat_to_reg_pat(char_u *pat, char_u *pat_end, -                            char *allow_dirs, -                            int no_bslash); -long read_eintr(int fd, void *buf, size_t bufsize); -long write_eintr(int fd, void *buf, size_t bufsize); - -#endif /* NVIM_FILEIO_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "fileio.h.generated.h" +#endif +#endif  // NVIM_FILEIO_H diff --git a/src/nvim/fold.c b/src/nvim/fold.c index fe05ba76ac..e623c388ff 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -60,37 +60,33 @@ typedef struct {  #define MAX_LEVEL       20      /* maximum fold depth */ +/* Define "fline_T", passed to get fold level for a line. {{{2 */ +typedef struct { +  win_T       *wp;              /* window */ +  linenr_T lnum;                /* current line number */ +  linenr_T off;                 /* offset between lnum and real line number */ +  linenr_T lnum_save;           /* line nr used by foldUpdateIEMSRecurse() */ +  int lvl;                      /* current level (-1 for undefined) */ +  int lvl_next;                 /* level used for next line */ +  int start;                    /* number of folds that are forced to start at +                                   this line. */ +  int end;                      /* level of fold that is forced to end below +                                   this line */ +  int had_end;                  /* level of fold that is forced to end above +                                   this line (copy of "end" of prev. line) */ +} fline_T; + +/* Flag is set when redrawing is needed. */ +static int fold_changed; + +/* Function used by foldUpdateIEMSRecurse */ +typedef void (*LevelGetter)(fline_T *); +  /* static functions {{{2 */ -static void newFoldLevelWin(win_T *wp); -static int checkCloseRec(garray_T *gap, linenr_T lnum, int level); -static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp); -static int foldLevelWin(win_T *wp, linenr_T lnum); -static void checkupdate(win_T *wp); -static void setFoldRepeat(linenr_T lnum, long count, int do_open); -static linenr_T setManualFold(linenr_T lnum, int opening, int recurse, -                              int *donep); -static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, -                                 int recurse, -                                 int *donep); -static void foldOpenNested(fold_T *fpr); -static void deleteFoldEntry(garray_T *gap, int idx, int recursive); -static void foldMarkAdjustRecurse(garray_T *gap, linenr_T line1, -                                  linenr_T line2, long amount, -                                  long amount_after); -static int getDeepestNestingRecurse(garray_T *gap); -static int check_closed(win_T *win, fold_T *fp, int *use_levelp, -                        int level, int *maybe_smallp, -                        linenr_T lnum_off); -static void checkSmall(win_T *wp, fold_T *fp, linenr_T lnum_off); -static void setSmallMaybe(garray_T *gap); -static void foldCreateMarkers(linenr_T start, linenr_T end); -static void foldAddMarker(linenr_T lnum, char_u *marker, int markerlen); -static void deleteFoldMarkers(fold_T *fp, int recursive, -                              linenr_T lnum_off); -static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen); -static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot); -static void parseMarker(win_T *wp); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "fold.c.generated.h" +#endif  static char *e_nofold = N_("E490: No fold found");  /* @@ -1868,39 +1864,7 @@ void foldtext_cleanup(char_u *str)  }  /* Folding by indent, expr, marker and syntax. {{{1 */ -/* Define "fline_T", passed to get fold level for a line. {{{2 */ -typedef struct { -  win_T       *wp;              /* window */ -  linenr_T lnum;                /* current line number */ -  linenr_T off;                 /* offset between lnum and real line number */ -  linenr_T lnum_save;           /* line nr used by foldUpdateIEMSRecurse() */ -  int lvl;                      /* current level (-1 for undefined) */ -  int lvl_next;                 /* level used for next line */ -  int start;                    /* number of folds that are forced to start at -                                   this line. */ -  int end;                      /* level of fold that is forced to end below -                                   this line */ -  int had_end;                  /* level of fold that is forced to end above -                                   this line (copy of "end" of prev. line) */ -} fline_T; - -/* Flag is set when redrawing is needed. */ -static int fold_changed; -  /* Function declarations. {{{2 */ -static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, -                                      linenr_T startlnum, fline_T *flp, -                                      void (*getlevel)(fline_T *), linenr_T bot, -                                      int topflags); -static void foldInsert(garray_T *gap, int i); -static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot); -static void foldRemove(garray_T *gap, linenr_T top, linenr_T bot); -static void foldMerge(fold_T *fp1, garray_T *gap, fold_T *fp2); -static void foldlevelIndent(fline_T *flp); -static void foldlevelDiff(fline_T *flp); -static void foldlevelExpr(fline_T *flp); -static void foldlevelMarker(fline_T *flp); -static void foldlevelSyntax(fline_T *flp);  /* foldUpdateIEMS() {{{2 */  /* @@ -2137,15 +2101,12 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)   * Returns bot, which may have been increased for lines that also need to be   * updated as a result of a detected change in the fold.   */ -static linenr_T foldUpdateIEMSRecurse(gap, level, startlnum, flp, getlevel, bot, -    topflags) -garray_T    *gap; -int level; -linenr_T startlnum; -fline_T     *flp; -void        (*getlevel)(fline_T *); -linenr_T bot; -int topflags;                   /* flags used by containing fold */ +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 */ +                                      )  {    linenr_T ll;    fold_T      *fp = NULL; @@ -2920,10 +2881,6 @@ static void foldlevelSyntax(fline_T *flp)  /* functions for storing the fold state in a View {{{1 */  /* put_folds() {{{2 */ -static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off); -static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, -                                linenr_T off); -static int put_fold_open_close(FILE *fd, fold_T *fp, linenr_T off);  /*   * Write commands to "fd" to restore the manual folds in window "wp". diff --git a/src/nvim/fold.h b/src/nvim/fold.h index 6fb51e4cf0..1cbd7af5da 100644 --- a/src/nvim/fold.h +++ b/src/nvim/fold.h @@ -13,53 +13,8 @@ typedef struct foldinfo {                                     line */  } foldinfo_T; -void copyFoldingState(win_T *wp_from, win_T *wp_to); -int hasAnyFolding(win_T *win); -int hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp); -int hasFoldingWin(win_T *win, linenr_T lnum, linenr_T *firstp, -                  linenr_T *lastp, int cache, -                  foldinfo_T *infop); -int foldLevel(linenr_T lnum); -int lineFolded(win_T *win, linenr_T lnum); -long foldedCount(win_T *win, linenr_T lnum, foldinfo_T *infop); -int foldmethodIsManual(win_T *wp); -int foldmethodIsIndent(win_T *wp); -int foldmethodIsExpr(win_T *wp); -int foldmethodIsMarker(win_T *wp); -int foldmethodIsSyntax(win_T *wp); -int foldmethodIsDiff(win_T *wp); -void closeFold(linenr_T lnum, long count); -void closeFoldRecurse(linenr_T lnum); -void opFoldRange(linenr_T first, linenr_T last, int opening, -                 int recurse, -                 int had_visual); -void openFold(linenr_T lnum, long count); -void openFoldRecurse(linenr_T lnum); -void foldOpenCursor(void); -void newFoldLevel(void); -void foldCheckClose(void); -int foldManualAllowed(int create); -void foldCreate(linenr_T start, linenr_T end); -void deleteFold(linenr_T start, linenr_T end, int recursive, -                int had_visual); -void clearFolding(win_T *win); -void foldUpdate(win_T *wp, linenr_T top, linenr_T bot); -void foldUpdateAll(win_T *win); -int foldMoveTo(int updown, int dir, long count); -void foldInitWin(win_T *new_win); -int find_wl_entry(win_T *win, linenr_T lnum); -void foldAdjustVisual(void); -void foldAdjustCursor(void); -void cloneFoldGrowArray(garray_T *from, garray_T *to); -void deleteFoldRecurse(garray_T *gap); -void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, -                    long amount, -                    long amount_after); -int getDeepestNesting(void); -char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, -                     foldinfo_T *foldinfo, -                     char_u *buf); -void foldtext_cleanup(char_u *str); -int put_folds(FILE *fd, win_T *wp); -#endif /* NVIM_FOLD_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "fold.h.generated.h" +#endif +#endif  // NVIM_FOLD_H diff --git a/src/nvim/func_attr.h b/src/nvim/func_attr.h index 6e7149e8fb..6c29f0fed4 100644 --- a/src/nvim/func_attr.h +++ b/src/nvim/func_attr.h @@ -1,5 +1,25 @@ -#ifndef NVIM_FUNC_ATTR_H -#define NVIM_FUNC_ATTR_H +// If DEFINE_FUNC_ATTRIBUTES macro is not defined then all function attributes  +// are defined as empty values. +// +// If DO_NOT_DEFINE_EMPTY_ATTRIBUTES then empty macros are not defined. Thus  +// undefined DEFINE_FUNC_ATTRIBUTES and defined DO_NOT_DEFINE_EMPTY_ATTRIBUTES  +// leaves file with untouched FUNC_ATTR_* macros. This variant is used for  +// scripts/gendeclarations.lua. +// +// Empty macros are used for *.c files. (undefined DEFINE_FUNC_ATTRIBUTES and  +// undefined DO_NOT_DEFINE_EMPTY_ATTRIBUTES) +// +// Macros defined as __attribute__((*)) are used by generated header files.  +// (defined DEFINE_FUNC_ATTRIBUTES and undefined  +// DO_NOT_DEFINE_EMPTY_ATTRIBUTES) +// +// Defined DEFINE_FUNC_ATTRIBUTES and defined DO_NOT_DEFINE_EMPTY_ATTRIBUTES is  +// not used by anything. + +// FUNC_ATTR_* macros should be in *.c files for declarations generator. If you  +// define a function for which declaration is not generated by  +// gendeclarations.lua (e.g. template hash implementation) then you should use  +// REAL_FATTR_* macros.  // gcc and clang expose their version as follows:  // @@ -21,90 +41,167 @@  // $ gcc -E -dM - </dev/null  // $ echo | clang -dM -E - -#ifdef __GNUC__ -  // place defines for all gnulikes here, for now that's gcc, clang and -  // intel. - -  // place these after the argument list of the function declaration -  // (not definition), like so: -  // void myfunc(void) FUNC_ATTR_ALWAYS_INLINE; -  #define FUNC_ATTR_MALLOC __attribute__((malloc)) -  #define FUNC_ATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x))) -  #define FUNC_ATTR_PURE __attribute__ ((pure)) -  #define FUNC_ATTR_CONST __attribute__((const)) -  #define FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -  #define FUNC_ATTR_ALWAYS_INLINE __attribute__((always_inline)) -  #define FUNC_ATTR_UNUSED __attribute__((unused)) - -  #ifdef __clang__ -    // clang only -  #elif defined(__INTEL_COMPILER) -    // intel only -  #else -    #define GCC_VERSION \ -           (__GNUC__ * 10000 + \ -            __GNUC_MINOR__ * 100 + \ -            __GNUC_PATCHLEVEL__) -    // gcc only -    #define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x))) -    #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y))) -    #define FUNC_ATTR_NONNULL_ALL __attribute__((nonnull)) -    #define FUNC_ATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__))) -    #if GCC_VERSION >= 40900 -      #define FUNC_ATTR_NONNULL_RET __attribute__((returns_nonnull)) -    #endif -  #endif +#ifdef FUNC_ATTR_MALLOC +  #undef FUNC_ATTR_MALLOC  #endif -// define function attributes that haven't been defined for this specific -// compiler. +#ifdef FUNC_ATTR_ALLOC_SIZE +  #undef FUNC_ATTR_ALLOC_SIZE +#endif -#ifndef FUNC_ATTR_MALLOC -  #define FUNC_ATTR_MALLOC +#ifdef FUNC_ATTR_ALLOC_SIZE_PROD +  #undef FUNC_ATTR_ALLOC_SIZE_PROD  #endif -#ifndef FUNC_ATTR_ALLOC_SIZE -  #define FUNC_ATTR_ALLOC_SIZE(x) +#ifdef FUNC_ATTR_ALLOC_ALIGN +  #undef FUNC_ATTR_ALLOC_ALIGN  #endif -#ifndef FUNC_ATTR_ALLOC_SIZE_PROD -  #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) +#ifdef FUNC_ATTR_PURE +  #undef FUNC_ATTR_PURE  #endif -#ifndef FUNC_ATTR_ALLOC_ALIGN -  #define FUNC_ATTR_ALLOC_ALIGN(x) +#ifdef FUNC_ATTR_CONST +  #undef FUNC_ATTR_CONST  #endif -#ifndef FUNC_ATTR_PURE -  #define FUNC_ATTR_PURE +#ifdef FUNC_ATTR_WARN_UNUSED_RESULT +  #undef FUNC_ATTR_WARN_UNUSED_RESULT  #endif -#ifndef FUNC_ATTR_CONST -  #define FUNC_ATTR_CONST +#ifdef FUNC_ATTR_ALWAYS_INLINE +  #undef FUNC_ATTR_ALWAYS_INLINE  #endif -#ifndef FUNC_ATTR_WARN_UNUSED_RESULT -  #define FUNC_ATTR_WARN_UNUSED_RESULT +#ifdef FUNC_ATTR_UNUSED +  #undef FUNC_ATTR_UNUSED  #endif -#ifndef FUNC_ATTR_ALWAYS_INLINE -  #define FUNC_ATTR_ALWAYS_INLINE +#ifdef FUNC_ATTR_NONNULL_ALL +  #undef FUNC_ATTR_NONNULL_ALL  #endif -#ifndef FUNC_ATTR_UNUSED -  #define FUNC_ATTR_UNUSED +#ifdef FUNC_ATTR_NONNULL_ARG +  #undef FUNC_ATTR_NONNULL_ARG  #endif -#ifndef FUNC_ATTR_NONNULL_ALL -  #define FUNC_ATTR_NONNULL_ALL +#ifdef FUNC_ATTR_NONNULL_RET +  #undef FUNC_ATTR_NONNULL_RET  #endif -#ifndef FUNC_ATTR_NONNULL_ARG -  #define FUNC_ATTR_NONNULL_ARG(...) +#ifndef DID_REAL_ATTR +  #define DID_REAL_ATTR +  #ifdef __GNUC__ +    // place defines for all gnulikes here, for now that's gcc, clang and +    // intel. + +    // place these after the argument list of the function declaration +    // (not definition), like so: +    // void myfunc(void) REAL_FATTR_ALWAYS_INLINE; +    #define REAL_FATTR_MALLOC __attribute__((malloc)) +    #define REAL_FATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x))) +    #define REAL_FATTR_PURE __attribute__ ((pure)) +    #define REAL_FATTR_CONST __attribute__((const)) +    #define REAL_FATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +    #define REAL_FATTR_ALWAYS_INLINE __attribute__((always_inline)) +    #define REAL_FATTR_UNUSED __attribute__((unused)) + +    #ifdef __clang__ +      // clang only +    #elif defined(__INTEL_COMPILER) +      // intel only +    #else +      #define GCC_VERSION \ +            (__GNUC__ * 10000 + \ +              __GNUC_MINOR__ * 100 + \ +              __GNUC_PATCHLEVEL__) +      // gcc only +      #define REAL_FATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x))) +      #define REAL_FATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y))) +      #define REAL_FATTR_NONNULL_ALL __attribute__((nonnull)) +      #define REAL_FATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__))) +      #if GCC_VERSION >= 40900 +        #define REAL_FATTR_NONNULL_RET __attribute__((returns_nonnull)) +      #endif +    #endif +  #endif + +  // define function attributes that haven't been defined for this specific +  // compiler. + +  #ifndef REAL_FATTR_MALLOC +    #define REAL_FATTR_MALLOC +  #endif + +  #ifndef REAL_FATTR_ALLOC_SIZE +    #define REAL_FATTR_ALLOC_SIZE(x) +  #endif + +  #ifndef REAL_FATTR_ALLOC_SIZE_PROD +    #define REAL_FATTR_ALLOC_SIZE_PROD(x,y) +  #endif + +  #ifndef REAL_FATTR_ALLOC_ALIGN +    #define REAL_FATTR_ALLOC_ALIGN(x) +  #endif + +  #ifndef REAL_FATTR_PURE +    #define REAL_FATTR_PURE +  #endif + +  #ifndef REAL_FATTR_CONST +    #define REAL_FATTR_CONST +  #endif + +  #ifndef REAL_FATTR_WARN_UNUSED_RESULT +    #define REAL_FATTR_WARN_UNUSED_RESULT +  #endif + +  #ifndef REAL_FATTR_ALWAYS_INLINE +    #define REAL_FATTR_ALWAYS_INLINE +  #endif + +  #ifndef REAL_FATTR_UNUSED +    #define REAL_FATTR_UNUSED +  #endif + +  #ifndef REAL_FATTR_NONNULL_ALL +    #define REAL_FATTR_NONNULL_ALL +  #endif + +  #ifndef REAL_FATTR_NONNULL_ARG +    #define REAL_FATTR_NONNULL_ARG(...) +  #endif + +  #ifndef REAL_FATTR_NONNULL_RET +    #define REAL_FATTR_NONNULL_RET +  #endif  #endif -#ifndef FUNC_ATTR_NONNULL_RET +#ifdef DEFINE_FUNC_ATTRIBUTES +  #define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC +  #define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x) +  #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) REAL_FATTR_ALLOC_SIZE_PROD(x,y) +  #define FUNC_ATTR_ALLOC_ALIGN(x) REAL_FATTR_ALLOC_ALIGN(x) +  #define FUNC_ATTR_PURE REAL_FATTR_PURE +  #define FUNC_ATTR_CONST REAL_FATTR_CONST +  #define FUNC_ATTR_WARN_UNUSED_RESULT REAL_FATTR_WARN_UNUSED_RESULT +  #define FUNC_ATTR_ALWAYS_INLINE REAL_FATTR_ALWAYS_INLINE +  #define FUNC_ATTR_UNUSED REAL_FATTR_UNUSED +  #define FUNC_ATTR_NONNULL_ALL REAL_FATTR_NONNULL_ALL +  #define FUNC_ATTR_NONNULL_ARG(...) REAL_FATTR_NONNULL_ARG(__VA_ARGS__) +  #define FUNC_ATTR_NONNULL_RET REAL_FATTR_NONNULL_RET +#elif !defined(DO_NOT_DEFINE_EMPTY_ATTRIBUTES) +  #define FUNC_ATTR_MALLOC +  #define FUNC_ATTR_ALLOC_SIZE(x) +  #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) +  #define FUNC_ATTR_ALLOC_ALIGN(x) +  #define FUNC_ATTR_PURE +  #define FUNC_ATTR_CONST +  #define FUNC_ATTR_WARN_UNUSED_RESULT +  #define FUNC_ATTR_ALWAYS_INLINE +  #define FUNC_ATTR_UNUSED +  #define FUNC_ATTR_NONNULL_ALL +  #define FUNC_ATTR_NONNULL_ARG(...)    #define FUNC_ATTR_NONNULL_RET  #endif - -#endif // NVIM_FUNC_ATTR_H diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 79dc2e5797..14c1b1a767 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -15,6 +15,10 @@  // #include "nvim/globals.h"  #include "nvim/memline.h" +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "garray.c.generated.h" +#endif +  /// Clear an allocated growing array.  void ga_clear(garray_T *gap)  { @@ -110,6 +114,7 @@ void ga_remove_duplicate_strings(garray_T *gap)  ///  /// @returns the concatenated strings  char_u *ga_concat_strings_sep(const garray_T *gap, const char *sep) +  FUNC_ATTR_NONNULL_RET  {    const size_t nelem = (size_t) gap->ga_len;    const char **strings = gap->ga_data; @@ -143,7 +148,7 @@ char_u *ga_concat_strings_sep(const garray_T *gap, const char *sep)  /// @param gap  ///  /// @returns the concatenated strings -char_u* ga_concat_strings(const garray_T *gap) +char_u* ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET  {    return ga_concat_strings_sep(gap, ",");  } @@ -177,7 +182,7 @@ void ga_append(garray_T *gap, char c)    gap->ga_len++;  } -#if defined(UNIX) || defined(WIN3264) +#if defined(UNIX) || defined(WIN3264) || defined(PROTO)  /// Append the text in "gap" below the cursor line and clear "gap".  /// diff --git a/src/nvim/garray.h b/src/nvim/garray.h index 2b54e56b2b..6e440039dd 100644 --- a/src/nvim/garray.h +++ b/src/nvim/garray.h @@ -1,8 +1,6 @@  #ifndef NVIM_GARRAY_H  #define NVIM_GARRAY_H -#include "nvim/func_attr.h" -  /// Structure used for growing arrays.  /// This is used to store information that only grows, is deleted all at  /// once, and needs to be accessed by index.  See ga_clear() and ga_grow(). @@ -18,16 +16,7 @@ typedef struct growarray {  #define GA_EMPTY(ga_ptr) ((ga_ptr)->ga_len <= 0) -void ga_clear(garray_T *gap); -void ga_clear_strings(garray_T *gap); -void ga_init(garray_T *gap, int itemsize, int growsize); -void ga_grow(garray_T *gap, int n); -char_u *ga_concat_strings_sep(const garray_T *gap, const char *sep) -  FUNC_ATTR_NONNULL_RET; -char_u *ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET; -void ga_remove_duplicate_strings(garray_T *gap); -void ga_concat(garray_T *gap, const char_u *restrict s); -void ga_append(garray_T *gap, char c); -void append_ga_line(garray_T *gap); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "garray.h.generated.h" +#endif  #endif  // NVIM_GARRAY_H diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 114182d462..c3ef6f0610 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -147,25 +147,9 @@ static char_u noremapbuf_init[TYPELEN_INIT];    /* initial typebuf.tb_noremap */  static int last_recorded_len = 0;       /* number of last recorded chars */ -static char_u *get_buffcont(buffheader_T *, int); -static void add_buff(buffheader_T *, char_u *, long n); -static void add_num_buff(buffheader_T *, long); -static void add_char_buff(buffheader_T *, int); -static int read_readbuffers(int advance); -static int read_readbuf(buffheader_T *buf, int advance); -static void start_stuff(void); -static int read_redo(int, int); -static void copy_redo(int); -static void init_typebuf(void); -static void gotchars(char_u *, int); -static void may_sync_undo(void); -static void closescript(void); -static int vgetorpeek(int); -static void map_free(mapblock_T **); -static void validate_maphash(void); -static void showmap(mapblock_T *mp, int local); -static char_u   *eval_map_expr(char_u *str, int c); -static bool is_user_input(int k); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "getchar.c.generated.h" +#endif  /*   * Free and clear a buffer. diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h index c34efc8d0c..802201c4e1 100644 --- a/src/nvim/getchar.h +++ b/src/nvim/getchar.h @@ -1,77 +1,7 @@  #ifndef NVIM_GETCHAR_H  #define NVIM_GETCHAR_H -/* getchar.c */ -void free_buff(buffheader_T *buf); -char_u *get_recorded(void); -char_u *get_inserted(void); -int stuff_empty(void); -int readbuf1_empty(void); -void typeahead_noflush(int c); -void flush_buffers(int flush_typeahead); -void ResetRedobuff(void); -void CancelRedo(void); -void saveRedobuff(void); -void restoreRedobuff(void); -void AppendToRedobuff(char_u *s); -void AppendToRedobuffLit(char_u *str, int len); -void AppendCharToRedobuff(int c); -void AppendNumberToRedobuff(long n); -void stuffReadbuff(char_u *s); -void stuffReadbuffLen(char_u *s, long len); -void stuffReadbuffSpec(char_u *s); -void stuffcharReadbuff(int c); -void stuffnumReadbuff(long n); -int start_redo(long count, int old_redo); -int start_redo_ins(void); -void stop_redo_ins(void); -int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, -                int silent); -void ins_char_typebuf(int c); -int typebuf_changed(int tb_change_cnt); -int typebuf_typed(void); -int typebuf_maplen(void); -void del_typebuf(int len, int offset); -void alloc_typebuf(void); -void free_typebuf(void); -void save_typebuf(void); -void save_typeahead(tasave_T *tp); -void restore_typeahead(tasave_T *tp); -void openscript(char_u *name, int directly); -void close_all_scripts(void); -int using_script(void); -void before_blocking(void); -void updatescript(int c); -int vgetc(void); -int safe_vgetc(void); -int plain_vgetc(void); -int vpeekc(void); -int vpeekc_nomap(void); -int vpeekc_any(void); -int char_avail(void); -void vungetc(int c); -int inchar(char_u *buf, int maxlen, long wait_time, int tb_change_cnt); -int fix_input_buffer(char_u *buf, int len, int script); -int input_available(void); -int do_map(int maptype, char_u *arg, int mode, int abbrev); -int get_map_mode(char_u **cmdp, int forceit); -void map_clear(char_u *cmdp, char_u *arg, int forceit, int abbr); -void map_clear_int(buf_T *buf, int mode, int local, int abbr); -char_u *map_mode_to_chars(int mode); -int map_to_exists(char_u *str, char_u *modechars, int abbr); -int map_to_exists_mode(char_u *rhs, int mode, int abbr); -char_u *set_context_in_map_cmd(expand_T *xp, char_u *cmd, char_u *arg, -                               int forceit, int isabbrev, int isunmap, -                               cmdidx_T cmdidx); -int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file); -int check_abbr(int c, char_u *ptr, int col, int mincol); -char_u *vim_strsave_escape_csi(char_u *p); -void vim_unescape_csi(char_u *p); -int makemap(FILE *fd, buf_T *buf); -int put_escstr(FILE *fd, char_u *strstart, int what); -void check_map_keycodes(void); -char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, -                  int abbr, mapblock_T **mp_ptr, -                  int *local_ptr); -void add_map(char_u *map, int mode); -#endif /* NVIM_GETCHAR_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "getchar.h.generated.h" +#endif +#endif  // NVIM_GETCHAR_H diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index dccc62d9a9..35cce64735 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -173,23 +173,79 @@ typedef struct {    int ff;                           /* seen form feed character */  } prt_pos_T; -static char_u *parse_list_options(char_u *option_str, -                                  option_table_T *table, -                                  int table_size); - -static long_u darken_rgb(long_u rgb); -static long_u prt_get_term_color(int colorindex); -static void prt_set_fg(long_u fg); -static void prt_set_bg(long_u bg); -static void prt_set_font(int bold, int italic, int underline); -static void prt_line_number(prt_settings_T *psettings, int page_line, -                            linenr_T lnum); -static void prt_header(prt_settings_T *psettings, int pagenum, -                       linenr_T lnum); -static void prt_message(char_u *s); -static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, -                             prt_pos_T *ppos); -static void prt_get_attr(int hl_id, prt_text_attr_T* pattr, int modec); +struct prt_mediasize_S { +  char        *name; +  float width;                  /* width and height in points for portrait */ +  float height; +}; + +/* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */ +struct prt_ps_font_S { +  int wx; +  int uline_offset; +  int uline_width; +  int bbox_min_y; +  int bbox_max_y; +  char        *(ps_fontname[4]); +}; + +/* Structures to map user named encoding and mapping to PS equivalents for + * building CID font name */ +struct prt_ps_encoding_S { +  char        *encoding; +  char        *cmap_encoding; +  int needs_charset; +}; + +struct prt_ps_charset_S { +  char        *charset; +  char        *cmap_charset; +  int has_charset; +}; + +/* Collections of encodings and charsets for multi-byte printing */ +struct prt_ps_mbfont_S { +  int num_encodings; +  struct prt_ps_encoding_S    *encodings; +  int num_charsets; +  struct prt_ps_charset_S     *charsets; +  char                        *ascii_enc; +  char                        *defcs; +}; + +struct prt_ps_resource_S { +  char_u name[64]; +  char_u filename[MAXPATHL + 1]; +  int type; +  char_u title[256]; +  char_u version[256]; +}; + +struct prt_dsc_comment_S { +  char        *string; +  int len; +  int type; +}; + +struct prt_dsc_line_S { +  int type; +  char_u      *string; +  int len; +}; + +/* Static buffer to read initial comments in a resource file, some can have a + * couple of KB of comments! */ +#define PRT_FILE_BUFFER_LEN (2048) +struct prt_resfile_buffer_S { +  char_u buffer[PRT_FILE_BUFFER_LEN]; +  int len; +  int line_start; +  int line_end; +}; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "hardcopy.c.generated.h" +#endif  /*   * Parse 'printoptions' and set the flags in "printer_opts". @@ -888,12 +944,6 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T  #define PRT_PS_DEFAULT_FONTSIZE     (10)  #define PRT_PS_DEFAULT_BUFFER_SIZE  (80) -struct prt_mediasize_S { -  char        *name; -  float width;                  /* width and height in points for portrait */ -  float height; -}; -  #define PRT_MEDIASIZE_LEN  (sizeof(prt_mediasize) / \                              sizeof(struct prt_mediasize_S)) @@ -915,16 +965,6 @@ static struct prt_mediasize_S prt_mediasize[] =    {"tabloid",         792.0, 1224.0}  }; -/* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */ -struct prt_ps_font_S { -  int wx; -  int uline_offset; -  int uline_width; -  int bbox_min_y; -  int bbox_max_y; -  char        *(ps_fontname[4]); -}; -  #define PRT_PS_FONT_ROMAN       (0)  #define PRT_PS_FONT_BOLD        (1)  #define PRT_PS_FONT_OBLIQUE     (2) @@ -951,20 +991,6 @@ static struct prt_ps_font_S prt_ps_mb_font =  /* Pointer to current font set being used */  static struct prt_ps_font_S* prt_ps_font; -/* Structures to map user named encoding and mapping to PS equivalents for - * building CID font name */ -struct prt_ps_encoding_S { -  char        *encoding; -  char        *cmap_encoding; -  int needs_charset; -}; - -struct prt_ps_charset_S { -  char        *charset; -  char        *cmap_charset; -  int has_charset; -}; -  #define CS_JIS_C_1978   (0x01)  #define CS_JIS_X_1983   (0x02) @@ -1103,16 +1129,6 @@ static struct prt_ps_charset_S k_charsets[] =    {"ISO10646",    "UniKS",    CS_KR_ISO10646}  }; -/* Collections of encodings and charsets for multi-byte printing */ -struct prt_ps_mbfont_S { -  int num_encodings; -  struct prt_ps_encoding_S    *encodings; -  int num_charsets; -  struct prt_ps_charset_S     *charsets; -  char                        *ascii_enc; -  char                        *defcs; -}; -  static struct prt_ps_mbfont_S prt_ps_mbfonts[] =  {    { @@ -1149,14 +1165,6 @@ static struct prt_ps_mbfont_S prt_ps_mbfonts[] =    }  }; -struct prt_ps_resource_S { -  char_u name[64]; -  char_u filename[MAXPATHL + 1]; -  int type; -  char_u title[256]; -  char_u version[256]; -}; -  /* Types of PS resource file currently used */  #define PRT_RESOURCE_TYPE_PROCSET   (0)  #define PRT_RESOURCE_TYPE_ENCODING  (1) @@ -1204,18 +1212,6 @@ static char *prt_resource_types[] =  #define PRT_DSC_VERSION             "%%Version:"  #define PRT_DSC_ENDCOMMENTS         "%%EndComments:" -struct prt_dsc_comment_S { -  char        *string; -  int len; -  int type; -}; - -struct prt_dsc_line_S { -  int type; -  char_u      *string; -  int len; -}; -  #define SIZEOF_CSTR(s)      (sizeof(s) - 1)  static struct prt_dsc_comment_S prt_dsc_table[] = @@ -1227,60 +1223,6 @@ static struct prt_dsc_comment_S prt_dsc_table[] =     PRT_DSC_ENDCOMMENTS_TYPE}  }; -static void prt_write_file_raw_len(char_u *buffer, int bytes); -static void prt_write_file(char_u *buffer); -static void prt_write_file_len(char_u *buffer, int bytes); -static void prt_write_string(char *s); -static void prt_write_int(int i); -static void prt_write_boolean(int b); -static void prt_def_font(char *new_name, char *encoding, int height, -                         char *font); -static void prt_real_bits(double real, int precision, int *pinteger, -                          int *pfraction); -static void prt_write_real(double val, int prec); -static void prt_def_var(char *name, double value, int prec); -static void prt_flush_buffer(void); -static void prt_resource_name(char_u *filename, void *cookie); -static int prt_find_resource(char *name, struct prt_ps_resource_S *resource); -static int prt_open_resource(struct prt_ps_resource_S *resource); -static int prt_check_resource(struct prt_ps_resource_S *resource, -                              char_u *version); -static void prt_dsc_start(void); -static void prt_dsc_noarg(char *comment); -static void prt_dsc_textline(char *comment, char *text); -static void prt_dsc_text(char *comment, char *text); -static void prt_dsc_ints(char *comment, int count, int *ints); -static void prt_dsc_requirements(int duplex, int tumble, int collate, -                                 int color, -                                 int num_copies); -static void prt_dsc_docmedia(char *paper_name, double width, -                             double height, double weight, char *colour, -                             char *type); -static void prt_dsc_resources(char *comment, char *type, char *strings); -static void prt_dsc_font_resource(char *resource, -                                  struct prt_ps_font_S *ps_font); -static float to_device_units(int idx, double physsize, int def_number); -static void prt_page_margins(double width, double height, double *left, -                             double *right, double *top, -                             double *bottom); -static void prt_font_metrics(int font_scale); -static int prt_get_cpl(void); -static int prt_get_lpp(void); -static int prt_add_resource(struct prt_ps_resource_S *resource); -static int prt_resfile_next_line(void); -static int prt_resfile_strncmp(int offset, char *string, int len); -static int prt_resfile_skip_nonws(int offset); -static int prt_resfile_skip_ws(int offset); -static int prt_next_dsc(struct prt_dsc_line_S *p_dsc_line); -static void prt_build_cid_fontname(int font, char_u *name, int name_len); -static void prt_def_cidfont(char *new_name, int height, char *cidfont); -static void prt_dup_cidfont(char *original_name, char *new_name); -static int prt_match_encoding(char *p_encoding, -                              struct prt_ps_mbfont_S *p_cmap, -                              struct prt_ps_encoding_S **pp_mbenc); -static int prt_match_charset(char *p_charset, -                             struct prt_ps_mbfont_S *p_cmap, -                             struct prt_ps_charset_S **pp_mbchar);  /*   * Variables for the output PostScript file. @@ -1615,16 +1557,6 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)  #define PSLF  (0x0a)  #define PSCR  (0x0d) -/* Static buffer to read initial comments in a resource file, some can have a - * couple of KB of comments! */ -#define PRT_FILE_BUFFER_LEN (2048) -struct prt_resfile_buffer_S { -  char_u buffer[PRT_FILE_BUFFER_LEN]; -  int len; -  int line_start; -  int line_end; -}; -  static struct prt_resfile_buffer_S prt_resfile;  static int prt_resfile_next_line(void) diff --git a/src/nvim/hardcopy.h b/src/nvim/hardcopy.h index 8824c9bd7e..fa171db989 100644 --- a/src/nvim/hardcopy.h +++ b/src/nvim/hardcopy.h @@ -70,24 +70,8 @@ typedef struct {  #define PRINT_NUMBER_WIDTH 8 -char_u *parse_printoptions(void); -char_u *parse_printmbfont(void); -int prt_header_height(void); -int prt_use_number(void); -int prt_get_unit(int idx); -void ex_hardcopy(exarg_T *eap); -void mch_print_cleanup(void); -int mch_print_init(prt_settings_T *psettings, char_u *jobname, -                   int forceit); -int mch_print_begin(prt_settings_T *psettings); -void mch_print_end(prt_settings_T *psettings); -int mch_print_end_page(void); -int mch_print_begin_page(char_u *str); -int mch_print_blank_page(void); -void mch_print_start_line(int margin, int page_line); -int mch_print_text_out(char_u *p, int len); -void mch_print_set_font(int iBold, int iItalic, int iUnderline); -void mch_print_set_bg(long_u bgcol); -void mch_print_set_fg(long_u fgcol); -#endif /* NVIM_HARDCOPY_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "hardcopy.h.generated.h" +#endif +#endif  // NVIM_HARDCOPY_H diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 4e4274bfa1..f8fd8f44af 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -30,7 +30,9 @@  // Magic value for algorithm that walks through the array.  #define PERTURB_SHIFT 5 -static int hash_may_resize(hashtab_T *ht, size_t minitems); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "hashtab.c.generated.h" +#endif  /// Initialize an empty hash table.  void hash_init(hashtab_T *ht) diff --git a/src/nvim/hashtab.h b/src/nvim/hashtab.h index bd64984ac8..c268175b01 100644 --- a/src/nvim/hashtab.h +++ b/src/nvim/hashtab.h @@ -66,18 +66,7 @@ typedef struct hashtable_S {    hashitem_T ht_smallarray[HT_INIT_SIZE];      /// initial array  } hashtab_T; -// hashtab.c -void hash_init(hashtab_T *ht); -void hash_clear(hashtab_T *ht); -void hash_clear_all(hashtab_T *ht, unsigned int off); -hashitem_T *hash_find(hashtab_T *ht, char_u *key); -hashitem_T *hash_lookup(hashtab_T *ht, char_u *key, hash_T hash); -void hash_debug_results(void); -int hash_add(hashtab_T *ht, char_u *key); -int hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash); -void hash_remove(hashtab_T *ht, hashitem_T *hi); -void hash_lock(hashtab_T *ht); -void hash_unlock(hashtab_T *ht); -hash_T hash_hash(char_u *key); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "hashtab.h.generated.h" +#endif  #endif  // NVIM_HASHTAB_H diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 7549e77223..0b3e06070c 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -33,45 +33,9 @@  #endif  #include "nvim/if_cscope_defs.h" -static void cs_usage_msg(csid_e x); -static int cs_add(exarg_T *eap); -static void cs_stat_emsg(char *fname); -static int cs_add_common(char *, char *, char *); -static int cs_check_for_connections(void); -static int cs_check_for_tags(void); -static int cs_cnt_connections(void); -static void cs_reading_emsg(int idx); -static int cs_cnt_matches(int idx); -static char *       cs_create_cmd(char *csoption, char *pattern); -static int cs_create_connection(int i); -static void do_cscope_general(exarg_T *eap, int make_split); -static void cs_file_results(FILE *, int *); -static void cs_fill_results(char *, int, int *, char ***, -                                    char ***, int *); -static int cs_find(exarg_T *eap); -static int cs_find_common(char *opt, char *pat, int, int, int, -                                  char_u *cmdline); -static int cs_help(exarg_T *eap); -static void clear_csinfo(int i); -static int cs_insert_filelist(char *, char *, char *, FileInfo *file_info); -static int cs_kill(exarg_T *eap); -static void cs_kill_execute(int, char *); -static cscmd_T *    cs_lookup_cmd(exarg_T *eap); -static char *       cs_make_vim_style_matches(char *, char *, -                                              char *, char *); -static char *       cs_manage_matches(char **, char **, int, mcmd_e); -static char *       cs_parse_results(int cnumber, char *buf, -                                     int bufsize, char **context, -                                     char **linenumber, -                                     char **search); -static char *       cs_pathcomponents(char *path); -static void cs_print_tags_priv(char **, char **, int); -static int cs_read_prompt(int); -static void cs_release_csp(int, int freefnpp); -static int cs_reset(exarg_T *eap); -static char *       cs_resolve_file(int, char *); -static int cs_show(exarg_T *eap); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "if_cscope.c.generated.h" +#endif  static csinfo_T *   csinfo = NULL;  static int csinfo_size = 0;             /* number of items allocated in @@ -1189,8 +1153,6 @@ static void clear_csinfo(int i)  }  #ifndef UNIX -static char *GetWin32Error(void); -  static char *GetWin32Error(void)  {    char *msg = NULL; @@ -1204,7 +1166,6 @@ static char *GetWin32Error(void)    }    return msg;  } -  #endif  /* @@ -1275,8 +1236,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,   *   * find cscope command in command table   */ -static cscmd_T * cs_lookup_cmd(eap) -exarg_T *eap; +static cscmd_T * cs_lookup_cmd(exarg_T *eap)  {    cscmd_T *cmdp;    char *stok; diff --git a/src/nvim/if_cscope.h b/src/nvim/if_cscope.h index 32824a7e3d..351d9caef6 100644 --- a/src/nvim/if_cscope.h +++ b/src/nvim/if_cscope.h @@ -1,16 +1,7 @@  #ifndef NVIM_IF_CSCOPE_H  #define NVIM_IF_CSCOPE_H -/* if_cscope.c */ -char_u *get_cscope_name(expand_T *xp, int idx); -void set_context_in_cscope_cmd(expand_T *xp, char_u *arg, -                               cmdidx_T cmdidx); -void do_cscope(exarg_T *eap); -void do_scscope(exarg_T *eap); -void do_cstag(exarg_T *eap); -int cs_fgets(char_u *buf, int size); -void cs_free_tags(void); -void cs_print_tags(void); -int cs_connection(int num, char_u *dbpath, char_u *ppath); -void cs_end(void); -#endif /* NVIM_IF_CSCOPE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "if_cscope.h.generated.h" +#endif +#endif  // NVIM_IF_CSCOPE_H diff --git a/src/nvim/indent.c b/src/nvim/indent.c index fcdc71e636..91fc1588cc 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -12,8 +12,10 @@  #include "nvim/strings.h"  #include "nvim/undo.h" -static int lisp_match(char_u *p); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "indent.c.generated.h" +#endif  // Count the size (in window cells) of the indent in the current line.  int get_indent(void) diff --git a/src/nvim/indent.h b/src/nvim/indent.h index c6fcba391f..26773a62d8 100644 --- a/src/nvim/indent.h +++ b/src/nvim/indent.h @@ -1,14 +1,9 @@  #ifndef NVIM_INDENT_H  #define NVIM_INDENT_H +  #include "nvim/vim.h" -int get_indent(void); -int get_indent_lnum(linenr_T lnum); -int get_indent_buf(buf_T *buf, linenr_T lnum); -int get_indent_str(char_u *ptr, int ts); -int set_indent(int size, int flags); -int copy_indent(int size, char_u *src); -int get_number_indent(linenr_T lnum); -int inindent(int extra); -int get_expr_indent(void); -int get_lisp_indent(void); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "indent.h.generated.h" +#endif  #endif  // NVIM_INDENT_H diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 631ef06d01..aeac5e0b8b 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -13,9 +13,10 @@  #include "nvim/strings.h" -static char_u   *skip_string(char_u *p); -static pos_T *ind_find_start_comment(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "indent_c.c.generated.h" +#endif  /*   * Find the start of a comment, not knowing if we are in a comment right now.   * Search starts at w_cursor.lnum and goes backwards. @@ -109,7 +110,6 @@ static char_u *skip_string(char_u *p)   * Below "XXX" means that this function may unlock the current line.   */ -int cin_is_cinword(char_u *line);  /*   * Return TRUE if the string "line" starts with a word from 'cinwords'. @@ -139,41 +139,6 @@ int cin_is_cinword(char_u *line)  } -static char_u   *cin_skipcomment(char_u *); -static int cin_nocode(char_u *); -static pos_T    *find_line_comment(void); -static int cin_islabel_skip(char_u **); -static int cin_isdefault(char_u *); -static char_u   *after_label(char_u *l); -static int get_indent_nolabel(linenr_T lnum); -static int skip_label(linenr_T, char_u **pp); -static int cin_first_id_amount(void); -static int cin_get_equal_amount(linenr_T lnum); -static int cin_ispreproc(char_u *); -static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump); -static int cin_iscomment(char_u *); -static int cin_islinecomment(char_u *); -static int cin_isterminated(char_u *, int, int); -static int cin_isinit(void); -static int cin_isfuncdecl(char_u **, linenr_T, linenr_T); -static int cin_isif(char_u *); -static int cin_iselse(char_u *); -static int cin_isdo(char_u *); -static int cin_iswhileofdo(char_u *, linenr_T); -static int cin_is_if_for_while_before_offset(char_u *line, int *poffset); -static int cin_iswhileofdo_end(int terminated); -static int cin_isbreak(char_u *); -static int cin_is_cpp_baseclass(colnr_T *col); -static int get_baseclass_amount(int col); -static int cin_ends_in(char_u *, char_u *, char_u *); -static int cin_starts_with(char_u *s, char *word); -static int cin_skip2pos(pos_T *trypos); -static pos_T    *find_start_brace(void); -static pos_T    *find_match_paren(int); -static int corr_ind_maxparen(pos_T *startpos); -static int find_last_paren(char_u *l, int start, int end); -static int find_match(int lookfor, linenr_T ourscope); -static int cin_is_cpp_namespace(char_u *);  /*   * Skip over white space and C comments within the line. diff --git a/src/nvim/indent_c.h b/src/nvim/indent_c.h index 4639bfe242..bd6eeed67d 100644 --- a/src/nvim/indent_c.h +++ b/src/nvim/indent_c.h @@ -1,12 +1,9 @@  #ifndef NVIM_INDENT_C_H  #define NVIM_INDENT_C_H +  #include "nvim/vim.h" -int cin_islabel(void); -int cin_iscase(char_u *s, int strict); -int cin_isscopedecl(char_u *s); -int cin_is_cinword(char_u *line); -int get_c_indent(void); -void do_c_expr_indent(void); -void parse_cino(buf_T *buf); -pos_T * find_start_comment(int ind_maxcomment); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "indent_c.h.generated.h"  #endif +#endif  // NVIM_INDENT_C_H diff --git a/src/nvim/keymap.h b/src/nvim/keymap.h index 7921b07904..490efdd7d9 100644 --- a/src/nvim/keymap.h +++ b/src/nvim/keymap.h @@ -498,18 +498,8 @@ enum key_extra {   */  #define MAX_KEY_CODE_LEN    6 -int name_to_mod_mask(int c); -int simplify_key(int key, int *modifiers); -int handle_x_keys(int key); -char_u *get_special_key_name(int c, int modifiers); -int trans_special(char_u **srcp, char_u *dst, int keycode); -int find_special_key(char_u **srcp, int *modp, int keycode, -                     int keep_x_key); -int extract_modifiers(int key, int *modp); -int find_special_key_in_table(int c); -int get_special_key_code(char_u *name); -char_u *get_key_name(int i); -int get_mouse_button(int code, int *is_click, int *is_drag); -int get_pseudo_mouse_code(int button, int is_click, int is_drag); - -#endif /* NVIM_KEYMAP_H */ + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "keymap.h.generated.h" +#endif +#endif  // NVIM_KEYMAP_H diff --git a/src/nvim/lib/khash.h b/src/nvim/lib/khash.h index 51a666733b..f706e994d5 100644 --- a/src/nvim/lib/khash.h +++ b/src/nvim/lib/khash.h @@ -129,9 +129,10 @@ int main() {  #include <string.h>  #include <limits.h> -#include "nvim/func_attr.h"  #include "nvim/memory.h" +#include "nvim/func_attr.h" +  /* compiler specific configuration */  #if UINT_MAX == 0xffffffffu @@ -206,7 +207,7 @@ static const double __ac_HASH_UPPER = 0.77;  		return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t));		\  	}																	\  	SCOPE void kh_destroy_##name(kh_##name##_t *h)						\ -		FUNC_ATTR_UNUSED;                                     \ +		REAL_FATTR_UNUSED;                                      \  	SCOPE void kh_destroy_##name(kh_##name##_t *h)						\  	{																	\  		if (h) {														\ @@ -216,7 +217,7 @@ static const double __ac_HASH_UPPER = 0.77;  		}																\  	}																	\  	SCOPE void kh_clear_##name(kh_##name##_t *h)						\ -		FUNC_ATTR_UNUSED;                                     \ +		REAL_FATTR_UNUSED;                                    \  	SCOPE void kh_clear_##name(kh_##name##_t *h)						\  	{																	\  		if (h && h->flags) {											\ @@ -225,7 +226,7 @@ static const double __ac_HASH_UPPER = 0.77;  		}																\  	}																	\  	SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) 	\ -		FUNC_ATTR_UNUSED;                                     \ +		REAL_FATTR_UNUSED;                                    \  	SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) 	\  	{																	\  		if (h->n_buckets) {												\ @@ -241,7 +242,7 @@ static const double __ac_HASH_UPPER = 0.77;  		} else return 0;												\  	}																	\  	SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ -		FUNC_ATTR_UNUSED;                                     \ +		REAL_FATTR_UNUSED;                                    \  	SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \  	{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \  		khint32_t *new_flags = 0;										\ @@ -302,7 +303,7 @@ static const double __ac_HASH_UPPER = 0.77;  		}																\  	}																	\  	SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \ -		FUNC_ATTR_UNUSED;                                     \ +		REAL_FATTR_UNUSED;                                    \  	SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \  	{																	\  		khint_t x;														\ @@ -344,7 +345,7 @@ static const double __ac_HASH_UPPER = 0.77;  		return x;														\  	}																	\  	SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x)				\ -		FUNC_ATTR_UNUSED;                                     \ +		REAL_FATTR_UNUSED;                                    \  	SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x)				\  	{																	\  		if (x != h->n_buckets && !__ac_iseither(h->flags, x)) {			\ @@ -622,5 +623,4 @@ typedef const char *kh_cstr_t;   */  #define KHASH_MAP_INIT_STR(name, khval_t)								\  	KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) -  #endif /* __AC_KHASH_H */ diff --git a/src/nvim/lib/klist.h b/src/nvim/lib/klist.h index 07fd872e1a..4cc87263a4 100644 --- a/src/nvim/lib/klist.h +++ b/src/nvim/lib/klist.h @@ -29,8 +29,8 @@  #include <stdbool.h>  #include <stdlib.h> -#include "nvim/func_attr.h"  #include "nvim/memory.h" +#include "nvim/func_attr.h"  #define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f)                       \      typedef struct {                                                    \ @@ -56,7 +56,7 @@          --mp->cnt;                                                      \          if (mp->n == mp->max) {                                         \              mp->max = mp->max? mp->max<<1 : 16;                         \ -            mp->buf = xrealloc(mp->buf, sizeof(kmptype_t *) * mp->max);       \ +            mp->buf = xrealloc(mp->buf, sizeof(kmptype_t *) * mp->max); \          }                                                               \          mp->buf[mp->n++] = p;                                           \      } @@ -79,7 +79,7 @@          kmp_##name##_t *mp;                                             \          size_t size;                                                    \      } kl_##name##_t;                                                    \ -    static inline kl_##name##_t *kl_init_##name(void) {                     \ +    static inline kl_##name##_t *kl_init_##name(void) {                 \          kl_##name##_t *kl = xcalloc(1, sizeof(kl_##name##_t));          \          kl->mp = kmp_init(name);                                        \          kl->head = kl->tail = kmp_alloc(name, kl->mp);                  \ @@ -87,7 +87,7 @@          return kl;                                                      \      }                                                                   \      static inline void kl_destroy_##name(kl_##name##_t *kl)             \ -        FUNC_ATTR_UNUSED;                                               \ +        REAL_FATTR_UNUSED;                                              \      static inline void kl_destroy_##name(kl_##name##_t *kl) {           \          kl1_##name *p;                                                  \          for (p = kl->head; p != kl->tail; p = p->next)                  \ @@ -124,5 +124,4 @@  #define kl_pushp(name, kl) kl_pushp_##name(kl)  #define kl_shift(name, kl, d) kl_shift_##name(kl, d)  #define kl_empty(kl) ((kl)->size == 0) -  #endif diff --git a/src/nvim/log.c b/src/nvim/log.c index a187cc4755..da28a18509 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -16,16 +16,12 @@  #define USR_LOG_FILE "$HOME/.nvimlog" -static FILE *open_log_file(void); -static bool do_log_to_file(FILE *log_file, int log_level, -                           const char *func_name, int line_num, -                           const char* fmt, ...); -static bool v_do_log_to_file(FILE *log_file, int log_level, -                             const char *func_name, int line_num, -                             const char* fmt, va_list args); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "log.c.generated.h" +#endif  bool do_log(int log_level, const char *func_name, int line_num, -            const char* fmt, ...) +            const char* fmt, ...) FUNC_ATTR_UNUSED  {    FILE *log_file = open_log_file(); diff --git a/src/nvim/log.h b/src/nvim/log.h index 4177a0a3d5..6d97304af4 100644 --- a/src/nvim/log.h +++ b/src/nvim/log.h @@ -3,16 +3,11 @@  #include <stdbool.h> -#include "nvim/func_attr.h" -  #define DEBUG_LOG_LEVEL 0  #define INFO_LOG_LEVEL 1  #define WARNING_LOG_LEVEL 2  #define ERROR_LOG_LEVEL 3 -bool do_log(int log_level, const char *func_name, int line_num, -            const char* fmt, ...) FUNC_ATTR_UNUSED; -  #define DLOG(...)  #define ILOG(...)  #define WLOG(...) @@ -53,5 +48,7 @@ bool do_log(int log_level, const char *func_name, int line_num,  #endif +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "log.h.generated.h" +#endif  #endif  // NVIM_LOG_H - diff --git a/src/nvim/main.c b/src/nvim/main.c index d992619287..7b567be564 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -98,40 +98,14 @@ typedef struct {  #define EDIT_TAG    3       /* tag name argument given, use tagname */  #define EDIT_QF     4       /* start in quickfix mode */ -#if defined(UNIX) && !defined(NO_VIM_MAIN) -static int file_owned(char *fname); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "main.c.generated.h"  #endif -static void mainerr(int, char_u *);  #ifndef NO_VIM_MAIN -static void main_msg(char *s); -static void usage(void); -static int get_number_arg(char_u *p, int *idx, int def);  # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)  static void init_locale(void);  # endif -static void parse_command_name(mparm_T *parmp); -static bool parse_char_i(char_u **input, char val); -static bool parse_string(char_u **input, char* val, int len); -static void command_line_scan(mparm_T *parmp); -static void init_params(mparm_T *parmp, int argc, char **argv); -static void init_startuptime(mparm_T *parmp); -static void allocate_generic_buffers(void); -static void check_and_set_isatty(mparm_T *parmp); -static char_u* get_fname(mparm_T *parmp); -static void set_window_layout(mparm_T *parmp); -static void load_plugins(void); -static void handle_quickfix(mparm_T *parmp); -static void handle_tag(char_u *tagname); -static void check_tty(mparm_T *parmp); -static void read_stdin(void); -static void create_windows(mparm_T *parmp); -static void edit_buffers(mparm_T *parmp); -static void exe_pre_commands(mparm_T *parmp); -static void exe_commands(mparm_T *parmp); -static void source_startup_scripts(mparm_T *parmp); -static void main_start_gui(void);  # if defined(HAS_SWAP_EXISTS_ACTION) -static void check_swap_exists_action(void);  # endif  #endif /* NO_VIM_MAIN */ @@ -158,7 +132,7 @@ static char *(main_errors[]) =  };  #ifndef NO_VIM_MAIN     /* skip this for unittests */ -  int main(int argc, char **argv) +int main(int argc, char **argv)  {    char_u      *fname = NULL;            /* file name from command line */    mparm_T params;                       /* various parameters passed between @@ -971,10 +945,7 @@ static bool parse_char_i(char_u **input, char val)    return false;  } -static bool parse_string(input, val, len) -  char_u      **input; -  char        *val; -  int len; +static bool parse_string(char_u **input, char *val, int len)  {    if (STRNICMP(*input, val, len) == 0) {      *input += len; @@ -2273,7 +2244,6 @@ static void check_swap_exists_action(void)  #endif  #if defined(STARTUPTIME) || defined(PROTO) -static void time_diff(struct timeval *then, struct timeval *now);  static struct timeval prev_timeval; diff --git a/src/nvim/main.h b/src/nvim/main.h index 92e0fcbc9a..084e247b7e 100644 --- a/src/nvim/main.h +++ b/src/nvim/main.h @@ -3,14 +3,7 @@  #include "nvim/normal.h" -void main_loop(int cmdwin, int noexmode); -void getout(int exitval); -int process_env(char_u *env, int is_viminit); -void mainerr_arg_missing(char_u *str); -void time_push(void *tv_rel, void *tv_start); -void time_pop(void *tp); -void time_msg(char *mesg, void *tv_start); -char_u *eval_client_expr_to_string(char_u *expr); -char_u *serverConvert(char_u *client_enc, char_u *data, char_u **tofree); - -#endif /* NVIM_MAIN_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "main.h.generated.h" +#endif +#endif  // NVIM_MAIN_H diff --git a/src/nvim/map.h b/src/nvim/map.h index 9fb23f8386..61f56821b8 100644 --- a/src/nvim/map.h +++ b/src/nvim/map.h @@ -44,4 +44,3 @@ MAP_DECLS(uint64_t, ptr_t)    kh_foreach_value(map->table, value, block)  #endif  // NVIM_MAP_H - diff --git a/src/nvim/map_defs.h b/src/nvim/map_defs.h index 38dc6d2a73..d5a302362f 100644 --- a/src/nvim/map_defs.h +++ b/src/nvim/map_defs.h @@ -1,7 +1,6 @@  #ifndef NVIM_MAP_DEFS_H  #define NVIM_MAP_DEFS_H -  #include "nvim/lib/khash.h"  typedef const char * cstr_t; @@ -11,4 +10,3 @@ typedef void * ptr_t;  #define PMap(T) Map(T, ptr_t)  #endif  // NVIM_MAP_DEFS_H - diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 23e7355e9c..068c26958a 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -51,13 +51,10 @@  #define EXTRA_MARKS 10                                  /* marks 0-9 */  static xfmark_T namedfm[NMARKS + EXTRA_MARKS];          /* marks with file nr */ -static void fname2fnum(xfmark_T *fm); -static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf); -static char_u *mark_line(pos_T *mp, int lead_len); -static void show_one_mark(int, char_u *, pos_T *, char_u *, int current); -static void cleanup_jumplist(void); -static void write_one_filemark(FILE *fp, xfmark_T *fm, int c1, int c2); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "mark.c.generated.h" +#endif  /*   * Set named mark "c" at current cursor position.   * Returns OK on success, FAIL if bad name given. @@ -1328,7 +1325,6 @@ int removable(char_u *name)    return retval;  } -static void write_one_mark(FILE *fp_out, int c, pos_T *pos);  /*   * Write all the named marks for all buffers. diff --git a/src/nvim/mark.h b/src/nvim/mark.h index 1fcbb0304c..aa89a5b625 100644 --- a/src/nvim/mark.h +++ b/src/nvim/mark.h @@ -5,38 +5,7 @@  #include "nvim/mark_defs.h"  #include "nvim/pos.h" -/* mark.c */ -int setmark(int c); -int setmark_pos(int c, pos_T *pos, int fnum); -void setpcmark(void); -void checkpcmark(void); -pos_T *movemark(int count); -pos_T *movechangelist(int count); -pos_T *getmark_buf(buf_T *buf, int c, int changefile); -pos_T *getmark(int c, int changefile); -pos_T *getmark_buf_fnum(buf_T *buf, int c, int changefile, int *fnum); -pos_T *getnextmark(pos_T *startpos, int dir, int begin_line); -void fmarks_check_names(buf_T *buf); -int check_mark(pos_T *pos); -void clrallmarks(buf_T *buf); -char_u *fm_getname(fmark_T *fmark, int lead_len); -void do_marks(exarg_T *eap); -void ex_delmarks(exarg_T *eap); -void ex_jumps(exarg_T *eap); -void ex_changes(exarg_T *eap); -void mark_adjust(linenr_T line1, linenr_T line2, long amount, -                 long amount_after); -void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, -                     long col_amount); -void copy_jumplist(win_T *from, win_T *to); -void free_jumplist(win_T *wp); -void set_last_cursor(win_T *win); -void free_all_marks(void); -int read_viminfo_filemark(vir_T *virp, int force); -void write_viminfo_filemarks(FILE *fp); -int removable(char_u *name); -int write_viminfo_marks(FILE *fp_out); -void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, -                        int flags); - -#endif /* NVIM_MARK_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "mark.h.generated.h" +#endif +#endif  // NVIM_MARK_H diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index ec1997657b..fd929cd0ae 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -95,19 +95,25 @@  #include "nvim/strings.h"  #include "nvim/ui.h"  #include "nvim/os/os.h" +#include "nvim/arabic.h"  # define WINBYTE BYTE -static int enc_canon_search(char_u *name); -static int dbcs_char2len(int c); -static int dbcs_char2bytes(int c, char_u *buf); -static int dbcs_ptr2len(char_u *p); -static int dbcs_ptr2len_len(char_u *p, int size); -static int utf_ptr2cells_len(char_u *p, int size); -static int dbcs_char2cells(int c); -static int dbcs_ptr2cells_len(char_u *p, int size); -static int dbcs_ptr2char(char_u *p); -static int utf_safe_read_char_adv(char_u **s, size_t *n); +typedef struct { +  int rangeStart; +  int rangeEnd; +  int step; +  int offset; +} convertStruct; + +struct interval { +  long first; +  long last; +}; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "mbyte.c.generated.h" +#endif  /*   * Lookup table to quickly get the length in bytes of a UTF-8 character from @@ -909,12 +915,6 @@ static int dbcs_ptr2len_len(char_u *p, int size)    return len;  } -struct interval { -  long first; -  long last; -}; -static int intable(struct interval *table, size_t size, int c); -  /*   * Return TRUE if "c" is in "table[size / sizeof(struct interval)]".   */ @@ -2170,12 +2170,6 @@ int utf_class(int c)   * range from 0x41 to 0x5a inclusive, stepping by 1, are changed to   * folded/upper/lower by adding 32.   */ -typedef struct { -  int rangeStart; -  int rangeEnd; -  int step; -  int offset; -} convertStruct;  static convertStruct foldCase[] =  { @@ -2337,8 +2331,6 @@ static convertStruct foldCase[] =    {0x10400,0x10427,1,40}  }; -static int utf_convert(int a, convertStruct table[], int tableSize); -static int utf_strnicmp(char_u *s1, char_u *s2, size_t n1, size_t n2);  /*   * Generic conversion function for case operations. @@ -3299,7 +3291,6 @@ int mb_fix_col(int col, int row)    return col;  } -static int enc_alias_search(char_u *name);  /*   * Skip the Vim specific head of a 'encoding' name. @@ -3457,9 +3448,6 @@ char_u * enc_locale()  # if defined(USE_ICONV) || defined(PROTO) -static char_u * -iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, -             int *resultlenp);  /*   * Call iconv_open() with a check if iconv() works properly (there are broken @@ -3734,10 +3722,7 @@ void iconv_end()   * Afterwards invoke with "from" and "to" equal to NULL to cleanup.   * Return FAIL when conversion is not supported, OK otherwise.   */ -int convert_setup(vcp, from, to) -  vimconv_T   *vcp; -  char_u      *from; -  char_u      *to; +int convert_setup(vimconv_T *vcp, char_u *from, char_u *to)  {    return convert_setup_ext(vcp, from, TRUE, to, TRUE);  } @@ -3746,12 +3731,8 @@ int convert_setup(vcp, from, to)   * As convert_setup(), but only when from_unicode_is_utf8 is TRUE will all   * "from" unicode charsets be considered utf-8.  Same for "to".   */ -int convert_setup_ext(vcp, from, from_unicode_is_utf8, to, to_unicode_is_utf8) -  vimconv_T   *vcp; -  char_u      *from; -  int from_unicode_is_utf8; -  char_u      *to; -  int to_unicode_is_utf8; +int convert_setup_ext(vimconv_T *vcp, char_u *from, int from_unicode_is_utf8, +                      char_u *to, int to_unicode_is_utf8)  {    int from_prop;    int to_prop; @@ -3822,10 +3803,7 @@ int convert_setup_ext(vcp, from, from_unicode_is_utf8, to, to_unicode_is_utf8)   * The input and output are not NUL terminated!   * Returns the length after conversion.   */ -int convert_input(ptr, len, maxlen) -  char_u      *ptr; -  int len; -  int maxlen; +int convert_input(char_u *ptr, int len, int maxlen)  {    return convert_input_safe(ptr, len, maxlen, NULL, NULL);  } @@ -3836,12 +3814,8 @@ int convert_input(ptr, len, maxlen)   * end return that as an allocated string in "restp" and set "*restlenp" to   * the length.  If "restp" is NULL it is not used.   */ -int convert_input_safe(ptr, len, maxlen, restp, restlenp) -  char_u      *ptr; -  int len; -  int maxlen; -  char_u      **restp; -  int         *restlenp; +int convert_input_safe(char_u *ptr, int len, int maxlen, char_u **restp, +                       int *restlenp)  {    char_u      *d;    int dlen = len; @@ -3874,10 +3848,7 @@ int convert_input_safe(ptr, len, maxlen, restp, restlenp)   * Illegal chars are often changed to "?", unless vcp->vc_fail is set.   * When something goes wrong, NULL is returned and "*lenp" is unchanged.   */ -char_u * string_convert(vcp, ptr, lenp) -  vimconv_T   *vcp; -  char_u      *ptr; -  int         *lenp; +char_u * string_convert(vimconv_T *vcp, char_u *ptr, int *lenp)  {    return string_convert_ext(vcp, ptr, lenp, NULL);  } @@ -3887,11 +3858,8 @@ char_u * string_convert(vcp, ptr, lenp)   * an incomplete sequence at the end it is not converted and "*unconvlenp" is   * set to the number of remaining bytes.   */ -char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp) -  vimconv_T   *vcp; -  char_u      *ptr; -  int         *lenp; -  int         *unconvlenp; +char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, +                            int *unconvlenp)  {    char_u      *retval = NULL;    char_u      *d; diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index aad0eba401..7bfc5454e1 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -1,87 +1,7 @@  #ifndef NVIM_MBYTE_H  #define NVIM_MBYTE_H -/* mbyte.c */ -int enc_canon_props(char_u *name); -char_u *mb_init(void); -int bomb_size(void); -void remove_bom(char_u *s); -int mb_get_class(char_u *p); -int mb_get_class_buf(char_u *p, buf_T *buf); -int dbcs_class(unsigned lead, unsigned trail); -int latin_char2len(int c); -int latin_char2bytes(int c, char_u *buf); -int latin_ptr2len(char_u *p); -int latin_ptr2len_len(char_u *p, int size); -int utf_char2cells(int c); -int latin_ptr2cells(char_u *p); -int utf_ptr2cells(char_u *p); -int dbcs_ptr2cells(char_u *p); -int latin_ptr2cells_len(char_u *p, int size); -int latin_char2cells(int c); -int mb_string2cells(char_u *p, int len); -int latin_off2cells(unsigned off, unsigned max_off); -int dbcs_off2cells(unsigned off, unsigned max_off); -int utf_off2cells(unsigned off, unsigned max_off); -int latin_ptr2char(char_u *p); -int utf_ptr2char(char_u *p); -int mb_ptr2char_adv(char_u **pp); -int mb_cptr2char_adv(char_u **pp); -int arabic_combine(int one, int two); -int arabic_maycombine(int two); -int utf_composinglike(char_u *p1, char_u *p2); -int utfc_ptr2char(char_u *p, int *pcc); -int utfc_ptr2char_len(char_u *p, int *pcc, int maxlen); -int utfc_char2bytes(int off, char_u *buf); -int utf_ptr2len(char_u *p); -int utf_byte2len(int b); -int utf_ptr2len_len(char_u *p, int size); -int utfc_ptr2len(char_u *p); -int utfc_ptr2len_len(char_u *p, int size); -int utf_char2len(int c); -int utf_char2bytes(int c, char_u *buf); -int utf_iscomposing(int c); -int utf_printable(int c); -int utf_class(int c); -int utf_fold(int a); -int utf_toupper(int a); -int utf_islower(int a); -int utf_tolower(int a); -int utf_isupper(int a); -int mb_strnicmp(char_u *s1, char_u *s2, size_t nn); -void show_utf8(void); -int latin_head_off(char_u *base, char_u *p); -int dbcs_head_off(char_u *base, char_u *p); -int dbcs_screen_head_off(char_u *base, char_u *p); -int utf_head_off(char_u *base, char_u *p); -void mb_copy_char(char_u **fp, char_u **tp); -int mb_off_next(char_u *base, char_u *p); -int mb_tail_off(char_u *base, char_u *p); -void utf_find_illegal(void); -void mb_adjust_cursor(void); -void mb_adjustpos(buf_T *buf, pos_T *lp); -char_u *mb_prevptr(char_u *line, char_u *p); -int mb_charlen(char_u *str); -int mb_charlen_len(char_u *str, int len); -char_u *mb_unescape(char_u **pp); -int mb_lefthalve(int row, int col); -int mb_fix_col(int col, int row); -char_u *enc_skip(char_u *p); -char_u *enc_canonize(char_u *enc); -char_u *enc_locale(void); -void *my_iconv_open(char_u *to, char_u *from); -int iconv_enabled(int verbose); -void iconv_end(void); -void im_set_active(int active); -int im_get_status(void); -int convert_setup(vimconv_T *vcp, char_u *from, char_u *to); -int convert_setup_ext(vimconv_T *vcp, char_u *from, -                      int from_unicode_is_utf8, char_u *to, -                      int to_unicode_is_utf8); -int convert_input(char_u *ptr, int len, int maxlen); -int convert_input_safe(char_u *ptr, int len, int maxlen, char_u **restp, -                       int *restlenp); -char_u *string_convert(vimconv_T *vcp, char_u *ptr, int *lenp); -char_u *string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, -                           int *unconvlenp); -#endif /* NVIM_MBYTE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "mbyte.h.generated.h" +#endif +#endif  // NVIM_MBYTE_H diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index f6bd8d7983..c681d0d43c 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -50,30 +50,10 @@  static long_u total_mem_used = 0;       /* total memory used for memfiles */ -static void mf_ins_hash(memfile_T *, bhdr_T *); -static void mf_rem_hash(memfile_T *, bhdr_T *); -static bhdr_T *mf_find_hash(memfile_T *, blocknr_T); -static void mf_ins_used(memfile_T *, bhdr_T *); -static void mf_rem_used(memfile_T *, bhdr_T *); -static bhdr_T *mf_release(memfile_T *, int); -static bhdr_T *mf_alloc_bhdr(memfile_T *, int); -static void mf_free_bhdr(bhdr_T *); -static void mf_ins_free(memfile_T *, bhdr_T *); -static bhdr_T *mf_rem_free(memfile_T *); -static int mf_read(memfile_T *, bhdr_T *); -static int mf_write(memfile_T *, bhdr_T *); -static int mf_write_block(memfile_T *mfp, bhdr_T *hp, off_t offset, -                          unsigned size); -static int mf_trans_add(memfile_T *, bhdr_T *); -static void mf_do_open(memfile_T *, char_u *, int); -static void mf_hash_init(mf_hashtab_T *); -static void mf_hash_free(mf_hashtab_T *); -static void mf_hash_free_all(mf_hashtab_T *); -static mf_hashitem_T *mf_hash_find(mf_hashtab_T *, blocknr_T); -static void mf_hash_add_item(mf_hashtab_T *, mf_hashitem_T *); -static void mf_hash_rem_item(mf_hashtab_T *, mf_hashitem_T *); -static void mf_hash_grow(mf_hashtab_T *); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memfile.c.generated.h" +#endif  /*   * The functions for using a memfile:   * diff --git a/src/nvim/memfile.h b/src/nvim/memfile.h index 5f21bdaf4f..94722171d7 100644 --- a/src/nvim/memfile.h +++ b/src/nvim/memfile.h @@ -4,22 +4,7 @@  #include "nvim/buffer_defs.h"  #include "nvim/memfile_defs.h" -/* memfile.c */ -memfile_T *mf_open(char_u *fname, int flags); -int mf_open_file(memfile_T *mfp, char_u *fname); -void mf_close(memfile_T *mfp, int del_file); -void mf_close_file(buf_T *buf, int getlines); -void mf_new_page_size(memfile_T *mfp, unsigned new_size); -bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count); -bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, int page_count); -void mf_put(memfile_T *mfp, bhdr_T *hp, int dirty, int infile); -void mf_free(memfile_T *mfp, bhdr_T *hp); -int mf_sync(memfile_T *mfp, int flags); -void mf_set_dirty(memfile_T *mfp); -int mf_release_all(void); -blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr); -void mf_set_ffname(memfile_T *mfp); -void mf_fullname(memfile_T *mfp); -int mf_need_trans(memfile_T *mfp); - -#endif /* NVIM_MEMFILE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memfile.h.generated.h" +#endif +#endif  // NVIM_MEMFILE_H diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 2526f9d98b..19c3cfe994 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -236,32 +236,9 @@ typedef enum {    , UB_SAME_DIR         /* update the B0_SAME_DIR flag */  } upd_block0_T; -static int ml_check_b0_id(ZERO_BL *b0p); -static void ml_upd_block0(buf_T *buf, upd_block0_T what); -static void set_b0_fname(ZERO_BL *, buf_T *buf); -static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf); -static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf); -static time_t swapfile_info(char_u *); -static int recov_file_names(char_u **, char_u *, int prepend_dot); -static int ml_append_int(buf_T *, linenr_T, char_u *, colnr_T, int, int); -static int ml_delete_int(buf_T *, linenr_T, int); -static char_u *findswapname(buf_T *, char_u **, char_u *); -static void ml_flush_line(buf_T *); -static bhdr_T *ml_new_data(memfile_T *, int, int); -static bhdr_T *ml_new_ptr(memfile_T *); -static bhdr_T *ml_find_line(buf_T *, linenr_T, int); -static int ml_add_stack(buf_T *); -static void ml_lineadd(buf_T *, int); -static int b0_magic_wrong(ZERO_BL *); -#ifdef CHECK_INODE -static int fnamecmp_ino(char_u *, char_u *, long); -#endif -static void long_to_char(long, char_u *); -static long char_to_long(char_u *); -#if defined(UNIX) || defined(WIN3264) -static char_u *make_percent_swname(char_u *dir, char_u *name); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memline.c.generated.h"  #endif -static void ml_updatechunk(buf_T *buf, long line, long len, int updtype);  /*   * Open a new memline for "buf". @@ -3186,7 +3163,6 @@ get_file_in_dir (    return retval;  } -static void attention_message(buf_T *buf, char_u *fname);  /*   * Print the ATTENTION message: info about an existing swap file. @@ -3237,7 +3213,6 @@ attention_message (    --no_wait_return;  } -static int do_swapexists(buf_T *buf, char_u *fname);  /*   * Trigger the SwapExists autocommands. diff --git a/src/nvim/memline.h b/src/nvim/memline.h index 831cf46a35..f84e86fea0 100644 --- a/src/nvim/memline.h +++ b/src/nvim/memline.h @@ -2,39 +2,8 @@  #define NVIM_MEMLINE_H  #include "nvim/types.h" -#include "nvim/func_attr.h" -int ml_open(buf_T *buf); -void ml_setname(buf_T *buf); -void ml_open_files(void); -void ml_open_file(buf_T *buf); -void check_need_swap(int newfile); -void ml_close(buf_T *buf, int del_file); -void ml_close_all(int del_file); -void ml_close_notmod(void); -void ml_timestamp(buf_T *buf); -void ml_recover(void); -int recover_names(char_u *fname, int list, int nr, char_u **fname_out); -void ml_sync_all(int check_file, int check_char); -void ml_preserve(buf_T *buf, int message); -char_u *ml_get(linenr_T lnum); -char_u *ml_get_pos(pos_T *pos); -char_u *ml_get_buf(buf_T *buf, linenr_T lnum, int will_change); -int ml_line_alloced(void); -int ml_append(linenr_T lnum, char_u *line, colnr_T len, int newfile); -int ml_append_buf(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, -                  int newfile); -int ml_replace(linenr_T lnum, char_u *line, int copy); -int ml_delete(linenr_T lnum, int message); -void ml_setmarked(linenr_T lnum); -linenr_T ml_firstmarked(void); -void ml_clearmarked(void); -int resolve_symlink(char_u *fname, char_u *buf); -char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, -                     char_u *dir_name); -char_u *get_file_in_dir(char_u *fname, char_u *dname); -void ml_setflags(buf_T *buf); -long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp); -void goto_byte(long cnt); - -#endif /* NVIM_MEMLINE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memline.h.generated.h" +#endif +#endif  // NVIM_MEMLINE_H diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 238a6791c0..fdec9a49f9 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -41,7 +41,9 @@  #include "nvim/window.h"  #include "nvim/os/os.h" -static void try_to_free_memory(); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memory.c.generated.h" +#endif  /// Try to free memory. Used when trying to recover from out of memory errors.  /// @see {xmalloc} @@ -63,7 +65,15 @@ static void try_to_free_memory()    trying_to_free = false;  } -void *try_malloc(size_t size) +/// malloc() wrapper +/// +/// try_malloc() is a malloc() wrapper that tries to free some memory before +/// trying again. +/// +/// @see {try_to_free_memory} +/// @param size +/// @return pointer to allocated space. NULL if out of memory +void *try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1)  {    void *ret = malloc(size); @@ -80,7 +90,13 @@ void *try_malloc(size_t size)    return ret;  } -void *verbose_try_malloc(size_t size) +/// try_malloc() wrapper that shows an out-of-memory error message to the user +/// before returning NULL +/// +/// @see {try_malloc} +/// @param size +/// @return pointer to allocated space. NULL if out of memory +void *verbose_try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1)  {    void *ret = try_malloc(size);    if (!ret) { @@ -89,7 +105,16 @@ void *verbose_try_malloc(size_t size)    return ret;  } +/// malloc() wrapper that never returns NULL +/// +/// xmalloc() succeeds or gracefully aborts when out of memory. +/// Before aborting try to free some memory and call malloc again. +/// +/// @see {try_to_free_memory} +/// @param size +/// @return pointer to allocated space. Never NULL  void *xmalloc(size_t size) +  FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1) FUNC_ATTR_NONNULL_RET  {    void *ret = try_malloc(size); @@ -100,7 +125,14 @@ void *xmalloc(size_t size)    return ret;  } +/// calloc() wrapper +/// +/// @see {xmalloc} +/// @param count +/// @param size +/// @return pointer to allocated space. Never NULL  void *xcalloc(size_t count, size_t size) +  FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE_PROD(1, 2) FUNC_ATTR_NONNULL_RET  {    void *ret = calloc(count, size); @@ -121,7 +153,13 @@ void *xcalloc(size_t count, size_t size)    return ret;  } +/// realloc() wrapper +/// +/// @see {xmalloc} +/// @param size +/// @return pointer to reallocated space. Never NULL  void *xrealloc(void *ptr, size_t size) +  FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALLOC_SIZE(2) FUNC_ATTR_NONNULL_RET  {    void *ret = realloc(ptr, size); @@ -142,6 +180,11 @@ void *xrealloc(void *ptr, size_t size)    return ret;  } +/// xmalloc() wrapper that allocates size + 1 bytes and zeroes the last byte +/// +/// @see {xmalloc} +/// @param size +/// @return pointer to allocated space. Never NULL  void *xmallocz(size_t size)  {    size_t total_size = size + 1; @@ -158,17 +201,62 @@ void *xmallocz(size_t size)    return ret;  } +/// Allocates (len + 1) bytes of memory, duplicates `len` bytes of +/// `data` to the allocated memory, zero terminates the allocated memory, +/// and returns a pointer to the allocated memory. If the allocation fails, +/// the program dies. +/// +/// @see {xmalloc} +/// @param data Pointer to the data that will be copied +/// @param len number of bytes that will be copied  void *xmemdupz(const void *data, size_t len)  {    return memcpy(xmallocz(len), data, len);  } +/// The xstpcpy() function shall copy the string pointed to by src (including +/// the terminating NUL character) into the array pointed to by dst. +/// +/// The xstpcpy() function shall return a pointer to the terminating NUL +/// character copied into the dst buffer. This is the only difference with +/// strcpy(), which returns dst. +/// +/// WARNING: If copying takes place between objects that overlap, the behavior is +/// undefined. +/// +/// This is the Neovim version of stpcpy(3) as defined in POSIX 2008. We +/// don't require that supported platforms implement POSIX 2008, so we +/// implement our own version. +/// +/// @param dst +/// @param src  char *xstpcpy(char *restrict dst, const char *restrict src)  {    const size_t len = strlen(src);    return (char *)memcpy(dst, src, len + 1) + len;  } +/// The xstpncpy() function shall copy not more than n bytes (bytes that follow +/// a NUL character are not copied) from the array pointed to by src to the +/// array pointed to by dst. +/// +/// If a NUL character is written to the destination, the xstpncpy() function +/// shall return the address of the first such NUL character. Otherwise, it +/// shall return &dst[maxlen]. +/// +/// WARNING: If copying takes place between objects that overlap, the behavior is +/// undefined. +/// +/// WARNING: xstpncpy will ALWAYS write maxlen bytes. If src is shorter than +/// maxlen, zeroes will be written to the remaining bytes. +/// +/// TODO(aktau): I don't see a good reason to have this last behaviour, and +/// it is potentially wasteful. Could we perhaps deviate from the standard +/// and not zero the rest of the buffer? +/// +/// @param dst +/// @param src +/// @param maxlen  char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen)  {      const char *p = memchr(src, '\0', maxlen); @@ -183,6 +271,17 @@ char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen)      }  } +/// xstrlcpy - Copy a %NUL terminated string into a sized buffer +/// +/// Compatible with *BSD strlcpy: the result is always a valid +/// NUL-terminated string that fits in the buffer (unless, +/// of course, the buffer size is zero). It does not pad +/// out the result like strncpy() does. +/// +/// @param dst Where to copy the string to +/// @param src Where to copy the string from +/// @param size Size of destination buffer +/// @return Length of the source string (i.e.: strlen(src))  size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size)  {      size_t ret = strlen(src); @@ -196,7 +295,13 @@ size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size)      return ret;  } +/// strdup() wrapper +/// +/// @see {xmalloc} +/// @param str 0-terminated string that will be copied +/// @return pointer to a copy of the string  char *xstrdup(const char *str) +  FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET  {    char *ret = strdup(str); @@ -212,12 +317,24 @@ char *xstrdup(const char *str)    return ret;  } +/// strndup() wrapper +/// +/// @see {xmalloc} +/// @param str 0-terminated string that will be copied +/// @return pointer to a copy of the string  char *xstrndup(const char *str, size_t len) +  FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET  {    char *p = memchr(str, '\0', len);    return xmemdupz(str, p ? (size_t)(p - str) : len);  } +/// Duplicates a chunk of memory using xmalloc +/// +/// @see {xmalloc} +/// @param data pointer to the chunk +/// @param len size of the chunk +/// @return a pointer  void *xmemdup(const void *data, size_t len)  {    return memcpy(xmalloc(len), data, len); diff --git a/src/nvim/memory.h b/src/nvim/memory.h index accf293176..3a05797e89 100644 --- a/src/nvim/memory.h +++ b/src/nvim/memory.h @@ -1,153 +1,10 @@  #ifndef NVIM_MEMORY_H  #define NVIM_MEMORY_H -#include "nvim/func_attr.h" -#include "nvim/types.h" +#include <stddef.h>  #include "nvim/vim.h" -/// malloc() wrapper -/// -/// try_malloc() is a malloc() wrapper that tries to free some memory before -/// trying again. -/// -/// @see {try_to_free_memory} -/// @param size -/// @return pointer to allocated space. NULL if out of memory -void *try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1); - -/// try_malloc() wrapper that shows an out-of-memory error message to the user -/// before returning NULL -/// -/// @see {try_malloc} -/// @param size -/// @return pointer to allocated space. NULL if out of memory -void *verbose_try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1); - -/// malloc() wrapper that never returns NULL -/// -/// xmalloc() succeeds or gracefully aborts when out of memory. -/// Before aborting try to free some memory and call malloc again. -/// -/// @see {try_to_free_memory} -/// @param size -/// @return pointer to allocated space. Never NULL -void *xmalloc(size_t size) -  FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1) FUNC_ATTR_NONNULL_RET; - -/// calloc() wrapper -/// -/// @see {xmalloc} -/// @param count -/// @param size -/// @return pointer to allocated space. Never NULL -void *xcalloc(size_t count, size_t size) -  FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE_PROD(1, 2) FUNC_ATTR_NONNULL_RET; - -/// realloc() wrapper -/// -/// @see {xmalloc} -/// @param size -/// @return pointer to reallocated space. Never NULL -void *xrealloc(void *ptr, size_t size) -  FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALLOC_SIZE(2) FUNC_ATTR_NONNULL_RET; - -/// xmalloc() wrapper that allocates size + 1 bytes and zeroes the last byte -/// -/// @see {xmalloc} -/// @param size -/// @return pointer to allocated space. Never NULL -void *xmallocz(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET; - -/// Allocates (len + 1) bytes of memory, duplicates `len` bytes of -/// `data` to the allocated memory, zero terminates the allocated memory, -/// and returns a pointer to the allocated memory. If the allocation fails, -/// the program dies. -/// -/// @see {xmalloc} -/// @param data Pointer to the data that will be copied -/// @param len number of bytes that will be copied -void *xmemdupz(const void *data, size_t len) FUNC_ATTR_NONNULL_RET; - -/// strdup() wrapper -/// -/// @see {xmalloc} -/// @param str 0-terminated string that will be copied -/// @return pointer to a copy of the string -char * xstrdup(const char *str) - FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET; - -/// strndup() wrapper -/// -/// @see {xmalloc} -/// @param str 0-terminated string that will be copied -/// @return pointer to a copy of the string -char * xstrndup(const char *str, size_t len) - FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET; - -/// The xstpcpy() function shall copy the string pointed to by src (including -/// the terminating NUL character) into the array pointed to by dst. -/// -/// The xstpcpy() function shall return a pointer to the terminating NUL -/// character copied into the dst buffer. This is the only difference with -/// strcpy(), which returns dst. -/// -/// WARNING: If copying takes place between objects that overlap, the behavior is -/// undefined. -/// -/// This is the Neovim version of stpcpy(3) as defined in POSIX 2008. We -/// don't require that supported platforms implement POSIX 2008, so we -/// implement our own version. -/// -/// @param dst -/// @param src -char *xstpcpy(char *restrict dst, const char *restrict src); - -/// The xstpncpy() function shall copy not more than n bytes (bytes that follow -/// a NUL character are not copied) from the array pointed to by src to the -/// array pointed to by dst. -/// -/// If a NUL character is written to the destination, the xstpncpy() function -/// shall return the address of the first such NUL character. Otherwise, it -/// shall return &dst[maxlen]. -/// -/// WARNING: If copying takes place between objects that overlap, the behavior is -/// undefined. -/// -/// WARNING: xstpncpy will ALWAYS write maxlen bytes. If src is shorter than -/// maxlen, zeroes will be written to the remaining bytes. -/// -/// TODO(aktau): I don't see a good reason to have this last behaviour, and -/// it is potentially wasteful. Could we perhaps deviate from the standard -/// and not zero the rest of the buffer? -/// -/// @param dst -/// @param src -/// @param maxlen -char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen); - -/// xstrlcpy - Copy a %NUL terminated string into a sized buffer -/// -/// Compatible with *BSD strlcpy: the result is always a valid -/// NUL-terminated string that fits in the buffer (unless, -/// of course, the buffer size is zero). It does not pad -/// out the result like strncpy() does. -/// -/// @param dst Where to copy the string to -/// @param src Where to copy the string from -/// @param size Size of destination buffer -/// @return Length of the source string (i.e.: strlen(src)) -size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size); - -/// Duplicates a chunk of memory using xmalloc -/// -/// @see {xmalloc} -/// @param data pointer to the chunk -/// @param len size of the chunk -/// @return a pointer -void *xmemdup(const void *data, size_t len) - FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET; - -void do_outofmem_msg(size_t size); -void free_all_mem(void); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "memory.h.generated.h"  #endif +#endif  // NVIM_MEMORY_H diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 0f86a65bb5..f1e305f625 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -32,29 +32,13 @@  #define MENUDEPTH   10          /* maximum depth of menus */ -static int add_menu_path(char_u *, vimmenu_T *, int *, char_u *); -static int menu_nable_recurse(vimmenu_T *menu, char_u *name, int modes, -                              int enable); -static int remove_menu(vimmenu_T **, char_u *, int, int silent); -static void free_menu(vimmenu_T **menup); -static void free_menu_string(vimmenu_T *, int); -static int show_menus(char_u *, int); -static void show_menus_recursive(vimmenu_T *, int, int); -static int menu_name_equal(char_u *name, vimmenu_T *menu); -static int menu_namecmp(char_u *name, char_u *mname); -static int get_menu_cmd_modes(char_u *, int, int *, int *); -static char_u *popup_mode_name(char_u *name, int idx); -static char_u *menu_text(char_u *text, int *mnemonic, char_u **actext); - - -static int menu_is_hidden(char_u *name); -static int menu_is_tearoff(char_u *name); - -static char_u *menu_skip_part(char_u *p); -static char_u *menutrans_lookup(char_u *name, int len); -static void menu_unescape_name(char_u  *p); - -static char_u *menu_translate_tab_and_shift(char_u *arg_start); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "menu.c.generated.h" +#endif + + +  /* The character for each menu mode */  static char_u menu_mode_chars[] = {'n', 'v', 's', 'o', 'i', 'c', 't'}; diff --git a/src/nvim/menu.h b/src/nvim/menu.h index 2e84d0107a..34965d3487 100644 --- a/src/nvim/menu.h +++ b/src/nvim/menu.h @@ -48,18 +48,8 @@ struct VimMenu {    vimmenu_T   *next;                /* Next item in menu */  }; -void ex_menu(exarg_T *eap); -char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, -                                int forceit); -char_u *get_menu_name(expand_T *xp, int idx); -char_u *get_menu_names(expand_T *xp, int idx); -char_u *menu_name_skip(char_u *name); -int menu_is_menubar(char_u *name); -int menu_is_popup(char_u *name); -int menu_is_toolbar(char_u *name); -int menu_is_separator(char_u *name); -void ex_emenu(exarg_T *eap); -vimmenu_T *gui_find_menu(char_u *path_name); -void ex_menutranslate(exarg_T *eap); -#endif /* NVIM_MENU_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "menu.h.generated.h" +#endif +#endif  // NVIM_MENU_H diff --git a/src/nvim/message.c b/src/nvim/message.c index 44fbdb6091..42162b9315 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -38,59 +38,24 @@  #include "nvim/os/os.h"  #include "nvim/os/event.h" -static int other_sourcing_name(void); -static char_u *get_emsg_source(void); -static char_u *get_emsg_lnum(void); -static void add_msg_hist(char_u *s, int len, int attr); -static void hit_return_msg(void); -static void msg_home_replace_attr(char_u *fname, int attr); -static char_u *screen_puts_mbyte(char_u *s, int l, int attr); -static void msg_puts_attr_len(char_u *str, int maxlen, int attr); -static void msg_puts_display(char_u *str, int maxlen, int attr, -                             int recurse); -static void msg_scroll_up(void); -static void inc_msg_scrolled(void); -static void store_sb_text(char_u **sb_str, char_u *s, int attr, -                          int *sb_col, -                          int finish); -static void t_puts(int *t_col, char_u *t_s, char_u *s, int attr); -static void msg_puts_printf(char_u *str, int maxlen); -static int do_more_prompt(int typed_char); -static void msg_screen_putchar(int c, int attr); -static int msg_check_screen(void); -static void redir_write(char_u *s, int maxlen); - -/// Allocates memory for dialog string & for storing hotkeys -/// -/// Finds the size of memory required for the confirm_msg & for storing hotkeys -/// and then allocates the memory for them. -/// has_hotkey array is also filled-up. -/// -/// @param message Message which will be part of the confirm_msg -/// @param buttons String containing button names -/// @param[out] has_hotkey A element in this array is set to true if -///                        corresponding button has a hotkey -/// -/// @return Pointer to memory allocated for storing hotkeys -static char_u * console_dialog_alloc(const char_u *message, -                                     char_u *buttons, -                                     bool has_hotkey[]); - -/// Copies hotkeys & dialog message into the memory allocated for it -/// -/// @param message Message which will be part of the confirm_msg -/// @param buttons String containing button names -/// @param default_button_idx Number of default button -/// @param has_hotkey A element in this array is true if corresponding button -///                   has a hotkey -/// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied -static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons, -                                 int default_button_idx, const bool has_hotkey[], -                                 char_u *hotkeys_ptr); +/* + * To be able to scroll back at the "more" and "hit-enter" prompts we need to + * store the displayed text and remember where screen lines start. + */ +typedef struct msgchunk_S msgchunk_T; +struct msgchunk_S { +  msgchunk_T  *sb_next; +  msgchunk_T  *sb_prev; +  char sb_eol;                  /* TRUE when line ends after this text */ +  int sb_msg_col;               /* column in which text starts */ +  int sb_attr;                  /* text attributes */ +  char_u sb_text[1];            /* text to be displayed, actually longer */ +}; -static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, -                                       int dfltbutton);  static int confirm_msg_used = FALSE;            /* displaying confirm_msg */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "message.c.generated.h" +#endif  static char_u   *confirm_msg = NULL;            /* ":confirm" message */  static char_u   *confirm_msg_tail;              /* tail of confirm_msg */ @@ -352,7 +317,6 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen)   * Note: Caller of smgs() and smsg_attr() must check the resulting string is   * shorter than IOSIZE!!!   */ -int vim_snprintf(char *str, size_t str_m, char *fmt, ...);  int smsg(char_u *s, ...)  { @@ -1845,24 +1809,8 @@ static void inc_msg_scrolled(void)    ++msg_scrolled;  } -/* - * To be able to scroll back at the "more" and "hit-enter" prompts we need to - * store the displayed text and remember where screen lines start. - */ -typedef struct msgchunk_S msgchunk_T; -struct msgchunk_S { -  msgchunk_T  *sb_next; -  msgchunk_T  *sb_prev; -  char sb_eol;                  /* TRUE when line ends after this text */ -  int sb_msg_col;               /* column in which text starts */ -  int sb_attr;                  /* text attributes */ -  char_u sb_text[1];            /* text to be displayed, actually longer */ -}; -  static msgchunk_T *last_msgchunk = NULL; /* last displayed text */ -static msgchunk_T *msg_sb_start(msgchunk_T *mps); -static msgchunk_T *disp_sb_line(int row, msgchunk_T *smp);  static int do_clear_sb_text = FALSE;    /* clear text on next msg */ @@ -2274,7 +2222,7 @@ static int do_more_prompt(int typed_char)    return retval;  } -#if defined(USE_MCH_ERRMSG) || defined(PROTO) +#if defined(USE_MCH_ERRMSG)  #ifdef mch_errmsg  # undef mch_errmsg @@ -2817,7 +2765,6 @@ do_dialog (    return retval;  } -static int copy_char(char_u *from, char_u *to, int lowercase);  /*   * Copy one character from "*from" to "*to", taking care of multi-byte @@ -2854,6 +2801,18 @@ copy_char (  #define HAS_HOTKEY_LEN 30  #define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1) +/// Allocates memory for dialog string & for storing hotkeys +/// +/// Finds the size of memory required for the confirm_msg & for storing hotkeys +/// and then allocates the memory for them. +/// has_hotkey array is also filled-up. +/// +/// @param message Message which will be part of the confirm_msg +/// @param buttons String containing button names +/// @param[out] has_hotkey A element in this array is set to true if +///                        corresponding button has a hotkey +/// +/// @return Pointer to memory allocated for storing hotkeys  static char_u * console_dialog_alloc(const char_u *message,                                       char_u *buttons,                                       bool has_hotkey[]) @@ -2924,6 +2883,14 @@ static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfl    return hotk;  } +/// Copies hotkeys & dialog message into the memory allocated for it +/// +/// @param message Message which will be part of the confirm_msg +/// @param buttons String containing button names +/// @param default_button_idx Number of default button +/// @param has_hotkey A element in this array is true if corresponding button +///                   has a hotkey +/// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied  static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,                                   int default_button_idx, const bool has_hotkey[],                                   char_u *hotkeys_ptr) @@ -3051,10 +3018,6 @@ int vim_dialog_yesnoallcancel(int type, char_u *title, char_u *message, int dflt  static char *e_printf = N_("E766: Insufficient arguments for printf()"); -static long tv_nr(typval_T *tvs, int *idxp); -static char *tv_str(typval_T *tvs, int *idxp); -static double tv_float(typval_T *tvs, int *idxp); -  /*   * Get number argument from "idxp" entry in "tvs".  First entry is 1.   */ diff --git a/src/nvim/message.h b/src/nvim/message.h index 11029aa6fd..662ae9a6ae 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -1,85 +1,7 @@  #ifndef NVIM_MESSAGE_H  #define NVIM_MESSAGE_H -/* message.c */ -int msg(char_u *s); -int verb_msg(char_u *s); -int msg_attr(char_u *s, int attr); -int msg_attr_keep(char_u *s, int attr, int keep); -char_u *msg_strtrunc(char_u *s, int force); -void trunc_string(char_u *s, char_u *buf, int room, int buflen); -void reset_last_sourcing(void); -void msg_source(int attr); -int emsg_not_now(void); -int emsg(char_u *s); -int emsg2(char_u *s, char_u *a1); -void emsg_invreg(int name); -char_u *msg_trunc_attr(char_u *s, int force, int attr); -char_u *msg_may_trunc(int force, char_u *s); -int delete_first_msg(void); -void ex_messages(exarg_T *eap); -void msg_end_prompt(void); -void wait_return(int redraw); -void set_keep_msg(char_u *s, int attr); -void set_keep_msg_from_hist(void); -void msg_start(void); -void msg_starthere(void); -void msg_putchar(int c); -void msg_putchar_attr(int c, int attr); -void msg_outnum(long n); -void msg_home_replace(char_u *fname); -void msg_home_replace_hl(char_u *fname); -int msg_outtrans(char_u *str); -int msg_outtrans_attr(char_u *str, int attr); -int msg_outtrans_len(char_u *str, int len); -char_u *msg_outtrans_one(char_u *p, int attr); -int msg_outtrans_len_attr(char_u *msgstr, int len, int attr); -void msg_make(char_u *arg); -int msg_outtrans_special(char_u *strstart, int from); -char_u *str2special_save(char_u *str, int is_lhs); -char_u *str2special(char_u **sp, int from); -void str2specialbuf(char_u *sp, char_u *buf, int len); -void msg_prt_line(char_u *s, int list); -void msg_puts(char_u *s); -void msg_puts_title(char_u *s); -void msg_puts_long_attr(char_u *longstr, int attr); -void msg_puts_long_len_attr(char_u *longstr, int len, int attr); -void msg_puts_attr(char_u *s, int attr); -void may_clear_sb_text(void); -void clear_sb_text(void); -void show_sb_text(void); -void msg_sb_eol(void); -int msg_use_printf(void); -#ifdef USE_MCH_ERRMSG -void mch_errmsg(char *str); -void mch_msg(char *str); -#endif -void msg_moremsg(int full); -void repeat_message(void); -void msg_clr_eos(void); -void msg_clr_eos_force(void); -void msg_clr_cmdline(void); -int msg_end(void); -void msg_check(void); -int redirecting(void); -void verbose_enter(void); -void verbose_leave(void); -void verbose_enter_scroll(void); -void verbose_leave_scroll(void); -void verbose_stop(void); -int verbose_open(void); -void give_warning(char_u *message, int hl); -void msg_advance(int col); -int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, -              int dfltbutton, char_u *textfield, -              int ex_cmd); -void display_confirm_msg(void); -int vim_dialog_yesno(int type, char_u *title, char_u *message, int dflt); -int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, -                           int dflt); -int vim_dialog_yesnoallcancel(int type, char_u *title, char_u *message, -                              int dflt); -char_u *do_browse(int flags, char_u *title, char_u *dflt, char_u *ext, -                  char_u *initdir, char_u *filter, -                  buf_T *buf); -#endif /* NVIM_MESSAGE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "message.h.generated.h" +#endif +#endif  // NVIM_MESSAGE_H diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 18a6e4bd7a..6774a578a2 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -52,10 +52,10 @@  #include "nvim/window.h"  #include "nvim/os/os.h"  #include "nvim/os/shell.h" -static char_u *vim_version_dir(char_u *vimdir); -static char_u *remove_tail(char_u *p, char_u *pend, char_u *name); -static void init_users(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "misc1.c.generated.h" +#endif  /* All user names (for ~user completion as done by shell). */  static garray_T ga_users; @@ -1855,11 +1855,6 @@ void changed_int(void)    need_maketitle = TRUE;            /* set window title later */  } -static void changedOneline(buf_T *buf, linenr_T lnum); -static void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, -                              long xtra); -static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, -                           long xtra);  /*   * Changed bytes within a single line for the current buffer. diff --git a/src/nvim/misc1.h b/src/nvim/misc1.h index 5d9d2f084b..ecf378afa4 100644 --- a/src/nvim/misc1.h +++ b/src/nvim/misc1.h @@ -3,72 +3,7 @@  #include "nvim/vim.h" -int open_line(int dir, int flags, int second_line_indent); -int get_leader_len(char_u *line, char_u **flags, int backward, -                   int include_space); -int get_last_leader_offset(char_u *line, char_u **flags); -int plines(linenr_T lnum); -int plines_win(win_T *wp, linenr_T lnum, int winheight); -int plines_nofill(linenr_T lnum); -int plines_win_nofill(win_T *wp, linenr_T lnum, int winheight); -int plines_win_nofold(win_T *wp, linenr_T lnum); -int plines_win_col(win_T *wp, linenr_T lnum, long column); -int plines_m_win(win_T *wp, linenr_T first, linenr_T last); -void ins_bytes(char_u *p); -void ins_bytes_len(char_u *p, int len); -void ins_char(int c); -void ins_char_bytes(char_u *buf, int charlen); -void ins_str(char_u *s); -int del_char(int fixpos); -int del_chars(long count, int fixpos); -int del_bytes(long count, int fixpos_arg, int use_delcombine); -void truncate_line(int fixpos); -void del_lines(long nlines, int undo); -int gchar_pos(pos_T *pos); -char_u *skip_to_option_part(char_u *p); -void changed(void); -void changed_int(void); -void changed_bytes(linenr_T lnum, colnr_T col); -void appended_lines(linenr_T lnum, long count); -void appended_lines_mark(linenr_T lnum, long count); -void deleted_lines(linenr_T lnum, long count); -void deleted_lines_mark(linenr_T lnum, long count); -void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, -                   long xtra); -void unchanged(buf_T *buf, int ff); -void check_status(buf_T *buf); -void change_warning(int col); -int ask_yesno(char_u *str, int direct); -int is_mouse_key(int c); -int get_keystroke(void); -int get_number(int colon, int *mouse_used); -int prompt_for_number(int *mouse_used); -void msgmore(long n); -void beep_flush(void); -void vim_beep(void); -void init_homedir(void); -void free_homedir(void); -void free_users(void); -char_u *expand_env_save(char_u *src); -char_u *expand_env_save_opt(char_u *src, int one); -void expand_env(char_u *src, char_u *dst, int dstlen); -void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, int esc, -                    int one, -                    char_u *startstr); -char_u *vim_getenv(char_u *name, int *mustfree); -void vim_setenv(char_u *name, char_u *val); -char_u *get_env_name(expand_T *xp, int idx); -char_u *get_users(expand_T *xp, int idx); -int match_user(char_u *name); -void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, -                  int one); -char_u *home_replace_save(buf_T *buf, char_u *src); -void prepare_to_exit(void); -void preserve_exit(void); -void line_breakcheck(void); -void fast_breakcheck(void); -char_u *get_cmd_output(char_u *cmd, char_u *infile, int flags); -void FreeWild(int count, char_u **files); -int goto_im(void); - -#endif /* NVIM_MISC1_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "misc1.h.generated.h" +#endif +#endif  // NVIM_MISC1_H diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index c9c3edca71..312154ee2b 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -52,6 +52,10 @@  #include "nvim/os/os.h"  #include "nvim/os/shell.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "misc2.c.generated.h" +#endif  /*   * Return TRUE if in the current mode we need to use virtual.   */ diff --git a/src/nvim/misc2.h b/src/nvim/misc2.h index b94e35e258..f7695d1b94 100644 --- a/src/nvim/misc2.h +++ b/src/nvim/misc2.h @@ -1,37 +1,9 @@  #ifndef NVIM_MISC2_H  #define NVIM_MISC2_H -#include "nvim/func_attr.h"  #include "nvim/os/shell.h" -/* misc2.c */ -int virtual_active(void); -int inc(pos_T *lp); -int incl(pos_T *lp); -int dec(pos_T *lp); -int decl(pos_T *lp); -int csh_like_shell(void); -int copy_option_part(char_u **option, char_u *buf, int maxlen, -                     char *sep_chars); -int get_fileformat(buf_T *buf); -int get_fileformat_force(buf_T *buf, exarg_T *eap); -void set_fileformat(int t, int opt_flags); -int default_fileformat(void); -int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg); -int get_real_state(void); -int vim_chdirfile(char_u *fname); -int illegal_slash(char *name); -int vim_chdir(char_u *new_dir); -int emsg3(char_u *s, char_u *a1, char_u *a2); -int emsgn(char_u *s, int64_t n); -int emsgu(char_u *s, uint64_t n); -int get2c(FILE *fd); -int get3c(FILE *fd); -int get4c(FILE *fd); -time_t get8ctime(FILE *fd); -char_u *read_string(FILE *fd, int cnt); -int put_bytes(FILE *fd, long_u nr, int len); -void put_time(FILE *fd, time_t the_time); -int has_non_ascii(char_u *s); - -#endif /* NVIM_MISC2_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "misc2.h.generated.h" +#endif +#endif  // NVIM_MISC2_H diff --git a/src/nvim/move.c b/src/nvim/move.c index f744e1b812..b150f06a95 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -31,25 +31,16 @@  #include "nvim/screen.h"  #include "nvim/strings.h" -static void comp_botline(win_T *wp); -static void redraw_for_cursorline(win_T *wp); -static int scrolljump_value(void); -static int check_top_offset(void); -static void curs_rows(win_T *wp, int do_botline); -static void validate_botline_win(win_T *wp); -static void validate_cheight(void); -  typedef struct {    linenr_T lnum;                /* line number */    int fill;                     /* filler lines */    int height;                   /* height of added line */  } lineoff_T; -static void topline_back(lineoff_T *lp); -static void botline_forw(lineoff_T *lp); -static void botline_topline(lineoff_T *lp); -static void topline_botline(lineoff_T *lp); -static void max_topfill(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "move.c.generated.h" +#endif +  /*   * Compute wp->w_botline for the current wp->w_topline.  Can be called after @@ -1775,7 +1766,6 @@ void cursor_correct(void)    curwin->w_valid |= VALID_TOPLINE;  } -static void get_scroll_overlap(lineoff_T *lp, int dir);  /*   * move screen 'count' pages up or down and update screen diff --git a/src/nvim/move.h b/src/nvim/move.h index 5e961661eb..cc65e467d5 100644 --- a/src/nvim/move.h +++ b/src/nvim/move.h @@ -1,43 +1,7 @@  #ifndef NVIM_MOVE_H  #define NVIM_MOVE_H -/* move.c */ -void update_topline_redraw(void); -void update_topline(void); -void update_curswant(void); -void check_cursor_moved(win_T *wp); -void changed_window_setting(void); -void changed_window_setting_win(win_T *wp); -void set_topline(win_T *wp, linenr_T lnum); -void changed_cline_bef_curs(void); -void changed_cline_bef_curs_win(win_T *wp); -void changed_line_abv_curs(void); -void changed_line_abv_curs_win(win_T *wp); -void validate_botline(void); -void invalidate_botline(void); -void invalidate_botline_win(win_T *wp); -void approximate_botline_win(win_T *wp); -int cursor_valid(void); -void validate_cursor(void); -void validate_virtcol(void); -void validate_virtcol_win(win_T *wp); -void validate_cursor_col(void); -int win_col_off(win_T *wp); -int curwin_col_off(void); -int win_col_off2(win_T *wp); -int curwin_col_off2(void); -void curs_columns(int may_scroll); -void scrolldown(long line_count, int byfold); -void scrollup(long line_count, int byfold); -void check_topfill(win_T *wp, int down); -void scrolldown_clamp(void); -void scrollup_clamp(void); -void scroll_cursor_top(int min_scroll, int always); -void set_empty_rows(win_T *wp, int used); -void scroll_cursor_bot(int min_scroll, int set_topbot); -void scroll_cursor_halfway(int atend); -void cursor_correct(void); -int onepage(int dir, long count); -void halfpage(int flag, linenr_T Prenum); -void do_check_cursorbind(void); -#endif /* NVIM_MOVE_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "move.h.generated.h" +#endif +#endif  // NVIM_MOVE_H diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 210fc1227c..f7558109fa 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -67,119 +67,15 @@ static int VIsual_mode_orig = NUL;              /* saved Visual mode */  static int restart_VIsual_select = 0; -static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); -static int -nv_compare(const void *s1, const void *s2); -static int find_command(int cmdchar); -static void op_colon(oparg_T *oap); -static void op_function(oparg_T *oap); -static void find_start_of_word(pos_T *); -static void find_end_of_word(pos_T *); -static int get_mouse_class(char_u *p); -static void prep_redo_cmd(cmdarg_T *cap); -static void prep_redo(int regname, long, int, int, int, int, int); -static int checkclearop(oparg_T *oap); -static int checkclearopq(oparg_T *oap); -static void clearop(oparg_T *oap); -static void clearopbeep(oparg_T *oap); -static void unshift_special(cmdarg_T *cap); -static void del_from_showcmd(int); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "normal.c.generated.h" +#endif  /*   * nv_*(): functions called to handle Normal and Visual mode commands.   * n_*(): functions called to handle Normal mode commands.   * v_*(): functions called to handle Visual mode commands.   */ -static void nv_ignore(cmdarg_T *cap); -static void nv_nop(cmdarg_T *cap); -static void nv_error(cmdarg_T *cap); -static void nv_help(cmdarg_T *cap); -static void nv_addsub(cmdarg_T *cap); -static void nv_page(cmdarg_T *cap); -static void nv_gd(oparg_T *oap, int nchar, int thisblock); -static int nv_screengo(oparg_T *oap, int dir, long dist); -static void nv_mousescroll(cmdarg_T *cap); -static void nv_mouse(cmdarg_T *cap); -static void nv_scroll_line(cmdarg_T *cap); -static void nv_zet(cmdarg_T *cap); -static void nv_exmode(cmdarg_T *cap); -static void nv_colon(cmdarg_T *cap); -static void nv_ctrlg(cmdarg_T *cap); -static void nv_ctrlh(cmdarg_T *cap); -static void nv_clear(cmdarg_T *cap); -static void nv_ctrlo(cmdarg_T *cap); -static void nv_hat(cmdarg_T *cap); -static void nv_Zet(cmdarg_T *cap); -static void nv_ident(cmdarg_T *cap); -static void nv_tagpop(cmdarg_T *cap); -static void nv_scroll(cmdarg_T *cap); -static void nv_right(cmdarg_T *cap); -static void nv_left(cmdarg_T *cap); -static void nv_up(cmdarg_T *cap); -static void nv_down(cmdarg_T *cap); -static void nv_gotofile(cmdarg_T *cap); -static void nv_end(cmdarg_T *cap); -static void nv_dollar(cmdarg_T *cap); -static void nv_search(cmdarg_T *cap); -static void nv_next(cmdarg_T *cap); -static void normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt); -static void nv_csearch(cmdarg_T *cap); -static void nv_brackets(cmdarg_T *cap); -static void nv_percent(cmdarg_T *cap); -static void nv_brace(cmdarg_T *cap); -static void nv_mark(cmdarg_T *cap); -static void nv_findpar(cmdarg_T *cap); -static void nv_undo(cmdarg_T *cap); -static void nv_kundo(cmdarg_T *cap); -static void nv_Replace(cmdarg_T *cap); -static void nv_vreplace(cmdarg_T *cap); -static void v_swap_corners(int cmdchar); -static void nv_replace(cmdarg_T *cap); -static void n_swapchar(cmdarg_T *cap); -static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos); -static void v_visop(cmdarg_T *cap); -static void nv_subst(cmdarg_T *cap); -static void nv_abbrev(cmdarg_T *cap); -static void nv_optrans(cmdarg_T *cap); -static void nv_gomark(cmdarg_T *cap); -static void nv_pcmark(cmdarg_T *cap); -static void nv_regname(cmdarg_T *cap); -static void nv_visual(cmdarg_T *cap); -static void n_start_visual_mode(int c); -static void nv_window(cmdarg_T *cap); -static void nv_suspend(cmdarg_T *cap); -static void nv_g_cmd(cmdarg_T *cap); -static void n_opencmd(cmdarg_T *cap); -static void nv_dot(cmdarg_T *cap); -static void nv_redo(cmdarg_T *cap); -static void nv_Undo(cmdarg_T *cap); -static void nv_tilde(cmdarg_T *cap); -static void nv_operator(cmdarg_T *cap); -static void set_op_var(int optype); -static void nv_lineop(cmdarg_T *cap); -static void nv_home(cmdarg_T *cap); -static void nv_pipe(cmdarg_T *cap); -static void nv_bck_word(cmdarg_T *cap); -static void nv_wordcmd(cmdarg_T *cap); -static void nv_beginline(cmdarg_T *cap); -static void adjust_cursor(oparg_T *oap); -static void adjust_for_sel(cmdarg_T *cap); -static int unadjust_for_sel(void); -static void nv_select(cmdarg_T *cap); -static void nv_goto(cmdarg_T *cap); -static void nv_normal(cmdarg_T *cap); -static void nv_esc(cmdarg_T *oap); -static void nv_edit(cmdarg_T *cap); -static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); -static void nv_object(cmdarg_T *cap); -static void nv_record(cmdarg_T *cap); -static void nv_at(cmdarg_T *cap); -static void nv_halfpage(cmdarg_T *cap); -static void nv_join(cmdarg_T *cap); -static void nv_put(cmdarg_T *cap); -static void nv_open(cmdarg_T *cap); -static void nv_cursorhold(cmdarg_T *cap); -static void nv_event(cmdarg_T *cap);  static char *e_noident = N_("E349: No identifier under cursor"); @@ -2938,7 +2834,6 @@ static char_u old_showcmd_buf[SHOWCMD_BUFLEN];    /* For push_showcmd() */  static int showcmd_is_clear = TRUE;  static int showcmd_visual = FALSE; -static void display_showcmd(void);  void clear_showcmd(void)  { diff --git a/src/nvim/normal.h b/src/nvim/normal.h index 522ecf5b02..e51ce97db3 100644 --- a/src/nvim/normal.h +++ b/src/nvim/normal.h @@ -56,31 +56,8 @@ typedef struct cmdarg_S {  #define CA_COMMAND_BUSY     1   /* skip restarting edit() once */  #define CA_NO_ADJ_OP_END    2   /* don't adjust operator end */ -void init_normal_cmds(void); -void normal_cmd(oparg_T *oap, int toplevel); -void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank); -int do_mouse(oparg_T *oap, int c, int dir, long count, int fixindent); -void check_visual_highlight(void); -void end_visual_mode(void); -void reset_VIsual_and_resel(void); -void reset_VIsual(void); -int find_ident_under_cursor(char_u **string, int find_type); -int find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, -                      char_u **string, -                      int find_type); -void clear_showcmd(void); -int add_to_showcmd(int c); -void add_to_showcmd_c(int c); -void push_showcmd(void); -void pop_showcmd(void); -void do_check_scrollbind(int check); -void check_scrollbind(linenr_T topline_diff, long leftcol_diff); -int find_decl(char_u *ptr, int len, int locally, int thisblock, -              int searchflags); -void scroll_redraw(int up, long count); -void do_nv_ident(int c1, int c2); -int get_visual_text(cmdarg_T *cap, char_u **pp, int *lenp); -void start_selection(void); -void may_start_select(int c); -#endif /* NVIM_NORMAL_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "normal.h.generated.h" +#endif +#endif  // NVIM_NORMAL_H diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4c5a9fdf63..1ee1ce6ecc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -90,30 +90,10 @@ struct block_def {    colnr_T start_char_vcols;       /* number of vcols of pre-block char */  }; -static void shift_block(oparg_T *oap, int amount); -static void block_insert(oparg_T *oap, char_u *s, int b_insert, -                         struct block_def*bdp); -static int stuff_yank(int, char_u *); -static void put_reedit_in_typebuf(int silent); -static int put_in_typebuf(char_u *s, int esc, int colon, -                          int silent); -static void stuffescaped(char_u *arg, int literally); -static void mb_adjust_opend(oparg_T *oap); -static void free_yank(long); -static void free_yank_all(void); -static void yank_copy_line(struct block_def *bd, long y_idx); -static void dis_msg(char_u *p, int skip_esc); -static char_u   *skip_comment(char_u *line, int process, -                              int include_space, -                              int *is_comment); -static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int); -static void str_to_reg(struct yankreg *y_ptr, int type, char_u *str, -                       long len, -                       long blocklen); -static int ends_in_white(linenr_T lnum); -static int same_leader(linenr_T lnum, int, char_u *, int, char_u *); -static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ops.c.generated.h" +#endif  /*   * The names of operators.   * IMPORTANT: Index must correspond with defines in vim.h!!! @@ -566,9 +546,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def  /*   * op_reindent - handle reindenting a block of lines.   */ -void op_reindent(oap, how) -oparg_T     *oap; -int         (*how)(void); +void op_reindent(oparg_T *oap, Indenter how)  {    long i;    char_u      *l; @@ -778,7 +756,7 @@ void *  get_register (      int name,      int copy               /* make a copy, if FALSE make register empty. */ -) +) FUNC_ATTR_NONNULL_RET  {    get_yank_register(name, 0); @@ -1861,7 +1839,6 @@ int op_replace(oparg_T *oap, int c)    return OK;  } -static int swapchars(int op_type, pos_T *pos, int length);  /*   * Handle the (non-standard vi) tilde operator.  Also for "gu", "gU" and "g?". @@ -4193,7 +4170,6 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i    bdp->textstart = pstart;  } -static void reverse_line(char_u *s);  static void reverse_line(char_u *s)  { @@ -4903,9 +4879,6 @@ void clear_oparg(oparg_T *oap)    memset(oap, 0, sizeof(oparg_T));  } -static long line_count_info(char_u *line, long *wc, long *cc, -                            long limit, -                            int eol_size);  /*   *  Count the number of bytes, characters and "words" in a line. diff --git a/src/nvim/ops.h b/src/nvim/ops.h index 12dd8351d5..8227821d35 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -1,66 +1,11 @@  #ifndef NVIM_OPS_H  #define NVIM_OPS_H -#include "nvim/func_attr.h"  #include "nvim/types.h" -/* ops.c */ -int get_op_type(int char1, int char2); -int op_on_lines(int op); -int get_op_char(int optype); -int get_extra_op_char(int optype); -void op_shift(oparg_T *oap, int curs_top, int amount); -void shift_line(int left, int round, int amount, int call_changed_bytes); -void op_reindent(oparg_T *oap, int (*how)(void)); -int get_expr_register(void); -void set_expr_line(char_u *new_line); -char_u *get_expr_line(void); -char_u *get_expr_line_src(void); -int valid_yank_reg(int regname, int writing); -void get_yank_register(int regname, int writing); -void *get_register(int name, int copy) FUNC_ATTR_NONNULL_RET; -void put_register(int name, void *reg); -int yank_register_mline(int regname); -int do_record(int c); -int do_execreg(int regname, int colon, int addcr, int silent); -int insert_reg(int regname, int literally); -int get_spec_reg(int regname, char_u **argp, int *allocated, int errmsg); -int cmdline_paste_reg(int regname, int literally, int remcr); -int op_delete(oparg_T *oap); -int op_replace(oparg_T *oap, int c); -void op_tilde(oparg_T *oap); -int swapchar(int op_type, pos_T *pos); -void op_insert(oparg_T *oap, long count1); -int op_change(oparg_T *oap); -void init_yank(void); -void clear_registers(void); -int op_yank(oparg_T *oap, int deleting, int mess); -void do_put(int regname, int dir, long count, int flags); -void adjust_cursor_eol(void); -int preprocs_left(void); -int get_register_name(int num); -void ex_display(exarg_T *eap); -int do_join(long count, -            int insert_space, -            int save_undo, -            int use_formatoptions, -            bool setmark); -void op_format(oparg_T *oap, int keep_cursor); -void op_formatexpr(oparg_T *oap); -int fex_format(linenr_T lnum, long count, int c); -void format_lines(linenr_T line_count, int avoid_fex); -int paragraph_start(linenr_T lnum); -int do_addsub(int command, linenr_T Prenum1); -int read_viminfo_register(vir_T *virp, int force); -void write_viminfo_registers(FILE *fp); -char_u get_reg_type(int regname, long *reglen); -char_u *get_reg_contents(int regname, int allowexpr, int expr_src); -void write_reg_contents(int name, char_u *str, int maxlen, -                        int must_append); -void write_reg_contents_ex(int name, char_u *str, int maxlen, -                           int must_append, int yank_type, -                           long block_len); -void clear_oparg(oparg_T *oap); -void cursor_pos_info(void); +typedef int (*Indenter)(void); -#endif /* NVIM_OPS_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ops.h.generated.h" +#endif +#endif  // NVIM_OPS_H diff --git a/src/nvim/option.c b/src/nvim/option.c index 1408979288..b5ee27f3b5 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1838,59 +1838,9 @@ static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",  static char *(p_fcl_values[]) = {"all", NULL};  static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL}; -static void set_option_default(int, int opt_flags, int compatible); -static void set_options_default(int opt_flags); -static char_u *term_bg_default(void); -static void did_set_option(int opt_idx, int opt_flags, int new_value); -static char_u *illegal_char(char_u *, int); -static int string_to_key(char_u *arg); -static char_u *check_cedit(void); -static void did_set_title(int icon); -static char_u *option_expand(int opt_idx, char_u *val); -static void didset_options(void); -static void check_string_option(char_u **pp); -static long_u *insecure_flag(int opt_idx, int opt_flags); -static void set_string_option_global(int opt_idx, char_u **varp); -static char_u *set_string_option(int opt_idx, char_u *value, -                                 int opt_flags); -static char_u *did_set_string_option(int opt_idx, char_u **varp, -                                     int new_value_alloced, -                                     char_u *oldval, char_u *errbuf, -                                     int opt_flags); -static char_u *set_chars_option(char_u **varp); -static int int_cmp(const void *a, const void *b); -static char_u *compile_cap_prog(synblock_T *synblock); -static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id); -static char_u *set_bool_option(int opt_idx, char_u *varp, int value, -                               int opt_flags); -static char_u *set_num_option(int opt_idx, char_u *varp, long value, -                              char_u *errbuf, size_t errbuflen, -                              int opt_flags); -static void check_redraw(long_u flags); -static int findoption(char_u *); -static int find_key_option(char_u *); -static void showoptions(int all, int opt_flags); -static int optval_default(struct vimoption *, char_u *varp); -static void showoneopt(struct vimoption *, int opt_flags); -static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, -                         int expand); -static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); -static int put_setbool(FILE *fd, char *cmd, char *name, int value); -static int istermoption(struct vimoption *); -static char_u *get_varp_scope(struct vimoption *p, int opt_flags); -static char_u *get_varp(struct vimoption *); -static void option_value2string(struct vimoption *, int opt_flags); -static int wc_use_keyname(char_u *varp, long *wcp); -static void langmap_init(void); -static void langmap_set(void); -static void paste_option_changed(void); -static void compatible_set(void); -static void fill_breakat_flags(void); -static int opt_strings_flags(char_u *val, char **values, -                             unsigned *flagp, -                             int list); -static int check_opt_strings(char_u *val, char **values, int); -static int check_opt_wim(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "option.c.generated.h" +#endif  /*   * Initialize the options, first part. @@ -3688,7 +3638,6 @@ static long_u *insecure_flag(int opt_idx, int opt_flags)    return &options[opt_idx].flags;  } -static void redraw_titles(void);  /*   * Redraw the window title and/or tab page text later. @@ -7572,7 +7521,6 @@ typedef struct {  } langmap_entry_T;  static garray_T langmap_mapga; -static void langmap_set_entry(int from, int to);  /*   * Search for an entry in "langmap_mapga" for "from".  If found set the "to" diff --git a/src/nvim/option.h b/src/nvim/option.h index cf0214c5c8..fd1f7f8d42 100644 --- a/src/nvim/option.h +++ b/src/nvim/option.h @@ -1,81 +1,7 @@  #ifndef NVIM_OPTION_H  #define NVIM_OPTION_H -#include <stdint.h> - -/* option.c */ -void set_init_1(void); -void set_string_default(char *name, char_u *val); -void set_number_default(char *name, long val); -void free_all_options(void); -void set_init_2(void); -void set_init_3(void); -void set_helplang_default(char_u *lang); -void set_title_defaults(void); -int do_set(char_u *arg, int opt_flags); -void set_options_bin(int oldval, int newval, int opt_flags); -int get_viminfo_parameter(int type); -char_u *find_viminfo_parameter(int type); -void check_options(void); -void check_buf_options(buf_T *buf); -void free_string_option(char_u *p); -void clear_string_option(char_u **pp); -void set_term_option_alloced(char_u **p); -int was_set_insecurely(char_u *opt, int opt_flags); -void set_string_option_direct(char_u *name, int opt_idx, char_u *val, -                                      int opt_flags, -                                      int set_sid); -char_u *check_colorcolumn(win_T *wp); -char_u *check_stl_option(char_u *s); -int get_option_value(char_u *name, long *numval, char_u **stringval, -                             int opt_flags); -int get_option_value_strict(char *name, -                            int64_t *numval, -                            char **stringval, -                            int opt_type, -                            void *from); -char_u *option_iter_next(void **option, int opt_type); -char_u *set_option_value(char_u *name, long number, char_u *string, -                                 int opt_flags); -char_u *get_term_code(char_u *tname); -char_u *get_highlight_default(void); -char_u *get_encoding_default(void); -int makeset(FILE *fd, int opt_flags, int local_only); -int makefoldset(FILE *fd); -void clear_termoptions(void); -void free_termoptions(void); -void free_one_termoption(char_u *var); -void set_term_defaults(void); -void comp_col(void); -void unset_global_local_option(char *name, void *from); -char_u *get_equalprg(void); -void win_copy_options(win_T *wp_from, win_T *wp_to); -void copy_winopt(winopt_T *from, winopt_T *to); -void check_win_options(win_T *win); -void check_winopt(winopt_T *wop); -void clear_winopt(winopt_T *wop); -void buf_copy_options(buf_T *buf, int flags); -void reset_modifiable(void); -void set_iminsert_global(void); -void set_imsearch_global(void); -void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags); -int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, -                           char_u ***file); -int ExpandOldSetting(int *num_file, char_u ***file); -int langmap_adjust_mb(int c); -int has_format_option(int x); -int shortmess(int x); -void vimrc_found(char_u *fname, char_u *envname); -void change_compatible(int on); -int option_was_set(char_u *name); -void reset_option_was_set(char_u *name); -int can_bs(int what); -void save_file_ff(buf_T *buf); -int file_ff_differs(buf_T *buf, int ignore_empty); -int check_ff_value(char_u *p); -long get_sw_value(buf_T *buf); -long get_sts_value(void); -void find_mps_values(int *initc, int *findc, int *backwards, -                             int switchit); - -#endif /* NVIM_OPTION_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "option.h.generated.h" +#endif +#endif  // NVIM_OPTION_H diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c index 6fd7cdbb7e..9a692cf9fe 100644 --- a/src/nvim/os/channel.c +++ b/src/nvim/os/channel.c @@ -38,17 +38,11 @@ static PMap(uint64_t) *channels = NULL;  static PMap(cstr_t) *event_strings = NULL;  static msgpack_sbuffer msgpack_event_buffer; -static void job_out(RStream *rstream, void *data, bool eof); -static void job_err(RStream *rstream, void *data, bool eof); -static void parse_msgpack(RStream *rstream, void *data, bool eof); -static void send_event(Channel *channel, char *type, typval_T *data); -static void broadcast_event(char *type, typval_T *data); -static void unsubscribe(Channel *channel, char *event); -static void close_channel(Channel *channel); -static void close_cb(uv_handle_t *handle); -static WBuffer *serialize_event(char *type, typval_T *data); -static Channel *register_channel(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/channel.c.generated.h" +#endif +/// Initializes the module  void channel_init()  {    channels = pmap_new(uint64_t)(); @@ -56,6 +50,7 @@ void channel_init()    msgpack_sbuffer_init(&msgpack_event_buffer);  } +/// Teardown the module  void channel_teardown()  {    if (!channels) { @@ -69,6 +64,10 @@ void channel_teardown()    });  } +/// Creates an API channel by starting a job and connecting to its +/// stdin/stdout. stderr is forwarded to the editor error stream. +/// +/// @param argv The argument vector for the process  void channel_from_job(char **argv)  {    Channel *channel = register_channel(); @@ -76,6 +75,10 @@ void channel_from_job(char **argv)    channel->data.job_id = job_start(argv, channel, job_out, job_err, NULL);  } +/// Creates an API channel from a libuv stream representing a tcp or +/// pipe/socket client connection +/// +/// @param stream The established connection  void channel_from_stream(uv_stream_t *stream)  {    Channel *channel = register_channel(); @@ -91,6 +94,13 @@ void channel_from_stream(uv_stream_t *stream)    channel->data.streams.uv = stream;  } +/// Sends event/data to channel +/// +/// @param id The channel id. If 0, the event will be sent to all +///        channels that have subscribed to the event type +/// @param type The event type, an arbitrary string +/// @param obj The event data +/// @return True if the data was sent successfully, false otherwise.  bool channel_send_event(uint64_t id, char *type, typval_T *data)  {    Channel *channel = NULL; @@ -107,6 +117,10 @@ bool channel_send_event(uint64_t id, char *type, typval_T *data)    return true;  } +/// Subscribes to event broadcasts +/// +/// @param id The channel id +/// @param event The event type string  void channel_subscribe(uint64_t id, char *event)  {    Channel *channel; @@ -125,6 +139,10 @@ void channel_subscribe(uint64_t id, char *event)    pmap_put(cstr_t)(channel->subscribed_events, event_string, event_string);  } +/// Unsubscribes to event broadcasts +/// +/// @param id The channel id +/// @param event The event type string  void channel_unsubscribe(uint64_t id, char *event)  {    Channel *channel; diff --git a/src/nvim/os/channel.h b/src/nvim/os/channel.h index b88cd2445f..240461d22e 100644 --- a/src/nvim/os/channel.h +++ b/src/nvim/os/channel.h @@ -2,49 +2,13 @@  #define NVIM_OS_CHANNEL_H  #include <uv.h> +#include <msgpack.h>  #include "nvim/vim.h"  #define EVENT_MAXLEN 512 -/// Initializes the module -void channel_init(void); - -/// Teardown the module -void channel_teardown(void); - -/// Creates an API channel from a libuv stream representing a tcp or -/// pipe/socket client connection -/// -/// @param stream The established connection -void channel_from_stream(uv_stream_t *stream); - -/// Creates an API channel by starting a job and connecting to its -/// stdin/stdout. stderr is forwarded to the editor error stream. -/// -/// @param argv The argument vector for the process -void channel_from_job(char **argv); - -/// Sends event/data to channel -/// -/// @param id The channel id. If 0, the event will be sent to all -///        channels that have subscribed to the event type -/// @param type The event type, an arbitrary string -/// @param obj The event data -/// @return True if the data was sent successfully, false otherwise. -bool channel_send_event(uint64_t id, char *type, typval_T *data); - -/// Subscribes to event broadcasts -/// -/// @param id The channel id -/// @param event The event type string -void channel_subscribe(uint64_t id, char *event); - -/// Unsubscribes to event broadcasts -/// -/// @param id The channel id -/// @param event The event type string -void channel_unsubscribe(uint64_t id, char *event); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/channel.h.generated.h" +#endif  #endif  // NVIM_OS_CHANNEL_H - diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index e7cfb8b176..6d20028c05 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -51,6 +51,9 @@ char *os_getenvname_at_index(size_t index)  } +/// Get the process ID of the Neovim process. +/// +/// @return the process ID.  int64_t os_get_pid()  {  #ifdef _WIN32 @@ -60,6 +63,10 @@ int64_t os_get_pid()  #endif  } +/// Get the hostname of the machine runing Neovim. +/// +/// @param hostname Buffer to store the hostname. +/// @param len Length of `hostname`.  void os_get_hostname(char *hostname, size_t len)  {  #ifdef HAVE_SYS_UTSNAME_H diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c index a89dcdc2ed..cdf40541d5 100644 --- a/src/nvim/os/event.c +++ b/src/nvim/os/event.c @@ -4,7 +4,6 @@  #include <uv.h> -#include "nvim/lib/klist.h"  #include "nvim/os/event.h"  #include "nvim/os/input.h"  #include "nvim/os/channel.h" @@ -16,15 +15,18 @@  #include "nvim/memory.h"  #include "nvim/misc2.h" +#include "nvim/lib/klist.h" +  // event will be cleaned up after it gets processed  #define _destroy_event(x)  // do nothing  KLIST_INIT(Event, Event, _destroy_event) +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/event.c.generated.h" +#endif  static klist_t(Event) *event_queue;  static uv_timer_t timer;  static uv_prepare_t timer_prepare; -static void timer_cb(uv_timer_t *handle); -static void timer_prepare_cb(uv_prepare_t *);  void event_init()  { diff --git a/src/nvim/os/event.h b/src/nvim/os/event.h index 345ddba27e..29e304adc8 100644 --- a/src/nvim/os/event.h +++ b/src/nvim/os/event.h @@ -7,12 +7,7 @@  #include "nvim/os/event_defs.h"  #include "nvim/os/job_defs.h" -void event_init(void); -void event_teardown(void); -bool event_poll(int32_t ms); -bool event_is_pending(void); -void event_push(Event event); -void event_process(void); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/event.h.generated.h" +#endif  #endif  // NVIM_OS_EVENT_H - diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 861e1b46c5..bdf20f22eb 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -8,13 +8,18 @@  #include "nvim/path.h"  #include "nvim/strings.h" -static bool is_executable(const char_u *name); -static bool is_executable_in_path(const char_u *name); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/fs.c.generated.h" +#endif  // Many fs functions from libuv return that value on success.  static const int kLibuvSuccess = 0; -int os_chdir(const char *path) { +/// Change to the given directory. +/// +/// @return `0` on success, a libuv error code on failure. +int os_chdir(const char *path) +{    if (p_verbose >= 5) {      verbose_enter();      smsg((char_u *)"chdir(%s)", path); @@ -23,6 +28,11 @@ int os_chdir(const char *path) {    return uv_chdir(path);  } +/// Get the name of current directory. +/// +/// @param buf Buffer to store the directory name. +/// @param len Length of `buf`. +/// @return `OK` for success, `FAIL` for failure.  int os_dirname(char_u *buf, size_t len)  {    assert(buf && len); @@ -35,6 +45,9 @@ int os_dirname(char_u *buf, size_t len)    return OK;  } +/// Check if the given path is a directory or not. +/// +/// @return `true` if `fname` is a directory.  bool os_isdir(const char_u *name)  {    int32_t mode = os_getperm(name); @@ -49,6 +62,14 @@ bool os_isdir(const char_u *name)    return true;  } +/// Check if the given path represents an executable file. +/// +/// @return `true` if `name` is executable and +///   - can be found in $PATH, +///   - is relative to current dir or +///   - is absolute. +/// +/// @return `false` otherwise.  bool os_can_exe(const char_u *name)  {    // If it's an absolute or relative path don't need to use $PATH. @@ -125,6 +146,9 @@ static bool is_executable_in_path(const char_u *name)    return false;  } +/// Get stat information for a file. +/// +/// @return OK on success, FAIL if an failure occured.  int os_stat(const char_u *name, uv_stat_t *statbuf)  {    uv_fs_t request; @@ -140,6 +164,9 @@ int os_stat(const char_u *name, uv_stat_t *statbuf)    return FAIL;  } +/// Get the file permissions for a given file. +/// +/// @return `-1` when `name` doesn't exist.  int32_t os_getperm(const char_u *name)  {    uv_stat_t statbuf; @@ -150,6 +177,9 @@ int32_t os_getperm(const char_u *name)    }  } +/// Set the permission of a file. +/// +/// @return `OK` for success, `FAIL` for failure.  int os_setperm(const char_u *name, int perm)  {    uv_fs_t request; @@ -164,6 +194,9 @@ int os_setperm(const char_u *name, int perm)    return FAIL;  } +/// Check if a file exists. +/// +/// @return `true` if `name` exists.  bool os_file_exists(const char_u *name)  {    uv_stat_t statbuf; @@ -174,11 +207,19 @@ bool os_file_exists(const char_u *name)    return false;  } +/// Check if a file is readonly. +/// +/// @return `true` if `name` is readonly.  bool os_file_is_readonly(const char *name)  {    return access(name, W_OK) != 0;  } +/// Check if a file is writable. +/// +/// @return `0` if `name` is not writable, +/// @return `1` if `name` is writable, +/// @return `2` for a directory which we have rights to write into.  int os_file_is_writable(const char *name)  {    if (access(name, W_OK) == 0) { @@ -190,6 +231,10 @@ int os_file_is_writable(const char *name)    return 0;  } +/// Get the size of a file in bytes. +/// +/// @param[out] size pointer to an off_t to put the size into. +/// @return `true` for success, `false` for failure.  bool os_get_file_size(const char *name, off_t *size)  {    uv_stat_t statbuf; @@ -200,6 +245,9 @@ bool os_get_file_size(const char *name, off_t *size)    return false;  } +/// Rename a file or directory. +/// +/// @return `OK` for success, `FAIL` for failure.  int os_rename(const char_u *path, const char_u *new_path)  {    uv_fs_t request; @@ -214,6 +262,9 @@ int os_rename(const char_u *path, const char_u *new_path)    return FAIL;  } +/// Make a directory. +/// +/// @return `0` for success, non-zero for failure.  int os_mkdir(const char *path, int32_t mode)  {    uv_fs_t request; @@ -222,6 +273,9 @@ int os_mkdir(const char *path, int32_t mode)    return result;  } +/// Remove a directory. +/// +/// @return `0` for success, non-zero for failure.  int os_rmdir(const char *path)  {    uv_fs_t request; @@ -230,6 +284,9 @@ int os_rmdir(const char *path)    return result;  } +/// Remove a file. +/// +/// @return `0` for success, non-zero for failure.  int os_remove(const char *path)  {    uv_fs_t request; @@ -238,6 +295,11 @@ int os_remove(const char *path)    return result;  } +/// Get the file information for a given path +/// +/// @param file_descriptor File descriptor of the file. +/// @param[out] file_info Pointer to a FileInfo to put the information in. +/// @return `true` on sucess, `false` for failure.  bool os_get_file_info(const char *path, FileInfo *file_info)  {    if (os_stat((char_u *)path, &(file_info->stat)) == OK) { @@ -246,6 +308,11 @@ bool os_get_file_info(const char *path, FileInfo *file_info)    return false;  } +/// Get the file information for a given path without following links +/// +/// @param path Path to the file. +/// @param[out] file_info Pointer to a FileInfo to put the information in. +/// @return `true` on sucess, `false` for failure.  bool os_get_file_info_link(const char *path, FileInfo *file_info)  {    uv_fs_t request; @@ -258,6 +325,11 @@ bool os_get_file_info_link(const char *path, FileInfo *file_info)    return false;  } +/// Get the file information for a given file descriptor +/// +/// @param file_descriptor File descriptor of the file. +/// @param[out] file_info Pointer to a FileInfo to put the information in. +/// @return `true` on sucess, `false` for failure.  bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info)  {    uv_fs_t request; @@ -270,9 +342,11 @@ bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info)    return false;  } +/// Compare the inodes of two FileInfos +/// +/// @return `true` if the two FileInfos represent the same file.  bool os_file_info_id_equal(FileInfo *file_info_1, FileInfo *file_info_2)  {    return file_info_1->stat.st_ino == file_info_2->stat.st_ino           && file_info_1->stat.st_dev == file_info_2->stat.st_dev;  } - diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index a673a6c8b8..3e9751a4db 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -25,12 +25,11 @@ typedef enum {  static RStream *read_stream;  static bool eof = false, started_reading = false; -static InbufPollResult inbuf_poll(int32_t ms); -static void stderr_switch(void); -static void read_cb(RStream *rstream, void *data, bool eof); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/input.c.generated.h" +#endif  // Helper function used to push bytes from the 'event' key sequence partially  // between calls to os_inchar when maxlen < 3 -static int push_event_key(uint8_t *buf, int maxlen);  void input_init()  { @@ -124,6 +123,10 @@ void os_breakcheck()      fill_input_buf(false);  } +/// Test whether a file descriptor refers to a terminal. +/// +/// @param fd File descriptor. +/// @return `true` if file descriptor refers to a terminal.  bool os_isatty(int fd)  {      return uv_guess_handle(fd) == UV_TTY; diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h index 298df04578..7543950b4f 100644 --- a/src/nvim/os/input.h +++ b/src/nvim/os/input.h @@ -4,20 +4,7 @@  #include <stdint.h>  #include <stdbool.h> -void input_init(void); -bool input_ready(void); -void input_start(void); -void input_stop(void); -uint32_t input_read(char *buf, uint32_t count); -int os_inchar(uint8_t *, int, int32_t, int); -bool os_char_avail(void); -void os_breakcheck(void); - -/// Test whether a file descriptor refers to a terminal. -/// -/// @param fd File descriptor. -/// @return `true` if file descriptor refers to a terminal. -bool os_isatty(int fd); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/input.h.generated.h" +#endif  #endif  // NVIM_OS_INPUT_H - diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index c4a9c85d1d..f9f94158ae 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -58,23 +58,20 @@ static uint32_t job_count = 0;  static uv_prepare_t job_prepare;  // Some helpers shared in this module -static bool is_alive(Job *job); -static Job * find_job(int id); -static void free_job(Job *job); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/job.c.generated.h" +#endif  // Callbacks for libuv -static void job_prepare_cb(uv_prepare_t *handle); -static void read_cb(RStream *rstream, void *data, bool eof); -static void exit_cb(uv_process_t *proc, int64_t status, int term_signal); -static void close_cb(uv_handle_t *handle); -static void emit_exit_event(Job *job); +/// Initializes job control resources  void job_init()  {    uv_disable_stdio_inheritance();    uv_prepare_init(uv_default_loop(), &job_prepare);  } +/// Releases job control resources and terminates running jobs  void job_teardown()  {    // 20 tries will give processes about 1 sec to exit cleanly @@ -121,6 +118,19 @@ void job_teardown()    }  } +/// Tries to start a new job. +/// +/// @param argv Argument vector for the process. The first item is the +///        executable to run. +/// @param data Caller data that will be associated with the job +/// @param stdout_cb Callback that will be invoked when data is available +///        on stdout +/// @param stderr_cb Callback that will be invoked when data is available +///        on stderr +/// @param exit_cb Callback that will be invoked when the job exits +/// @return The job id if the job started successfully. If the the first item / +///         of `argv`(the program) could not be executed, -1 will be returned. +//          0 will be returned if the job table is full.  int job_start(char **argv,                void *data,                rstream_cb stdout_cb, @@ -212,6 +222,12 @@ int job_start(char **argv,    return job->id;  } +/// Terminates a job. This is a non-blocking operation, but if the job exists +/// it's guaranteed to succeed(SIGKILL will eventually be sent) +/// +/// @param id The job id +/// @return true if the stop request was successfully sent, false if the job +///              id is invalid(probably because it has already stopped)  bool job_stop(int id)  {    Job *job = find_job(id); @@ -225,6 +241,14 @@ bool job_stop(int id)    return true;  } +/// Writes data to the job's stdin. This is a non-blocking operation, it +/// returns when the write request was sent. +/// +/// @param id The job id +/// @param data Buffer containing the data to be written +/// @param len Size of the data +/// @return true if the write request was successfully sent, false if the job +///              id is invalid(probably because it has already stopped)  bool job_write(int id, char *data, uint32_t len)  {    Job *job = find_job(id); @@ -242,6 +266,9 @@ bool job_write(int id, char *data, uint32_t len)    return true;  } +/// Runs the read callback associated with the job exit event +/// +/// @param event Object containing data necessary to invoke the callback  void job_exit_event(Event event)  {    Job *job = event.data.job; @@ -265,11 +292,19 @@ void job_exit_event(Event event)    }  } +/// Get the job id +/// +/// @param job A pointer to the job +/// @return The job id  int job_id(Job *job)  {    return job->id;  } +/// Get data associated with a job +/// +/// @param job A pointer to the job +/// @return The job data  void *job_data(Job *job)  {    return job->data; diff --git a/src/nvim/os/job.h b/src/nvim/os/job.h index 4ddbc75807..f48218ffe7 100644 --- a/src/nvim/os/job.h +++ b/src/nvim/os/job.h @@ -10,69 +10,10 @@  #include <stdint.h>  #include <stdbool.h> -#include "nvim/os/event_defs.h"  #include "nvim/os/rstream_defs.h" +#include "nvim/os/event_defs.h" -/// Initializes job control resources -void job_init(void); - -/// Releases job control resources and terminates running jobs -void job_teardown(void); - -/// Tries to start a new job. -/// -/// @param argv Argument vector for the process. The first item is the -///        executable to run. -/// @param data Caller data that will be associated with the job -/// @param stdout_cb Callback that will be invoked when data is available -///        on stdout -/// @param stderr_cb Callback that will be invoked when data is available -///        on stderr -/// @param exit_cb Callback that will be invoked when the job exits. This is -///        optional. -/// @return The job id if the job started successfully. If the the first item / -///         of `argv`(the program) could not be executed, -1 will be returned. -//          0 will be returned if the job table is full. -int job_start(char **argv, -              void *data, -              rstream_cb stdout_cb, -              rstream_cb stderr_cb, -              job_exit_cb exit_cb); - -/// Terminates a job. This is a non-blocking operation, but if the job exists -/// it's guaranteed to succeed(SIGKILL will eventually be sent) -/// -/// @param id The job id -/// @return true if the stop request was successfully sent, false if the job -///              id is invalid(probably because it has already stopped) -bool job_stop(int id); - -/// Writes data to the job's stdin. This is a non-blocking operation, it -/// returns when the write request was sent. -/// -/// @param id The job id -/// @param data Buffer containing the data to be written -/// @param len Size of the data -/// @return true if the write request was successfully sent, false if the job -///              id is invalid(probably because it has already stopped) -bool job_write(int id, char *data, uint32_t len); - -/// Runs the read callback associated with the job exit event -/// -/// @param event Object containing data necessary to invoke the callback -void job_exit_event(Event event); - -/// Get the job id -/// -/// @param job A pointer to the job -/// @return The job id -int job_id(Job *job); - -/// Get data associated with a job -/// -/// @param job A pointer to the job -/// @return The job data -void *job_data(Job *job); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/job.h.generated.h" +#endif  #endif  // NVIM_OS_JOB_H - diff --git a/src/nvim/os/job_defs.h b/src/nvim/os/job_defs.h index 8e4dc0cd88..a9caa169a8 100644 --- a/src/nvim/os/job_defs.h +++ b/src/nvim/os/job_defs.h @@ -12,4 +12,3 @@ typedef struct job Job;  typedef void (*job_exit_cb)(Job *job, void *data);  #endif  // NVIM_OS_JOB_DEFS_H - diff --git a/src/nvim/os/mem.c b/src/nvim/os/mem.c index 6c8b49d04e..5e483c0c3d 100644 --- a/src/nvim/os/mem.c +++ b/src/nvim/os/mem.c @@ -4,7 +4,9 @@  #include "nvim/os/os.h" -uint64_t os_get_total_mem_kib(void) { +/// Get the total system physical memory in KiB. +uint64_t os_get_total_mem_kib(void) +{    // Convert bytes to KiB.    return uv_get_total_memory() >> 10;  } diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index fa040d29bd..5dd498e3dc 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -4,143 +4,16 @@  #include "nvim/vim.h" -/// Change to the given directory. -/// -/// @return `0` on success, a libuv error code on failure. -int os_chdir(const char *path); - -/// Get the name of current directory. -/// -/// @param buf Buffer to store the directory name. -/// @param len Length of `buf`. -/// @return `OK` for success, `FAIL` for failure. -int os_dirname(char_u *buf, size_t len); - -/// Check if the given path is a directory or not. -/// -/// @return `true` if `fname` is a directory. -bool os_isdir(const char_u *name); - -/// Check if the given path represents an executable file. -/// -/// @return `true` if `name` is executable and -///   - can be found in $PATH, -///   - is relative to current dir or -///   - is absolute. -/// -/// @return `false` otherwise. -bool os_can_exe(const char_u *name); - -/// Get the file permissions for a given file. -/// -/// @return `-1` when `name` doesn't exist. -int32_t os_getperm(const char_u *name); - -/// Set the permission of a file. -/// -/// @return `OK` for success, `FAIL` for failure. -int os_setperm(const char_u *name, int perm); - -/// Check if a file exists. -/// -/// @return `true` if `name` exists. -bool os_file_exists(const char_u *name); - -/// Check if a file is readonly. -/// -/// @return `true` if `name` is readonly. -bool os_file_is_readonly(const char *name); - -/// Check if a file is writable. -/// -/// @return `0` if `name` is not writable, -/// @return `1` if `name` is writable, -/// @return `2` for a directory which we have rights to write into. -int os_file_is_writable(const char *name); - -/// Get the size of a file in bytes. -/// -/// @param[out] size pointer to an off_t to put the size into. -/// @return `true` for success, `false` for failure. -bool os_get_file_size(const char *name, off_t *size); - -/// Rename a file or directory. -/// -/// @return `OK` for success, `FAIL` for failure. -int os_rename(const char_u *path, const char_u *new_path); - -/// Make a directory. -/// -/// @return `0` for success, non-zero for failure. -int os_mkdir(const char *path, int32_t mode); - -/// Remove a directory. -/// -/// @return `0` for success, non-zero for failure. -int os_rmdir(const char *path); - -/// Remove a file. -/// -/// @return `0` for success, non-zero for failure. -int os_remove(const char *path); - -/// Get the total system physical memory in KiB. -uint64_t os_get_total_mem_kib(void); -const char *os_getenv(const char *name); -int os_setenv(const char *name, const char *value, int overwrite); -char *os_getenvname_at_index(size_t index); - -/// Get the process ID of the Neovim process. -/// -/// @return the process ID. -int64_t os_get_pid(void); - -/// Get the hostname of the machine runing Neovim. -/// -/// @param hostname Buffer to store the hostname. -/// @param len Length of `hostname`. -void os_get_hostname(char *hostname, size_t len); - -int os_get_usernames(garray_T *usernames); -int os_get_user_name(char *s, size_t len); -int os_get_uname(uid_t uid, char *s, size_t len); -char *os_get_user_directory(const char *name); - -/// Get stat information for a file. -/// -/// @return OK on success, FAIL if an failure occured. -int os_stat(const char_u *name, uv_stat_t *statbuf); -  /// Struct which encapsulates stat information.  typedef struct {    // TODO(stefan991): make stat private    uv_stat_t stat;  } FileInfo; -/// Get the file information for a given path -/// -/// @param file_descriptor File descriptor of the file. -/// @param[out] file_info Pointer to a FileInfo to put the information in. -/// @return `true` on sucess, `false` for failure. -bool os_get_file_info(const char *path, FileInfo *file_info); - -/// Get the file information for a given path without following links -/// -/// @param path Path to the file. -/// @param[out] file_info Pointer to a FileInfo to put the information in. -/// @return `true` on sucess, `false` for failure. -bool os_get_file_info_link(const char *path, FileInfo *file_info); - -/// Get the file information for a given file descriptor -/// -/// @param file_descriptor File descriptor of the file. -/// @param[out] file_info Pointer to a FileInfo to put the information in. -/// @return `true` on sucess, `false` for failure. -bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info); - -/// Compare the inodes of two FileInfos -/// -/// @return `true` if the two FileInfos represent the same file. -bool os_file_info_id_equal(FileInfo *file_info_1, FileInfo *file_info_2); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/fs.h.generated.h" +# include "os/mem.h.generated.h" +# include "os/env.h.generated.h" +# include "os/users.h.generated.h" +#endif  #endif  // NVIM_OS_OS_H diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 4e6fc55d3b..9b2cea52a5 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -27,13 +27,22 @@ struct rstream {    bool reading, free_handle, async;  }; -// Callbacks used by libuv -static void alloc_cb(uv_handle_t *, size_t, uv_buf_t *); -static void read_cb(uv_stream_t *, ssize_t, const uv_buf_t *); -static void fread_idle_cb(uv_idle_t *); -static void close_cb(uv_handle_t *handle); -static void emit_read_event(RStream *rstream, bool eof); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/rstream.c.generated.h" +#endif + +/// Creates a new RStream instance. A RStream encapsulates all the boilerplate +/// necessary for reading from a libuv stream. +/// +/// @param cb A function that will be called whenever some data is available +///        for reading with `rstream_read` +/// @param buffer_size Size in bytes of the internal buffer. +/// @param data Some state to associate with the `RStream` instance +/// @param async Flag that specifies if the callback should only be called +///        outside libuv event loop(When processing async events with +///        KE_EVENT). Only the RStream instance reading user input should set +///        this to false +/// @return The newly-allocated `RStream` instance  RStream * rstream_new(rstream_cb cb,                        size_t buffer_size,                        void *data, @@ -54,6 +63,9 @@ RStream * rstream_new(rstream_cb cb,    return rv;  } +/// Frees all memory allocated for a RStream instance +/// +/// @param rstream The `RStream` instance  void rstream_free(RStream *rstream)  {    if (rstream->free_handle) { @@ -68,12 +80,21 @@ void rstream_free(RStream *rstream)    free(rstream);  } +/// Sets the underlying `uv_stream_t` instance +/// +/// @param rstream The `RStream` instance +/// @param stream The new `uv_stream_t` instance  void rstream_set_stream(RStream *rstream, uv_stream_t *stream)  {    handle_set_rstream((uv_handle_t *)stream, rstream);    rstream->stream = stream;  } +/// Sets the underlying file descriptor that will be read from. Only pipes +/// and regular files are supported for now. +/// +/// @param rstream The `RStream` instance +/// @param file The file descriptor  void rstream_set_file(RStream *rstream, uv_file file)  {    rstream->file_type = uv_guess_handle(file); @@ -111,11 +132,18 @@ void rstream_set_file(RStream *rstream, uv_file file)    rstream->free_handle = true;  } +/// Tests if the stream is backed by a regular file +/// +/// @param rstream The `RStream` instance +/// @return True if the underlying file descriptor represents a regular file  bool rstream_is_regular_file(RStream *rstream)  {    return rstream->file_type == UV_FILE;  } +/// Starts watching for events from a `RStream` instance. +/// +/// @param rstream The `RStream` instance  void rstream_start(RStream *rstream)  {    if (rstream->file_type == UV_FILE) { @@ -126,6 +154,9 @@ void rstream_start(RStream *rstream)    }  } +/// Stops watching for events from a `RStream` instance. +/// +/// @param rstream The `RStream` instance  void rstream_stop(RStream *rstream)  {    if (rstream->file_type == UV_FILE) { @@ -135,6 +166,12 @@ void rstream_stop(RStream *rstream)    }  } +/// Reads data from a `RStream` instance into a buffer. +/// +/// @param rstream The `RStream` instance +/// @param buffer The buffer which will receive the data +/// @param count Number of bytes that `buffer` can accept +/// @return The number of bytes copied into `buffer`  size_t rstream_read(RStream *rstream, char *buf, size_t count)  {    size_t read_count = rstream->wpos - rstream->rpos; @@ -167,11 +204,18 @@ size_t rstream_read(RStream *rstream, char *buf, size_t count)    return read_count;  } +/// Returns the number of bytes available for reading from `rstream` +/// +/// @param rstream The `RStream` instance +/// @return The number of bytes available  size_t rstream_available(RStream *rstream)  {    return rstream->wpos - rstream->rpos;  } +/// Runs the read callback associated with the rstream +/// +/// @param event Object containing data necessary to invoke the callback  void rstream_read_event(Event event)  {    RStream *rstream = event.data.rstream.ptr; @@ -179,6 +223,8 @@ void rstream_read_event(Event event)    rstream->cb(rstream, rstream->data, event.data.rstream.eof);  } +// Callbacks used by libuv +  // Called by libuv to allocate memory for reading.  static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)  { diff --git a/src/nvim/os/rstream.h b/src/nvim/os/rstream.h index 5afa864f04..713d1e77e6 100644 --- a/src/nvim/os/rstream.h +++ b/src/nvim/os/rstream.h @@ -4,79 +4,11 @@  #include <stdbool.h>  #include <stdint.h>  #include <uv.h> -  #include "nvim/os/event_defs.h" -#include "nvim/os/rstream_defs.h" - -/// Creates a new RStream instance. A RStream encapsulates all the boilerplate -/// necessary for reading from a libuv stream. -/// -/// @param cb A function that will be called whenever some data is available -///        for reading with `rstream_read` -/// @param buffer_size Size in bytes of the internal buffer. -/// @param data Some state to associate with the `RStream` instance -/// @param async Flag that specifies if the callback should only be called -///        outside libuv event loop(When processing async events with -///        KE_EVENT). Only the RStream instance reading user input should set -///        this to false -/// @return The newly-allocated `RStream` instance -RStream * rstream_new(rstream_cb cb, -                      size_t buffer_size, -                      void *data, -                      bool async); - -/// Frees all memory allocated for a RStream instance -/// -/// @param rstream The `RStream` instance -void rstream_free(RStream *rstream); - -/// Sets the underlying `uv_stream_t` instance -/// -/// @param rstream The `RStream` instance -/// @param stream The new `uv_stream_t` instance -void rstream_set_stream(RStream *rstream, uv_stream_t *stream); - -/// Sets the underlying file descriptor that will be read from. Only pipes -/// and regular files are supported for now. -/// -/// @param rstream The `RStream` instance -/// @param file The file descriptor -void rstream_set_file(RStream *rstream, uv_file file); - -/// Tests if the stream is backed by a regular file -/// -/// @param rstream The `RStream` instance -/// @return True if the underlying file descriptor represents a regular file -bool rstream_is_regular_file(RStream *rstream); -/// Starts watching for events from a `RStream` instance. -/// -/// @param rstream The `RStream` instance -void rstream_start(RStream *rstream); - -/// Stops watching for events from a `RStream` instance. -/// -/// @param rstream The `RStream` instance -void rstream_stop(RStream *rstream); - -/// Reads data from a `RStream` instance into a buffer. -/// -/// @param rstream The `RStream` instance -/// @param buffer The buffer which will receive the data -/// @param count Number of bytes that `buffer` can accept -/// @return The number of bytes copied into `buffer` -size_t rstream_read(RStream *rstream, char *buffer, size_t count); - -/// Returns the number of bytes available for reading from `rstream` -/// -/// @param rstream The `RStream` instance -/// @return The number of bytes available -size_t rstream_available(RStream *rstream); - -/// Runs the read callback associated with the rstream -/// -/// @param event Object containing data necessary to invoke the callback -void rstream_read_event(Event event); +#include "nvim/os/rstream_defs.h" +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/rstream.h.generated.h" +#endif  #endif  // NVIM_OS_RSTREAM_H - diff --git a/src/nvim/os/server.c b/src/nvim/os/server.c index 4aac2babc6..b5d8d8af64 100644 --- a/src/nvim/os/server.c +++ b/src/nvim/os/server.c @@ -42,10 +42,11 @@ typedef struct {  static PMap(cstr_t) *servers = NULL; -static void connection_cb(uv_stream_t *server, int status); -static void free_client(uv_handle_t *handle); -static void free_server(uv_handle_t *handle); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/server.c.generated.h" +#endif +/// Initializes the module  void server_init()  {    servers = pmap_new(cstr_t)(); @@ -59,6 +60,7 @@ void server_init()    server_start((char *)os_getenv("NEOVIM_LISTEN_ADDRESS"));  } +/// Teardown the server module  void server_teardown()  {    if (!servers) { @@ -76,6 +78,15 @@ void server_teardown()    });  } +/// Starts listening on arbitrary tcp/unix addresses specified by +/// `endpoint` for API calls. The type of socket used(tcp or unix/pipe) will +/// be determined by parsing `endpoint`: If it's a valid tcp address in the +/// 'ip:port' format, then it will be tcp socket, else it will be a unix +/// socket or named pipe. +/// +/// @param endpoint Address of the server. Either a 'ip:port' string or an +///        arbitrary identifier(trimmed to 256 bytes) for the unix socket or +///        named pipe.  void server_start(char *endpoint)  {    char addr[ADDRESS_MAX_SIZE]; @@ -175,6 +186,9 @@ void server_start(char *endpoint)    pmap_put(cstr_t)(servers, addr, server);  } +/// Stops listening on the address specified by `endpoint`. +/// +/// @param endpoint Address of the server.  void server_stop(char *endpoint)  {    Server *server; diff --git a/src/nvim/os/server.h b/src/nvim/os/server.h index f6270b42e9..43592a91e4 100644 --- a/src/nvim/os/server.h +++ b/src/nvim/os/server.h @@ -1,27 +1,7 @@  #ifndef NVIM_OS_SERVER_H  #define NVIM_OS_SERVER_H -/// Initializes the module -void server_init(); - -/// Teardown the server module -void server_teardown(); - -/// Starts listening on arbitrary tcp/unix addresses specified by -/// `endpoint` for API calls. The type of socket used(tcp or unix/pipe) will -/// be determined by parsing `endpoint`: If it's a valid tcp address in the -/// 'ip:port' format, then it will be tcp socket, else it will be a unix -/// socket or named pipe. -/// -/// @param endpoint Address of the server. Either a 'ip:port' string or an -///        arbitrary identifier(trimmed to 256 bytes) for the unix socket or -///        named pipe. -void server_start(char *endpoint); - -/// Stops listening on the address specified by `endpoint`. -/// -/// @param endpoint Address of the server. -void server_stop(char *endpoint); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/server.h.generated.h" +#endif  #endif  // NVIM_OS_SERVER_H - diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 8e49f8f2bb..766b055450 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -31,42 +31,22 @@ typedef struct {    garray_T ga;  } ProcessData; -/// Parses a command string into a sequence of words, taking quotes into -/// consideration. -/// -/// @param str The command string to be parsed -/// @param argv The vector that will be filled with copies of the parsed -///        words. It can be NULL if the caller only needs to count words. -/// @return The number of words parsed. -static int tokenize(char_u *str, char **argv); -/// Calculates the length of a shell word. -/// -/// @param str A pointer to the first character of the word -/// @return The offset from `str` at which the word ends. -static int word_length(char_u *command); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/shell.c.generated.h" +#endif -/// Queues selected range for writing to the child process stdin. -/// -/// @param req The structure containing information to peform the write -static void write_selection(uv_write_t *req); -/// Cleanup memory and restore state modified by `os_call_shell`. -/// -/// @param data State shared by all functions collaborating with -///        `os_call_shell`. -/// @param opts Process spawning options, containing some allocated memory -/// @param shellopts Options passed to `os_call_shell`. Used for deciding -///        if/which messages are displayed. -static int proc_cleanup_exit(ProcessData *data, -                             uv_process_options_t *opts, -                             int shellopts);  // Callbacks for libuv -static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf); -static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf); -static void write_cb(uv_write_t *req, int status); -static void exit_cb(uv_process_t *proc, int64_t status, int term_signal); +/// Builds the argument vector for running the shell configured in `sh` +/// ('shell' option), optionally with a command that will be passed with `shcf` +/// ('shellcmdflag'). +/// +/// @param cmd Command string. If NULL it will run an interactive shell. +/// @param extra_shell_opt Extra argument to the shell. If NULL it is ignored +/// @return A newly allocated argument vector. It must be freed with +///         `shell_free_argv` when no longer needed.  char ** shell_build_argv(char_u *cmd, char_u *extra_shell_opt)  {    int i; @@ -94,6 +74,9 @@ char ** shell_build_argv(char_u *cmd, char_u *extra_shell_opt)    return rv;  } +/// Releases the memory allocated by `shell_build_argv`. +/// +/// @param argv The argument vector.  void shell_free_argv(char **argv)  {    char **p = argv; @@ -112,6 +95,13 @@ void shell_free_argv(char **argv)    free(argv);  } +/// Calls the user shell for running a command, interactive session or +/// wildcard expansion. It uses the shell set in the `sh` option. +/// +/// @param cmd The command to be executed. If NULL it will run an interactive +///        shell +/// @param opts Various options that control how the shell will work +/// @param extra_shell_arg Extra argument to be passed to the shell  int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)  {    uv_stdio_container_t proc_stdio[3]; @@ -247,6 +237,13 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)    return proc_cleanup_exit(&pdata, &proc_opts, opts);  } +/// Parses a command string into a sequence of words, taking quotes into +/// consideration. +/// +/// @param str The command string to be parsed +/// @param argv The vector that will be filled with copies of the parsed +///        words. It can be NULL if the caller only needs to count words. +/// @return The number of words parsed.  static int tokenize(char_u *str, char **argv)  {    int argc = 0, len; @@ -270,6 +267,10 @@ static int tokenize(char_u *str, char **argv)    return argc;  } +/// Calculates the length of a shell word. +/// +/// @param str A pointer to the first character of the word +/// @return The offset from `str` at which the word ends.  static int word_length(char_u *str)  {    char_u *p = str; @@ -296,6 +297,9 @@ static int word_length(char_u *str)  /// event loop starts. If we don't(by writing in chunks returned by `ml_get`)  /// the buffer being modified might get modified by reading from the process  /// before we finish writing. +/// Queues selected range for writing to the child process stdin. +/// +/// @param req The structure containing information to peform the write  static void write_selection(uv_write_t *req)  {    ProcessData *pdata = (ProcessData *)req->data; @@ -429,6 +433,13 @@ static void write_cb(uv_write_t *req, int status)    pdata->exited++;  } +/// Cleanup memory and restore state modified by `os_call_shell`. +/// +/// @param data State shared by all functions collaborating with +///        `os_call_shell`. +/// @param opts Process spawning options, containing some allocated memory +/// @param shellopts Options passed to `os_call_shell`. Used for deciding +///        if/which messages are displayed.  static int proc_cleanup_exit(ProcessData *proc_data,                               uv_process_options_t *proc_opts,                               int shellopts) diff --git a/src/nvim/os/shell.h b/src/nvim/os/shell.h index 226ef97579..e912baedf8 100644 --- a/src/nvim/os/shell.h +++ b/src/nvim/os/shell.h @@ -2,7 +2,6 @@  #define NVIM_OS_SHELL_H  #include <stdbool.h> -  #include "nvim/types.h"  // Flags for mch_call_shell() second argument @@ -17,29 +16,7 @@ typedef enum {    kShellOptHideMess = 128,  ///< previously a global variable from os_unix.c  } ShellOpts; -/// Builds the argument vector for running the shell configured in `sh` -/// ('shell' option), optionally with a command that will be passed with `shcf` -/// ('shellcmdflag'). -/// -/// @param cmd Command string. If NULL it will run an interactive shell. -/// @param extra_shell_opt Extra argument to the shell. If NULL it is ignored -/// @return A newly allocated argument vector. It must be freed with -///         `shell_free_argv` when no longer needed. -char ** shell_build_argv(char_u *cmd, char_u *extra_shell_arg); - -/// Releases the memory allocated by `shell_build_argv`. -/// -/// @param argv The argument vector. -void shell_free_argv(char **argv); - -/// Calls the user shell for running a command, interactive session or -/// wildcard expansion. It uses the shell set in the `sh` option. -/// -/// @param cmd The command to be executed. If NULL it will run an interactive -///        shell -/// @param opts Various options that control how the shell will work -/// @param extra_shell_arg Extra argument to be passed to the shell -int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/shell.h.generated.h" +#endif  #endif  // NVIM_OS_SHELL_H - diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 68a455c5a2..85aa8ae5cb 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -21,10 +21,10 @@ static uv_signal_t spwr;  #endif  static bool rejecting_deadly; -static char * signal_name(int signum); -static void deadly_signal(int signum); -static void signal_cb(uv_signal_t *, int signum); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/signal.c.generated.h" +#endif  void signal_init()  {    uv_signal_init(uv_default_loop(), &sint); diff --git a/src/nvim/os/signal.h b/src/nvim/os/signal.h index 6a0ad5e9ac..927437b2db 100644 --- a/src/nvim/os/signal.h +++ b/src/nvim/os/signal.h @@ -3,11 +3,7 @@  #include "nvim/os/event_defs.h" -void signal_init(void); -void signal_stop(void); -void signal_accept_deadly(void); -void signal_reject_deadly(void); -void signal_handle(Event event); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/signal.h.generated.h" +#endif  #endif  // NVIM_OS_SIGNAL_H - diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 2a607de36d..977a4f19c4 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -11,19 +11,30 @@  static uv_mutex_t delay_mutex;  static uv_cond_t delay_cond; -static void microdelay(uint64_t ms); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/time.c.generated.h" +#endif +/// Initializes the time module  void time_init()  {    uv_mutex_init(&delay_mutex);    uv_cond_init(&delay_cond);  } +/// Sleeps for a certain amount of milliseconds +/// +/// @param milliseconds Number of milliseconds to sleep +/// @param ignoreinput If true, allow a SIGINT to interrupt us  void os_delay(uint64_t milliseconds, bool ignoreinput)  {    os_microdelay(milliseconds * 1000, ignoreinput);  } +/// Sleeps for a certain amount of microseconds +/// +/// @param microseconds Number of microseconds to sleep +/// @param ignoreinput If true, allow a SIGINT to interrupt us  void os_microdelay(uint64_t microseconds, bool ignoreinput)  {    int old_tmode; @@ -61,6 +72,9 @@ static void microdelay(uint64_t microseconds)    uv_mutex_unlock(&delay_mutex);  } +/// Portable version of POSIX localtime_r() +/// +/// @return NULL in case of error  struct tm *os_localtime_r(const time_t *clock, struct tm *result)  {  #ifdef UNIX @@ -75,6 +89,11 @@ return result;  #endif  } +/// Obtains the current UNIX timestamp and adjusts it to local time +/// +/// @param result Pointer to a 'struct tm' where the result should be placed +/// @return A pointer to a 'struct tm' in the current time zone (the 'result' +///         argument) or NULL in case of error  struct tm *os_get_localtime(struct tm *result)  {    struct timeval tv; diff --git a/src/nvim/os/time.h b/src/nvim/os/time.h index 02fd77551e..8c73fc0c3b 100644 --- a/src/nvim/os/time.h +++ b/src/nvim/os/time.h @@ -4,32 +4,7 @@  #include <stdint.h>  #include <stdbool.h> -/// Initializes the time module -void time_init(void); - -/// Sleeps for a certain amount of milliseconds -/// -/// @param milliseconds Number of milliseconds to sleep -/// @param ignoreinput If true, allow a SIGINT to interrupt us -void os_delay(uint64_t milliseconds, bool ignoreinput); - -/// Sleeps for a certain amount of microseconds -/// -/// @param microseconds Number of microseconds to sleep -/// @param ignoreinput If true, allow a SIGINT to interrupt us -void os_microdelay(uint64_t microseconds, bool ignoreinput); - -/// Portable version of POSIX localtime_r() -/// -/// @return NULL in case of error -struct tm *os_localtime_r(const time_t *clock, struct tm *result); - -/// Obtains the current UNIX timestamp and adjusts it to local time -/// -/// @param result Pointer to a 'struct tm' where the result should be placed -/// @return A pointer to a 'struct tm' in the current time zone (the 'result' -///         argument) or NULL in case of error -struct tm *os_get_localtime(struct tm *result); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/time.h.generated.h" +#endif  #endif  // NVIM_OS_TIME_H - diff --git a/src/nvim/os/uv_helpers.c b/src/nvim/os/uv_helpers.c index f8371c04c2..a3c9dd5fbf 100644 --- a/src/nvim/os/uv_helpers.c +++ b/src/nvim/os/uv_helpers.c @@ -13,8 +13,15 @@ typedef struct {    Job *job;  } HandleData; -static HandleData *init(uv_handle_t *handle); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/uv_helpers.c.generated.h" +#endif + +/// Gets the RStream instance associated with a libuv handle +/// +/// @param handle libuv handle +/// @return the RStream pointer  RStream *handle_get_rstream(uv_handle_t *handle)  {    RStream *rv = init(handle)->rstream; @@ -22,11 +29,19 @@ RStream *handle_get_rstream(uv_handle_t *handle)    return rv;  } +/// Associates a RStream instance with a libuv handle +/// +/// @param handle libuv handle +/// @param rstream the RStream pointer  void handle_set_rstream(uv_handle_t *handle, RStream *rstream)  {    init(handle)->rstream = rstream;  } +/// Gets the WStream instance associated with a libuv handle +/// +/// @param handle libuv handle +/// @return the WStream pointer  WStream *handle_get_wstream(uv_handle_t *handle)  {    WStream *rv = init(handle)->wstream; @@ -34,12 +49,20 @@ WStream *handle_get_wstream(uv_handle_t *handle)    return rv;  } +/// Associates a WStream instance with a libuv handle +/// +/// @param handle libuv handle +/// @param wstream the WStream pointer  void handle_set_wstream(uv_handle_t *handle, WStream *wstream)  {    HandleData *data = init(handle);    data->wstream = wstream;  } +/// Gets the Job instance associated with a libuv handle +/// +/// @param handle libuv handle +/// @return the Job pointer  Job *handle_get_job(uv_handle_t *handle)  {    Job *rv = init(handle)->job; @@ -47,6 +70,10 @@ Job *handle_get_job(uv_handle_t *handle)    return rv;  } +/// Associates a Job instance with a libuv handle +/// +/// @param handle libuv handle +/// @param job the Job pointer  void handle_set_job(uv_handle_t *handle, Job *job)  {    init(handle)->job = job; diff --git a/src/nvim/os/uv_helpers.h b/src/nvim/os/uv_helpers.h index 03fd64457f..b49656bcb8 100644 --- a/src/nvim/os/uv_helpers.h +++ b/src/nvim/os/uv_helpers.h @@ -7,41 +7,7 @@  #include "nvim/os/rstream_defs.h"  #include "nvim/os/job_defs.h" -/// Gets the RStream instance associated with a libuv handle -/// -/// @param handle libuv handle -/// @return the RStream pointer -RStream *handle_get_rstream(uv_handle_t *handle); - -/// Associates a RStream instance with a libuv handle -/// -/// @param handle libuv handle -/// @param rstream the RStream pointer -void handle_set_rstream(uv_handle_t *handle, RStream *rstream); - -/// Gets the WStream instance associated with a libuv handle -/// -/// @param handle libuv handle -/// @return the WStream pointer -WStream *handle_get_wstream(uv_handle_t *handle); - -/// Associates a WStream instance with a libuv handle -/// -/// @param handle libuv handle -/// @param wstream the WStream pointer -void handle_set_wstream(uv_handle_t *handle, WStream *wstream); - -/// Gets the Job instance associated with a libuv handle -/// -/// @param handle libuv handle -/// @return the Job pointer -Job *handle_get_job(uv_handle_t *handle); - -/// Associates a Job instance with a libuv handle -/// -/// @param handle libuv handle -/// @param job the Job pointer -void handle_set_job(uv_handle_t *handle, Job *job); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/uv_helpers.h.generated.h" +#endif  #endif  // NVIM_OS_UV_HELPERS_H - diff --git a/src/nvim/os/wstream.c b/src/nvim/os/wstream.c index 57afdd0e8f..c2ed05b78f 100644 --- a/src/nvim/os/wstream.c +++ b/src/nvim/os/wstream.c @@ -30,8 +30,16 @@ typedef struct {    WBuffer *buffer;  } WriteData; -static void write_cb(uv_write_t *req, int status); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/wstream.c.generated.h" +#endif + +/// Creates a new WStream instance. A WStream encapsulates all the boilerplate +/// necessary for writing to a libuv stream. +/// +/// @param maxmem Maximum amount memory used by this `WStream` instance. +/// @return The newly-allocated `WStream` instance  WStream * wstream_new(size_t maxmem)  {    WStream *rv = xmalloc(sizeof(WStream)); @@ -44,6 +52,9 @@ WStream * wstream_new(size_t maxmem)    return rv;  } +/// Frees all memory allocated for a WStream instance +/// +/// @param wstream The `WStream` instance  void wstream_free(WStream *wstream)  {    if (!wstream->pending_reqs) { @@ -53,12 +64,23 @@ void wstream_free(WStream *wstream)    }  } +/// Sets the underlying `uv_stream_t` instance +/// +/// @param wstream The `WStream` instance +/// @param stream The new `uv_stream_t` instance  void wstream_set_stream(WStream *wstream, uv_stream_t *stream)  {    handle_set_wstream((uv_handle_t *)stream, wstream);    wstream->stream = stream;  } +/// Queues data for writing to the backing file descriptor of a `WStream` +/// instance. This will fail if the write would cause the WStream use more +/// memory than specified by `maxmem`. +/// +/// @param wstream The `WStream` instance +/// @param buffer The buffer which contains data to be written +/// @return false if the write failed  bool wstream_write(WStream *wstream, WBuffer *buffer)  {    WriteData *data; @@ -87,6 +109,15 @@ bool wstream_write(WStream *wstream, WBuffer *buffer)    return true;  } +/// Creates a WBuffer object for holding output data. Instances of this +/// object can be reused across WStream instances, and the memory is freed +/// automatically when no longer needed(it tracks the number of references +/// internally) +/// +/// @param data Data stored by the WBuffer +/// @param size The size of the data array +/// @param copy If true, the data will be copied into the WBuffer +/// @return The allocated WBuffer instance  WBuffer *wstream_new_buffer(char *data, size_t size, bool copy)  {    WBuffer *rv = xmalloc(sizeof(WBuffer)); diff --git a/src/nvim/os/wstream.h b/src/nvim/os/wstream.h index 1f61f6afd0..d0e9bef93a 100644 --- a/src/nvim/os/wstream.h +++ b/src/nvim/os/wstream.h @@ -7,43 +7,7 @@  #include "nvim/os/wstream_defs.h" -/// Creates a new WStream instance. A WStream encapsulates all the boilerplate -/// necessary for writing to a libuv stream. -/// -/// @param maxmem Maximum amount memory used by this `WStream` instance. -/// @return The newly-allocated `WStream` instance -WStream * wstream_new(size_t maxmem); - -/// Frees all memory allocated for a WStream instance -/// -/// @param wstream The `WStream` instance -void wstream_free(WStream *wstream); - -/// Sets the underlying `uv_stream_t` instance -/// -/// @param wstream The `WStream` instance -/// @param stream The new `uv_stream_t` instance -void wstream_set_stream(WStream *wstream, uv_stream_t *stream); - -/// Queues data for writing to the backing file descriptor of a `WStream` -/// instance. This will fail if the write would cause the WStream use more -/// memory than specified by `maxmem`. -/// -/// @param wstream The `WStream` instance -/// @param buffer The buffer which contains data to be written -/// @return false if the write failed -bool wstream_write(WStream *wstream, WBuffer *buffer); - -/// Creates a WBuffer object for holding output data. Instances of this -/// object can be reused across WStream instances, and the memory is freed -/// automatically when no longer needed(it tracks the number of references -/// internally) -/// -/// @param data Data stored by the WBuffer -/// @param size The size of the data array -/// @param copy If true, the data will be copied into the WBuffer -/// @return The allocated WBuffer instance -WBuffer *wstream_new_buffer(char *data, size_t size, bool copy); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/wstream.h.generated.h" +#endif  #endif  // NVIM_OS_WSTREAM_H - diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index e0b838ed26..5471a2216f 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -80,19 +80,16 @@  static int selinux_enabled = -1;  #endif -static int get_x11_title(int); -static int get_x11_icon(int); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os_unix.c.generated.h" +#endif  static char_u   *oldtitle = NULL;  static int did_set_title = FALSE;  static char_u   *oldicon = NULL;  static int did_set_icon = FALSE; -static int have_wildcard(int, char_u **); -static int have_dollars(int, char_u **); -static void save_patterns(int num_pat, char_u **pat, int *num_file, -                          char_u ***file);  /*   * Write s[len] to the screen. @@ -381,7 +378,7 @@ int vim_is_fastterm(char_u *name)   */  void fname_case(  char_u      *name, -int len;              /* buffer size, only used when name gets longer */ +int len               /* buffer size, only used when name gets longer */  )  {    struct stat st; @@ -555,7 +552,6 @@ void mch_free_mem()          {  #endif -static void exit_scroll(void);  /*   * Output a newline when exiting. @@ -773,8 +769,7 @@ void get_stty()  /*   * Set mouse clicks on or off.   */ -void mch_setmouse(on) -int on; +void mch_setmouse(int on)  {    static int ison = FALSE;    int xterm_mouse_vers; @@ -1010,12 +1005,10 @@ void mch_set_shellsize()  #define SHELL_SPECIAL (char_u *)"\t \"&'$;<>()\\|" -int mch_expand_wildcards(num_pat, pat, num_file, file, flags) -int num_pat; -char_u       **pat; -int           *num_file; -char_u      ***file; -int flags;                      /* EW_* flags */ +int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, +                         char_u ***file, +                         int flags /* EW_* flags */ +                         )  {    int i;    size_t len; @@ -1426,11 +1419,8 @@ notfound:  } -static void save_patterns(num_pat, pat, num_file, file) -int num_pat; -char_u      **pat; -int         *num_file; -char_u      ***file; +static void save_patterns(int num_pat, char_u **pat, int *num_file, +                          char_u ***file)  {    int i;    char_u      *s; @@ -1451,8 +1441,7 @@ char_u      ***file;   * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can   * expand.   */ -int mch_has_exp_wildcard(p) -char_u  *p; +int mch_has_exp_wildcard(char_u *p)  {    for (; *p; mb_ptr_adv(p)) {      if (*p == '\\' && p[1] != NUL) @@ -1469,8 +1458,7 @@ char_u  *p;   * Return TRUE if the string "p" contains a wildcard.   * Don't recognize '~' at the end as a wildcard.   */ -int mch_has_wildcard(p) -char_u  *p; +int mch_has_wildcard(char_u *p)  {    for (; *p; mb_ptr_adv(p)) {      if (*p == '\\' && p[1] != NUL) @@ -1484,9 +1472,7 @@ char_u  *p;    return FALSE;  } -static int have_wildcard(num, file) -int num; -char_u  **file; +static int have_wildcard(int num, char_u **file)  {    int i; @@ -1496,9 +1482,7 @@ char_u  **file;    return 0;  } -static int have_dollars(num, file) -int num; -char_u  **file; +static int have_dollars(int num, char_u **file)  {    int i; @@ -1518,14 +1502,12 @@ typedef int (*INTPROCINT)(int);   * Call a DLL routine which takes either a string or int param   * and returns an allocated string.   */ -int mch_libcall(libname, funcname, argstring, argint, string_result, -    number_result) -char_u      *libname; -char_u      *funcname; -char_u      *argstring;         /* NULL when using a argint */ -int argint; -char_u      **string_result;    /* NULL when using number_result */ -int         *number_result; +int mch_libcall(char_u *libname, +                char_u *funcname, +                char_u *argstring,         /* NULL when using a argint */ +                int argint, +                char_u **string_result,    /* NULL when using number_result */ +                int *number_result)  {  # if defined(USE_DLOPEN)    void        *hinstLib; diff --git a/src/nvim/os_unix.h b/src/nvim/os_unix.h index 0180677717..3c2f1603b3 100644 --- a/src/nvim/os_unix.h +++ b/src/nvim/os_unix.h @@ -3,44 +3,7 @@  #include "nvim/os/shell.h" -/* os_unix.c */ -void mch_write(char_u *s, int len); -void mch_suspend(void); -void mch_init(void); -int mch_can_restore_title(void); -int mch_can_restore_icon(void); -void mch_settitle(char_u *title, char_u *icon); -void mch_restore_title(int which); -int vim_is_xterm(char_u *name); -int use_xterm_like_mouse(char_u *name); -int use_xterm_mouse(void); -int vim_is_iris(char_u *name); -int vim_is_vt300(char_u *name); -int vim_is_fastterm(char_u *name); -void slash_adjust(char_u *p); -void fname_case(char_u *name, int len); -void mch_copy_sec(char_u *from_file, char_u *to_file); -vim_acl_T mch_get_acl(char_u *fname); -void mch_set_acl(char_u *fname, vim_acl_T aclent); -void mch_free_acl(vim_acl_T aclent); -void mch_hide(char_u *name); -int mch_nodetype(char_u *name); -void mch_early_init(void); -void mch_free_mem(void); -void mch_exit(int r); -void mch_settmode(int tmode); -void get_stty(void); -void mch_setmouse(int on); -void check_mouse_termcode(void); -int mch_get_shellsize(void); -void mch_set_shellsize(void); -int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, -                         char_u ***file, -                         int flags); -int mch_has_exp_wildcard(char_u *p); -int mch_has_wildcard(char_u *p); -int mch_libcall(char_u *libname, char_u *funcname, char_u *argstring, -                int argint, char_u **string_result, -                int *number_result); - -#endif /* NVIM_OS_UNIX_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os_unix.h.generated.h" +#endif +#endif  // NVIM_OS_UNIX_H diff --git a/src/nvim/path.c b/src/nvim/path.c index 1222b97fd6..3edadeebef 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -31,8 +31,21 @@  #define URL_SLASH       1               /* path_is_url() has found "://" */  #define URL_BACKSLASH   2               /* path_is_url() has found ":\\" */ -static int path_get_absolute_path(char_u *fname, char_u *buf, int len, int force); +#ifdef gen_expand_wildcards +# undef gen_expand_wildcards +#endif + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "path.c.generated.h" +#endif +/// Compare two file names. +/// +/// @param s1 First file name. Environment variables in this name will be +///   expanded. +/// @param s2 Second file name. +/// @param checkname When both files don't exist, only compare their names. +/// @return Enum of type FileComparison. @see FileComparison.  FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)  {    assert(s1 && s2); @@ -64,6 +77,14 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)    return kDifferentFiles;  } +/// Get the tail of a path: the file name. +/// +/// @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.  char_u *path_tail(char_u *fname)  {    if (fname == NULL) { @@ -82,6 +103,15 @@ char_u *path_tail(char_u *fname)    return tail;  } +/// Get pointer to tail of "fname", including path separators. +/// +/// Takes care of "c:/" and "//". That means `path_tail_with_sep("dir///file.txt")` +/// will return a pointer to `"///file.txt"`. +/// @param fname A file path. (Must be != NULL.) +/// @return +///   - Pointer to the last path separator of `fname`, if there is any. +///   - `fname` if it contains no path separator. +///   - Never NULL.  char_u *path_tail_with_sep(char_u *fname)  {    assert(fname != NULL); @@ -95,6 +125,11 @@ char_u *path_tail_with_sep(char_u *fname)    return tail;  } +/// Get the next path component of a path name. +/// +/// @param fname A file path. (Must be != NULL.) +/// @return Pointer to first found path separator + 1. +/// An empty string, if `fname` doesn't contain a path separator,  char_u *path_next_component(char_u *fname)  {    assert(fname != NULL); @@ -269,6 +304,7 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len)   * Only add a '/' or '\\' when 'sep' is TRUE and it is necessary.   */  char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep) +  FUNC_ATTR_NONNULL_RET  {    char_u *dest = xmalloc(STRLEN(fname1) + STRLEN(fname2) + 3); @@ -321,17 +357,11 @@ FullName_save (  #if !defined(NO_EXPANDPATH) || defined(PROTO) -static int vim_backtick(char_u *p); -static int expand_backtick(garray_T *gap, char_u *pat, int flags); - -  #if defined(UNIX) || defined(USE_UNIXFILENAME) || defined(PROTO)  /*   * Unix style wildcard expansion code.   * It's here because it's used both for Unix and Mac.   */ -static int pstrcmp(const void *, const void *); -  static int pstrcmp(const void *a, const void *b)  {    return pathcmp(*(char **)a, *(char **)b, -1); @@ -532,13 +562,6 @@ unix_expandpath (  }  #endif -static int find_previous_pathsep(char_u *path, char_u **psep); -static int is_unique(char_u *maybe_unique, garray_T *gap, int i); -static void expand_path_option(char_u *curdir, garray_T *gap); -static char_u *get_path_cutoff(char_u *fname, garray_T *gap); -static void uniquefy_paths(garray_T *gap, char_u *pattern); -static int expand_in_path(garray_T *gap, char_u *pattern, int flags); -  /*   * Moves "*psep" back to the previous path separator in "path".   * Returns FAIL is "*psep" ends up at the beginning of "path". @@ -688,8 +711,6 @@ static char_u *get_path_cutoff(char_u *fname, garray_T *gap)    return cutoff;  } -static char_u *gettail_dir(char_u *fname); -  /*   * Sorts, removes duplicates and modifies all the fullpath names in "gap" so   * that they are unique with respect to each other while conserving the part @@ -921,8 +942,6 @@ expand_in_path (  } -static int has_env_var(char_u *p); -  /*   * Return TRUE if "p" contains what looks like an environment variable.   * Allowing for escaping. @@ -941,8 +960,6 @@ static int has_env_var(char_u *p)  }  #ifdef SPECIAL_WILDCHAR -static int has_special_wildchar(char_u *p); -  /*   * Return TRUE if "p" contains a special wildcard character.   * Allowing for escaping. @@ -1384,8 +1401,6 @@ void simplify_filename(char_u *filename)    } while (*p != NUL);  } -static char_u *eval_includeexpr(char_u *ptr, int len); -  static char_u *eval_includeexpr(char_u *ptr, int len)  {    char_u      *res; @@ -1668,16 +1683,23 @@ int pathcmp(const char *p, const char *q, int maxlen)   * "?", "[a-z]", "**", etc.   * "path" has backslashes before chars that are not to be expanded.   * Returns the number of matches found. + * + * Uses EW_* flags   */ -int mch_expandpath(gap, path, flags) -garray_T    *gap; -char_u      *path; -int flags;                      /* EW_* flags */ +int mch_expandpath(garray_T *gap, char_u *path, int flags)  {    return unix_expandpath(gap, path, 0, flags, FALSE);  }  #endif +/// Try to find a shortname by comparing the fullname with the current +/// directory. +/// +/// @param full_path The full path of the file. +/// @return +///   - Pointer into `full_path` if shortened. +///   - `full_path` unchanged if no shorter name is possible. +///   - NULL if `full_path` is NULL.  char_u *path_shorten_fname_if_possible(char_u *full_path)  {    char_u *dirname = xmalloc(MAXPATHL); @@ -1693,6 +1715,13 @@ char_u *path_shorten_fname_if_possible(char_u *full_path)    return p;  } +/// Try to find a shortname by comparing the fullname with `dir_name`. +/// +/// @param full_path The full path of the file. +/// @param dir_name The directory to shorten relative to. +/// @return +///   - Pointer into `full_path` if shortened. +///   - NULL if no shorter name is possible.  char_u *path_shorten_fname(char_u *full_path, char_u *dir_name)  {    if (full_path == NULL) { @@ -1711,18 +1740,18 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name)    return p + 1;  } -/* - * Invoke expand_wildcards() for one pattern. - * Expand items like "%:h" before the expansion. - * Returns OK or FAIL. - */ -int  -expand_wildcards_eval ( -    char_u **pat,             /* pointer to input pattern */ -    int *num_file,        /* resulting number of files */ -    char_u ***file,            /* array of resulting files */ -    int flags                      /* EW_DIR, etc. */ -) +/// Invoke expand_wildcards() for one pattern +/// +/// One should expand items like "%:h" before the expansion. +/// +/// @param[in]   pat       Pointer to the input pattern. +/// @param[out]  num_file  Resulting number of files. +/// @param[out]  file      Array of resulting files. +/// @param[in]   flags     Flags passed to expand_wildcards(). +/// +/// @return OK or FAIL. +int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file, +                          int flags)  {    int ret = FAIL;    char_u      *eval_pat = NULL; @@ -1853,6 +1882,10 @@ int match_suffix(char_u *fname)    return setsuflen != 0;  } +/// Get the absolute name of the given relative directory. +/// +/// @param directory Directory name, relative to current directory. +/// @return `FAIL` for failure, `OK` for success.  int path_full_dir_name(char *directory, char *buffer, int len)  {    int SUCCESS = 0; @@ -1894,6 +1927,7 @@ int path_full_dir_name(char *directory, char *buffer, int len)  }  // Append to_append to path with a slash in between. +// Append to_append to path with a slash in between.  int append_path(char *path, const char *to_append, int max_len)  {    int current_length = STRLEN(path); @@ -1963,6 +1997,10 @@ static int path_get_absolute_path(char_u *fname, char_u *buf, int len, int force    return append_path((char *) buf, (char *) end_of_path, len);  } +/// Check if the given file is absolute. +/// +/// This just checks if the file name starts with '/' or '~'. +/// @return `TRUE` if "fname" is absolute.  int path_is_absolute_path(const char_u *fname)  {    return *fname == '/' || *fname == '~'; diff --git a/src/nvim/path.h b/src/nvim/path.h index 9272922c8a..4ea1e978a6 100644 --- a/src/nvim/path.h +++ b/src/nvim/path.h @@ -14,115 +14,7 @@ typedef enum file_comparison {    kEqualFileNames = 7     ///< Both don't exist and file names are same.  } FileComparison; -/// Compare two file names. -/// -/// @param s1 First file name. Environment variables in this name will be -///   expanded. -/// @param s2 Second file name. -/// @param checkname When both files don't exist, only compare their names. -/// @return Enum of type FileComparison. @see FileComparison. -FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname); - -/// Get the tail of a path: the file name. -/// -/// @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. -char_u *path_tail(char_u *fname); - -/// Get pointer to tail of "fname", including path separators. -/// -/// Takes care of "c:/" and "//". That means `path_tail_with_sep("dir///file.txt")` -/// will return a pointer to `"///file.txt"`. -/// @param fname A file path. (Must be != NULL.) -/// @return -///   - Pointer to the last path separator of `fname`, if there is any. -///   - `fname` if it contains no path separator. -///   - Never NULL. -char_u *path_tail_with_sep(char_u *fname); - -/// Get the next path component of a path name. -/// -/// @param fname A file path. (Must be != NULL.) -/// @return Pointer to first found path separator + 1. -/// An empty string, if `fname` doesn't contain a path separator, -char_u *path_next_component(char_u *fname); - -int vim_ispathsep(int c); -int vim_ispathsep_nocolon(int c); -int vim_ispathlistsep(int c); -void shorten_dir(char_u *str); -int dir_of_file_exists(char_u *fname); -int vim_fnamecmp(char_u *x, char_u *y); -int vim_fnamencmp(char_u *x, char_u *y, size_t len); -char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep) -  FUNC_ATTR_NONNULL_RET; -int unix_expandpath(garray_T *gap, char_u *path, int wildoff, int flags, -                    int didstar); -int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, -                         char_u ***file, -                         int flags); -void addfile(garray_T *gap, char_u *f, int flags); -char_u *get_past_head(char_u *path); -char_u *concat_str(char_u *str1, char_u *str2) FUNC_ATTR_NONNULL_RET; -void add_pathsep(char_u *p); -char_u *FullName_save(char_u *fname, int force); -void simplify_filename(char_u *filename); -char_u *find_file_name_in_path(char_u *ptr, int len, int options, -                               long count, -                               char_u *rel_fname); -int path_is_url(char_u *p); -int path_with_url(char_u *fname); -int vim_isAbsName(char_u *name); -int vim_FullName(char_u *fname, char_u *buf, int len, int force); -char_u *fix_fname(char_u *fname); -int after_pathsep(char_u *b, char_u *p); -int same_directory(char_u *f1, char_u *f2); -int pathcmp(const char *p, const char *q, int maxlen); -int mch_expandpath(garray_T *gap, char_u *path, int flags); - -/// Try to find a shortname by comparing the fullname with the current -/// directory. -/// -/// @param full_path The full path of the file. -/// @return -///   - Pointer into `full_path` if shortened. -///   - `full_path` unchanged if no shorter name is possible. -///   - NULL if `full_path` is NULL. -char_u *path_shorten_fname_if_possible(char_u *full_path); - -/// Try to find a shortname by comparing the fullname with `dir_name`. -/// -/// @param full_path The full path of the file. -/// @param dir_name The directory to shorten relative to. -/// @return -///   - Pointer into `full_path` if shortened. -///   - NULL if no shorter name is possible. -char_u *path_shorten_fname(char_u *full_path, char_u *dir_name); - -int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file, -                          int flags); -int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u * -                     **file, -                     int flags); -int match_suffix(char_u *fname); - -/// Get the absolute name of the given relative directory. -/// -/// @param directory Directory name, relative to current directory. -/// @return `FAIL` for failure, `OK` for success. -int path_full_dir_name(char *directory, char *buffer, int len); - -// Append to_append to path with a slash in between. -int append_path(char *path, const char *to_append, int max_len); - -/// Check if the given file is absolute. -/// -/// This just checks if the file name starts with '/' or '~'. -/// @return `TRUE` if "fname" is absolute. -int path_is_absolute_path(const char_u *fname); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "path.h.generated.h" +#endif  #endif diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 4c31e9e0ae..97db6efe37 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -31,8 +31,10 @@ static int pum_col;                 // left column of pum  static int pum_do_redraw = FALSE;   // do redraw anyway -static int pum_set_selected(int n, int repeat); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "popupmnu.c.generated.h" +#endif  #define PUM_DEF_HEIGHT 10  #define PUM_DEF_WIDTH  15 diff --git a/src/nvim/popupmnu.h b/src/nvim/popupmnu.h index 0607e93622..2b181f2c4a 100644 --- a/src/nvim/popupmnu.h +++ b/src/nvim/popupmnu.h @@ -9,11 +9,8 @@ typedef struct {    char_u *pum_info;        // extra info  } pumitem_T; -void pum_display(pumitem_T *array, int size, int selected); -void pum_redraw(void); -void pum_undisplay(void); -void pum_clear(void); -int pum_visible(void); -int pum_get_height(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "popupmnu.h.generated.h" +#endif  #endif  // NVIM_POPUPMNU_H diff --git a/src/nvim/pos.h b/src/nvim/pos.h index dd647e52e4..11f62ad480 100644 --- a/src/nvim/pos.h +++ b/src/nvim/pos.h @@ -20,4 +20,4 @@ typedef struct {    colnr_T col;          /* column number */  } lpos_T; -#endif /* NVIM_POS_H */ +#endif  // NVIM_POS_H diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index cba6b5f94d..775b6e717e 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -134,43 +134,10 @@ struct efm_S {    int conthere;                 /* %> used */  }; -static int qf_init_ext(qf_info_T *qi, char_u *efile, buf_T *buf, -                       typval_T *tv, char_u *errorformat, int newlist, -                       linenr_T lnumfirst, -                       linenr_T lnumlast, -                       char_u *qf_title); -static void qf_new_list(qf_info_T *qi, char_u *qf_title); -static void ll_free_all(qf_info_T **pqi); -static int qf_add_entry(qf_info_T *qi, qfline_T **prevp, char_u *dir, -                        char_u *fname, int bufnum, char_u *mesg, -                        long lnum, int col, int vis_col, -                        char_u *pattern, int nr, int type, -                        int valid); -static qf_info_T *ll_new_list(void); -static void qf_msg(qf_info_T *qi); -static void qf_free(qf_info_T *qi, int idx); -static char_u   *qf_types(int, int); -static int qf_get_fnum(char_u *, char_u *); -static char_u   *qf_push_dir(char_u *, struct dir_stack_T **); -static char_u   *qf_pop_dir(struct dir_stack_T **); -static char_u   *qf_guess_filepath(char_u *); -static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); -static void qf_clean_dir_stack(struct dir_stack_T **); -static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); -static int is_qf_win(win_T *win, qf_info_T *qi); -static win_T    *qf_find_win(qf_info_T *qi); -static buf_T    *qf_find_buf(qf_info_T *qi); -static void qf_update_buffer(qf_info_T *qi); -static void qf_set_title(qf_info_T *qi); -static void qf_fill_buffer(qf_info_T *qi); -static char_u   *get_mef_name(void); -static void restore_start_dir(char_u *dirname_start); -static buf_T    *load_dummy_buffer(char_u *fname, char_u *dirname_start, -                                           char_u *resulting_dir); -static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); -static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); -static qf_info_T *ll_get_or_alloc_list(win_T *); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "quickfix.c.generated.h" +#endif  /* Quickfix window check helper macro */  #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL)  /* Location list window check helper macro */ diff --git a/src/nvim/quickfix.h b/src/nvim/quickfix.h index b4869ac35c..c3b7d714c7 100644 --- a/src/nvim/quickfix.h +++ b/src/nvim/quickfix.h @@ -1,36 +1,7 @@  #ifndef NVIM_QUICKFIX_H  #define NVIM_QUICKFIX_H -/* quickfix.c */ -int qf_init(win_T *wp, char_u *efile, char_u *errorformat, int newlist, -            char_u *qf_title); -void qf_free_all(win_T *wp); -void copy_loclist(win_T *from, win_T *to); -void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit); -void qf_list(exarg_T *eap); -void qf_age(exarg_T *eap); -void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, -                    long amount, -                    long amount_after); -void ex_cwindow(exarg_T *eap); -void ex_cclose(exarg_T *eap); -void ex_copen(exarg_T *eap); -linenr_T qf_current_entry(win_T *wp); -int bt_quickfix(buf_T *buf); -int bt_nofile(buf_T *buf); -int bt_dontwrite(buf_T *buf); -int bt_dontwrite_msg(buf_T *buf); -int buf_hide(buf_T *buf); -int grep_internal(cmdidx_T cmdidx); -void ex_make(exarg_T *eap); -void ex_cc(exarg_T *eap); -void ex_cnext(exarg_T *eap); -void ex_cfile(exarg_T *eap); -void ex_vimgrep(exarg_T *eap); -char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags); -int get_errorlist(win_T *wp, list_T *list); -int set_errorlist(win_T *wp, list_T *list, int action, char_u *title); -void ex_cbuffer(exarg_T *eap); -void ex_cexpr(exarg_T *eap); -void ex_helpgrep(exarg_T *eap); -#endif /* NVIM_QUICKFIX_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "quickfix.h.generated.h" +#endif +#endif  // NVIM_QUICKFIX_H diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 6f2a522801..8c0652dd01 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -265,9 +265,115 @@  #define un_Magic(x)     ((x) + 256)  #define is_Magic(x)     ((x) < 0) -static int no_Magic(int x); -static int toggle_Magic(int x); +/* + * We should define ftpr as a pointer to a function returning a pointer to + * a function returning a pointer to a function ... + * This is impossible, so we declare a pointer to a function returning a + * pointer to a function returning void. This should work for all compilers. + */ +typedef void (*(*fptr_T)(int *, int))(); + +typedef struct { +  char_u     *regparse; +  int prevchr_len; +  int curchr; +  int prevchr; +  int prevprevchr; +  int nextchr; +  int at_start; +  int prev_at_start; +  int regnpar; +} parse_state_T; + +/* + * Structure used to save the current input state, when it needs to be + * restored after trying a match.  Used by reg_save() and reg_restore(). + * Also stores the length of "backpos". + */ +typedef struct { +  union { +    char_u  *ptr;       /* reginput pointer, for single-line regexp */ +    lpos_T pos;         /* reginput pos, for multi-line regexp */ +  } rs_u; +  int rs_len; +} regsave_T; + +/* struct to save start/end pointer/position in for \(\) */ +typedef struct { +  union { +    char_u  *ptr; +    lpos_T pos; +  } se_u; +} save_se_T; + +/* used for BEHIND and NOBEHIND matching */ +typedef struct regbehind_S { +  regsave_T save_after; +  regsave_T save_behind; +  int save_need_clear_subexpr; +  save_se_T save_start[NSUBEXP]; +  save_se_T save_end[NSUBEXP]; +} regbehind_T; + +/* Values for rs_state in regitem_T. */ +typedef enum regstate_E { +  RS_NOPEN = 0          /* NOPEN and NCLOSE */ +  , RS_MOPEN            /* MOPEN + [0-9] */ +  , RS_MCLOSE           /* MCLOSE + [0-9] */ +  , RS_ZOPEN            /* ZOPEN + [0-9] */ +  , RS_ZCLOSE           /* ZCLOSE + [0-9] */ +  , RS_BRANCH           /* BRANCH */ +  , RS_BRCPLX_MORE      /* BRACE_COMPLEX and trying one more match */ +  , RS_BRCPLX_LONG      /* BRACE_COMPLEX and trying longest match */ +  , RS_BRCPLX_SHORT     /* BRACE_COMPLEX and trying shortest match */ +  , RS_NOMATCH          /* NOMATCH */ +  , RS_BEHIND1          /* BEHIND / NOBEHIND matching rest */ +  , RS_BEHIND2          /* BEHIND / NOBEHIND matching behind part */ +  , RS_STAR_LONG        /* STAR/PLUS/BRACE_SIMPLE longest match */ +  , RS_STAR_SHORT       /* STAR/PLUS/BRACE_SIMPLE shortest match */ +} regstate_T; + +/* + * When there are alternatives a regstate_T is put on the regstack to remember + * what we are doing. + * Before it may be another type of item, depending on rs_state, to remember + * more things. + */ +typedef struct regitem_S { +  regstate_T rs_state;          /* what we are doing, one of RS_ above */ +  char_u      *rs_scan;         /* current node in program */ +  union { +    save_se_T sesave; +    regsave_T regsave; +  } rs_un;                      /* room for saving reginput */ +  short rs_no;                  /* submatch nr or BEHIND/NOBEHIND */ +} regitem_T; + +/* used for STAR, PLUS and BRACE_SIMPLE matching */ +typedef struct regstar_S { +  int nextb;                    /* next byte */ +  int nextb_ic;                 /* next byte reverse case */ +  long count; +  long minval; +  long maxval; +} regstar_T; + +/* used to store input position when a BACK was encountered, so that we now if + * we made any progress since the last time. */ +typedef struct backpos_S { +  char_u      *bp_scan;         /* "scan" where BACK was encountered */ +  regsave_T bp_pos;             /* last input position */ +} backpos_T; + +typedef struct { +  int a, b, c; +} decomp_T; + + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "regexp.c.generated.h" +#endif  static int no_Magic(int x)  {    if (is_Magic(x)) @@ -360,9 +466,6 @@ static int toggle_Magic(int x)  #define MAX_LIMIT       (32767L << 16L) -static int re_multi_type(int); -static int cstrncmp(char_u *s1, char_u *s2, int *n); -static char_u *cstrchr(char_u *, int);  #ifdef BT_REGEXP_DUMP  static void regdump(char_u *, bt_regprog_T *); @@ -433,13 +536,6 @@ static char_u           *reg_prev_sub = NULL;  static char_u REGEXP_INRANGE[] = "]^-n\\";  static char_u REGEXP_ABBR[] = "nrtebdoxuU"; -static int backslash_trans(int c); -static int get_char_class(char_u **pp); -static int get_equi_class(char_u **pp); -static void reg_equi_class(int c); -static int get_coll_element(char_u **pp); -static char_u   *skip_anyof(char_u *p); -static void init_class_tab(void);  /*   * Translate '\x' to its control character, except "\n", which is Magic. @@ -641,54 +737,11 @@ static int nextchr;             /* used for ungetchr() */  #define REG_ZPAREN      2       /* \z(\) */  #define REG_NPAREN      3       /* \%(\) */ -typedef struct { -  char_u     *regparse; -  int prevchr_len; -  int curchr; -  int prevchr; -  int prevprevchr; -  int nextchr; -  int at_start; -  int prev_at_start; -  int regnpar; -} parse_state_T; -  /*   * Forward declarations for vim_regcomp()'s friends.   */ -static void initchr(char_u *); -static void save_parse_state(parse_state_T *ps); -static void restore_parse_state(parse_state_T *ps); -static int getchr(void); -static void skipchr_keepstart(void); -static int peekchr(void); -static void skipchr(void); -static void ungetchr(void); -static int gethexchrs(int maxinputlen); -static int getoctchrs(void); -static int getdecchrs(void); -static int coll_get_char(void); -static void regcomp_start(char_u *expr, int flags); -static char_u   *reg(int, int *); -static char_u   *regbranch(int *flagp); -static char_u   *regconcat(int *flagp); -static char_u   *regpiece(int *); -static char_u   *regatom(int *); -static char_u   *regnode(int); -static int use_multibytecode(int c); -static int prog_magic_wrong(void); -static char_u   *regnext(char_u *); -static void regc(int b); -static void regmbc(int c);  # define REGMBC(x) regmbc(x);  # define CASEMBC(x) case x: -static void reginsert(int, char_u *); -static void reginsert_nr(int op, long val, char_u *opnd); -static void reginsert_limits(int, long, long, char_u *); -static char_u   *re_put_long(char_u *pr, long_u val); -static int read_limits(long *, long *); -static void regtail(char_u *, char_u *); -static void regoptail(char_u *, char_u *);  static regengine_T bt_regengine;  static regengine_T nfa_regengine; @@ -1061,7 +1114,6 @@ static int get_coll_element(char_u **pp)    return 0;  } -static void get_cpo_flags(void);  static int reg_cpo_lit; /* 'cpoptions' contains 'l' flag */  static int reg_cpo_bsl; /* 'cpoptions' contains '\' flag */ @@ -1158,8 +1210,6 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char_u **newp)    return p;  } -static regprog_T  *bt_regcomp(char_u *expr, int re_flags); -static void bt_regfree(regprog_T *prog);  /*   * bt_regcomp() - compile a regular expression into internal code for the @@ -3050,49 +3100,6 @@ static int need_clear_subexpr;          /* subexpressions still need to be  static int need_clear_zsubexpr = FALSE;         /* extmatch subexpressions                                                   * still need to be cleared */ -/* - * Structure used to save the current input state, when it needs to be - * restored after trying a match.  Used by reg_save() and reg_restore(). - * Also stores the length of "backpos". - */ -typedef struct { -  union { -    char_u  *ptr;       /* reginput pointer, for single-line regexp */ -    lpos_T pos;         /* reginput pos, for multi-line regexp */ -  } rs_u; -  int rs_len; -} regsave_T; - -/* struct to save start/end pointer/position in for \(\) */ -typedef struct { -  union { -    char_u  *ptr; -    lpos_T pos; -  } se_u; -} save_se_T; - -/* used for BEHIND and NOBEHIND matching */ -typedef struct regbehind_S { -  regsave_T save_after; -  regsave_T save_behind; -  int save_need_clear_subexpr; -  save_se_T save_start[NSUBEXP]; -  save_se_T save_end[NSUBEXP]; -} regbehind_T; - -static char_u   *reg_getline(linenr_T lnum); -static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm); -static long regtry(bt_regprog_T *prog, colnr_T col); -static void cleanup_subexpr(void); -static void cleanup_zsubexpr(void); -static void save_subexpr(regbehind_T *bp); -static void restore_subexpr(regbehind_T *bp); -static void reg_nextline(void); -static void reg_save(regsave_T *save, garray_T *gap); -static void reg_restore(regsave_T *save, garray_T *gap); -static int reg_save_equal(regsave_T *save); -static void save_se_multi(save_se_T *savep, lpos_T *posp); -static void save_se_one(save_se_T *savep, char_u **pp);  /* Save the sub-expressions before attempting a match. */  #define save_se(savep, posp, pp) \ @@ -3105,12 +3112,6 @@ static void save_se_one(save_se_T *savep, char_u **pp);      else \        *(pp) = (savep)->se_u.ptr; } -static int re_num_cmp(long_u val, char_u *scan); -static int match_with_backref(linenr_T start_lnum, colnr_T start_col, -                              linenr_T end_lnum, colnr_T end_col, -                              int *bytelen); -static int regmatch(char_u *prog); -static int regrepeat(char_u *p, long maxcount);  #ifdef REGEXP_DEBUG  int regnarrate = 0; @@ -3172,59 +3173,6 @@ static linenr_T reg_firstlnum;  static linenr_T reg_maxline;  static int reg_line_lbr;                    /* "\n" in string is line break */ -/* Values for rs_state in regitem_T. */ -typedef enum regstate_E { -  RS_NOPEN = 0          /* NOPEN and NCLOSE */ -  , RS_MOPEN            /* MOPEN + [0-9] */ -  , RS_MCLOSE           /* MCLOSE + [0-9] */ -  , RS_ZOPEN            /* ZOPEN + [0-9] */ -  , RS_ZCLOSE           /* ZCLOSE + [0-9] */ -  , RS_BRANCH           /* BRANCH */ -  , RS_BRCPLX_MORE      /* BRACE_COMPLEX and trying one more match */ -  , RS_BRCPLX_LONG      /* BRACE_COMPLEX and trying longest match */ -  , RS_BRCPLX_SHORT     /* BRACE_COMPLEX and trying shortest match */ -  , RS_NOMATCH          /* NOMATCH */ -  , RS_BEHIND1          /* BEHIND / NOBEHIND matching rest */ -  , RS_BEHIND2          /* BEHIND / NOBEHIND matching behind part */ -  , RS_STAR_LONG        /* STAR/PLUS/BRACE_SIMPLE longest match */ -  , RS_STAR_SHORT       /* STAR/PLUS/BRACE_SIMPLE shortest match */ -} regstate_T; - -/* - * When there are alternatives a regstate_T is put on the regstack to remember - * what we are doing. - * Before it may be another type of item, depending on rs_state, to remember - * more things. - */ -typedef struct regitem_S { -  regstate_T rs_state;          /* what we are doing, one of RS_ above */ -  char_u      *rs_scan;         /* current node in program */ -  union { -    save_se_T sesave; -    regsave_T regsave; -  } rs_un;                      /* room for saving reginput */ -  short rs_no;                  /* submatch nr or BEHIND/NOBEHIND */ -} regitem_T; - -static regitem_T *regstack_push(regstate_T state, char_u *scan); -static void regstack_pop(char_u **scan); - -/* used for STAR, PLUS and BRACE_SIMPLE matching */ -typedef struct regstar_S { -  int nextb;                    /* next byte */ -  int nextb_ic;                 /* next byte reverse case */ -  long count; -  long minval; -  long maxval; -} regstar_T; - -/* used to store input position when a BACK was encountered, so that we now if - * we made any progress since the last time. */ -typedef struct backpos_S { -  char_u      *bp_scan;         /* "scan" where BACK was encountered */ -  regsave_T bp_pos;             /* last input position */ -} backpos_T; -  /*   * "regstack" and "backpos" are used by regmatch().  They are kept over calls   * to avoid invoking malloc() and free() often. @@ -3285,7 +3233,6 @@ static lpos_T reg_endzpos[NSUBEXP];     /* idem, end pos */  /* TRUE if using multi-line regexp. */  #define REG_MULTI       (reg_match == NULL) -static int bt_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col, bool line_lbr);  /*   * Match a regexp against a string. @@ -3315,9 +3262,6 @@ bt_regexec_nl (    return bt_regexec_both(line, col, NULL) != 0;  } -static long bt_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, -                             linenr_T lnum, colnr_T col, -                             proftime_T *tm);  /*   * Match a regexp against multiple lines. @@ -3357,10 +3301,10 @@ proftime_T  *tm;                /* timeout limit or NULL */   * Match a regexp against a string ("line" points to the string) or multiple   * lines ("line" is NULL, use reg_getline()).   */ -static long bt_regexec_both(line, col, tm) -char_u      *line; -colnr_T col;                    /* column to start looking for match */ -proftime_T  *tm;         /* timeout limit or NULL */ +static long bt_regexec_both(char_u *line, +                            colnr_T col, /* column to start looking for match */ +                            proftime_T *tm /* timeout limit or NULL */ +                            )  {    bt_regprog_T        *prog;    char_u      *s; @@ -3543,7 +3487,6 @@ theend:    return retval;  } -static reg_extmatch_T *make_extmatch(void);  /*   * Create a new extmatch and mark it as referenced once. @@ -3645,7 +3588,6 @@ static long regtry(bt_regprog_T *prog, colnr_T col)    return 1 + reglnum;  } -static int reg_prev_class(void);  /*   * Get class of previous character. @@ -3658,7 +3600,6 @@ static int reg_prev_class(void)    return -1;  } -static int reg_match_visual(void);  /*   * Return TRUE if the current reginput position matches the Visual area. @@ -6153,11 +6094,6 @@ static char_u *regprop(char_u *op)  }  #endif      /* REGEXP_DEBUG */ -static void mb_decompose(int c, int *c1, int *c2, int *c3); - -typedef struct { -  int a, b, c; -} decomp_T;  /* 0xfb20 - 0xfb4f */ @@ -6326,22 +6262,7 @@ static char_u *cstrchr(char_u *s, int c)  /* This stuff below really confuses cc on an SGI -- webb */ -/* - * We should define ftpr as a pointer to a function returning a pointer to - * a function returning a pointer to a function ... - * This is impossible, so we declare a pointer to a function returning a - * pointer to a function returning void. This should work for all compilers. - */ -typedef void (*(*fptr_T)(int *, int))(); -static fptr_T do_upper(int *, int); -static fptr_T do_Upper(int *, int); -static fptr_T do_lower(int *, int); -static fptr_T do_Lower(int *, int); - -static int vim_regsub_both(char_u *source, char_u *dest, int copy, -                           int magic, -                           int backslash);  static fptr_T do_upper(d, c)  int         *d; @@ -6791,7 +6712,6 @@ exit:    return (int)((dst - dest) + 1);  } -static char_u *reg_getline_submatch(linenr_T lnum);  /*   * Call reg_getline() with the line numbers from the submatch.  If a @@ -6961,7 +6881,10 @@ static regengine_T bt_regengine =  }; -#include "nvim/regexp_nfa.c" +// XXX Do not allow headers generator to catch definitions from regexp_nfa.c +#ifndef DO_NOT_DEFINE_EMPTY_ATTRIBUTES +# include "nvim/regexp_nfa.c" +#endif  static regengine_T nfa_regengine =  { @@ -7102,13 +7025,14 @@ int vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col)   * Return zero if there is no match.  Return number of lines contained in the   * match otherwise.   */ -long vim_regexec_multi(rmp, win, buf, lnum, col, tm) -regmmatch_T *rmp; -win_T       *win;               /* window in which to search or NULL */ -buf_T       *buf;               /* buffer in which to search */ -linenr_T lnum;                  /* nr of line to start looking for match */ -colnr_T col;                    /* column to start looking for match */ -proftime_T  *tm;                /* timeout limit or NULL */ +long vim_regexec_multi( +  regmmatch_T *rmp, +  win_T       *win,               /* window in which to search or NULL */ +  buf_T       *buf,               /* buffer in which to search */ +  linenr_T lnum,                  /* nr of line to start looking for match */ +  colnr_T col,                    /* column to start looking for match */ +  proftime_T  *tm                 /* timeout limit or NULL */ +)  {    return rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm);  } diff --git a/src/nvim/regexp.h b/src/nvim/regexp.h index 64f664985a..9be0e562c7 100644 --- a/src/nvim/regexp.h +++ b/src/nvim/regexp.h @@ -1,27 +1,8 @@  #ifndef NVIM_REGEXP_H  #define NVIM_REGEXP_H  /* regexp.c */ -int re_multiline(regprog_T *prog); -char_u *skip_regexp(char_u *startp, int dirc, int magic, char_u **newp); -int vim_regcomp_had_eol(void); -void free_regexp_stuff(void); -reg_extmatch_T *ref_extmatch(reg_extmatch_T *em); -void unref_extmatch(reg_extmatch_T *em); -char_u *regtilde(char_u *source, int magic); -int vim_regsub(regmatch_T *rmp, char_u *source, char_u *dest, int copy, -                       int magic, -                       int backslash); -int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, -                             char_u *dest, int copy, int magic, -                             int backslash); -char_u *reg_submatch(int no); -list_T *reg_submatch_list(int no); -regprog_T *vim_regcomp(char_u *expr_arg, int re_flags); -void vim_regfree(regprog_T *prog); -int vim_regexec(regmatch_T *rmp, char_u *line, colnr_T col); -int vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col); -long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, -                               linenr_T lnum, colnr_T col, -                               proftime_T *tm); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "regexp.h.generated.h" +#endif  #endif /* NVIM_REGEXP_H */ diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index d263a000d7..2926206ba7 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -241,6 +241,72 @@ static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c");  static char_u e_ill_char_class[] = N_(      "E877: (NFA regexp) Invalid character class: %" PRId64); +/* Since the out pointers in the list are always + * uninitialized, we use the pointers themselves + * as storage for the Ptrlists. */ +typedef union Ptrlist Ptrlist; +union Ptrlist { +  Ptrlist     *next; +  nfa_state_T *s; +}; + +struct Frag { +  nfa_state_T *start; +  Ptrlist     *out; +}; +typedef struct Frag Frag_T; + +typedef struct { +  int in_use;       /* number of subexpr with useful info */ + +  /* When REG_MULTI is TRUE list.multi is used, otherwise list.line. */ +  union { +    struct multipos { +      lpos_T start; +      lpos_T end; +    } multi[NSUBEXP]; +    struct linepos { +      char_u      *start; +      char_u      *end; +    } line[NSUBEXP]; +  } list; +} regsub_T; + +typedef struct { +  regsub_T norm;      /* \( .. \) matches */ +  regsub_T synt;      /* \z( .. \) matches */ +} regsubs_T; + +/* nfa_pim_T stores a Postponed Invisible Match. */ +typedef struct nfa_pim_S nfa_pim_T; +struct nfa_pim_S { +  int result;                   /* NFA_PIM_*, see below */ +  nfa_state_T *state;           /* the invisible match start state */ +  regsubs_T subs;               /* submatch info, only party used */ +  union { +    lpos_T pos; +    char_u  *ptr; +  } end;                        /* where the match must end */ +}; + +/* nfa_thread_T contains execution information of a NFA state */ +typedef struct { +  nfa_state_T *state; +  int count; +  nfa_pim_T pim;                /* if pim.result != NFA_PIM_UNUSED: postponed +                                 * invisible match */ +  regsubs_T subs;               /* submatch info, only party used */ +} nfa_thread_T; + +/* nfa_list_T contains the alternative NFA execution states. */ +typedef struct { +  nfa_thread_T    *t;           /* allocated array of states */ +  int n;                        /* nr of states currently in "t" */ +  int len;                      /* max nr of states in "t" */ +  int id;                       /* ID of the list */ +  int has_pim;                  /* TRUE when any state has a PIM */ +} nfa_list_T; +  /* NFA regexp \ze operator encountered. */  static int nfa_has_zend; @@ -274,48 +340,9 @@ static int nfa_alt_listid;  /* 0 for first call to nfa_regmatch(), 1 for recursive call. */  static int nfa_ll_index = 0; -static void nfa_regcomp_start(char_u *expr, int re_flags); -static int nfa_get_reganch(nfa_state_T *start, int depth); -static int nfa_get_regstart(nfa_state_T *start, int depth); -static char_u *nfa_get_match_text(nfa_state_T *start); -static void realloc_post_list(void); -static int nfa_recognize_char_class(char_u *start, char_u *end, -                                    int extra_newl); -static void nfa_emit_equi_class(int c); -static int nfa_regatom(void); -static int nfa_regpiece(void); -static int nfa_regconcat(void); -static int nfa_regbranch(void); -static int nfa_reg(int paren); -#ifdef REGEXP_DEBUG -static void nfa_set_code(int c); -static void nfa_postfix_dump(char_u *expr, int retval); -static void nfa_print_state(FILE *debugf, nfa_state_T *state); -static void nfa_print_state2(FILE *debugf, nfa_state_T *state, -                             garray_T *indent); -static void nfa_dump(nfa_regprog_T *prog); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "regexp_nfa.c.generated.h"  #endif -static int *re2post(void); -static nfa_state_T *alloc_state(int c, nfa_state_T *out, -                                nfa_state_T *out1); -static void st_error(int *postfix, int *end, int *p); -static int nfa_max_width(nfa_state_T *startstate, int depth); -static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size); -static void nfa_postprocess(nfa_regprog_T *prog); -static int check_char_class(int class, int c); -static void nfa_save_listids(nfa_regprog_T *prog, int *list); -static void nfa_restore_listids(nfa_regprog_T *prog, int *list); -static int nfa_re_num_cmp(long_u val, int op, long_u pos); -static long nfa_regtry(nfa_regprog_T *prog, colnr_T col); -static long nfa_regexec_both(char_u *line, colnr_T col); -static regprog_T *nfa_regcomp(char_u *expr, int re_flags); -static void nfa_regfree(regprog_T *prog); -static int nfa_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col, bool line_lbr); -static long nfa_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, -                              linenr_T lnum, colnr_T col, -                              proftime_T *tm); -static int match_follows(nfa_state_T *startstate, int depth); -static int failure_chance(nfa_state_T *state, int depth);  /* helper functions used when doing re2post() ... regatom() parsing */  #define EMIT(c) do {                            \ @@ -2480,27 +2507,6 @@ static nfa_state_T *alloc_state(int c, nfa_state_T *out, nfa_state_T *out1)   * next state for this fragment.   */ -/* Since the out pointers in the list are always - * uninitialized, we use the pointers themselves - * as storage for the Ptrlists. */ -typedef union Ptrlist Ptrlist; -union Ptrlist { -  Ptrlist     *next; -  nfa_state_T *s; -}; - -struct Frag { -  nfa_state_T *start; -  Ptrlist     *out; -}; -typedef struct Frag Frag_T; - -static Frag_T frag(nfa_state_T *start, Ptrlist *out); -static Ptrlist *list1(nfa_state_T **outp); -static void patch(Ptrlist *l, nfa_state_T *s); -static Ptrlist *append(Ptrlist *l1, Ptrlist *l2); -static void st_push(Frag_T s, Frag_T **p, Frag_T *stack_end); -static Frag_T st_pop(Frag_T **p, Frag_T *stack);  /*   * Initialize a Frag_T struct and return it. @@ -3374,39 +3380,6 @@ static void nfa_postprocess(nfa_regprog_T *prog)  * NFA execution code.  ****************************************************************/ -typedef struct { -  int in_use;       /* number of subexpr with useful info */ - -  /* When REG_MULTI is TRUE list.multi is used, otherwise list.line. */ -  union { -    struct multipos { -      lpos_T start; -      lpos_T end; -    } multi[NSUBEXP]; -    struct linepos { -      char_u      *start; -      char_u      *end; -    } line[NSUBEXP]; -  } list; -} regsub_T; - -typedef struct { -  regsub_T norm;      /* \( .. \) matches */ -  regsub_T synt;      /* \z( .. \) matches */ -} regsubs_T; - -/* nfa_pim_T stores a Postponed Invisible Match. */ -typedef struct nfa_pim_S nfa_pim_T; -struct nfa_pim_S { -  int result;                   /* NFA_PIM_*, see below */ -  nfa_state_T *state;           /* the invisible match start state */ -  regsubs_T subs;               /* submatch info, only party used */ -  union { -    lpos_T pos; -    char_u  *ptr; -  } end;                        /* where the match must end */ -}; -  /* Values for done in nfa_pim_T. */  #define NFA_PIM_UNUSED   0      /* pim not used */  #define NFA_PIM_TODO     1      /* pim not done yet */ @@ -3414,29 +3387,7 @@ struct nfa_pim_S {  #define NFA_PIM_NOMATCH  3      /* pim executed, no match */ -/* nfa_thread_T contains execution information of a NFA state */ -typedef struct { -  nfa_state_T *state; -  int count; -  nfa_pim_T pim;                /* if pim.result != NFA_PIM_UNUSED: postponed -                                 * invisible match */ -  regsubs_T subs;               /* submatch info, only party used */ -} nfa_thread_T; - -/* nfa_list_T contains the alternative NFA execution states. */ -typedef struct { -  nfa_thread_T    *t;           /* allocated array of states */ -  int n;                        /* nr of states currently in "t" */ -  int len;                      /* max nr of states in "t" */ -  int id;                       /* ID of the list */ -  int has_pim;                  /* TRUE when any state has a PIM */ -} nfa_list_T; -  #ifdef REGEXP_DEBUG -static void log_subsexpr(regsubs_T *subs); -static void log_subexpr(regsub_T *sub); -static char *pim_info(nfa_pim_T *pim); -  static void log_subsexpr(regsubs_T *subs)  {    log_subexpr(&subs->norm); @@ -3485,25 +3436,6 @@ static char *pim_info(nfa_pim_T *pim)  /* Used during execution: whether a match has been found. */  static int nfa_match; -static void copy_pim(nfa_pim_T *to, nfa_pim_T *from); -static void clear_sub(regsub_T *sub); -static void copy_sub(regsub_T *to, regsub_T *from); -static void copy_sub_off(regsub_T *to, regsub_T *from); -static void copy_ze_off(regsub_T *to, regsub_T *from); -static int sub_equal(regsub_T *sub1, regsub_T *sub2); -static int match_backref(regsub_T *sub, int subidx, int *bytelen); -static int has_state_with_pos(nfa_list_T *l, nfa_state_T *state, -                              regsubs_T *subs, -                              nfa_pim_T *pim); -static int pim_equal(nfa_pim_T *one, nfa_pim_T *two); -static int state_in_list(nfa_list_T *l, nfa_state_T *state, -                         regsubs_T *subs); -static regsubs_T *addstate(nfa_list_T *l, nfa_state_T *state, -                           regsubs_T *subs_arg, nfa_pim_T *pim, -                           int off); -static void addstate_here(nfa_list_T *l, nfa_state_T *state, -                          regsubs_T *subs, nfa_pim_T *pim, -                          int *ip);  /*   * Copy postponed invisible match info from "from" to "to". @@ -4357,7 +4289,6 @@ retempty:  } -static int match_zref(int subidx, int *bytelen);  /*   * Check for a match with \z subexpression "subidx". @@ -4427,13 +4358,6 @@ static int nfa_re_num_cmp(long_u val, int op, long_u pos)    return val == pos;  } -static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, -                              nfa_regprog_T *prog, regsubs_T *submatch, -                              regsubs_T *m, -                              int **listids); -static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, -                        regsubs_T *submatch, -                        regsubs_T *m);  /*   * Recursively call nfa_regmatch() @@ -4576,9 +4500,6 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T    return result;  } -static int skip_to_start(int c, colnr_T *colp); -static long find_match_text(colnr_T startcol, int regstart, -                            char_u *match_text);  /*   * Estimate the chance of a match with "state" failing. diff --git a/src/nvim/screen.c b/src/nvim/screen.c index aba229f1d1..d36ce6ca2b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -152,53 +152,13 @@ static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */   */  static schar_T  *current_ScreenLine; -static void win_update(win_T *wp); -static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, -                         hlf_T hl); -static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, -                      linenr_T lnum, -                      int row); -static void fill_foldcolumn(char_u *p, win_T *wp, int closed, -                            linenr_T lnum); -static void copy_text_attr(int off, char_u *buf, int len, int attr); -static int win_line(win_T *, linenr_T, int, int, int nochange); -static int char_needs_redraw(int off_from, int off_to, int cols); -static void screen_line(int row, int coloff, int endcol, -                        int clear_width, -                        int rlflag);  # define SCREEN_LINE(r, o, e, c, rl)    screen_line((r), (o), (e), (c), (rl)) -static void draw_vsep_win(win_T *wp, int row); -static void redraw_custom_statusline(win_T *wp); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "screen.c.generated.h" +#endif  #define SEARCH_HL_PRIORITY 0 -static void start_search_hl(void); -static void end_search_hl(void); -static void init_search_hl(win_T *wp); -static void prepare_search_hl(win_T *wp, linenr_T lnum); -static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, -                           colnr_T mincol); -static void screen_start_highlight(int attr); -static void screen_char(unsigned off, int row, int col); -static void screen_char_2(unsigned off, int row, int col); -static void screenclear2(void); -static void lineclear(unsigned off, int width); -static void lineinvalid(unsigned off, int width); -static void linecopy(int to, int from, win_T *wp); -static void redraw_block(int row, int end, win_T *wp); -static int win_do_lines(win_T *wp, int row, int line_count, -                        int mayclear, -                        int del); -static void win_rest_invalid(win_T *wp); -static void msg_pos_mode(void); -static void draw_tabline(void); -static int fillchar_status(int *attr, int is_curwin); -static int fillchar_vsep(int *attr); -static void win_redr_custom(win_T *wp, int draw_ruler); -static void win_redr_ruler(win_T *wp, int always);  //signs column -static void update_prepare(void); -static void update_finish(void); -static int draw_signcolumn (win_T *wp);  /* Ugly global: overrule attribute used by screen_char() */  static int screen_char_attr = 0; @@ -1811,7 +1771,6 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h    set_empty_rows(wp, row);  } -static int advance_color_col(int vcol, int **color_cols);  /*   * Advance **color_cols and return TRUE when there are columns to draw. @@ -4176,7 +4135,6 @@ win_line (    return row;  } -static int comp_char_differs(int, int);  /*   * Return if the composing characters at "off_from" and "off_to" differ. @@ -4580,8 +4538,6 @@ static void draw_vsep_win(win_T *wp, int row)    }  } -static int status_match_len(expand_T *xp, char_u *s); -static int skip_status_match_char(expand_T *xp, char_u *s);  /*   * Get the length of an item as it will be shown in the status line. @@ -5226,7 +5182,6 @@ void screen_getbytes(int row, int col, char_u *bytes, int *attrp)    }  } -static int screen_comp_differs(int, int*);  /*   * Return TRUE if composing characters for screen posn "off" differs from diff --git a/src/nvim/screen.h b/src/nvim/screen.h index d0f66710fc..72bdc07fe3 100644 --- a/src/nvim/screen.h +++ b/src/nvim/screen.h @@ -1,68 +1,7 @@  #ifndef NVIM_SCREEN_H  #define NVIM_SCREEN_H -/* screen.c */ -void redraw_later(int type); -void redraw_win_later(win_T *wp, int type); -void redraw_later_clear(void); -void redraw_all_later(int type); -void redraw_curbuf_later(int type); -void redraw_buf_later(buf_T *buf, int type); -int redraw_asap(int type); -void redrawWinline(linenr_T lnum, int invalid); -void update_curbuf(int type); -void update_screen(int type); -int conceal_cursor_line(win_T *wp); -void conceal_check_cursur_line(void); -void update_single_line(win_T *wp, linenr_T lnum); -void update_debug_sign(buf_T *buf, linenr_T lnum); -void rl_mirror(char_u *str); -void status_redraw_all(void); -void status_redraw_curbuf(void); -void redraw_statuslines(void); -void win_redraw_last_status(frame_T *frp); -void win_redr_status_matches(expand_T *xp, int num_matches, char_u * -                             *matches, int match, -                             int showtail); -void win_redr_status(win_T *wp); -int stl_connected(win_T *wp); -int get_keymap_str(win_T *wp, char_u *buf, int len); -void screen_putchar(int c, int row, int col, int attr); -void screen_getbytes(int row, int col, char_u *bytes, int *attrp); -void screen_puts(char_u *text, int row, int col, int attr); -void screen_puts_len(char_u *text, int len, int row, int col, int attr); -void screen_stop_highlight(void); -void reset_cterm_colors(void); -void screen_draw_rectangle(int row, int col, int height, int width, -                           int invert); -void screen_fill(int start_row, int end_row, int start_col, int end_col, -                 int c1, int c2, -                 int attr); -void check_for_delay(int check_msg_scroll); -int screen_valid(int doclear); -void screenalloc(int doclear); -void free_screenlines(void); -void screenclear(void); -int can_clear(char_u *p); -void screen_start(void); -void windgoto(int row, int col); -void setcursor(void); -int win_ins_lines(win_T *wp, int row, int line_count, int invalid, -                  int mayclear); -int win_del_lines(win_T *wp, int row, int line_count, int invalid, -                  int mayclear); -int screen_ins_lines(int off, int row, int line_count, int end, -                     win_T *wp); -int screen_del_lines(int off, int row, int line_count, int end, -                     int force, -                     win_T *wp); -int showmode(void); -void unshowmode(int force); -void get_trans_bufname(buf_T *buf); -int redrawing(void); -int messaging(void); -void showruler(int always); -int number_width(win_T *wp); -int screen_screencol(void); -int screen_screenrow(void); -#endif /* NVIM_SCREEN_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "screen.h.generated.h" +#endif +#endif  // NVIM_SCREEN_H diff --git a/src/nvim/search.c b/src/nvim/search.c index b341b4be68..5ba30eeb00 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -44,21 +44,10 @@  #include "nvim/ui.h"  #include "nvim/window.h" -static void save_re_pat(int idx, char_u *pat, int magic); -static void set_vv_searchforward(void); -static int first_submatch(regmmatch_T *rp); -static int check_prevcol(char_u *linep, int col, int ch, int *prevcol); -static int inmacro(char_u *, char_u *); -static int check_linecomment(char_u *line); -static int cls(void); -static int skip_chars(int, int); -static void back_in_line(void); -static void find_first_blank(pos_T *); -static void findsent_forward(long count, int at_start_sent); -static void show_pat_in_path(char_u *, int, -                             int, int, FILE *, linenr_T *, long); -static void wvsp_one(FILE *fp, int idx, char *s, int sc); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "search.c.generated.h" +#endif  /*   * This file contains various searching-related routines. These fall into   * three groups: @@ -452,18 +441,19 @@ void last_pat_prog(regmmatch_T *regmatch)   * Returns the index of the first matching   * subpattern plus one; one if there was none.   */ -int searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm) -win_T       *win;               /* window to search in; can be NULL for a -                                   buffer without a window! */ -buf_T       *buf; -pos_T       *pos; -int dir; -char_u      *pat; -long count; -int options; -int pat_use;                    /* which pattern to use when "pat" is empty */ -linenr_T stop_lnum;             /* stop after this line number when != 0 */ -proftime_T  *tm;         /* timeout limit or NULL */ +int searchit( +    win_T       *win,               /* window to search in, can be NULL for a +                                       buffer without a window! */ +    buf_T       *buf, +    pos_T       *pos, +    int dir, +    char_u      *pat, +    long count, +    int options, +    int pat_use,                    /* which pattern to use when "pat" is empty */ +    linenr_T stop_lnum,             /* stop after this line number when != 0 */ +    proftime_T  *tm          /* timeout limit or NULL */ +)  {    int found;    linenr_T lnum;                /* no init to shut up Apollo cc */ @@ -899,13 +889,14 @@ static int first_submatch(regmmatch_T *rp)   *   * return 0 for failure, 1 for found, 2 for found and line offset added   */ -int do_search(oap, dirc, pat, count, options, tm) -oparg_T         *oap;           /* can be NULL */ -int dirc;                       /* '/' or '?' */ -char_u          *pat; -long count; -int options; -proftime_T      *tm;            /* timeout limit or NULL */ +int do_search( +    oparg_T         *oap,           /* can be NULL */ +    int dirc,                       /* '/' or '?' */ +    char_u          *pat, +    long count, +    int options, +    proftime_T      *tm             /* timeout limit or NULL */ +)  {    pos_T pos;                    /* position of the last match */    char_u          *searchstr; @@ -3091,7 +3082,6 @@ current_block (    return OK;  } -static int in_html_tag(int);  /*   * Return TRUE if the cursor is on a "<aaa>" tag.  Ignore "<aaa/>". @@ -3486,10 +3476,6 @@ extend:    return OK;  } -static int find_next_quote(char_u *top_ptr, int col, int quotechar, -                           char_u *escape); -static int find_prev_quote(char_u *line, int col_start, int quotechar, -                           char_u *escape);  /*   * Search quote char from string line[col]. @@ -3766,7 +3752,6 @@ current_quote (  } -static int is_one_char(char_u *pattern);  /*   * Find next search match under cursor, cursor at end. diff --git a/src/nvim/search.h b/src/nvim/search.h index 122fdce04c..7dc45f307c 100644 --- a/src/nvim/search.h +++ b/src/nvim/search.h @@ -1,52 +1,7 @@  #ifndef NVIM_SEARCH_H  #define NVIM_SEARCH_H -/* search.c */ -int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, -                   regmmatch_T *regmatch); -char_u *get_search_pat(void); -char_u *reverse_text(char_u *s); -void save_search_patterns(void); -void restore_search_patterns(void); -void free_search_patterns(void); -int ignorecase(char_u *pat); -int pat_has_uppercase(char_u *pat); -char_u *last_search_pat(void); -void reset_search_dir(void); -void set_last_search_pat(char_u *s, int idx, int magic, int setlast); -void last_pat_prog(regmmatch_T *regmatch); -int searchit(win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, -             long count, int options, int pat_use, linenr_T stop_lnum, -             proftime_T *tm); -void set_search_direction(int cdir); -int do_search(oparg_T *oap, int dirc, char_u *pat, long count, -              int options, -              proftime_T *tm); -int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat); -int searchc(cmdarg_T *cap, int t_cmd); -pos_T *findmatch(oparg_T *oap, int initc); -pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int maxtravel); -void showmatch(int c); -int findsent(int dir, long count); -int findpar(int *pincl, int dir, long count, int what, int both); -int startPS(linenr_T lnum, int para, int both); -int fwd_word(long count, int bigword, int eol); -int bck_word(long count, int bigword, int stop); -int end_word(long count, int bigword, int stop, int empty); -int bckend_word(long count, int bigword, int eol); -int current_word(oparg_T *oap, long count, int include, int bigword); -int current_sent(oparg_T *oap, long count, int include); -int current_block(oparg_T *oap, long count, int include, int what, -                  int other); -int current_tagblock(oparg_T *oap, long count_arg, int include); -int current_par(oparg_T *oap, long count, int include, int type); -int current_quote(oparg_T *oap, long count, int include, int quotechar); -int current_search(long count, int forward); -int linewhite(linenr_T lnum); -void find_pattern_in_path(char_u *ptr, int dir, int len, int whole, -                          int skip_comments, int type, long count, -                          int action, linenr_T start_lnum, -                          linenr_T end_lnum); -int read_viminfo_search_pattern(vir_T *virp, int force); -void write_viminfo_search_pattern(FILE *fp); -#endif /* NVIM_SEARCH_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "search.h.generated.h" +#endif +#endif  // NVIM_SEARCH_H diff --git a/src/nvim/sha256.c b/src/nvim/sha256.c index 4a61ddc66f..587e0504bf 100644 --- a/src/nvim/sha256.c +++ b/src/nvim/sha256.c @@ -17,8 +17,10 @@  #include "nvim/vim.h"  #include "nvim/sha256.h" -static void sha256_process(context_sha256_T *ctx, char_u data[64]); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "sha256.c.generated.h" +#endif  #define GET_UINT32(n, b, i) { \    (n) = ((uint32_t)(b)[(i)] << 24) \          | ((uint32_t)(b)[(i) + 1] << 16) \ @@ -248,7 +250,6 @@ void sha256_finish(context_sha256_T *ctx, char_u digest[32])    PUT_UINT32(ctx->state[7], digest, 28);  } -static unsigned int get_some_time(void);  /// Gets the hex digest of the buffer.  /// diff --git a/src/nvim/sha256.h b/src/nvim/sha256.h index 355b758cdd..c8ffa94cc4 100644 --- a/src/nvim/sha256.h +++ b/src/nvim/sha256.h @@ -7,11 +7,7 @@ typedef struct {    char_u buffer[64];  } context_sha256_T; -void sha256_start(context_sha256_T *ctx); -void sha256_update(context_sha256_T *ctx, char_u *input, uint32_t length); -void sha256_finish(context_sha256_T *ctx, char_u digest[32]); -char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, int salt_len); -int sha256_self_test(void); -void sha2_seed(char_u *header, int header_len, char_u *salt, int salt_len); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "sha256.h.generated.h" +#endif  #endif  // NVIM_SHA256_H diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 901115e55f..a3e104b160 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -716,20 +716,6 @@ typedef struct spelltab_S {    char_u st_upper[256];       // chars: upper case  } spelltab_T; -static spelltab_T spelltab; -static int did_set_spelltab; - -#define CF_WORD         0x01 -#define CF_UPPER        0x02 - -static void clear_spell_chartab(spelltab_T *sp); -static int set_spell_finish(spelltab_T  *new_st); -static int spell_iswordp(char_u *p, win_T *wp); -static int spell_iswordp_nmw(char_u *p, win_T *wp); -static int spell_mb_isword_class(int cl, win_T *wp); -static int spell_iswordp_w(int *p, win_T *wp); -static int write_spell_prefcond(FILE *fd, garray_T *gap); -  // For finding suggestions: At each node in the tree these states are tried:  typedef enum {    STATE_START = 0,      // At start of node check for NUL bytes (goodword @@ -780,6 +766,230 @@ typedef struct trystate_S {                                  // valid when "ts_flags" has TSF_DIDDEL  } trystate_T; +// Structure used for the cookie argument of do_in_runtimepath(). +typedef struct spelload_S { +  char_u sl_lang[MAXWLEN + 1];          // language name +  slang_T *sl_slang;                    // resulting slang_T struct +  int sl_nobreak;                       // NOBREAK language found +} spelload_T; + +#define SY_MAXLEN   30 +typedef struct syl_item_S { +  char_u sy_chars[SY_MAXLEN];               // the sequence of chars +  int sy_len; +} syl_item_T; + +#define MAXLINELEN  500         // Maximum length in bytes of a line in a .aff +                                // and .dic file. +// Main structure to store the contents of a ".aff" file. +typedef struct afffile_S { +  char_u      *af_enc;          // "SET", normalized, alloc'ed string or NULL +  int af_flagtype;              // AFT_CHAR, AFT_LONG, AFT_NUM or AFT_CAPLONG +  unsigned af_rare;             // RARE ID for rare word +  unsigned af_keepcase;         // KEEPCASE ID for keep-case word +  unsigned af_bad;              // BAD ID for banned word +  unsigned af_needaffix;        // NEEDAFFIX ID +  unsigned af_circumfix;        // CIRCUMFIX ID +  unsigned af_needcomp;         // NEEDCOMPOUND ID +  unsigned af_comproot;         // COMPOUNDROOT ID +  unsigned af_compforbid;       // COMPOUNDFORBIDFLAG ID +  unsigned af_comppermit;       // COMPOUNDPERMITFLAG ID +  unsigned af_nosuggest;        // NOSUGGEST ID +  int af_pfxpostpone;           // postpone prefixes without chop string and +                                // without flags +  hashtab_T af_pref;            // hashtable for prefixes, affheader_T +  hashtab_T af_suff;            // hashtable for suffixes, affheader_T +  hashtab_T af_comp;            // hashtable for compound flags, compitem_T +} afffile_T; + +#define AFT_CHAR        0       // flags are one character +#define AFT_LONG        1       // flags are two characters +#define AFT_CAPLONG     2       // flags are one or two characters +#define AFT_NUM         3       // flags are numbers, comma separated + +typedef struct affentry_S affentry_T; +// Affix entry from ".aff" file.  Used for prefixes and suffixes. +struct affentry_S { +  affentry_T  *ae_next;         // next affix with same name/number +  char_u      *ae_chop;         // text to chop off basic word (can be NULL) +  char_u      *ae_add;          // text to add to basic word (can be NULL) +  char_u      *ae_flags;        // flags on the affix (can be NULL) +  char_u      *ae_cond;         // condition (NULL for ".") +  regprog_T   *ae_prog;         // regexp program for ae_cond or NULL +  char ae_compforbid;           // COMPOUNDFORBIDFLAG found +  char ae_comppermit;           // COMPOUNDPERMITFLAG found +}; + +# define AH_KEY_LEN 17          // 2 x 8 bytes + NUL + +// Affix header from ".aff" file.  Used for af_pref and af_suff. +typedef struct affheader_S { +  char_u ah_key[AH_KEY_LEN];    // key for hashtab == name of affix +  unsigned ah_flag;             // affix name as number, uses "af_flagtype" +  int ah_newID;                 // prefix ID after renumbering; 0 if not used +  int ah_combine;               // suffix may combine with prefix +  int ah_follows;               // another affix block should be following +  affentry_T  *ah_first;        // first affix entry +} affheader_T; + +#define HI2AH(hi)   ((affheader_T *)(hi)->hi_key) + +// Flag used in compound items. +typedef struct compitem_S { +  char_u ci_key[AH_KEY_LEN];    // key for hashtab == name of compound +  unsigned ci_flag;             // affix name as number, uses "af_flagtype" +  int ci_newID;                 // affix ID after renumbering. +} compitem_T; + +#define HI2CI(hi)   ((compitem_T *)(hi)->hi_key) + +// Structure that is used to store the items in the word tree.  This avoids +// the need to keep track of each allocated thing, everything is freed all at +// once after ":mkspell" is done. +// Note: "sb_next" must be just before "sb_data" to make sure the alignment of +// "sb_data" is correct for systems where pointers must be aligned on +// pointer-size boundaries and sizeof(pointer) > sizeof(int) (e.g., Sparc). +#define  SBLOCKSIZE 16000       // size of sb_data +typedef struct sblock_S sblock_T; +struct sblock_S { +  int sb_used;                  // nr of bytes already in use +  sblock_T    *sb_next;         // next block in list +  char_u sb_data[1];            // data, actually longer +}; + +// A node in the tree. +typedef struct wordnode_S wordnode_T; +struct wordnode_S { +  union     // shared to save space +  { +    char_u hashkey[6];          // the hash key, only used while compressing +    int index;                  // index in written nodes (valid after first +                                // round) +  } wn_u1; +  union     // shared to save space +  { +    wordnode_T *next;           // next node with same hash key +    wordnode_T *wnode;          // parent node that will write this node +  } wn_u2; +  wordnode_T  *wn_child;        // child (next byte in word) +  wordnode_T  *wn_sibling;      // next sibling (alternate byte in word, +                                //   always sorted) +  int wn_refs;                  // Nr. of references to this node.  Only +                                //   relevant for first node in a list of +                                //   siblings, in following siblings it is +                                //   always one. +  char_u wn_byte;               // Byte for this node. NUL for word end + +  // Info for when "wn_byte" is NUL. +  // In PREFIXTREE "wn_region" is used for the prefcondnr. +  // In the soundfolded word tree "wn_flags" has the MSW of the wordnr and +  // "wn_region" the LSW of the wordnr. +  char_u wn_affixID;            // supported/required prefix ID or 0 +  uint16_t wn_flags;            // WF_ flags +  short wn_region;              // region mask + +#ifdef SPELL_PRINTTREE +  int wn_nr;                    // sequence nr for printing +#endif +}; + +#define WN_MASK  0xffff         // mask relevant bits of "wn_flags" + +#define HI2WN(hi)    (wordnode_T *)((hi)->hi_key) + +// Info used while reading the spell files. +typedef struct spellinfo_S { +  wordnode_T  *si_foldroot;     // tree with case-folded words +  long si_foldwcount;           // nr of words in si_foldroot + +  wordnode_T  *si_keeproot;     // tree with keep-case words +  long si_keepwcount;           // nr of words in si_keeproot + +  wordnode_T  *si_prefroot;     // tree with postponed prefixes + +  long si_sugtree;              // creating the soundfolding trie + +  sblock_T    *si_blocks;       // memory blocks used +  long si_blocks_cnt;           // memory blocks allocated +  int si_did_emsg;              // TRUE when ran out of memory + +  long si_compress_cnt;         // words to add before lowering +                                // compression limit +  wordnode_T  *si_first_free;   // List of nodes that have been freed during +                                // compression, linked by "wn_child" field. +  long si_free_count;           // number of nodes in si_first_free +#ifdef SPELL_PRINTTREE +  int si_wordnode_nr;           // sequence nr for nodes +#endif +  buf_T       *si_spellbuf;     // buffer used to store soundfold word table + +  int si_ascii;                 // handling only ASCII words +  int si_add;                   // addition file +  int si_clear_chartab;             // when TRUE clear char tables +  int si_region;                // region mask +  vimconv_T si_conv;            // for conversion to 'encoding' +  int si_memtot;                // runtime memory used +  int si_verbose;               // verbose messages +  int si_msg_count;             // number of words added since last message +  char_u      *si_info;         // info text chars or NULL +  int si_region_count;          // number of regions supported (1 when there +                                // are no regions) +  char_u si_region_name[17];    // region names; used only if +                                // si_region_count > 1) + +  garray_T si_rep;              // list of fromto_T entries from REP lines +  garray_T si_repsal;           // list of fromto_T entries from REPSAL lines +  garray_T si_sal;              // list of fromto_T entries from SAL lines +  char_u      *si_sofofr;       // SOFOFROM text +  char_u      *si_sofoto;       // SOFOTO text +  int si_nosugfile;             // NOSUGFILE item found +  int si_nosplitsugs;           // NOSPLITSUGS item found +  int si_followup;              // soundsalike: ? +  int si_collapse;              // soundsalike: ? +  hashtab_T si_commonwords;     // hashtable for common words +  time_t si_sugtime;            // timestamp for .sug file +  int si_rem_accents;           // soundsalike: remove accents +  garray_T si_map;              // MAP info concatenated +  char_u      *si_midword;      // MIDWORD chars or NULL +  int si_compmax;               // max nr of words for compounding +  int si_compminlen;            // minimal length for compounding +  int si_compsylmax;            // max nr of syllables for compounding +  int si_compoptions;           // COMP_ flags +  garray_T si_comppat;          // CHECKCOMPOUNDPATTERN items, each stored as +                                // a string +  char_u      *si_compflags;    // flags used for compounding +  char_u si_nobreak;            // NOBREAK +  char_u      *si_syllable;     // syllable string +  garray_T si_prefcond;         // table with conditions for postponed +                                // prefixes, each stored as a string +  int si_newprefID;             // current value for ah_newID +  int si_newcompID;             // current value for compound ID +} spellinfo_T; + +static spelltab_T spelltab; +static int did_set_spelltab; + +#define CF_WORD         0x01 +#define CF_UPPER        0x02 + +// structure used to store soundfolded words that add_sound_suggest() has +// handled already. +typedef struct { +  short sft_score;              // lowest score used +  char_u sft_word[1];           // soundfolded word, actually longer +} sftword_T; + +typedef struct { +  int badi; +  int goodi; +  int score; +} limitscore_T; + + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "spell.c.generated.h" +#endif +  // values for ts_isdiff  #define DIFF_NONE       0       // no different byte (yet)  #define DIFF_YES        1       // different byte found @@ -802,133 +1012,6 @@ typedef struct trystate_S {  #define FIND_COMPOUND       3   // find case-folded compound word  #define FIND_KEEPCOMPOUND   4   // find keep-case compound word -static slang_T *slang_alloc(char_u *lang); -static void slang_free(slang_T *lp); -static void slang_clear(slang_T *lp); -static void slang_clear_sug(slang_T *lp); -static void find_word(matchinf_T *mip, int mode); -static int match_checkcompoundpattern(char_u *ptr, int wlen, -                                      garray_T *gap); -static int can_compound(slang_T *slang, char_u *word, char_u *flags); -static int can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, -                           int flag); -static int match_compoundrule(slang_T *slang, char_u *compflags); -static int valid_word_prefix(int totprefcnt, int arridx, int flags, -                             char_u *word, slang_T *slang, -                             int cond_req); -static void find_prefix(matchinf_T *mip, int mode); -static int fold_more(matchinf_T *mip); -static int spell_valid_case(int wordflags, int treeflags); -static int no_spell_checking(win_T *wp); -static void spell_load_lang(char_u *lang); -static char_u *spell_enc(void); -static void int_wordlist_spl(char_u *fname); -static void spell_load_cb(char_u *fname, void *cookie); -static slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, -                                int silent); -static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *lenp); -static int read_region_section(FILE *fd, slang_T *slang, int len); -static int read_charflags_section(FILE *fd); -static int read_prefcond_section(FILE *fd, slang_T *lp); -static int read_rep_section(FILE *fd, garray_T *gap, short *first); -static int read_sal_section(FILE *fd, slang_T *slang); -static int read_words_section(FILE *fd, slang_T *lp, int len); -static void count_common_word(slang_T *lp, char_u *word, int len, -                              int count); -static int score_wordcount_adj(slang_T *slang, int score, char_u *word, -                               int split); -static int read_sofo_section(FILE *fd, slang_T *slang); -static int read_compound(FILE *fd, slang_T *slang, int len); -static int byte_in_str(char_u *str, int byte); -static int init_syl_tab(slang_T *slang); -static int count_syllables(slang_T *slang, char_u *word); -static int set_sofo(slang_T *lp, char_u *from, char_u *to); -static void set_sal_first(slang_T *lp); -static int *mb_str2wide(char_u *s); -static int spell_read_tree(FILE *fd, char_u **bytsp, idx_T **idxsp, -                           int prefixtree, -                           int prefixcnt); -static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, -                            int maxidx, idx_T startidx, int prefixtree, -                            int maxprefcondnr); -static void clear_midword(win_T *buf); -static void use_midword(slang_T *lp, win_T *buf); -static int find_region(char_u *rp, char_u *region); -static int captype(char_u *word, char_u *end); -static int badword_captype(char_u *word, char_u *end); -static void spell_reload_one(char_u *fname, int added_word); -static void set_spell_charflags(char_u *flags, int cnt, char_u *upp); -static int set_spell_chartab(char_u *fol, char_u *low, char_u *upp); -static int spell_casefold(char_u *p, int len, char_u *buf, int buflen); -static int check_need_cap(linenr_T lnum, colnr_T col); -static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, -                               int maxcount, int banbadword, -                               int need_cap, -                               int interactive); -static void spell_suggest_expr(suginfo_T *su, char_u *expr); -static void spell_suggest_file(suginfo_T *su, char_u *fname); -static void spell_suggest_intern(suginfo_T *su, int interactive); -static void suggest_load_files(void); -static void tree_count_words(char_u *byts, idx_T *idxs); -static void spell_find_cleanup(suginfo_T *su); -static void onecap_copy(char_u *word, char_u *wcopy, int upper); -static void allcap_copy(char_u *word, char_u *wcopy); -static void suggest_try_special(suginfo_T *su); -static void suggest_try_change(suginfo_T *su); -static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, -                              int soundfold); -static void go_deeper(trystate_T *stack, int depth, int score_add); -static int nofold_len(char_u *fword, int flen, char_u *word); -static void find_keepcap_word(slang_T *slang, char_u *fword, -                              char_u *kword); -static void score_comp_sal(suginfo_T *su); -static void score_combine(suginfo_T *su); -static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, -                         char_u *badsound); -static void suggest_try_soundalike_prep(void); -static void suggest_try_soundalike(suginfo_T *su); -static void suggest_try_soundalike_finish(void); -static void add_sound_suggest(suginfo_T *su, char_u *goodword, -                              int score, -                              langp_T *lp); -static int soundfold_find(slang_T *slang, char_u *word); -static void make_case_word(char_u *fword, char_u *cword, int flags); -static void set_map_str(slang_T *lp, char_u *map); -static int similar_chars(slang_T *slang, int c1, int c2); -static void add_suggestion(suginfo_T *su, garray_T *gap, char_u *goodword, -                           int badlen, int score, -                           int altscore, int had_bonus, slang_T *slang, -                           int maxsf); -static void check_suggestions(suginfo_T *su, garray_T *gap); -static void add_banned(suginfo_T *su, char_u *word); -static void rescore_suggestions(suginfo_T *su); -static void rescore_one(suginfo_T *su, suggest_T *stp); -static int cleanup_suggestions(garray_T *gap, int maxscore, int keep); -static void spell_soundfold(slang_T *slang, char_u *inword, int folded, -                            char_u *res); -static void spell_soundfold_sofo(slang_T *slang, char_u *inword, -                                 char_u *res); -static void spell_soundfold_sal(slang_T *slang, char_u *inword, -                                char_u *res); -static void spell_soundfold_wsal(slang_T *slang, char_u *inword, -                                 char_u *res); -static int soundalike_score(char_u *goodsound, char_u *badsound); -static int spell_edit_score(slang_T *slang, char_u *badword, -                            char_u *goodword); -static int spell_edit_score_limit(slang_T *slang, char_u *badword, -                                  char_u *goodword, -                                  int limit); -static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, -                                    char_u *goodword, -                                    int limit); -static void dump_word(slang_T *slang, char_u *word, char_u *pat, -                      int *dir, int round, int flags, -                      linenr_T lnum); -static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, -                              int *dir, int round, int flags, -                              linenr_T startlnum); -static buf_T *open_spellbuf(void); -static void close_spellbuf(buf_T *buf);  // Use our own character-case definitions, because the current locale may  // differ from what the .spl file uses. @@ -2198,13 +2281,6 @@ void spell_cat_line(char_u *buf, char_u *line, int maxlen)    }  } -// Structure used for the cookie argument of do_in_runtimepath(). -typedef struct spelload_S { -  char_u sl_lang[MAXWLEN + 1];          // language name -  slang_T *sl_slang;                    // resulting slang_T struct -  int sl_nobreak;                       // NOBREAK language found -} spelload_T; -  // Load word list(s) for "lang" from Vim spell file(s).  // "lang" must be the language without the region: e.g., "en".  static void spell_load_lang(char_u *lang) @@ -3252,12 +3328,6 @@ static int byte_in_str(char_u *str, int n)    return FALSE;  } -#define SY_MAXLEN   30 -typedef struct syl_item_S { -  char_u sy_chars[SY_MAXLEN];               // the sequence of chars -  int sy_len; -} syl_item_T; -  // Truncate "slang->sl_syllable" at the first slash and put the following items  // in "slang->sl_syl_items".  static int init_syl_tab(slang_T *slang) @@ -4141,262 +4211,6 @@ spell_reload_one (  // Functions for ":mkspell". -#define MAXLINELEN  500         // Maximum length in bytes of a line in a .aff -                                // and .dic file. -// Main structure to store the contents of a ".aff" file. -typedef struct afffile_S { -  char_u      *af_enc;          // "SET", normalized, alloc'ed string or NULL -  int af_flagtype;              // AFT_CHAR, AFT_LONG, AFT_NUM or AFT_CAPLONG -  unsigned af_rare;             // RARE ID for rare word -  unsigned af_keepcase;         // KEEPCASE ID for keep-case word -  unsigned af_bad;              // BAD ID for banned word -  unsigned af_needaffix;        // NEEDAFFIX ID -  unsigned af_circumfix;        // CIRCUMFIX ID -  unsigned af_needcomp;         // NEEDCOMPOUND ID -  unsigned af_comproot;         // COMPOUNDROOT ID -  unsigned af_compforbid;       // COMPOUNDFORBIDFLAG ID -  unsigned af_comppermit;       // COMPOUNDPERMITFLAG ID -  unsigned af_nosuggest;        // NOSUGGEST ID -  int af_pfxpostpone;           // postpone prefixes without chop string and -                                // without flags -  hashtab_T af_pref;            // hashtable for prefixes, affheader_T -  hashtab_T af_suff;            // hashtable for suffixes, affheader_T -  hashtab_T af_comp;            // hashtable for compound flags, compitem_T -} afffile_T; - -#define AFT_CHAR        0       // flags are one character -#define AFT_LONG        1       // flags are two characters -#define AFT_CAPLONG     2       // flags are one or two characters -#define AFT_NUM         3       // flags are numbers, comma separated - -typedef struct affentry_S affentry_T; -// Affix entry from ".aff" file.  Used for prefixes and suffixes. -struct affentry_S { -  affentry_T  *ae_next;         // next affix with same name/number -  char_u      *ae_chop;         // text to chop off basic word (can be NULL) -  char_u      *ae_add;          // text to add to basic word (can be NULL) -  char_u      *ae_flags;        // flags on the affix (can be NULL) -  char_u      *ae_cond;         // condition (NULL for ".") -  regprog_T   *ae_prog;         // regexp program for ae_cond or NULL -  char ae_compforbid;           // COMPOUNDFORBIDFLAG found -  char ae_comppermit;           // COMPOUNDPERMITFLAG found -}; - -# define AH_KEY_LEN 17          // 2 x 8 bytes + NUL - -// Affix header from ".aff" file.  Used for af_pref and af_suff. -typedef struct affheader_S { -  char_u ah_key[AH_KEY_LEN];    // key for hashtab == name of affix -  unsigned ah_flag;             // affix name as number, uses "af_flagtype" -  int ah_newID;                 // prefix ID after renumbering; 0 if not used -  int ah_combine;               // suffix may combine with prefix -  int ah_follows;               // another affix block should be following -  affentry_T  *ah_first;        // first affix entry -} affheader_T; - -#define HI2AH(hi)   ((affheader_T *)(hi)->hi_key) - -// Flag used in compound items. -typedef struct compitem_S { -  char_u ci_key[AH_KEY_LEN];    // key for hashtab == name of compound -  unsigned ci_flag;             // affix name as number, uses "af_flagtype" -  int ci_newID;                 // affix ID after renumbering. -} compitem_T; - -#define HI2CI(hi)   ((compitem_T *)(hi)->hi_key) - -// Structure that is used to store the items in the word tree.  This avoids -// the need to keep track of each allocated thing, everything is freed all at -// once after ":mkspell" is done. -// Note: "sb_next" must be just before "sb_data" to make sure the alignment of -// "sb_data" is correct for systems where pointers must be aligned on -// pointer-size boundaries and sizeof(pointer) > sizeof(int) (e.g., Sparc). -#define  SBLOCKSIZE 16000       // size of sb_data -typedef struct sblock_S sblock_T; -struct sblock_S { -  int sb_used;                  // nr of bytes already in use -  sblock_T    *sb_next;         // next block in list -  char_u sb_data[1];            // data, actually longer -}; - -// A node in the tree. -typedef struct wordnode_S wordnode_T; -struct wordnode_S { -  union     // shared to save space -  { -    char_u hashkey[6];          // the hash key, only used while compressing -    int index;                  // index in written nodes (valid after first -                                // round) -  } wn_u1; -  union     // shared to save space -  { -    wordnode_T *next;           // next node with same hash key -    wordnode_T *wnode;          // parent node that will write this node -  } wn_u2; -  wordnode_T  *wn_child;        // child (next byte in word) -  wordnode_T  *wn_sibling;      // next sibling (alternate byte in word, -                                //   always sorted) -  int wn_refs;                  // Nr. of references to this node.  Only -                                //   relevant for first node in a list of -                                //   siblings, in following siblings it is -                                //   always one. -  char_u wn_byte;               // Byte for this node. NUL for word end - -  // Info for when "wn_byte" is NUL. -  // In PREFIXTREE "wn_region" is used for the prefcondnr. -  // In the soundfolded word tree "wn_flags" has the MSW of the wordnr and -  // "wn_region" the LSW of the wordnr. -  char_u wn_affixID;            // supported/required prefix ID or 0 -  uint16_t wn_flags;            // WF_ flags -  short wn_region;              // region mask - -#ifdef SPELL_PRINTTREE -  int wn_nr;                    // sequence nr for printing -#endif -}; - -#define WN_MASK  0xffff         // mask relevant bits of "wn_flags" - -#define HI2WN(hi)    (wordnode_T *)((hi)->hi_key) - -// Info used while reading the spell files. -typedef struct spellinfo_S { -  wordnode_T  *si_foldroot;     // tree with case-folded words -  long si_foldwcount;           // nr of words in si_foldroot - -  wordnode_T  *si_keeproot;     // tree with keep-case words -  long si_keepwcount;           // nr of words in si_keeproot - -  wordnode_T  *si_prefroot;     // tree with postponed prefixes - -  long si_sugtree;              // creating the soundfolding trie - -  sblock_T    *si_blocks;       // memory blocks used -  long si_blocks_cnt;           // memory blocks allocated -  int si_did_emsg;              // TRUE when ran out of memory - -  long si_compress_cnt;         // words to add before lowering -                                // compression limit -  wordnode_T  *si_first_free;   // List of nodes that have been freed during -                                // compression, linked by "wn_child" field. -  long si_free_count;           // number of nodes in si_first_free -#ifdef SPELL_PRINTTREE -  int si_wordnode_nr;           // sequence nr for nodes -#endif -  buf_T       *si_spellbuf;     // buffer used to store soundfold word table - -  int si_ascii;                 // handling only ASCII words -  int si_add;                   // addition file -  int si_clear_chartab;             // when TRUE clear char tables -  int si_region;                // region mask -  vimconv_T si_conv;            // for conversion to 'encoding' -  int si_memtot;                // runtime memory used -  int si_verbose;               // verbose messages -  int si_msg_count;             // number of words added since last message -  char_u      *si_info;         // info text chars or NULL -  int si_region_count;          // number of regions supported (1 when there -                                // are no regions) -  char_u si_region_name[17];    // region names; used only if -                                // si_region_count > 1) - -  garray_T si_rep;              // list of fromto_T entries from REP lines -  garray_T si_repsal;           // list of fromto_T entries from REPSAL lines -  garray_T si_sal;              // list of fromto_T entries from SAL lines -  char_u      *si_sofofr;       // SOFOFROM text -  char_u      *si_sofoto;       // SOFOTO text -  int si_nosugfile;             // NOSUGFILE item found -  int si_nosplitsugs;           // NOSPLITSUGS item found -  int si_followup;              // soundsalike: ? -  int si_collapse;              // soundsalike: ? -  hashtab_T si_commonwords;     // hashtable for common words -  time_t si_sugtime;            // timestamp for .sug file -  int si_rem_accents;           // soundsalike: remove accents -  garray_T si_map;              // MAP info concatenated -  char_u      *si_midword;      // MIDWORD chars or NULL -  int si_compmax;               // max nr of words for compounding -  int si_compminlen;            // minimal length for compounding -  int si_compsylmax;            // max nr of syllables for compounding -  int si_compoptions;           // COMP_ flags -  garray_T si_comppat;          // CHECKCOMPOUNDPATTERN items, each stored as -                                // a string -  char_u      *si_compflags;    // flags used for compounding -  char_u si_nobreak;            // NOBREAK -  char_u      *si_syllable;     // syllable string -  garray_T si_prefcond;         // table with conditions for postponed -                                // prefixes, each stored as a string -  int si_newprefID;             // current value for ah_newID -  int si_newcompID;             // current value for compound ID -} spellinfo_T; - -static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname); -static int is_aff_rule(char_u **items, int itemcnt, char *rulename, -                       int mincount); -static void aff_process_flags(afffile_T *affile, affentry_T *entry); -static int spell_info_item(char_u *s); -static unsigned affitem2flag(int flagtype, char_u *item, char_u *fname, -                             int lnum); -static unsigned get_affitem(int flagtype, char_u **pp); -static void process_compflags(spellinfo_T *spin, afffile_T *aff, -                              char_u *compflags); -static void check_renumber(spellinfo_T *spin); -static int flag_in_afflist(int flagtype, char_u *afflist, unsigned flag); -static void aff_check_number(int spinval, int affval, char *name); -static void aff_check_string(char_u *spinval, char_u *affval, -                             char *name); -static int str_equal(char_u *s1, char_u *s2); -static void add_fromto(spellinfo_T *spin, garray_T *gap, char_u *from, -                       char_u *to); -static int sal_to_bool(char_u *s); -static void spell_free_aff(afffile_T *aff); -static int spell_read_dic(spellinfo_T *spin, char_u *fname, -                          afffile_T *affile); -static int get_affix_flags(afffile_T *affile, char_u *afflist); -static int get_pfxlist(afffile_T *affile, char_u *afflist, -                       char_u *store_afflist); -static void get_compflags(afffile_T *affile, char_u *afflist, -                          char_u *store_afflist); -static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, -                          afffile_T *affile, hashtab_T *ht, -                          hashtab_T *xht, int condit, int flags, -                          char_u *pfxlist, -                          int pfxlen); -static int spell_read_wordfile(spellinfo_T *spin, char_u *fname); -static void *getroom(spellinfo_T *spin, size_t len, int align); -static char_u *getroom_save(spellinfo_T *spin, char_u *s); -static void free_blocks(sblock_T *bl); -static wordnode_T *wordtree_alloc(spellinfo_T *spin); -static int store_word(spellinfo_T *spin, char_u *word, int flags, -                      int region, char_u *pfxlist, -                      int need_affix); -static int tree_add_word(spellinfo_T *spin, char_u *word, -                         wordnode_T *tree, int flags, int region, -                         int affixID); -static wordnode_T *get_wordnode(spellinfo_T *spin); -static int deref_wordnode(spellinfo_T *spin, wordnode_T *node); -static void free_wordnode(spellinfo_T *spin, wordnode_T *n); -static void wordtree_compress(spellinfo_T *spin, wordnode_T *root); -static int node_compress(spellinfo_T *spin, wordnode_T *node, -                         hashtab_T *ht, -                         int *tot); -static int node_equal(wordnode_T *n1, wordnode_T *n2); -static int write_vim_spell(spellinfo_T *spin, char_u *fname); -static void clear_node(wordnode_T *node); -static int put_node(FILE *fd, wordnode_T *node, int idx, int regionmask, -                    int prefixtree); -static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname); -static int sug_filltree(spellinfo_T *spin, slang_T *slang); -static int sug_maketable(spellinfo_T *spin); -static int sug_filltable(spellinfo_T *spin, wordnode_T *node, -                         int startwordnr, -                         garray_T *gap); -static int offset2bytes(int nr, char_u *buf); -static int bytes2offset(char_u **pp); -static void sug_write(spellinfo_T *spin, char_u *fname); -static void mkspell(int fcount, char_u **fnames, int ascii, -                    int over_write, -                    int added_word); -static void spell_message(spellinfo_T *spin, char_u *str); -static void init_spellfile(void);  // In the postponed prefixes tree wn_flags is used to store the WFP_ flags,  // but it must be negative to indicate the prefix tree to tree_add_word(). @@ -6779,8 +6593,6 @@ static int node_equal(wordnode_T *n1, wordnode_T *n2)    return p1 == NULL && p2 == NULL;  } -static int -rep_compare(const void *s1, const void *s2);  // Function given to qsort() to sort the REP items on "from" string.  static int rep_compare(const void *s1, const void *s2) @@ -11176,13 +10988,6 @@ stp_sal_score (    return soundalike_score(goodsound, pbad);  } -// structure used to store soundfolded words that add_sound_suggest() has -// handled already. -typedef struct { -  short sft_score;              // lowest score used -  char_u sft_word[1];           // soundfolded word, actually longer -} sftword_T; -  static sftword_T dumsft;  #define HIKEY2SFT(p)  ((sftword_T *)(p - (dumsft.sft_word - (char_u *)&dumsft)))  #define HI2SFT(hi)     HIKEY2SFT((hi)->hi_key) @@ -11820,8 +11625,6 @@ static void rescore_one(suginfo_T *su, suggest_T *stp)    }  } -static int -sug_compare(const void *s1, const void *s2);  // Function given to qsort() to sort the suggestions on st_score.  // First on "st_score", then "st_altscore" then alphabetically. @@ -12801,12 +12604,6 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword)    return i;  } -typedef struct { -  int badi; -  int goodi; -  int score; -} limitscore_T; -  // Like spell_edit_score(), but with a limit on the score to make it faster.  // May return SCORE_MAXMAX when the score is higher than "limit".  // diff --git a/src/nvim/spell.h b/src/nvim/spell.h index ac0f904b4f..2945fcbdcb 100644 --- a/src/nvim/spell.h +++ b/src/nvim/spell.h @@ -1,33 +1,7 @@  #ifndef NVIM_SPELL_H  #define NVIM_SPELL_H -int spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, -                int docount); -int spell_move_to(win_T *wp, int dir, int allwords, int curline, -                  hlf_T *attrp); -void spell_cat_line(char_u *buf, char_u *line, int maxlen); -char_u *did_set_spelllang(win_T *wp); -void spell_delete_wordlist(void); -void spell_free_all(void); -void spell_reload(void); -int spell_check_msm(void); -void ex_mkspell(exarg_T *eap); -void ex_spell(exarg_T *eap); -void spell_add_word(char_u *word, int len, int bad, int idx, int undo); -void init_spell_chartab(void); -int spell_check_sps(void); -void spell_suggest(int count); -void ex_spellrepall(exarg_T *eap); -void spell_suggest_list(garray_T *gap, char_u *word, int maxcount, -                        int need_cap, -                        int interactive); -char_u *eval_soundfold(char_u *word); -void ex_spellinfo(exarg_T *eap); -void ex_spelldump(exarg_T *eap); -void spell_dump_compl(char_u *pat, int ic, int *dir, int dumpflags_arg); -char_u *spell_to_word_end(char_u *start, win_T *win); -int spell_word_start(int startcol); -void spell_expand_check_cap(colnr_T col); -int expand_spelling(linenr_T lnum, char_u *pat, char_u ***matchp); - -#endif // NVIM_SPELL_H +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "spell.h.generated.h" +#endif +#endif  // NVIM_SPELL_H diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 70fa43be2c..8c82186e15 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -43,7 +43,7 @@  /*   * Copy "string" into newly allocated memory.   */ -char_u *vim_strsave(char_u *string) +char_u *vim_strsave(char_u *string) FUNC_ATTR_NONNULL_RET  {    return (char_u *)xstrdup((char *)string);  } @@ -54,7 +54,7 @@ char_u *vim_strsave(char_u *string)   * The allocated memory always has size "len + 1", also when "string" is   * shorter.   */ -char_u *vim_strnsave(char_u *string, int len) +char_u *vim_strnsave(char_u *string, int len) FUNC_ATTR_NONNULL_RET  {    return (char_u *)strncpy(xmallocz(len), (char *)string, len);  } @@ -487,9 +487,10 @@ int vim_isspace(int x)  /*   * Sort an array of strings.   */ -static int -sort_compare(const void *s1, const void *s2); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "strings.c.generated.h" +#endif  static int sort_compare(const void *s1, const void *s2)  {    return STRCMP(*(char **)s1, *(char **)s2); @@ -519,7 +520,7 @@ int has_non_ascii(char_u *s)   * Concatenate two strings and return the result in allocated memory.   * Returns NULL when out of memory.   */ -char_u *concat_str(char_u *str1, char_u *str2) +char_u *concat_str(char_u *str1, char_u *str2) FUNC_ATTR_NONNULL_RET  {    size_t l = STRLEN(str1);    char_u *dest = xmalloc(l + STRLEN(str2) + 1); diff --git a/src/nvim/strings.h b/src/nvim/strings.h index aec9e4d06d..fcc88763c2 100644 --- a/src/nvim/strings.h +++ b/src/nvim/strings.h @@ -1,30 +1,7 @@  #ifndef NVIM_STRINGS_H  #define NVIM_STRINGS_H -#include "func_attr.h" - -char_u *vim_strsave(char_u *string) FUNC_ATTR_NONNULL_RET; -char_u *vim_strnsave(char_u *string, int len) FUNC_ATTR_NONNULL_RET; -char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars); -char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, -                                int cc, -                                int bsl); -char_u *vim_strsave_shellescape(char_u *string, bool do_special, bool do_newline); -char_u *vim_strsave_up(char_u *string); -char_u *vim_strnsave_up(char_u *string, int len); -void vim_strup(char_u *p); -char_u *strup_save(char_u *orig); -void copy_spaces(char_u *ptr, size_t count); -void copy_chars(char_u *ptr, size_t count, int c); -void del_trailing_spaces(char_u *ptr); -void vim_strncpy(char_u *to, char_u *from, size_t len); -void vim_strcat(char_u *to, char_u *from, size_t tosize); -int vim_stricmp(char *s1, char *s2); -int vim_strnicmp(char *s1, char *s2, size_t len); -char_u *vim_strchr(char_u *string, int c); -char_u *vim_strbyte(char_u *string, int c); -char_u *vim_strrchr(char_u *string, int c); -int vim_isspace(int x); -void sort_strings(char_u **files, int count); -char_u *concat_str(char_u *str1, char_u *str2); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "strings.h.generated.h"  #endif +#endif  // NVIM_STRINGS_H diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7d39a61b69..854e120466 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -81,6 +81,16 @@ static garray_T highlight_ga;   /* highlight groups for 'highlight' option */  #define MAX_HL_ID       20000   /* maximum value for a highlight ID. */ +/* different types of offsets that are possible */ +#define SPO_MS_OFF      0       /* match  start offset */ +#define SPO_ME_OFF      1       /* match  end	offset */ +#define SPO_HS_OFF      2       /* highl. start offset */ +#define SPO_HE_OFF      3       /* highl. end	offset */ +#define SPO_RS_OFF      4       /* region start offset */ +#define SPO_RE_OFF      5       /* region end	offset */ +#define SPO_LC_OFF      6       /* leading context offset */ +#define SPO_COUNT       7 +  /* Flags to indicate an additional string for highlight name completion. */  static int include_none = 0;    /* when 1 include "nvim/None" */  static int include_default = 0; /* when 1 include "nvim/default" */ @@ -97,40 +107,6 @@ static int hl_attr_table[] =  {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE,   HL_INVERSE, 0}; -static int get_attr_entry(garray_T *table, attrentry_T *aep); -static void syn_unadd_group(void); -static void set_hl_attr(int idx); -static void highlight_list_one(int id); -static int highlight_list_arg(int id, int didh, int type, int iarg, -                              char_u *sarg, -                              char *name); -static int syn_add_group(char_u *name); -static int syn_list_header(int did_header, int outlen, int id); -static int hl_has_settings(int idx, int check_link); -static void highlight_clear(int idx); - - -/* - * An attribute number is the index in attr_table plus ATTR_OFF. - */ -#define ATTR_OFF (HL_ALL + 1) - - -#define SYN_NAMELEN     50              /* maximum length of a syntax name */ - -/* different types of offsets that are possible */ -#define SPO_MS_OFF      0       /* match  start offset */ -#define SPO_ME_OFF      1       /* match  end	offset */ -#define SPO_HS_OFF      2       /* highl. start offset */ -#define SPO_HE_OFF      3       /* highl. end	offset */ -#define SPO_RS_OFF      4       /* region start offset */ -#define SPO_RE_OFF      5       /* region end	offset */ -#define SPO_LC_OFF      6       /* leading context offset */ -#define SPO_COUNT       7 - -static char *(spo_name_tab[SPO_COUNT]) = -{"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; -  /*   * The patterns that are being searched for are stored in a syn_pattern.   * A match item consists of one pattern. @@ -162,6 +138,87 @@ typedef struct syn_pattern {    int sp_startcol;                      /* next match in sp_line_id line */  } synpat_T; + +typedef struct syn_cluster_S { +  char_u          *scl_name;        /* syntax cluster name */ +  char_u          *scl_name_u;      /* uppercase of scl_name */ +  short           *scl_list;        /* IDs in this syntax cluster */ +} syn_cluster_T; + +/* + * For the current state we need to remember more than just the idx. + * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. + * (The end positions have the column number of the next char) + */ +typedef struct state_item { +  int si_idx;                           /* index of syntax pattern or +                                           KEYWORD_IDX */ +  int si_id;                            /* highlight group ID for keywords */ +  int si_trans_id;                      /* idem, transparency removed */ +  int si_m_lnum;                        /* lnum of the match */ +  int si_m_startcol;                    /* starting column of the match */ +  lpos_T si_m_endpos;                   /* just after end posn of the match */ +  lpos_T si_h_startpos;                 /* start position of the highlighting */ +  lpos_T si_h_endpos;                   /* end position of the highlighting */ +  lpos_T si_eoe_pos;                    /* end position of end pattern */ +  int si_end_idx;                       /* group ID for end pattern or zero */ +  int si_ends;                          /* if match ends before si_m_endpos */ +  int si_attr;                          /* attributes in this state */ +  long si_flags;                        /* HL_HAS_EOL flag in this state, and +                                         * HL_SKIP* for si_next_list */ +  int si_seqnr;                         /* sequence number */ +  int si_cchar;                         /* substitution character for conceal */ +  short       *si_cont_list;            /* list of contained groups */ +  short       *si_next_list;            /* nextgroup IDs after this item ends */ +  reg_extmatch_T *si_extmatch;          /* \z(...\) matches from start +                                         * pattern */ +} stateitem_T; + +/* + * Struct to reduce the number of arguments to get_syn_options(), it's used + * very often. + */ +typedef struct { +  int flags;                    /* flags for contained and transparent */ +  int keyword;                  /* TRUE for ":syn keyword" */ +  int         *sync_idx;        /* syntax item for "grouphere" argument, NULL +                                   if not allowed */ +  char has_cont_list;           /* TRUE if "cont_list" can be used */ +  short       *cont_list;       /* group IDs for "contains" argument */ +  short       *cont_in_list;    /* group IDs for "containedin" argument */ +  short       *next_list;       /* group IDs for "nextgroup" argument */ +} syn_opt_arg_T; + +typedef struct { +  proftime_T total; +  int count; +  int match; +  proftime_T slowest; +  proftime_T average; +  int id; +  char_u      *pattern; +} time_entry_T; + +struct name_list { +  int flag; +  char        *name; +}; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "syntax.c.generated.h" +#endif + +/* + * An attribute number is the index in attr_table plus ATTR_OFF. + */ +#define ATTR_OFF (HL_ALL + 1) + + +#define SYN_NAMELEN     50              /* maximum length of a syntax name */ + +static char *(spo_name_tab[SPO_COUNT]) = +{"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; +  /* The sp_off_flags are computed like this:   * offset from the start of the matched text: (1 << SPO_XX_OFF)   * offset from the end	 of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) @@ -198,12 +255,6 @@ static int current_flags = 0;  static int current_seqnr = 0;  static int current_sub_char = 0; -typedef struct syn_cluster_S { -  char_u          *scl_name;        /* syntax cluster name */ -  char_u          *scl_name_u;      /* uppercase of scl_name */ -  short           *scl_list;        /* IDs in this syntax cluster */ -} syn_cluster_T; -  /*   * Methods of combining two clusters   */ @@ -265,35 +316,6 @@ static int keepend_level = -1;  static char msg_no_items[] = N_("No Syntax items defined for this buffer"); -/* - * For the current state we need to remember more than just the idx. - * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. - * (The end positions have the column number of the next char) - */ -typedef struct state_item { -  int si_idx;                           /* index of syntax pattern or -                                           KEYWORD_IDX */ -  int si_id;                            /* highlight group ID for keywords */ -  int si_trans_id;                      /* idem, transparency removed */ -  int si_m_lnum;                        /* lnum of the match */ -  int si_m_startcol;                    /* starting column of the match */ -  lpos_T si_m_endpos;                   /* just after end posn of the match */ -  lpos_T si_h_startpos;                 /* start position of the highlighting */ -  lpos_T si_h_endpos;                   /* end position of the highlighting */ -  lpos_T si_eoe_pos;                    /* end position of end pattern */ -  int si_end_idx;                       /* group ID for end pattern or zero */ -  int si_ends;                          /* if match ends before si_m_endpos */ -  int si_attr;                          /* attributes in this state */ -  long si_flags;                        /* HL_HAS_EOL flag in this state, and -                                         * HL_SKIP* for si_next_list */ -  int si_seqnr;                         /* sequence number */ -  int si_cchar;                         /* substitution character for conceal */ -  short       *si_cont_list;            /* list of contained groups */ -  short       *si_next_list;            /* nextgroup IDs after this item ends */ -  reg_extmatch_T *si_extmatch;          /* \z(...\) matches from start -                                         * pattern */ -} stateitem_T; -  #define KEYWORD_IDX     -1          /* value of si_idx for keywords */  #define ID_LIST_ALL     (short *)-1 /* valid of si_cont_list for containing all                                         but contained groups */ @@ -301,21 +323,6 @@ typedef struct state_item {  static int next_seqnr = 0;              /* value to use for si_seqnr */  /* - * Struct to reduce the number of arguments to get_syn_options(), it's used - * very often. - */ -typedef struct { -  int flags;                    /* flags for contained and transparent */ -  int keyword;                  /* TRUE for ":syn keyword" */ -  int         *sync_idx;        /* syntax item for "grouphere" argument, NULL -                                   if not allowed */ -  char has_cont_list;           /* TRUE if "cont_list" can be used */ -  short       *cont_list;       /* group IDs for "contains" argument */ -  short       *cont_in_list;    /* group IDs for "containedin" argument */ -  short       *next_list;       /* group IDs for "nextgroup" argument */ -} syn_opt_arg_T; - -/*   * The next possible match in the current line for any pattern is remembered,   * to avoid having to try for a match in each column.   * If next_match_idx == -1, not tried (in this line) yet. @@ -360,115 +367,10 @@ static int current_line_id = 0;         /* unique number for current line */  #define CUR_STATE(idx)  ((stateitem_T *)(current_state.ga_data))[idx] -static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid); -static int syn_match_linecont(linenr_T lnum); -static void syn_start_line(void); -static void syn_update_ends(int startofline); -static void syn_stack_alloc(void); -static int syn_stack_cleanup(void); -static void syn_stack_free_entry(synblock_T *block, synstate_T *p); -static synstate_T *syn_stack_find_entry(linenr_T lnum); -static synstate_T *store_current_state(void); -static void load_current_state(synstate_T *from); -static void invalidate_current_state(void); -static int syn_stack_equal(synstate_T *sp); -static void validate_current_state(void); -static int syn_finish_line(int syncing); -static int syn_current_attr(int syncing, int displaying, int *can_spell, -                            int keep_state); -static int did_match_already(int idx, garray_T *gap); -static stateitem_T *push_next_match(stateitem_T *cur_si); -static void check_state_ends(void); -static void update_si_attr(int idx); -static void check_keepend(void); -static void update_si_end(stateitem_T *sip, int startcol, int force); -static short *copy_id_list(short *list); -static int in_id_list(stateitem_T *item, short *cont_list, -                      struct sp_syn *ssp, -                      int contained); -static void push_current_state(int idx); -static void pop_current_state(void); -static void syn_clear_time(syn_time_T *tt); -static void syntime_clear(void); -static int syn_compare_syntime(const void *v1, const void *v2); -static void syntime_report(void);  static int syn_time_on = FALSE;  # define IF_SYN_TIME(p) (p) -static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf); -static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, -                        lpos_T *hl_endpos, long *flagsp, lpos_T *end_endpos, -                        int *end_idx, reg_extmatch_T *start_ext); -static void clear_syn_state(synstate_T *p); -static void clear_current_state(void); - -static void limit_pos(lpos_T *pos, lpos_T *limit); -static void limit_pos_zero(lpos_T *pos, lpos_T *limit); -static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, -                            synpat_T *spp, int idx, -                            int extra); -static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, -                              synpat_T *spp, int idx, -                              int extra); -static char_u *syn_getcurline(void); -static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, -                       syn_time_T *st); -static int check_keyword_id(char_u *line, int startcol, int *endcol, -                            long *flags, short **next_list, -                            stateitem_T *cur_si, -                            int *ccharp); -static keyentry_T *match_keyword(char_u *keyword, hashtab_T *ht, -                                 stateitem_T *cur_si); -static void syn_cmd_case(exarg_T *eap, int syncing); -static void syn_cmd_spell(exarg_T *eap, int syncing); -static void syntax_sync_clear(void); -static void syn_remove_pattern(synblock_T *block, int idx); -static void syn_clear_pattern(synblock_T *block, int i); -static void syn_clear_cluster(synblock_T *block, int i); -static void syn_cmd_clear(exarg_T *eap, int syncing); -static void syn_cmd_conceal(exarg_T *eap, int syncing); -static void syn_clear_one(int id, int syncing); -static void syn_cmd_on(exarg_T *eap, int syncing); -static void syn_cmd_enable(exarg_T *eap, int syncing); -static void syn_cmd_reset(exarg_T *eap, int syncing); -static void syn_cmd_manual(exarg_T *eap, int syncing); -static void syn_cmd_off(exarg_T *eap, int syncing); -static void syn_cmd_onoff(exarg_T *eap, char *name); -static void syn_cmd_list(exarg_T *eap, int syncing); -static void syn_lines_msg(void); -static void syn_match_msg(void); -static void syn_stack_free_block(synblock_T *block); -static void syn_list_one(int id, int syncing, int link_only); -static void syn_list_cluster(int id); -static void put_id_list(char_u *name, short *list, int attr); -static void put_pattern(char *s, int c, synpat_T *spp, int attr); -static int syn_list_keywords(int id, hashtab_T *ht, int did_header, -                             int attr); -static void syn_clear_keyword(int id, hashtab_T *ht); -static void clear_keywtab(hashtab_T *ht); -static void add_keyword(char_u *name, int id, int flags, -                        short *cont_in_list, short *next_list, -                        int conceal_char); -static char_u *get_group_name(char_u *arg, char_u **name_end); -static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, -                               int *conceal_char); -static void syn_cmd_include(exarg_T *eap, int syncing); -static void syn_cmd_keyword(exarg_T *eap, int syncing); -static void syn_cmd_match(exarg_T *eap, int syncing); -static void syn_cmd_region(exarg_T *eap, int syncing); -static int syn_compare_stub(const void *v1, const void *v2); -static void syn_cmd_cluster(exarg_T *eap, int syncing); -static int syn_scl_name2id(char_u *name); -static int syn_scl_namen2id(char_u *linep, int len); -static int syn_check_cluster(char_u *pp, int len); -static int syn_add_cluster(char_u *name); -static void init_syn_patterns(void); -static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); -static void syn_cmd_sync(exarg_T *eap, int syncing); -static int get_id_list(char_u **arg, int keylen, short **list); -static void syn_combine_list(short **clstr1, short **clstr2, -                             int list_op); -static void syn_incl_toplevel(int id, int *flagsp); +  /*   * Start the syntax recognition for a line.  This function is normally called @@ -3518,12 +3420,6 @@ static void syn_match_msg(void)  static int last_matchgroup; -struct name_list { -  int flag; -  char        *name; -}; - -static void syn_list_flags(struct name_list *nl, int flags, int attr);  /*   * List one syntax item, for ":syntax" or "syntax list syntax_name". @@ -5788,16 +5684,6 @@ char_u *get_syntime_arg(expand_T *xp, int idx)    return NULL;  } -typedef struct { -  proftime_T total; -  int count; -  int match; -  proftime_T slowest; -  proftime_T average; -  int id; -  char_u      *pattern; -} time_entry_T; -  static int syn_compare_syntime(const void *v1, const void *v2)  {    const time_entry_T  *s1 = v1; @@ -7688,8 +7574,6 @@ int highlight_changed(void)    return OK;  } -static void highlight_list(void); -static void highlight_list_two(int cnt, int attr);  /*   * Handle command line completion for :highlight command. diff --git a/src/nvim/syntax.h b/src/nvim/syntax.h index f9b57993d9..ce79c49e69 100644 --- a/src/nvim/syntax.h +++ b/src/nvim/syntax.h @@ -5,54 +5,8 @@  typedef int guicolor_T; -/* syntax.c */ -void syntax_start(win_T *wp, linenr_T lnum); -void syn_stack_free_all(synblock_T *block); -void syn_stack_apply_changes(buf_T *buf); -void syntax_end_parsing(linenr_T lnum); -int syntax_check_changed(linenr_T lnum); -int get_syntax_attr(colnr_T col, int *can_spell, int keep_state); -void syntax_clear(synblock_T *block); -void reset_synblock(win_T *wp); -void ex_syntax(exarg_T *eap); -void ex_ownsyntax(exarg_T *eap); -int syntax_present(win_T *win); -void reset_expand_highlight(void); -void set_context_in_echohl_cmd(expand_T *xp, char_u *arg); -void set_context_in_syntax_cmd(expand_T *xp, char_u *arg); -char_u *get_syntax_name(expand_T *xp, int idx); -int syn_get_id(win_T *wp, long lnum, colnr_T col, int trans, -               int *spellp, -               int keep_state); -int get_syntax_info(int *seqnrp); -int syn_get_sub_char(void); -int syn_get_stack_item(int i); -int syn_get_foldlevel(win_T *wp, long lnum); -void ex_syntime(exarg_T *eap); -char_u *get_syntime_arg(expand_T *xp, int idx); -void init_highlight(int both, int reset); -int load_colors(char_u *name); -void do_highlight(char_u *line, int forceit, int init); -void free_highlight(void); -void restore_cterm_colors(void); -char_u *hl_get_font_name(void); -void clear_hl_tables(void); -int hl_combine_attr(int char_attr, int prim_attr); -attrentry_T *syn_gui_attr2entry(int attr); -int syn_attr2attr(int attr); -attrentry_T *syn_term_attr2entry(int attr); -attrentry_T *syn_cterm_attr2entry(int attr); -char_u *highlight_has_attr(int id, int flag, int modec); -char_u *highlight_color(int id, char_u *what, int modec); -int syn_name2id(char_u *name); -int highlight_exists(char_u *name); -char_u *syn_id2name(int id); -int syn_namen2id(char_u *linep, int len); -int syn_check_group(char_u *pp, int len); -int syn_id2attr(int hl_id); -int syn_get_final_id(int hl_id); -int highlight_changed(void); -void set_context_in_highlight_cmd(expand_T *xp, char_u *arg); -char_u *get_highlight_name(expand_T *xp, int idx); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "syntax.h.generated.h" +#endif -#endif /* NVIM_SYNTAX_H */ +#endif  // NVIM_SYNTAX_H diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 3b1610682b..4be18b7b34 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -66,6 +66,17 @@ typedef struct tag_pointers {  } tagptrs_T;  /* + * Structure to hold info about the tag pattern being used. + */ +typedef struct { +  char_u      *pat;             /* the pattern */ +  int len;                      /* length of pat[] */ +  char_u      *head;            /* start of pattern head */ +  int headlen;                  /* length of head[] */ +  regmatch_T regmatch;          /* regexp program, may be NULL */ +} pat_T; + +/*   * The matching tags are first stored in ga_match[].  In which one depends on   * the priority of the match.   * At the end, the matches from ga_match[] are concatenated, to make a list @@ -90,17 +101,10 @@ static char     *mt_names[MT_COUNT/2] =  #define NOTAGFILE       99              /* return value for jumpto_tag */  static char_u   *nofile_fname = NULL;   /* fname for NOTAGFILE error */ -static void taglen_advance(int l); -static int jumpto_tag(char_u *lbuf, int forceit, int keep_help); -static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp); -static int test_for_static(tagptrs_T *); -static int parse_match(char_u *lbuf, tagptrs_T *tagp); -static char_u *tag_full_fname(tagptrs_T *tagp); -static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, -                                int expand); -static int test_for_current(char_u *, char_u *, char_u *, char_u *); -static int find_extra(char_u **pp); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "tag.c.generated.h" +#endif  static char_u *bottommsg = (char_u *)N_("E555: at bottom of tag stack");  static char_u *topmsg = (char_u *)N_("E556: at top of tag stack"); @@ -991,7 +995,6 @@ void do_tags(exarg_T *eap)  # define tag_fgets vim_fgets  #endif -static int tag_strnicmp(char_u *s1, char_u *s2, size_t len);  /*   * Compare two strings, for length "len", ignoring case the ASCII way. @@ -1015,18 +1018,6 @@ static int tag_strnicmp(char_u *s1, char_u *s2, size_t len)    return 0;                             /* strings match */  } -/* - * Structure to hold info about the tag pattern being used. - */ -typedef struct { -  char_u      *pat;             /* the pattern */ -  int len;                      /* length of pat[] */ -  char_u      *head;            /* start of pattern head */ -  int headlen;                  /* length of head[] */ -  regmatch_T regmatch;          /* regexp program, may be NULL */ -} pat_T; - -static void prepare_pats(pat_T *pats, int has_re);  /*   * Extract info from the tag search pattern "pats->pat". @@ -2006,7 +1997,6 @@ findtag_end:  }  static garray_T tag_fnames = GA_EMPTY_INIT_VALUE; -static void found_tagfile_cb(char_u *fname, void *cookie);  /*   * Callback function for finding all "tags" and "tags-??" files in @@ -2773,8 +2763,6 @@ expand_tags (    return ret;  } -static int add_tag_field(dict_T *dict, char *field_name, char_u *start, -                         char_u *end);  /*   * Add a tag field to the dictionary "dict". diff --git a/src/nvim/tag.h b/src/nvim/tag.h index 91a2ebe849..c26f6b3388 100644 --- a/src/nvim/tag.h +++ b/src/nvim/tag.h @@ -12,17 +12,8 @@ typedef struct {    void        *tn_search_ctx;  } tagname_T; -int do_tag(char_u *tag, int type, int count, int forceit, int verbose); -void tag_freematch(void); -void do_tags(exarg_T *eap); -int find_tags(char_u *pat, int *num_matches, char_u ***matchesp, -              int flags, int mincount, -              char_u *buf_ffname); -void free_tag_stuff(void); -int get_tagfname(tagname_T *tnp, int first, char_u *buf); -void tagname_free(tagname_T *tnp); -int expand_tags(int tagnames, char_u *pat, int *num_file, -                char_u ***file); -int get_tags(list_T *list, char_u *pat); -#endif /* NVIM_TAG_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "tag.h.generated.h" +#endif +#endif  // NVIM_TAG_H diff --git a/src/nvim/term.c b/src/nvim/term.c index 932d58f76d..34cc90620b 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -91,23 +91,14 @@ struct builtin_term {  /* start of keys that are not directly used by Vim but can be mapped */  #define BT_EXTRA_KEYS   0x101 -static struct builtin_term *find_builtin_term(char_u *name); -static void parse_builtin_tcap(char_u *s); -static void term_color(char_u *s, int n); -static void gather_termleader(void); -static void req_codes_from_term(void); -static void req_more_codes_from_term(void); -static void got_code_from_term(char_u *code, int len); -static void check_for_codes_from_term(void); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "term.c.generated.h" +#endif  #if defined(FEAT_GUI) \    || (defined(FEAT_MOUSE) && (!defined(UNIX) || defined(FEAT_MOUSE_XTERM) \    || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE)))  static int get_bytes_from_buf(char_u *, char_u *, int);  #endif -static void del_termcode_idx(int idx); -static int term_is_builtin(char_u *name); -static int term_7to8bit(char_u *p); -static void switch_to_8bit(void);  #ifdef HAVE_TGETENT  static char_u *tgetent_error(char_u *, char_u *); @@ -155,7 +146,6 @@ char *UP, *BC, PC;  # define TGETSTR(s, p)  vim_tgetstr((s), (p))  # define TGETENT(b, t)  tgetent((char *)(b), (char *)(t)) -static char_u *vim_tgetstr(char *s, char_u **pp);  #endif /* HAVE_TGETENT */  static int detected_8bit = FALSE;       /* detected 8-bit terminal */ @@ -1216,7 +1206,6 @@ static void parse_builtin_tcap(char_u *term)      }    }  } -static void set_color_count(int nr);  /*   * Set number of colors. @@ -1939,7 +1928,6 @@ char_u *tltoa(unsigned long i)   * minimal tgoto() implementation.   * no padding and we only parse for %i %d and %+char   */ -static char *tgoto(char *, int, int);  static char *tgoto(char *cm, int x, int y)  { @@ -2064,7 +2052,6 @@ void out_char(unsigned c)      out_flush();  } -static void out_char_nf(unsigned);  /*   * out_char_nf(c): like out_char(), but don't flush when p_wd is set @@ -2321,8 +2308,6 @@ void ttest(int pairs)  }  #if defined(FEAT_GUI) || defined(PROTO) -static int get_long_from_buf(char_u *buf, long_u *val); -  /*   * Interpret the next string of bytes in buf as a long integer, with the most   * significant byte first.  Note that it is assumed that buf has been through @@ -2922,7 +2907,6 @@ static struct termcode {  static int tc_max_len = 0;  /* number of entries that termcodes[] can hold */  static int tc_len = 0;      /* current number of entries in termcodes[] */ -static int termcode_star(char_u *code, int len);  void clear_termcodes(void)  { diff --git a/src/nvim/term.h b/src/nvim/term.h index 20d46e179b..a96a2fd6a6 100644 --- a/src/nvim/term.h +++ b/src/nvim/term.h @@ -1,63 +1,7 @@  #ifndef NVIM_TERM_H  #define NVIM_TERM_H -/* term.c */ -int set_termname(char_u *term); -void set_mouse_termcode(int n, char_u *s); -void del_mouse_termcode(int n); -void getlinecol(long *cp, long *rp); -int add_termcap_entry(char_u *name, int force); -int term_is_8bit(char_u *name); -char_u *tltoa(unsigned long i); -void termcapinit(char_u *name); -void out_flush(void); -void out_flush_check(void); -void out_char(unsigned c); -void out_str_nf(char_u *s); -void out_str(char_u *s); -void term_windgoto(int row, int col); -void term_cursor_right(int i); -void term_append_lines(int line_count); -void term_delete_lines(int line_count); -void term_set_winpos(int x, int y); -void term_set_winsize(int width, int height); -void term_fg_color(int n); -void term_bg_color(int n); -void term_settitle(char_u *title); -void ttest(int pairs); -void check_shellsize(void); -void limit_screen_size(void); -void win_new_shellsize(void); -void shell_resized(void); -void shell_resized_check(void); -void set_shellsize(int width, int height, int mustset); -void settmode(int tmode); -void starttermcap(void); -void stoptermcap(void); -void may_req_termresponse(void); -void may_req_ambiguous_char_width(void); -int swapping_screen(void); -void setmouse(void); -int mouse_has(int c); -int mouse_model_popup(void); -void scroll_start(void); -void cursor_on(void); -void cursor_off(void); -void term_cursor_shape(void); -void scroll_region_set(win_T *wp, int off); -void scroll_region_reset(void); -void clear_termcodes(void); -void add_termcode(char_u *name, char_u *string, int flags); -char_u *find_termcode(char_u *name); -char_u *get_termcode(int i); -void del_termcode(char_u *name); -void set_mouse_topline(win_T *wp); -int check_termcode(int max_offset, char_u *buf, int bufsize, -                           int *buflen); -char_u *replace_termcodes(char_u *from, char_u **bufp, int from_part, -                                  int do_lt, -                                  int special); -int find_term_bykeys(char_u *src); -void show_termcodes(void); -int show_one_termcode(char_u *name, char_u *code, int printit); -char_u *translate_mapping(char_u *str, int expmap); -#endif /* NVIM_TERM_H */ + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "term.h.generated.h" +#endif +#endif  // NVIM_TERM_H diff --git a/src/nvim/ui.h b/src/nvim/ui.h index d9c3acc5f8..d26f6ab9cf 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -1,29 +1,7 @@  #ifndef NVIM_UI_H  #define NVIM_UI_H -/* ui.c */ -void ui_write(char_u *s, int len); -int ui_inchar(char_u *buf, int maxlen, long wtime, int tb_change_cnt); -int ui_char_avail(void); -void ui_delay(long msec, int ignoreinput); -void ui_suspend(void); -int ui_get_shellsize(void); -void ui_set_shellsize(int mustset); -void ui_breakcheck(void); -int vim_is_input_buf_full(void); -int vim_is_input_buf_empty(void); -char_u *get_input_buf(void); -void set_input_buf(char_u *p); -void add_to_input_buf(char_u *s, int len); -void add_to_input_buf_csi(char_u *str, int len); -void trash_input_buf(void); -int read_from_input_buf(char_u *buf, long maxlen); -void fill_input_buf(int exit_on_error); -void read_error_exit(void); -void ui_cursor_shape(void); -int check_col(int col); -int check_row(int row); -int jump_to_mouse(int flags, int *inclusive, int which_button); -int mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump); -win_T *mouse_find_win(int *rowp, int *colp); -void im_save_status(long *psave); -#endif /* NVIM_UI_H */ + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "ui.h.generated.h" +#endif +#endif  // NVIM_UI_H diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 42804210d0..5bc99f4e3e 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -106,34 +106,9 @@  #include "nvim/os/os.h"  #include "nvim/os/time.h" -static long get_undolevel(void); -static void u_unch_branch(u_header_T *uhp); -static u_entry_T *u_get_headentry(void); -static void u_getbot(void); -static void u_doit(int count); -static void u_undoredo(int undo); -static void u_undo_end(int did_undo, int absolute); -static void u_add_time(char_u *buf, size_t buflen, time_t tt); -static void u_freeheader(buf_T *buf, u_header_T *uhp, u_header_T **uhpp); -static void u_freebranch(buf_T *buf, u_header_T *uhp, u_header_T **uhpp); -static void u_freeentries(buf_T *buf, u_header_T *uhp, -                          u_header_T **uhpp); -static void u_freeentry(u_entry_T *, long); -static void corruption_error(char *mesg, char_u *file_name); -static void u_free_uhp(u_header_T *uhp); -static int serialize_header(FILE *fp, buf_T *buf, char_u *hash); -static int serialize_uhp(FILE *fp, buf_T *buf, u_header_T *uhp); -static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name); -static int serialize_uep(FILE *fp, buf_T *buf, u_entry_T *uep); -static u_entry_T *unserialize_uep(FILE *fp, int *error, -                                  char_u *file_name); -static void serialize_pos(pos_T pos, FILE *fp); -static void unserialize_pos(pos_T *pos, FILE *fp); -static void serialize_visualinfo(visualinfo_T *info, FILE *fp); -static void unserialize_visualinfo(visualinfo_T *info, FILE *fp); -static void put_header_ptr(FILE *fp, u_header_T *uhp); - -static char_u *u_save_line(linenr_T); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "undo.c.generated.h" +#endif  /* used in undo_end() to report number of added and deleted lines */  static long u_newcount, u_oldcount; diff --git a/src/nvim/undo.h b/src/nvim/undo.h index 5f37a5849e..ab8584fbb2 100644 --- a/src/nvim/undo.h +++ b/src/nvim/undo.h @@ -3,34 +3,7 @@  #include "nvim/undo_defs.h" -/* undo.c */ -int u_save_cursor(void); -int u_save(linenr_T top, linenr_T bot); -int u_savesub(linenr_T lnum); -int u_inssub(linenr_T lnum); -int u_savedel(linenr_T lnum, long nlines); -int undo_allowed(void); -int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, -                 int reload); -void u_compute_hash(char_u *hash); -char_u *u_get_undo_file_name(char_u *buf_ffname, int reading); -void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash); -void u_read_undo(char_u *name, char_u *hash, char_u *orig_name); -void u_undo(int count); -void u_redo(int count); -void undo_time(long step, int sec, int file, int absolute); -void u_sync(int force); -void ex_undolist(exarg_T *eap); -void ex_undojoin(exarg_T *eap); -void u_unchanged(buf_T *buf); -void u_find_first_changed(void); -void u_update_save_nr(buf_T *buf); -void u_clearall(buf_T *buf); -void u_saveline(linenr_T lnum); -void u_clearline(void); -void u_undoline(void); -void u_blockfree(buf_T *buf); -int bufIsChanged(buf_T *buf); -int curbufIsChanged(void); -void u_eval_tree(u_header_T *first_uhp, list_T *list); -#endif /* NVIM_UNDO_H */ +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "undo.h.generated.h" +#endif +#endif  // NVIM_UNDO_H diff --git a/src/nvim/version.c b/src/nvim/version.c index 0b899532e3..3deb9eb7c6 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -25,9 +25,10 @@ static char *mediumVersion = VIM_VERSION_MEDIUM;  char *longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")"; -static void list_features(void); -static void version_msg(char *s); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "version.c.generated.h" +#endif  static char *(features[]) = {  #ifdef HAVE_ACL    "+acl", @@ -749,7 +750,6 @@ static void version_msg(char *s)    }  } -static void do_intro_line(int row, char_u *mesg, int add_version, int attr);  /// Show the intro message when not editing a file.  void maybe_intro_message(void) diff --git a/src/nvim/version.h b/src/nvim/version.h index e98e8c1eeb..d1b19a062f 100644 --- a/src/nvim/version.h +++ b/src/nvim/version.h @@ -1,12 +1,7 @@  #ifndef NVIM_VERSION_H  #define NVIM_VERSION_H -int highest_patch(void); -int has_patch(int n); -void ex_version(exarg_T *eap); -void list_version(void); -void maybe_intro_message(void); -void intro_message(int colon); -void ex_intro(exarg_T *eap); - +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "version.h.generated.h" +#endif  #endif  // NVIM_VERSION_H diff --git a/src/nvim/window.c b/src/nvim/window.c index 11ed1c0730..906a5a14d8 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -49,68 +49,13 @@  #include "nvim/undo.h"  #include "nvim/os/os.h" -static void win_init(win_T *newp, win_T *oldp, int flags); -static void win_init_some(win_T *newp, win_T *oldp); -static void frame_comp_pos(frame_T *topfrp, int *row, int *col); -static void frame_setheight(frame_T *curfrp, int height); -static void frame_setwidth(frame_T *curfrp, int width); -static void win_exchange(long); -static void win_rotate(int, int); -static void win_totop(int size, int flags); -static void win_equal_rec(win_T *next_curwin, int current, frame_T *topfr, -                          int dir, int col, int row, int width, -                          int height); -static int last_window(void); -static int close_last_window_tabpage(win_T *win, int free_buf, -                                     tabpage_T *prev_curtab); -static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp); -static frame_T *win_altframe(win_T *win, tabpage_T *tp); -static tabpage_T *alt_tabpage(void); -static win_T *frame2win(frame_T *frp); -static int frame_has_win(frame_T *frp, win_T *wp); -static void frame_new_height(frame_T *topfrp, int height, int topfirst, -                             int wfh); -static int frame_fixed_height(frame_T *frp); -static int frame_fixed_width(frame_T *frp); -static void frame_add_statusline(frame_T *frp); -static void frame_new_width(frame_T *topfrp, int width, int leftfirst, -                            int wfw); -static void frame_add_vsep(frame_T *frp); -static int frame_minwidth(frame_T *topfrp, win_T *next_curwin); -static void frame_fix_width(win_T *wp); -static int win_alloc_firstwin(win_T *oldwin); -static void new_frame(win_T *wp); -static tabpage_T *alloc_tabpage(void); -static int leave_tabpage(buf_T *new_curbuf, int trigger_leave_autocmds); -static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, -                          int trigger_enter_autocmds, -                          int trigger_leave_autocmds); -static void frame_fix_height(win_T *wp); -static int frame_minheight(frame_T *topfrp, win_T *next_curwin); -static void win_enter_ext(win_T *wp, int undo_sync, int no_curwin, -                          int trigger_enter_autocmds, -                          int trigger_leave_autocmds); -static void win_free(win_T *wp, tabpage_T *tp); -static void frame_append(frame_T *after, frame_T *frp); -static void frame_insert(frame_T *before, frame_T *frp); -static void frame_remove(frame_T *frp); -static void win_goto_ver(int up, long count); -static void win_goto_hor(int left, long count); -static void frame_add_height(frame_T *frp, int n); -static void last_status_rec(frame_T *fr, int statusline); - -static void make_snapshot_rec(frame_T *fr, frame_T **frp); -static void clear_snapshot(tabpage_T *tp, int idx); -static void clear_snapshot_rec(frame_T *fr); -static int check_snapshot_rec(frame_T *sn, frame_T *fr); -static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr); - -static int frame_check_height(frame_T *topfrp, int height); -static int frame_check_width(frame_T *topfrp, int width); - - -static win_T *win_alloc(win_T *after, int hidden); -static void set_fraction(win_T *wp); + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "window.c.generated.h" +#endif + + +  #define NOWIN           (win_T *)-1     /* non-existing window */ diff --git a/src/nvim/window.h b/src/nvim/window.h index 34bc2fc30e..1c0633c4f2 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -1,85 +1,7 @@  #ifndef NVIM_WINDOW_H  #define NVIM_WINDOW_H -/* window.c */ -void do_window(int nchar, long Prenum, int xchar); -int win_split(int size, int flags); -int win_split_ins(int size, int flags, win_T *new_wp, int dir); -int win_valid(win_T *win); -int win_count(void); -int make_windows(int count, int vertical); -void win_move_after(win_T *win1, win_T *win2); -void win_equal(win_T *next_curwin, int current, int dir); -void close_windows(buf_T *buf, int keep_curwin); -int one_window(void); -int win_close(win_T *win, int free_buf); -void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp); -void win_free_all(void); -win_T *winframe_remove(win_T *win, int *dirp, tabpage_T *tp); -void close_others(int message, int forceit); -void curwin_init(void); -void win_init_empty(win_T *wp); -int win_alloc_first(void); -void win_alloc_aucmd_win(void); -void win_init_size(void); -void free_tabpage(tabpage_T *tp); -int win_new_tabpage(int after); -int may_open_tabpage(void); -int make_tabpages(int maxcount); -int valid_tabpage(tabpage_T *tpc); -tabpage_T *find_tabpage(int n); -int tabpage_index(tabpage_T *ftp); -void goto_tabpage(int n); -void goto_tabpage_tp(tabpage_T *tp, int trigger_enter_autocmds, -                     int trigger_leave_autocmds); -void goto_tabpage_win(tabpage_T *tp, win_T *wp); -void tabpage_move(int nr); -void win_goto(win_T *wp); -tabpage_T *win_find_tabpage(win_T *win); -void win_enter(win_T *wp, int undo_sync); -win_T *buf_jump_open_win(buf_T *buf); -win_T *buf_jump_open_tab(buf_T *buf); -void win_append(win_T *after, win_T *wp); -void win_remove(win_T *wp, tabpage_T *tp); -void win_alloc_lines(win_T *wp); -void win_free_lsize(win_T *wp); -void shell_new_rows(void); -void shell_new_columns(void); -void win_size_save(garray_T *gap); -void win_size_restore(garray_T *gap); -int win_comp_pos(void); -void win_setheight(int height); -void win_setheight_win(int height, win_T *win); -void win_setwidth(int width); -void win_setwidth_win(int width, win_T *wp); -void win_setminheight(void); -void win_drag_status_line(win_T *dragwin, int offset); -void win_drag_vsep_line(win_T *dragwin, int offset); -void win_new_height(win_T *wp, int height); -void win_new_width(win_T *wp, int width); -void win_comp_scroll(win_T *wp); -void command_height(void); -char_u *grab_file_name(long count, linenr_T *file_lnum); -char_u *file_name_at_cursor(int options, long count, -                            linenr_T *file_lnum); -char_u *file_name_in_line(char_u *line, int col, int options, -                          long count, char_u *rel_fname, -                          linenr_T *file_lnum); -void last_status(int morewin); -int tabline_height(void); -int min_rows(void); -int only_one_window(void); -void check_lnums(int do_curwin); -void make_snapshot(int idx); -void restore_snapshot(int idx, int close_curwin); -int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, -               tabpage_T *tp, -               int no_display); -void restore_win(win_T *save_curwin, tabpage_T *save_curtab, -                 int no_display); -void switch_buffer(buf_T **save_curbuf, buf_T *buf); -void restore_buffer(buf_T *save_curbuf); -int match_add(win_T *wp, char_u *grp, char_u *pat, int prio, int id); -int match_delete(win_T *wp, int id, int perr); -void clear_matches(win_T *wp); -matchitem_T *get_match(win_T *wp, int id); -#endif /* NVIM_WINDOW_H */ + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "window.h.generated.h" +#endif +#endif  // NVIM_WINDOW_H diff --git a/test/config/paths.lua.in b/test/config/paths.lua.in index 9ec8b23055..a13230ed28 100644 --- a/test/config/paths.lua.in +++ b/test/config/paths.lua.in @@ -7,5 +7,6 @@ end  module.test_include_path = "${CMAKE_BINARY_DIR}/test/includes/post"  module.test_libnvim_path = "${TEST_LIBNVIM_PATH}" +table.insert(module.include_paths, "${CMAKE_BINARY_DIR}/include")  return module diff --git a/test/unit/preprocess.moon b/test/unit/preprocess.moon index 88580476b2..cf98ac3c8b 100644 --- a/test/unit/preprocess.moon +++ b/test/unit/preprocess.moon @@ -85,7 +85,8 @@ class Gcc     '-D "__asm(ARGS)="',     '-D "__asm__(ARGS)="',     '-D "__inline__="', -   '-D_GNU_SOURCE' +   '-D_GNU_SOURCE', +   '-DINCLUDE_GENERATED_DECLARATIONS'    }    new: (path) => | 
