diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-08 16:20:24 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-13 09:33:40 -0300 |
commit | 7b04674174c00b85fb75579bbc49524f7ba74afa (patch) | |
tree | 646f1d217cf2ea6a4d7ead84409e48e8a11a66ae | |
parent | e07099cb7892a4786416c516eea29480e159b128 (diff) | |
download | rneovim-7b04674174c00b85fb75579bbc49524f7ba74afa.tar.gz rneovim-7b04674174c00b85fb75579bbc49524f7ba74afa.tar.bz2 rneovim-7b04674174c00b85fb75579bbc49524f7ba74afa.zip |
API: Move helper functions to another module
-rw-r--r-- | src/CMakeLists.txt | 11 | ||||
-rw-r--r-- | src/api/helpers.c | 54 | ||||
-rw-r--r-- | src/api/helpers.h | 19 | ||||
-rw-r--r-- | src/api/vim.c | 57 |
4 files changed, 85 insertions, 56 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ee6739a34..46e3469e20 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,17 @@ file(GLOB API_HEADERS api/*.h) set(MSGPACK_RPC_HEADER ${PROJECT_SOURCE_DIR}/src/os/msgpack_rpc.h) set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c) +# Remove helpers.h from API_HEADERS since it doesn't contain public API +# functions +foreach(sfile ${API_HEADERS}) + get_filename_component(f ${sfile} NAME) + if(${f} MATCHES "^(helpers.h)$") + list(APPEND to_remove ${sfile}) + endif() +endforeach() +list(REMOVE_ITEM API_HEADERS ${to_remove}) +set(to_remove) + file(MAKE_DIRECTORY ${GENERATED_DIR}) add_custom_command(OUTPUT ${MSGPACK_DISPATCH} diff --git a/src/api/helpers.c b/src/api/helpers.c new file mode 100644 index 0000000000..425da998bc --- /dev/null +++ b/src/api/helpers.c @@ -0,0 +1,54 @@ +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> + +#include "api/helpers.h" +#include "api/defs.h" +#include "../vim.h" + +void try_start() +{ + ++trylevel; +} + +bool try_end(Error *err) +{ + --trylevel; + + // Without this it stops processing all subsequent VimL commands and + // generates strange error messages if I e.g. try calling Test() in a + // cycle + did_emsg = false; + + if (got_int) { + const char msg[] = "Keyboard interrupt"; + + if (did_throw) { + // If we got an interrupt, discard the current exception + discard_current_exception(); + } + + strncpy(err->msg, msg, sizeof(err->msg)); + err->set = true; + got_int = false; + } else if (msg_list != NULL && *msg_list != NULL) { + int should_free; + char *msg = (char *)get_exception_string(*msg_list, + ET_ERROR, + NULL, + &should_free); + strncpy(err->msg, msg, sizeof(err->msg)); + err->set = true; + free_global_msglist(); + + if (should_free) { + free(msg); + } + } else if (did_throw) { + strncpy(err->msg, (char *)current_exception->value, sizeof(err->msg)); + err->set = true; + } + + return err->set; +} + diff --git a/src/api/helpers.h b/src/api/helpers.h new file mode 100644 index 0000000000..6d73b6f742 --- /dev/null +++ b/src/api/helpers.h @@ -0,0 +1,19 @@ +#ifndef NEOVIM_API_HELPERS_H +#define NEOVIM_API_HELPERS_H + +#include <stdbool.h> + +#include "api/defs.h" + +/// 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); + +#endif /* NEOVIM_API_HELPERS_H */ + diff --git a/src/api/vim.c b/src/api/vim.c index bc17772bc9..eb195270d9 100644 --- a/src/api/vim.c +++ b/src/api/vim.c @@ -5,6 +5,7 @@ #include "api/vim.h" #include "api/defs.h" +#include "api/helpers.h" #include "../vim.h" #include "types.h" #include "ascii.h" @@ -18,16 +19,6 @@ KHASH_SET_INIT_INT64(Lookup) -/// Start block that may cause vimscript exceptions -static 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 -static bool try_end(Error *err); - /// Convert a vim object to an `Object` instance, recursively expanding /// Arrays/Dictionaries. /// @@ -251,52 +242,6 @@ void vim_set_current_tabpage(Tabpage tabpage) abort(); } -static void try_start() -{ - ++trylevel; -} - -static bool try_end(Error *err) -{ - --trylevel; - - // Without this it stops processing all subsequent VimL commands and - // generates strange error messages if I e.g. try calling Test() in a - // cycle - did_emsg = false; - - if (got_int) { - const char msg[] = "Keyboard interrupt"; - - if (did_throw) { - // If we got an interrupt, discard the current exception - discard_current_exception(); - } - - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; - got_int = false; - } else if (msg_list != NULL && *msg_list != NULL) { - int should_free; - char *msg = (char *)get_exception_string(*msg_list, - ET_ERROR, - NULL, - &should_free); - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; - free_global_msglist(); - - if (should_free) { - free(msg); - } - } else if (did_throw) { - strncpy(err->msg, (char *)current_exception->value, sizeof(err->msg)); - err->set = true; - } - - return err->set; -} - static Object vim_to_object(typval_T *obj) { Object rv; |