mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
commit
172d099c32
@ -89,7 +89,7 @@ endforeach()
|
||||
|
||||
list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove})
|
||||
|
||||
# Handle legacy files that don't yet pass -Wconversion.
|
||||
# Legacy files that do not yet pass -Wconversion.
|
||||
set(CONV_SOURCES
|
||||
buffer.c
|
||||
diff.c
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/ex_cmds.h"
|
||||
#include "nvim/mark.h"
|
||||
#include "nvim/fileio.h"
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "nvim/msgpack_rpc/channel.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/buffer.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/window.h"
|
||||
#include "nvim/types.h"
|
||||
#include "nvim/ex_docmd.h"
|
||||
@ -21,7 +22,7 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/eval.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/os/input.h"
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "nvim/window.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/misc2.h"
|
||||
|
||||
|
||||
/// Gets the current buffer in a window
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "nvim/ex_eval.h"
|
||||
#include "nvim/ex_getln.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/fold.h"
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/hashtab.h"
|
||||
@ -48,7 +49,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/option.h"
|
||||
|
@ -19,10 +19,11 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/os_unix.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/path.h"
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/ascii.h"
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/misc2.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "cursor.h.generated.h"
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/cursor_shape.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/ex_getln.h"
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/strings.h"
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/normal.h"
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/normal.h"
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/normal.h"
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/map.h"
|
||||
#include "nvim/file_search.h"
|
||||
@ -63,6 +62,7 @@
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/sha256.h"
|
||||
#include "nvim/spell.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/tag.h"
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/move.h"
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "nvim/menu.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/garray.h"
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "nvim/ex_cmds2.h"
|
||||
#include "nvim/ex_docmd.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/regexp.h"
|
||||
#include "nvim/strings.h"
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "nvim/menu.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/cursor_shape.h"
|
||||
#include "nvim/keymap.h"
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/vim.h"
|
||||
|
@ -1,48 +1,44 @@
|
||||
/* TODO: make some #ifdef for this */
|
||||
/*--------[ file searching ]-------------------------------------------------*/
|
||||
/*
|
||||
* File searching functions for 'path', 'tags' and 'cdpath' options.
|
||||
* External visible functions:
|
||||
* vim_findfile_init() creates/initialises the search context
|
||||
* vim_findfile_free_visited() free list of visited files/dirs of search
|
||||
* context
|
||||
* vim_findfile() find a file in the search context
|
||||
* vim_findfile_cleanup() cleanup/free search context created by
|
||||
* vim_findfile_init()
|
||||
*
|
||||
* All static functions and variables start with 'ff_'
|
||||
*
|
||||
* In general it works like this:
|
||||
* First you create yourself a search context by calling vim_findfile_init().
|
||||
* It is possible to give a search context from a previous call to
|
||||
* vim_findfile_init(), so it can be reused. After this you call vim_findfile()
|
||||
* until you are satisfied with the result or it returns NULL. On every call it
|
||||
* returns the next file which matches the conditions given to
|
||||
* vim_findfile_init(). If it doesn't find a next file it returns NULL.
|
||||
*
|
||||
* It is possible to call vim_findfile_init() again to reinitialise your search
|
||||
* with some new parameters. Don't forget to pass your old search context to
|
||||
* it, so it can reuse it and especially reuse the list of already visited
|
||||
* directories. If you want to delete the list of already visited directories
|
||||
* simply call vim_findfile_free_visited().
|
||||
*
|
||||
* When you are done call vim_findfile_cleanup() to free the search context.
|
||||
*
|
||||
* The function vim_findfile_init() has a long comment, which describes the
|
||||
* needed parameters.
|
||||
*
|
||||
*
|
||||
*
|
||||
* ATTENTION:
|
||||
* ==========
|
||||
* Also we use an allocated search context here, this functions are NOT
|
||||
* thread-safe!!!!!
|
||||
*
|
||||
* To minimize parameter passing (or because I'm to lazy), only the
|
||||
* external visible functions get a search context as a parameter. This is
|
||||
* then assigned to a static global, which is used throughout the local
|
||||
* functions.
|
||||
*/
|
||||
// File searching functions for 'path', 'tags' and 'cdpath' options.
|
||||
//
|
||||
// External visible functions:
|
||||
// vim_findfile_init() creates/initialises the search context
|
||||
// vim_findfile_free_visited() free list of visited files/dirs of search
|
||||
// context
|
||||
// vim_findfile() find a file in the search context
|
||||
// vim_findfile_cleanup() cleanup/free search context created by
|
||||
// vim_findfile_init()
|
||||
//
|
||||
// All static functions and variables start with 'ff_'
|
||||
//
|
||||
// In general it works like this:
|
||||
// First you create yourself a search context by calling vim_findfile_init().
|
||||
// It is possible to give a search context from a previous call to
|
||||
// vim_findfile_init(), so it can be reused. After this you call vim_findfile()
|
||||
// until you are satisfied with the result or it returns NULL. On every call it
|
||||
// returns the next file which matches the conditions given to
|
||||
// vim_findfile_init(). If it doesn't find a next file it returns NULL.
|
||||
//
|
||||
// It is possible to call vim_findfile_init() again to reinitialise your search
|
||||
// with some new parameters. Don't forget to pass your old search context to
|
||||
// it, so it can reuse it and especially reuse the list of already visited
|
||||
// directories. If you want to delete the list of already visited directories
|
||||
// simply call vim_findfile_free_visited().
|
||||
//
|
||||
// When you are done call vim_findfile_cleanup() to free the search context.
|
||||
//
|
||||
// The function vim_findfile_init() has a long comment, which describes the
|
||||
// needed parameters.
|
||||
//
|
||||
//
|
||||
//
|
||||
// ATTENTION:
|
||||
// ==========
|
||||
// We use an allocated search context, these functions are NOT thread-safe!!!!!
|
||||
//
|
||||
// To minimize parameter passing (or because I'm too lazy), only the
|
||||
// external visible functions get a search context as a parameter. This is
|
||||
// then assigned to a static global, which is used throughout the local
|
||||
// functions.
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
@ -59,7 +55,7 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/os_unix.h"
|
||||
#include "nvim/path.h"
|
||||
#include "nvim/strings.h"
|
||||
@ -1526,3 +1522,28 @@ theend:
|
||||
return file_name;
|
||||
}
|
||||
|
||||
/// Change to a file's directory.
|
||||
/// Caller must call shorten_fnames()!
|
||||
/// @return OK or FAIL
|
||||
int vim_chdirfile(char_u *fname)
|
||||
{
|
||||
char_u dir[MAXPATHL];
|
||||
|
||||
STRLCPY(dir, fname, MAXPATHL);
|
||||
*path_tail_with_sep(dir) = NUL;
|
||||
return os_chdir((char *)dir) == 0 ? OK : FAIL;
|
||||
}
|
||||
|
||||
/// Change directory to "new_dir". Search 'cdpath' for relative directory names.
|
||||
int vim_chdir(char_u *new_dir)
|
||||
{
|
||||
char_u *dir_name = find_directory_in_path(new_dir, STRLEN(new_dir),
|
||||
FNAME_MESS, curbuf->b_ffname);
|
||||
if (dir_name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int r = os_chdir((char *)dir_name);
|
||||
xfree(dir_name);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/normal.h"
|
||||
@ -44,6 +43,7 @@
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/sha256.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/types.h"
|
||||
@ -4447,11 +4447,95 @@ bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL
|
||||
return eof == NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* os_rename() only works if both files are on the same file system, this
|
||||
* function will (attempts to?) copy the file across if rename fails -- webb
|
||||
* Return -1 for failure, 0 for success.
|
||||
*/
|
||||
/// Read 2 bytes from "fd" and turn them into an int, MSB first.
|
||||
int get2c(FILE *fd)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = getc(fd);
|
||||
n = (n << 8) + getc(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Read 3 bytes from "fd" and turn them into an int, MSB first.
|
||||
int get3c(FILE *fd)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = getc(fd);
|
||||
n = (n << 8) + getc(fd);
|
||||
n = (n << 8) + getc(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Read 4 bytes from "fd" and turn them into an int, MSB first.
|
||||
int get4c(FILE *fd)
|
||||
{
|
||||
// Use unsigned rather than int otherwise result is undefined
|
||||
// when left-shift sets the MSB.
|
||||
unsigned n;
|
||||
|
||||
n = (unsigned)getc(fd);
|
||||
n = (n << 8) + (unsigned)getc(fd);
|
||||
n = (n << 8) + (unsigned)getc(fd);
|
||||
n = (n << 8) + (unsigned)getc(fd);
|
||||
return (int)n;
|
||||
}
|
||||
|
||||
/// Read 8 bytes from `fd` and turn them into a time_t, MSB first.
|
||||
time_t get8ctime(FILE *fd)
|
||||
{
|
||||
time_t n = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
n = (n << 8) + getc(fd);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Reads a string of length "cnt" from "fd" into allocated memory.
|
||||
/// @return pointer to the string or NULL when unable to read that many bytes.
|
||||
char *read_string(FILE *fd, size_t cnt)
|
||||
{
|
||||
char *str = xmallocz(cnt);
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
int c = getc(fd);
|
||||
if (c == EOF) {
|
||||
xfree(str);
|
||||
return NULL;
|
||||
}
|
||||
str[i] = (char)c;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/// Writes a number to file "fd", most significant bit first, in "len" bytes.
|
||||
/// @returns false in case of an error.
|
||||
bool put_bytes(FILE *fd, uintmax_t number, size_t len)
|
||||
{
|
||||
assert(len > 0);
|
||||
for (size_t i = len - 1; i < len; i--) {
|
||||
if (putc((int)(number >> (i * 8)), fd) == EOF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Writes time_t to file "fd" in 8 bytes.
|
||||
/// @returns FAIL when the write failed.
|
||||
int put_time(FILE *fd, time_t time_)
|
||||
{
|
||||
uint8_t buf[8];
|
||||
time_to_bytes(time_, buf);
|
||||
return fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd) == 1 ? OK : FAIL;
|
||||
}
|
||||
|
||||
/// os_rename() only works if both files are on the same file system, this
|
||||
/// function will (attempts to?) copy the file across if rename fails -- webb
|
||||
//
|
||||
/// @return -1 for failure, 0 for success
|
||||
int vim_rename(char_u *from, char_u *to)
|
||||
{
|
||||
int fd_in;
|
||||
|
@ -12,6 +12,8 @@
|
||||
#define READ_DUMMY 0x10 /* reading into a dummy buffer */
|
||||
#define READ_KEEP_UNDO 0x20 /* keep undo info*/
|
||||
|
||||
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
||||
|
||||
/*
|
||||
* Struct to save values in before executing autocommands for a buffer that is
|
||||
* not the current buffer.
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/option.h"
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/log.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/path.h"
|
||||
#include "nvim/garray.h"
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
@ -38,6 +37,7 @@
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/regexp.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/undo.h"
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/path.h"
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "nvim/hashtab.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc2.h"
|
||||
|
||||
// Magic value for algorithm that walks through the array.
|
||||
#define PERTURB_SHIFT 5
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "nvim/eval.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/os/time.h"
|
||||
#include "nvim/path.h"
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/regexp.h"
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "nvim/indent_c.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/strings.h"
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/log.h"
|
||||
#include "nvim/memory.h"
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/normal.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/path.h"
|
||||
|
@ -84,7 +84,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/screen.h"
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/os_unix.h"
|
||||
#include "nvim/path.h"
|
||||
|
@ -55,7 +55,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/os_unix.h"
|
||||
#include "nvim/path.h"
|
||||
@ -3964,20 +3963,19 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Goto byte in buffer with offset 'cnt'.
|
||||
*/
|
||||
/// Goto byte in buffer with offset 'cnt'.
|
||||
void goto_byte(long cnt)
|
||||
{
|
||||
long boff = cnt;
|
||||
linenr_T lnum;
|
||||
|
||||
ml_flush_line(curbuf); /* cached line may be dirty */
|
||||
ml_flush_line(curbuf); // cached line may be dirty
|
||||
setpcmark();
|
||||
if (boff)
|
||||
--boff;
|
||||
if (boff) {
|
||||
boff--;
|
||||
}
|
||||
lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff);
|
||||
if (lnum < 1) { /* past the end */
|
||||
if (lnum < 1) { // past the end
|
||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||
curwin->w_curswant = MAXCOL;
|
||||
coladvance((colnr_T)MAXCOL);
|
||||
@ -3989,7 +3987,84 @@ void goto_byte(long cnt)
|
||||
}
|
||||
check_cursor();
|
||||
|
||||
/* Make sure the cursor is on the first byte of a multi-byte char. */
|
||||
if (has_mbyte)
|
||||
// Make sure the cursor is on the first byte of a multi-byte char.
|
||||
if (has_mbyte) {
|
||||
mb_adjust_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
/// Increment the line pointer "lp" crossing line boundaries as necessary.
|
||||
/// Return 1 when going to the next line.
|
||||
/// Return 2 when moving forward onto a NUL at the end of the line).
|
||||
/// Return -1 when at the end of file.
|
||||
/// Return 0 otherwise.
|
||||
int inc(pos_T *lp)
|
||||
{
|
||||
char_u *p = ml_get_pos(lp);
|
||||
|
||||
if (*p != NUL) { // still within line, move to next char (may be NUL)
|
||||
if (has_mbyte) {
|
||||
int l = (*mb_ptr2len)(p);
|
||||
|
||||
lp->col += l;
|
||||
return (p[l] != NUL) ? 0 : 2;
|
||||
}
|
||||
lp->col++;
|
||||
lp->coladd = 0;
|
||||
return (p[1] != NUL) ? 0 : 2;
|
||||
}
|
||||
if (lp->lnum != curbuf->b_ml.ml_line_count) { // there is a next line
|
||||
lp->col = 0;
|
||||
lp->lnum++;
|
||||
lp->coladd = 0;
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Same as inc(), but skip NUL at the end of non-empty lines.
|
||||
int incl(pos_T *lp)
|
||||
{
|
||||
int r;
|
||||
|
||||
if ((r = inc(lp)) >= 1 && lp->col) {
|
||||
r = inc(lp);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int dec(pos_T *lp)
|
||||
{
|
||||
char_u *p;
|
||||
|
||||
lp->coladd = 0;
|
||||
if (lp->col > 0) { // still within line
|
||||
lp->col--;
|
||||
if (has_mbyte) {
|
||||
p = ml_get(lp->lnum);
|
||||
lp->col -= (*mb_head_off)(p, p + lp->col);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (lp->lnum > 1) { // there is a prior line
|
||||
lp->lnum--;
|
||||
p = ml_get(lp->lnum);
|
||||
lp->col = (colnr_T)STRLEN(p);
|
||||
if (has_mbyte) {
|
||||
lp->col -= (*mb_head_off)(p, p + lp->col);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return -1; // at start of file
|
||||
}
|
||||
|
||||
/// Same as dec(), but skip NUL at the end of non-empty lines.
|
||||
int decl(pos_T *lp)
|
||||
{
|
||||
int r;
|
||||
|
||||
if ((r = dec(lp)) == 1 && lp->col) {
|
||||
r = dec(lp);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
@ -440,6 +440,16 @@ void do_outofmem_msg(size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes time_t to "buf[8]".
|
||||
void time_to_bytes(time_t time_, uint8_t buf[8])
|
||||
{
|
||||
// time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits
|
||||
// systems, thus we can't use put_bytes() here.
|
||||
for (size_t i = 7, bufi = 0; bufi < 8; i--, bufi++) {
|
||||
buf[bufi] = (uint8_t)((uint64_t)time_ >> (i * 8));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(EXITFREE)
|
||||
|
||||
#include "nvim/file_search.h"
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdint.h> // for uint8_t
|
||||
#include <stddef.h> // for size_t
|
||||
#include <time.h> // for time_t
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "memory.h.generated.h"
|
||||
|
@ -18,9 +18,9 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/ui.h"
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/ops.h"
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/mouse.h"
|
||||
@ -41,6 +40,7 @@
|
||||
#include "nvim/regexp.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/tag.h"
|
||||
#include "nvim/ui.h"
|
||||
@ -1745,18 +1745,6 @@ int gchar_pos(pos_T *pos)
|
||||
return (int)*ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip to next part of an option argument: Skip space and comma.
|
||||
*/
|
||||
char_u *skip_to_option_part(char_u *p)
|
||||
{
|
||||
if (*p == ',')
|
||||
++p;
|
||||
while (*p == ' ')
|
||||
++p;
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call this function when something in the current buffer is changed.
|
||||
*
|
||||
@ -2691,6 +2679,42 @@ void fast_breakcheck(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Call shell. Calls os_call_shell, with 'shellxquote' added.
|
||||
int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
|
||||
{
|
||||
int retval;
|
||||
proftime_T wait_time;
|
||||
|
||||
if (p_verbose > 3) {
|
||||
verbose_enter();
|
||||
smsg(_("Calling shell to execute: \"%s\""),
|
||||
cmd == NULL ? p_sh : cmd);
|
||||
ui_putc('\n');
|
||||
verbose_leave();
|
||||
}
|
||||
|
||||
if (do_profiling == PROF_YES) {
|
||||
prof_child_enter(&wait_time);
|
||||
}
|
||||
|
||||
if (*p_sh == NUL) {
|
||||
EMSG(_(e_shellempty));
|
||||
retval = -1;
|
||||
} else {
|
||||
// The external command may update a tags file, clear cached tags.
|
||||
tag_freematch();
|
||||
|
||||
retval = os_call_shell(cmd, opts, extra_shell_arg);
|
||||
}
|
||||
|
||||
set_vim_var_nr(VV_SHELL_ERROR, (varnumber_T)retval);
|
||||
if (do_profiling == PROF_YES) {
|
||||
prof_child_exit(&wait_time);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// Get the stdout of an external command.
|
||||
/// If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not
|
||||
/// NULL store the length there.
|
||||
|
464
src/nvim/misc2.c
464
src/nvim/misc2.c
@ -1,464 +0,0 @@
|
||||
/*
|
||||
* misc2.c: Various functions.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/buffer.h"
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/cursor.h"
|
||||
#include "nvim/diff.h"
|
||||
#include "nvim/edit.h"
|
||||
#include "nvim/eval.h"
|
||||
#include "nvim/ex_cmds.h"
|
||||
#include "nvim/ex_docmd.h"
|
||||
#include "nvim/ex_getln.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/fold.h"
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/macros.h"
|
||||
#include "nvim/mark.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memfile.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/ops.h"
|
||||
#include "nvim/os_unix.h"
|
||||
#include "nvim/path.h"
|
||||
#include "nvim/quickfix.h"
|
||||
#include "nvim/regexp.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/spell.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/tag.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/window.h"
|
||||
#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.
|
||||
*/
|
||||
int virtual_active(void)
|
||||
{
|
||||
/* While an operator is being executed we return "virtual_op", because
|
||||
* VIsual_active has already been reset, thus we can't check for "block"
|
||||
* being used. */
|
||||
if (virtual_op != MAYBE)
|
||||
return virtual_op;
|
||||
return ve_flags == VE_ALL
|
||||
|| ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V)
|
||||
|| ((ve_flags & VE_INSERT) && (State & INSERT));
|
||||
}
|
||||
|
||||
/*
|
||||
* Increment the line pointer "lp" crossing line boundaries as necessary.
|
||||
* Return 1 when going to the next line.
|
||||
* Return 2 when moving forward onto a NUL at the end of the line).
|
||||
* Return -1 when at the end of file.
|
||||
* Return 0 otherwise.
|
||||
*/
|
||||
int inc(pos_T *lp)
|
||||
{
|
||||
char_u *p = ml_get_pos(lp);
|
||||
|
||||
if (*p != NUL) { /* still within line, move to next char (may be NUL) */
|
||||
if (has_mbyte) {
|
||||
int l = (*mb_ptr2len)(p);
|
||||
|
||||
lp->col += l;
|
||||
return (p[l] != NUL) ? 0 : 2;
|
||||
}
|
||||
lp->col++;
|
||||
lp->coladd = 0;
|
||||
return (p[1] != NUL) ? 0 : 2;
|
||||
}
|
||||
if (lp->lnum != curbuf->b_ml.ml_line_count) { /* there is a next line */
|
||||
lp->col = 0;
|
||||
lp->lnum++;
|
||||
lp->coladd = 0;
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* incl(lp): same as inc(), but skip the NUL at the end of non-empty lines
|
||||
*/
|
||||
int incl(pos_T *lp)
|
||||
{
|
||||
int r;
|
||||
|
||||
if ((r = inc(lp)) >= 1 && lp->col)
|
||||
r = inc(lp);
|
||||
return r;
|
||||
}
|
||||
|
||||
int dec(pos_T *lp)
|
||||
{
|
||||
char_u *p;
|
||||
|
||||
lp->coladd = 0;
|
||||
if (lp->col > 0) { /* still within line */
|
||||
lp->col--;
|
||||
if (has_mbyte) {
|
||||
p = ml_get(lp->lnum);
|
||||
lp->col -= (*mb_head_off)(p, p + lp->col);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (lp->lnum > 1) { /* there is a prior line */
|
||||
lp->lnum--;
|
||||
p = ml_get(lp->lnum);
|
||||
lp->col = (colnr_T)STRLEN(p);
|
||||
if (has_mbyte)
|
||||
lp->col -= (*mb_head_off)(p, p + lp->col);
|
||||
return 1;
|
||||
}
|
||||
return -1; /* at start of file */
|
||||
}
|
||||
|
||||
/*
|
||||
* decl(lp): same as dec(), but skip the NUL at the end of non-empty lines
|
||||
*/
|
||||
int decl(pos_T *lp)
|
||||
{
|
||||
int r;
|
||||
|
||||
if ((r = dec(lp)) == 1 && lp->col)
|
||||
r = dec(lp);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE when 'shell' has "csh" in the tail.
|
||||
*/
|
||||
int csh_like_shell(void)
|
||||
{
|
||||
return strstr((char *)path_tail(p_sh), "csh") != NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Isolate one part of a string option where parts are separated with
|
||||
* "sep_chars".
|
||||
* The part is copied into "buf[maxlen]".
|
||||
* "*option" is advanced to the next part.
|
||||
* The length is returned.
|
||||
*/
|
||||
size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen, char *sep_chars)
|
||||
{
|
||||
size_t len = 0;
|
||||
char_u *p = *option;
|
||||
|
||||
/* skip '.' at start of option part, for 'suffixes' */
|
||||
if (*p == '.')
|
||||
buf[len++] = *p++;
|
||||
while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) {
|
||||
/*
|
||||
* Skip backslash before a separator character and space.
|
||||
*/
|
||||
if (p[0] == '\\' && vim_strchr((char_u *)sep_chars, p[1]) != NULL)
|
||||
++p;
|
||||
if (len < maxlen - 1)
|
||||
buf[len++] = *p;
|
||||
++p;
|
||||
}
|
||||
buf[len] = NUL;
|
||||
|
||||
if (*p != NUL && *p != ',') /* skip non-standard separator */
|
||||
++p;
|
||||
p = skip_to_option_part(p); /* p points to next file name */
|
||||
|
||||
*option = p;
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC.
|
||||
*/
|
||||
int get_fileformat(buf_T *buf)
|
||||
{
|
||||
int c = *buf->b_p_ff;
|
||||
|
||||
if (buf->b_p_bin || c == 'u')
|
||||
return EOL_UNIX;
|
||||
if (c == 'm')
|
||||
return EOL_MAC;
|
||||
return EOL_DOS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like get_fileformat(), but override 'fileformat' with "p" for "++opt=val"
|
||||
* argument.
|
||||
*/
|
||||
int
|
||||
get_fileformat_force (
|
||||
buf_T *buf,
|
||||
exarg_T *eap /* can be NULL! */
|
||||
)
|
||||
{
|
||||
int c;
|
||||
|
||||
if (eap != NULL && eap->force_ff != 0)
|
||||
c = eap->cmd[eap->force_ff];
|
||||
else {
|
||||
if ((eap != NULL && eap->force_bin != 0)
|
||||
? (eap->force_bin == FORCE_BIN) : buf->b_p_bin)
|
||||
return EOL_UNIX;
|
||||
c = *buf->b_p_ff;
|
||||
}
|
||||
if (c == 'u')
|
||||
return EOL_UNIX;
|
||||
if (c == 'm')
|
||||
return EOL_MAC;
|
||||
return EOL_DOS;
|
||||
}
|
||||
|
||||
/// Set the current end-of-line type to EOL_UNIX, EOL_MAC, or EOL_DOS.
|
||||
///
|
||||
/// Sets 'fileformat'.
|
||||
///
|
||||
/// @param eol_style End-of-line style.
|
||||
/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
|
||||
void set_fileformat(int eol_style, int opt_flags)
|
||||
{
|
||||
char *p = NULL;
|
||||
|
||||
switch (eol_style) {
|
||||
case EOL_UNIX:
|
||||
p = FF_UNIX;
|
||||
break;
|
||||
case EOL_MAC:
|
||||
p = FF_MAC;
|
||||
break;
|
||||
case EOL_DOS:
|
||||
p = FF_DOS;
|
||||
break;
|
||||
}
|
||||
|
||||
// p is NULL if "eol_style" is EOL_UNKNOWN.
|
||||
if (p != NULL) {
|
||||
set_string_option_direct((char_u *)"ff",
|
||||
-1,
|
||||
(char_u *)p,
|
||||
OPT_FREE | opt_flags,
|
||||
0);
|
||||
}
|
||||
|
||||
// This may cause the buffer to become (un)modified.
|
||||
check_status(curbuf);
|
||||
redraw_tabline = TRUE;
|
||||
need_maketitle = TRUE; // Set window title later.
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the default fileformat from 'fileformats'.
|
||||
*/
|
||||
int default_fileformat(void)
|
||||
{
|
||||
switch (*p_ffs) {
|
||||
case 'm': return EOL_MAC;
|
||||
case 'd': return EOL_DOS;
|
||||
}
|
||||
return EOL_UNIX;
|
||||
}
|
||||
|
||||
// Call shell. Calls os_call_shell, with 'shellxquote' added.
|
||||
int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
|
||||
{
|
||||
int retval;
|
||||
proftime_T wait_time;
|
||||
|
||||
if (p_verbose > 3) {
|
||||
verbose_enter();
|
||||
smsg(_("Calling shell to execute: \"%s\""),
|
||||
cmd == NULL ? p_sh : cmd);
|
||||
ui_putc('\n');
|
||||
verbose_leave();
|
||||
}
|
||||
|
||||
if (do_profiling == PROF_YES)
|
||||
prof_child_enter(&wait_time);
|
||||
|
||||
if (*p_sh == NUL) {
|
||||
EMSG(_(e_shellempty));
|
||||
retval = -1;
|
||||
} else {
|
||||
/* The external command may update a tags file, clear cached tags. */
|
||||
tag_freematch();
|
||||
|
||||
retval = os_call_shell(cmd, opts, extra_shell_arg);
|
||||
}
|
||||
|
||||
set_vim_var_nr(VV_SHELL_ERROR, (varnumber_T) retval);
|
||||
if (do_profiling == PROF_YES) {
|
||||
prof_child_exit(&wait_time);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to
|
||||
* NORMAL State with a condition. This function returns the real State.
|
||||
*/
|
||||
int get_real_state(void)
|
||||
{
|
||||
if (State & NORMAL) {
|
||||
if (VIsual_active) {
|
||||
if (VIsual_select)
|
||||
return SELECTMODE;
|
||||
return VISUAL;
|
||||
} else if (finish_op)
|
||||
return OP_PENDING;
|
||||
}
|
||||
return State;
|
||||
}
|
||||
|
||||
/*
|
||||
* Change to a file's directory.
|
||||
* Caller must call shorten_fnames()!
|
||||
* Return OK or FAIL.
|
||||
*/
|
||||
int vim_chdirfile(char_u *fname)
|
||||
{
|
||||
char_u dir[MAXPATHL];
|
||||
|
||||
STRLCPY(dir, fname, MAXPATHL);
|
||||
*path_tail_with_sep(dir) = NUL;
|
||||
return os_chdir((char *)dir) == 0 ? OK : FAIL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Change directory to "new_dir". Search 'cdpath' for relative directory names.
|
||||
*/
|
||||
int vim_chdir(char_u *new_dir)
|
||||
{
|
||||
char_u *dir_name;
|
||||
int r;
|
||||
|
||||
dir_name = find_directory_in_path(new_dir, STRLEN(new_dir),
|
||||
FNAME_MESS, curbuf->b_ffname);
|
||||
if (dir_name == NULL)
|
||||
return -1;
|
||||
r = os_chdir((char *)dir_name);
|
||||
xfree(dir_name);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read 2 bytes from "fd" and turn them into an int, MSB first.
|
||||
*/
|
||||
int get2c(FILE *fd)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = getc(fd);
|
||||
n = (n << 8) + getc(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read 3 bytes from "fd" and turn them into an int, MSB first.
|
||||
*/
|
||||
int get3c(FILE *fd)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = getc(fd);
|
||||
n = (n << 8) + getc(fd);
|
||||
n = (n << 8) + getc(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read 4 bytes from "fd" and turn them into an int, MSB first.
|
||||
*/
|
||||
int get4c(FILE *fd)
|
||||
{
|
||||
/* Use unsigned rather than int otherwise result is undefined
|
||||
* when left-shift sets the MSB. */
|
||||
unsigned n;
|
||||
|
||||
n = (unsigned)getc(fd);
|
||||
n = (n << 8) + (unsigned)getc(fd);
|
||||
n = (n << 8) + (unsigned)getc(fd);
|
||||
n = (n << 8) + (unsigned)getc(fd);
|
||||
return (int)n;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read 8 bytes from "fd" and turn them into a time_t, MSB first.
|
||||
*/
|
||||
time_t get8ctime(FILE *fd)
|
||||
{
|
||||
time_t n = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; ++i)
|
||||
n = (n << 8) + getc(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Reads a string of length "cnt" from "fd" into allocated memory.
|
||||
/// @return pointer to the string or NULL when unable to read that many bytes.
|
||||
char *read_string(FILE *fd, size_t cnt)
|
||||
{
|
||||
uint8_t *str = xmallocz(cnt);
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
int c = getc(fd);
|
||||
if (c == EOF) {
|
||||
xfree(str);
|
||||
return NULL;
|
||||
}
|
||||
str[i] = (uint8_t)c;
|
||||
}
|
||||
return (char *)str;
|
||||
}
|
||||
|
||||
/// Writes a number to file "fd", most significant bit first, in "len" bytes.
|
||||
/// @returns false in case of an error.
|
||||
bool put_bytes(FILE *fd, uintmax_t number, size_t len)
|
||||
{
|
||||
assert(len > 0);
|
||||
for (size_t i = len - 1; i < len; i--) {
|
||||
if (putc((int)(number >> (i * 8)), fd) == EOF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Writes time_t to file "fd" in 8 bytes.
|
||||
/// @returns FAIL when the write failed.
|
||||
int put_time(FILE *fd, time_t time_)
|
||||
{
|
||||
uint8_t buf[8];
|
||||
time_to_bytes(time_, buf);
|
||||
return fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd) == 1 ? OK : FAIL;
|
||||
}
|
||||
|
||||
/// Writes time_t to "buf[8]".
|
||||
void time_to_bytes(time_t time_, uint8_t buf[8])
|
||||
{
|
||||
// time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits
|
||||
// systems, thus we can't use put_bytes() here.
|
||||
for (size_t i = 7, bufi = 0; bufi < 8; i--, bufi++) {
|
||||
buf[bufi] = (uint8_t)((uint64_t)time_ >> (i * 8));
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#ifndef NVIM_MISC2_H
|
||||
#define NVIM_MISC2_H
|
||||
|
||||
#include "nvim/os/shell.h"
|
||||
|
||||
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "misc2.h.generated.h"
|
||||
#endif
|
||||
|
||||
#endif // NVIM_MISC2_H
|
@ -4,6 +4,7 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/window.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/syntax.h"
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/popupmnu.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/strings.h"
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/mouse.h"
|
||||
|
@ -30,13 +30,13 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/normal.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/path.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/terminal.h"
|
||||
#include "nvim/ui.h"
|
||||
|
@ -6712,3 +6712,148 @@ unsigned int get_bkc_value(buf_T *buf)
|
||||
{
|
||||
return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
|
||||
}
|
||||
|
||||
/// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC.
|
||||
int get_fileformat(buf_T *buf)
|
||||
{
|
||||
int c = *buf->b_p_ff;
|
||||
|
||||
if (buf->b_p_bin || c == 'u') {
|
||||
return EOL_UNIX;
|
||||
}
|
||||
if (c == 'm') {
|
||||
return EOL_MAC;
|
||||
}
|
||||
return EOL_DOS;
|
||||
}
|
||||
|
||||
/// Like get_fileformat(), but override 'fileformat' with "p" for "++opt=val"
|
||||
/// argument.
|
||||
///
|
||||
/// @param eap can be NULL!
|
||||
int get_fileformat_force(buf_T *buf, exarg_T *eap)
|
||||
{
|
||||
int c;
|
||||
|
||||
if (eap != NULL && eap->force_ff != 0) {
|
||||
c = eap->cmd[eap->force_ff];
|
||||
} else {
|
||||
if ((eap != NULL && eap->force_bin != 0)
|
||||
? (eap->force_bin == FORCE_BIN) : buf->b_p_bin) {
|
||||
return EOL_UNIX;
|
||||
}
|
||||
c = *buf->b_p_ff;
|
||||
}
|
||||
if (c == 'u') {
|
||||
return EOL_UNIX;
|
||||
}
|
||||
if (c == 'm') {
|
||||
return EOL_MAC;
|
||||
}
|
||||
return EOL_DOS;
|
||||
}
|
||||
|
||||
/// Return the default fileformat from 'fileformats'.
|
||||
int default_fileformat(void)
|
||||
{
|
||||
switch (*p_ffs) {
|
||||
case 'm': return EOL_MAC;
|
||||
case 'd': return EOL_DOS;
|
||||
}
|
||||
return EOL_UNIX;
|
||||
}
|
||||
|
||||
/// Set the current end-of-line type to EOL_UNIX, EOL_MAC, or EOL_DOS.
|
||||
///
|
||||
/// Sets 'fileformat'.
|
||||
///
|
||||
/// @param eol_style End-of-line style.
|
||||
/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
|
||||
void set_fileformat(int eol_style, int opt_flags)
|
||||
{
|
||||
char *p = NULL;
|
||||
|
||||
switch (eol_style) {
|
||||
case EOL_UNIX:
|
||||
p = FF_UNIX;
|
||||
break;
|
||||
case EOL_MAC:
|
||||
p = FF_MAC;
|
||||
break;
|
||||
case EOL_DOS:
|
||||
p = FF_DOS;
|
||||
break;
|
||||
}
|
||||
|
||||
// p is NULL if "eol_style" is EOL_UNKNOWN.
|
||||
if (p != NULL) {
|
||||
set_string_option_direct((char_u *)"ff",
|
||||
-1,
|
||||
(char_u *)p,
|
||||
OPT_FREE | opt_flags,
|
||||
0);
|
||||
}
|
||||
|
||||
// This may cause the buffer to become (un)modified.
|
||||
check_status(curbuf);
|
||||
redraw_tabline = true;
|
||||
need_maketitle = true; // Set window title later.
|
||||
}
|
||||
|
||||
/// Skip to next part of an option argument: Skip space and comma.
|
||||
char_u *skip_to_option_part(char_u *p)
|
||||
{
|
||||
if (*p == ',') {
|
||||
p++;
|
||||
}
|
||||
while (*p == ' ') {
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/// Isolate one part of a string option separated by `sep_chars`.
|
||||
///
|
||||
/// @param[in,out] option advanced to the next part
|
||||
/// @param[in,out] buf copy of the isolated part
|
||||
/// @param[in] maxlen length of `buf`
|
||||
/// @param[in] sep_chars chars that separate the option parts
|
||||
///
|
||||
/// @return length of `*option`
|
||||
size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen,
|
||||
char *sep_chars)
|
||||
{
|
||||
size_t len = 0;
|
||||
char_u *p = *option;
|
||||
|
||||
// skip '.' at start of option part, for 'suffixes'
|
||||
if (*p == '.') {
|
||||
buf[len++] = *p++;
|
||||
}
|
||||
while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) {
|
||||
// Skip backslash before a separator character and space.
|
||||
if (p[0] == '\\' && vim_strchr((char_u *)sep_chars, p[1]) != NULL) {
|
||||
p++;
|
||||
}
|
||||
if (len < maxlen - 1) {
|
||||
buf[len++] = *p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
buf[len] = NUL;
|
||||
|
||||
if (*p != NUL && *p != ',') { // skip non-standard separator
|
||||
p++;
|
||||
}
|
||||
p = skip_to_option_part(p); // p points to next file name
|
||||
|
||||
*option = p;
|
||||
return len;
|
||||
}
|
||||
|
||||
/// Return TRUE when 'shell' has "csh" in the tail.
|
||||
int csh_like_shell(void)
|
||||
{
|
||||
return strstr((char *)path_tail(p_sh), "csh") != NULL;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef NVIM_OPTION_H
|
||||
#define NVIM_OPTION_H
|
||||
|
||||
#include "nvim/ex_cmds_defs.h" // for exarg_T
|
||||
|
||||
/* flags for buf_copy_options() */
|
||||
#define BCO_ENTER 1 /* going to enter the buffer */
|
||||
#define BCO_ALWAYS 2 /* always copy the options */
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/path.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/eval.h"
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/assert.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/path.h"
|
||||
#include "nvim/strings.h"
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/state.h"
|
||||
|
||||
#define READ_BUFFER_SIZE 0xfff
|
||||
#define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4)
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/option_defs.h"
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/event/signal.h"
|
||||
#include "nvim/os/signal.h"
|
||||
#include "nvim/event/loop.h"
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/strings.h"
|
||||
#ifdef HAVE_PWD_H
|
||||
# include <pwd.h>
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/mouse.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/path.h"
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/shell.h"
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/ex_cmds.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/option.h"
|
||||
#include "nvim/screen.h"
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/normal.h"
|
||||
|
@ -59,7 +59,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/strings.h"
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
|
||||
/*
|
||||
|
@ -108,7 +108,6 @@
|
||||
#include "nvim/menu.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/normal.h"
|
||||
@ -120,6 +119,7 @@
|
||||
#include "nvim/regexp.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/spell.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/terminal.h"
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/move.h"
|
||||
#include "nvim/mouse.h"
|
||||
#include "nvim/normal.h"
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/buffer.h"
|
||||
#include "nvim/buffer_defs.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/ex_getln.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/regexp.h"
|
||||
|
@ -312,7 +312,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/normal.h"
|
||||
#include "nvim/option.h"
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
#include "nvim/lib/kvec.h"
|
||||
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/option_defs.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/os/input.h"
|
||||
|
||||
@ -61,3 +63,35 @@ getkey:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return TRUE if in the current mode we need to use virtual.
|
||||
int virtual_active(void)
|
||||
{
|
||||
// While an operator is being executed we return "virtual_op", because
|
||||
// VIsual_active has already been reset, thus we can't check for "block"
|
||||
// being used.
|
||||
if (virtual_op != MAYBE) {
|
||||
return virtual_op;
|
||||
}
|
||||
return ve_flags == VE_ALL
|
||||
|| ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V)
|
||||
|| ((ve_flags & VE_INSERT) && (State & INSERT));
|
||||
}
|
||||
|
||||
/// VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to
|
||||
/// NORMAL State with a condition. This function returns the real State.
|
||||
int get_real_state(void)
|
||||
{
|
||||
if (State & NORMAL) {
|
||||
if (VIsual_active) {
|
||||
if (VIsual_select) {
|
||||
return SELECTMODE;
|
||||
}
|
||||
return VISUAL;
|
||||
} else if (finish_op) {
|
||||
return OP_PENDING;
|
||||
}
|
||||
}
|
||||
return State;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/buffer.h"
|
||||
#include "nvim/charset.h"
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/keymap.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/option.h"
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/memory.h"
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/input.h"
|
||||
#include "nvim/event/rstream.h"
|
||||
|
@ -12,10 +12,8 @@
|
||||
#include "nvim/ex_cmds2.h"
|
||||
#include "nvim/fold.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/memory.h"
|
||||
|
@ -99,6 +99,7 @@
|
||||
#include "nvim/quickfix.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/sha256.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/types.h"
|
||||
#include "nvim/os/os.h"
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/strings.h"
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/message.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/misc2.h"
|
||||
#include "nvim/file_search.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/move.h"
|
||||
@ -41,6 +40,7 @@
|
||||
#include "nvim/regexp.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/search.h"
|
||||
#include "nvim/state.h"
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/terminal.h"
|
||||
|
Loading…
Reference in New Issue
Block a user