diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2016-09-11 04:01:41 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2016-09-13 16:20:09 +0200 |
| commit | df072c3b2b20fb7d3d9d50b5ab0df92827aa628f (patch) | |
| tree | fb80cb1409d60a6316d534b989451cd9986934e6 /src | |
| parent | 7eb4d2f79dcc712dae1513516b9db5f574d51437 (diff) | |
| download | rneovim-df072c3b2b20fb7d3d9d50b5ab0df92827aa628f.tar.gz rneovim-df072c3b2b20fb7d3d9d50b5ab0df92827aa628f.tar.bz2 rneovim-df072c3b2b20fb7d3d9d50b5ab0df92827aa628f.zip | |
refactor: eliminate misc2.c
move `call_shell` to misc1.c
Move some fns to state.c
Move some fns to option.c
Move some fns to memline.c
Move `vim_chdir*` fns to file_search.c
Move some fns to new module, bytes.c
Move some fns to fileio.c
Diffstat (limited to 'src')
72 files changed, 489 insertions, 609 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index e2de2530d6..2b29482a13 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -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 diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index cf8d538f86..602372a661 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.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" diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 70e0c55528..d123b6b8d8 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -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" diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 9c7fdb0697..ade0fe7c01 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -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 diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index af29798654..b42ad1c18a 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -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" diff --git a/src/nvim/charset.c b/src/nvim/charset.c index b5154819b9..78f5d96fc7 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -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" diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index afaa6022c9..3ba9da34f2 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -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" diff --git a/src/nvim/cursor.h b/src/nvim/cursor.h index 09cc5a813c..1cbe8a609e 100644 --- a/src/nvim/cursor.h +++ b/src/nvim/cursor.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" diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 87425ca567..b50462664c 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -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" diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 4826e70727..ef5acf4845 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -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" diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 4512b97967..6ba6e659a6 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -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" diff --git a/src/nvim/edit.c b/src/nvim/edit.c index af5ec6c5ac..ff1107db6c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -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" diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 72b1807334..ccbc5a6264 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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" diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index d0a17ed099..f68663c60c 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -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" diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e3ca177029..45407b7f12 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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" diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 82d4c2b2d5..f518fa0d66 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -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" diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index cd28554970..1a97dc3d6f 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -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" diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c index 61e17128ea..eb22ad1428 100644 --- a/src/nvim/farsi.c +++ b/src/nvim/farsi.c @@ -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" diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 78b224f04c..c6cfba8142 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -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; +} + diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 89e5fdb776..4226f2e8d2 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -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) +{ + 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; +} + +/// 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; diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h index d93f3f3eb3..ceb101167d 100644 --- a/src/nvim/fileio.h +++ b/src/nvim/fileio.h @@ -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)) |