From d8f8521915984a00623562d8606c04e247fa2967 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 8 May 2014 13:41:58 -0300 Subject: API: Implement vim_list_runtime_paths --- src/api/vim.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/api/vim.c b/src/api/vim.c index 33e5a8ad85..361a57218c 100644 --- a/src/api/vim.c +++ b/src/api/vim.c @@ -11,6 +11,7 @@ #include "ex_docmd.h" #include "screen.h" #include "eval.h" +#include "misc2.h" #include "memory.h" #include "lib/khash.h" @@ -88,7 +89,40 @@ int64_t vim_strwidth(String str) StringArray vim_list_runtime_paths(void) { - abort(); + StringArray rv = {.size = 0}; + uint8_t *rtp = p_rtp; + + if (*rtp == NUL) { + // No paths + return rv; + } + + // Count the number of paths in rtp + while (*rtp != NUL) { + if (*rtp == ',') { + rv.size++; + } + rtp++; + } + + // index + uint32_t i = 0; + // Allocate memory for the copies + rv.items = xmalloc(sizeof(String) * rv.size); + // reset the position + rtp = p_rtp; + // Start copying + while (*rtp != NUL) { + rv.items[i].data = xmalloc(MAXPATHL); + // Copy the path from 'runtimepath' to rv.items[i] + rv.items[i].size = copy_option_part(&rtp, + (char_u *)rv.items[i].data, + MAXPATHL, + ","); + i++; + } + + return rv; } void vim_change_directory(String dir) -- cgit