aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/usercmd.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
commit1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch)
treecd08258054db80bb9a11b1061bb091c70b76926a /src/nvim/usercmd.c
parenteaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-aucmd_textputpost.tar.gz
rneovim-aucmd_textputpost.tar.bz2
rneovim-aucmd_textputpost.zip
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'src/nvim/usercmd.c')
-rw-r--r--src/nvim/usercmd.c288
1 files changed, 139 insertions, 149 deletions
diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c
index ef13f67e49..7c65af5138 100644
--- a/src/nvim/usercmd.c
+++ b/src/nvim/usercmd.c
@@ -1,41 +1,40 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
// usercmd.c: User defined command support
#include <assert.h>
#include <inttypes.h>
+#include <lauxlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "auto/config.h"
-#include "lauxlib.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
-#include "nvim/ascii.h"
+#include "nvim/ascii_defs.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
+#include "nvim/cmdexpand_defs.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
+#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/gettext.h"
#include "nvim/globals.h"
-#include "nvim/highlight_defs.h"
+#include "nvim/highlight.h"
#include "nvim/keycodes.h"
#include "nvim/lua/executor.h"
-#include "nvim/macros.h"
+#include "nvim/macros_defs.h"
#include "nvim/mapping.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/menu.h"
#include "nvim/message.h"
-#include "nvim/option_defs.h"
+#include "nvim/option_vars.h"
#include "nvim/os/input.h"
#include "nvim/runtime.h"
#include "nvim/strings.h"
#include "nvim/usercmd.h"
-#include "nvim/vim.h"
+#include "nvim/vim_defs.h"
#include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -44,11 +43,13 @@
garray_T ucmds = { 0, 0, sizeof(ucmd_T), 4, NULL };
-static char e_complete_used_without_allowing_arguments[]
- = N_("E1208: -complete used without allowing arguments");
-static char e_no_such_user_defined_command_str[]
+static const char e_argument_required_for_str[]
+ = N_("E179: Argument required for %s");
+static const char e_no_such_user_defined_command_str[]
= N_("E184: No such user-defined command: %s");
-static char e_no_such_user_defined_command_in_current_buffer_str[]
+static const char e_complete_used_without_allowing_arguments[]
+ = N_("E1208: -complete used without allowing arguments");
+static const char e_no_such_user_defined_command_in_current_buffer_str[]
= N_("E1237: No such user-defined command in current buffer: %s");
/// List of names for completion for ":command" with the EXPAND_ flag.
@@ -56,7 +57,6 @@ static char e_no_such_user_defined_command_in_current_buffer_str[]
static const char *command_complete[] = {
[EXPAND_ARGLIST] = "arglist",
[EXPAND_AUGROUP] = "augroup",
- [EXPAND_BEHAVE] = "behave",
[EXPAND_BUFFERS] = "buffer",
[EXPAND_CHECKHEALTH] = "checkhealth",
[EXPAND_COLORS] = "color",
@@ -129,23 +129,21 @@ static struct {
char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp)
{
int len = (int)(p - eap->cmd);
- int j, k, matchlen = 0;
- ucmd_T *uc;
+ int matchlen = 0;
bool found = false;
bool possible = false;
- char *cp, *np; // Point into typed cmd and test name
- garray_T *gap;
bool amb_local = false; // Found ambiguous buffer-local command,
// only full match global is accepted.
// Look for buffer-local user commands first, then global ones.
- gap = &prevwin_curwin()->w_buffer->b_ucmds;
- for (;;) {
+ garray_T *gap = &prevwin_curwin()->w_buffer->b_ucmds;
+ while (true) {
+ int j;
for (j = 0; j < gap->ga_len; j++) {
- uc = USER_CMD_GA(gap, j);
- cp = eap->cmd;
- np = uc->uc_name;
- k = 0;
+ ucmd_T *uc = USER_CMD_GA(gap, j);
+ char *cp = eap->cmd;
+ char *np = uc->uc_name;
+ int k = 0;
while (k < len && *np != NUL && *cp++ == *np++) {
k++;
}
@@ -234,7 +232,7 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in)
// Check for attributes
while (*arg == '-') {
arg++; // Skip "-".
- p = (const char *)skiptowhite(arg);
+ p = skiptowhite(arg);
if (*p == NUL) {
// Cursor is still in the attribute.
p = strchr(arg, '=');
@@ -262,11 +260,11 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in)
}
return NULL;
}
- arg = (const char *)skipwhite(p);
+ arg = skipwhite(p);
}
// After the attributes comes the new command name.
- p = (const char *)skiptowhite(arg);
+ p = skiptowhite(arg);
if (*p == NUL) {
xp->xp_context = EXPAND_USER_COMMANDS;
xp->xp_pattern = (char *)arg;
@@ -274,7 +272,7 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in)
}
// And finally comes a normal command.
- return (const char *)skipwhite(p);
+ return skipwhite(p);
}
/// Set the completion context for the argument of a user defined command.
@@ -292,14 +290,14 @@ const char *set_context_in_user_cmdarg(const char *cmd FUNC_ATTR_UNUSED, const c
}
if (context == EXPAND_MENUS) {
- return (const char *)set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit);
+ return set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit);
}
if (context == EXPAND_COMMANDS) {
return arg;
}
if (context == EXPAND_MAPPINGS) {
- return (const char *)set_context_in_map_cmd(xp, "map", (char *)arg, forceit, false, false,
- CMD_map);
+ return set_context_in_map_cmd(xp, "map", (char *)arg, forceit, false, false,
+ CMD_map);
}
// Find start of last argument.
const char *p = arg;
@@ -424,6 +422,13 @@ char *get_user_cmd_complete(expand_T *xp, int idx)
int cmdcomplete_str_to_type(const char *complete_str)
{
+ if (strncmp(complete_str, "custom,", 7) == 0) {
+ return EXPAND_USER_DEFINED;
+ }
+ if (strncmp(complete_str, "customlist,", 11) == 0) {
+ return EXPAND_USER_LIST;
+ }
+
for (int i = 0; i < (int)(ARRAY_SIZE(command_complete)); i++) {
char *cmd_compl = get_command_complete(i);
if (cmd_compl == NULL) {
@@ -439,17 +444,15 @@ int cmdcomplete_str_to_type(const char *complete_str)
static void uc_list(char *name, size_t name_len)
{
- int i, j;
bool found = false;
- ucmd_T *cmd;
- uint32_t a;
// In cmdwin, the alternative buffer should be used.
const garray_T *gap = &prevwin_curwin()->w_buffer->b_ucmds;
- for (;;) {
+ while (true) {
+ int i;
for (i = 0; i < gap->ga_len; i++) {
- cmd = USER_CMD_GA(gap, i);
- a = cmd->uc_argt;
+ ucmd_T *cmd = USER_CMD_GA(gap, i);
+ uint32_t a = cmd->uc_argt;
// Skip commands which don't match the requested prefix and
// commands filtered out.
@@ -470,7 +473,7 @@ static void uc_list(char *name, size_t name_len)
}
// Special cases
- int len = 4;
+ size_t len = 4;
if (a & EX_BANG) {
msg_putchar('!');
len--;
@@ -491,8 +494,8 @@ static void uc_list(char *name, size_t name_len)
msg_putchar(' ');
}
- msg_outtrans_attr(cmd->uc_name, HL_ATTR(HLF_D));
- len = (int)strlen(cmd->uc_name) + 4;
+ msg_outtrans(cmd->uc_name, HL_ATTR(HLF_D));
+ len = strlen(cmd->uc_name) + 4;
do {
msg_putchar(' ');
@@ -501,7 +504,7 @@ static void uc_list(char *name, size_t name_len)
// "over" is how much longer the name is than the column width for
// the name, we'll try to align what comes after.
- const int over = len - 22;
+ const int64_t over = (int64_t)len - 22;
len = 0;
// Arguments
@@ -525,22 +528,22 @@ static void uc_list(char *name, size_t name_len)
do {
IObuff[len++] = ' ';
- } while (len < 5 - over);
+ } while ((int64_t)len < 5 - over);
// Address / Range
if (a & (EX_RANGE | EX_COUNT)) {
if (a & EX_COUNT) {
// -count=N
- snprintf(IObuff + len, IOSIZE, "%" PRId64 "c",
- (int64_t)cmd->uc_def);
- len += (int)strlen(IObuff + len);
+ int rc = snprintf(IObuff + len, IOSIZE - len, "%" PRId64 "c", cmd->uc_def);
+ assert(rc > 0);
+ len += (size_t)rc;
} else if (a & EX_DFLALL) {
IObuff[len++] = '%';
} else if (cmd->uc_def >= 0) {
// -range=N
- snprintf(IObuff + len, IOSIZE, "%" PRId64 "",
- (int64_t)cmd->uc_def);
- len += (int)strlen(IObuff + len);
+ int rc = snprintf(IObuff + len, IOSIZE - len, "%" PRId64 "", cmd->uc_def);
+ assert(rc > 0);
+ len += (size_t)rc;
} else {
IObuff[len++] = '.';
}
@@ -548,35 +551,37 @@ static void uc_list(char *name, size_t name_len)
do {
IObuff[len++] = ' ';
- } while (len < 8 - over);
+ } while ((int64_t)len < 8 - over);
// Address Type
- for (j = 0; addr_type_complete[j].expand != ADDR_NONE; j++) {
+ for (int j = 0; addr_type_complete[j].expand != ADDR_NONE; j++) {
if (addr_type_complete[j].expand != ADDR_LINES
&& addr_type_complete[j].expand == cmd->uc_addr_type) {
- STRCPY(IObuff + len, addr_type_complete[j].shortname);
- len += (int)strlen(IObuff + len);
+ int rc = snprintf(IObuff + len, IOSIZE - len, "%s", addr_type_complete[j].shortname);
+ assert(rc > 0);
+ len += (size_t)rc;
break;
}
}
do {
IObuff[len++] = ' ';
- } while (len < 13 - over);
+ } while ((int64_t)len < 13 - over);
// Completion
char *cmd_compl = get_command_complete(cmd->uc_compl);
if (cmd_compl != NULL) {
- STRCPY(IObuff + len, get_command_complete(cmd->uc_compl));
- len += (int)strlen(IObuff + len);
+ int rc = snprintf(IObuff + len, IOSIZE - len, "%s", get_command_complete(cmd->uc_compl));
+ assert(rc > 0);
+ len += (size_t)rc;
}
do {
IObuff[len++] = ' ';
- } while (len < 25 - over);
+ } while ((int64_t)len < 25 - over);
IObuff[len] = '\0';
- msg_outtrans(IObuff);
+ msg_outtrans(IObuff, 0);
if (cmd->uc_luaref != LUA_NOREF) {
char *fn = nlua_funcref_str(cmd->uc_luaref);
@@ -605,7 +610,7 @@ static void uc_list(char *name, size_t name_len)
}
if (!found) {
- msg(_("No user-defined commands found"));
+ msg(_("No user-defined commands found"), 0);
}
}
@@ -613,11 +618,11 @@ static void uc_list(char *name, size_t name_len)
int parse_addr_type_arg(char *value, int vallen, cmd_addr_T *addr_type_arg)
FUNC_ATTR_NONNULL_ALL
{
- int i, a, b;
+ int i;
for (i = 0; addr_type_complete[i].expand != ADDR_NONE; i++) {
- a = (int)strlen(addr_type_complete[i].name) == vallen;
- b = strncmp(value, addr_type_complete[i].name, (size_t)vallen) == 0;
+ int a = (int)strlen(addr_type_complete[i].name) == vallen;
+ int b = strncmp(value, addr_type_complete[i].name, (size_t)vallen) == 0;
if (a && b) {
*addr_type_arg = addr_type_complete[i].expand;
break;
@@ -647,11 +652,10 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt,
{
const char *arg = NULL;
size_t arglen = 0;
- int i;
int valend = vallen;
// Look for any argument part - which is the part after any ','
- for (i = 0; i < vallen; i++) {
+ for (int i = 0; i < vallen; i++) {
if (value[i] == ',') {
arg = (char *)&value[i + 1];
arglen = (size_t)(vallen - i - 1);
@@ -660,6 +664,7 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt,
}
}
+ int i;
for (i = 0; i < (int)ARRAY_SIZE(command_complete); i++) {
if (get_command_complete(i) == NULL) {
continue;
@@ -699,12 +704,10 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt,
return OK;
}
-static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, long *def, int *flags, int *complp,
+static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, int *def, int *flags, int *complp,
char **compl_arg, cmd_addr_T *addr_type_arg)
FUNC_ATTR_NONNULL_ALL
{
- char *p;
-
if (len == 0) {
emsg(_("E175: No attribute specified"));
return FAIL;
@@ -722,13 +725,12 @@ static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, long *def, int *
} else if (STRNICMP(attr, "bar", len) == 0) {
*argt |= EX_TRLBAR;
} else {
- int i;
char *val = NULL;
size_t vallen = 0;
size_t attrlen = len;
// Look for the attribute name - which is the part before any '='
- for (i = 0; i < (int)len; i++) {
+ for (int i = 0; i < (int)len; i++) {
if (attr[i] == '=') {
val = &attr[i + 1];
vallen = len - (size_t)i - 1;
@@ -762,14 +764,14 @@ wrong_nargs:
if (vallen == 1 && *val == '%') {
*argt |= EX_DFLALL;
} else if (val != NULL) {
- p = val;
+ char *p = val;
if (*def >= 0) {
two_count:
emsg(_("E177: Count cannot be specified twice"));
return FAIL;
}
- *def = getdigits_long(&p, true, 0);
+ *def = getdigits_int(&p, true, 0);
*argt |= EX_ZEROR;
if (p != val + vallen || vallen == 0) {
@@ -790,12 +792,12 @@ invalid_count:
}
if (val != NULL) {
- p = val;
+ char *p = val;
if (*def >= 0) {
goto two_count;
}
- *def = getdigits_long(&p, true, 0);
+ *def = getdigits_int(&p, true, 0);
if (p != val + vallen) {
goto invalid_count;
@@ -807,7 +809,7 @@ invalid_count:
}
} else if (STRNICMP(attr, "complete", attrlen) == 0) {
if (val == NULL) {
- emsg(_("E179: argument required for -complete"));
+ semsg(_(e_argument_required_for_str), "-complete");
return FAIL;
}
@@ -818,7 +820,7 @@ invalid_count:
} else if (STRNICMP(attr, "addr", attrlen) == 0) {
*argt |= EX_RANGE;
if (val == NULL) {
- emsg(_("E179: argument required for -addr"));
+ semsg(_(e_argument_required_for_str), "-addr");
return FAIL;
}
if (parse_addr_type_arg(val, (int)vallen, addr_type_arg) == FAIL) {
@@ -862,18 +864,17 @@ char *uc_validate_name(char *name)
/// This function takes ownership of compl_arg, compl_luaref, and luaref.
///
/// @return OK if the command is created, FAIL otherwise.
-int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, long def, int flags,
- int compl, char *compl_arg, LuaRef compl_luaref, LuaRef preview_luaref,
- cmd_addr_T addr_type, LuaRef luaref, bool force)
+int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, int64_t def,
+ int flags, int context, char *compl_arg, LuaRef compl_luaref,
+ LuaRef preview_luaref, cmd_addr_T addr_type, LuaRef luaref, bool force)
FUNC_ATTR_NONNULL_ARG(1, 3)
{
ucmd_T *cmd = NULL;
- int i;
int cmp = 1;
char *rep_buf = NULL;
garray_T *gap;
- replace_termcodes(rep, strlen(rep), &rep_buf, 0, NULL, CPO_TO_CPO_FLAGS);
+ replace_termcodes(rep, strlen(rep), &rep_buf, 0, 0, NULL, CPO_TO_CPO_FLAGS);
if (rep_buf == NULL) {
// Can't replace termcodes - try using the string as is
rep_buf = xstrdup(rep);
@@ -889,12 +890,12 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt,
gap = &ucmds;
}
+ int i;
+
// Search for the command in the already defined commands.
for (i = 0; i < gap->ga_len; i++) {
- size_t len;
-
cmd = USER_CMD_GA(gap, i);
- len = strlen(cmd->uc_name);
+ size_t len = strlen(cmd->uc_name);
cmp = strncmp(name, cmd->uc_name, name_len);
if (cmp == 0) {
if (name_len < len) {
@@ -946,7 +947,7 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt,
cmd->uc_rep = rep_buf;
cmd->uc_argt = argt;
cmd->uc_def = def;
- cmd->uc_compl = compl;
+ cmd->uc_compl = context;
cmd->uc_script_ctx = current_sctx;
cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM;
nlua_set_sctx(&cmd->uc_script_ctx);
@@ -970,25 +971,22 @@ fail:
/// ":command ..."
void ex_command(exarg_T *eap)
{
- char *name;
char *end;
- char *p;
uint32_t argt = 0;
- long def = -1;
+ int def = -1;
int flags = 0;
- int compl = EXPAND_NOTHING;
+ int context = EXPAND_NOTHING;
char *compl_arg = NULL;
cmd_addr_T addr_type_arg = ADDR_NONE;
int has_attr = (eap->arg[0] == '-');
- size_t name_len;
- p = eap->arg;
+ char *p = eap->arg;
// Check for attributes
while (*p == '-') {
p++;
end = skiptowhite(p);
- if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, &compl_arg,
+ if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &context, &compl_arg,
&addr_type_arg) == FAIL) {
goto theend;
}
@@ -996,13 +994,13 @@ void ex_command(exarg_T *eap)
}
// Get the name (if any) and skip to the following argument.
- name = p;
+ char *name = p;
end = uc_validate_name(name);
if (!end) {
emsg(_("E182: Invalid command name"));
goto theend;
}
- name_len = (size_t)(end - name);
+ size_t name_len = (size_t)(end - name);
// If there is nothing after the name, and no attributes were specified,
// we are listing commands
@@ -1013,10 +1011,10 @@ void ex_command(exarg_T *eap)
emsg(_("E183: User defined commands must start with an uppercase letter"));
} else if (name_len <= 4 && strncmp(name, "Next", name_len) == 0) {
emsg(_("E841: Reserved name, cannot be used for user defined command"));
- } else if (compl > 0 && (argt & EX_EXTRA) == 0) {
+ } else if (context > 0 && (argt & EX_EXTRA) == 0) {
emsg(_(e_complete_used_without_allowing_arguments));
} else {
- uc_add_command(name, name_len, p, argt, def, flags, compl, compl_arg, LUA_NOREF, LUA_NOREF,
+ uc_add_command(name, name_len, p, argt, def, flags, context, compl_arg, LUA_NOREF, LUA_NOREF,
addr_type_arg, LUA_NOREF, eap->forceit);
return; // success
@@ -1055,7 +1053,6 @@ void ex_delcommand(exarg_T *eap)
int i = 0;
ucmd_T *cmd = NULL;
int res = -1;
- garray_T *gap;
const char *arg = eap->arg;
bool buffer_only = false;
@@ -1064,8 +1061,8 @@ void ex_delcommand(exarg_T *eap)
arg = skipwhite(arg + 7);
}
- gap = &curbuf->b_ucmds;
- for (;;) {
+ garray_T *gap = &curbuf->b_ucmds;
+ while (true) {
for (i = 0; i < gap->ga_len; i++) {
cmd = USER_CMD_GA(gap, i);
res = strcmp(arg, cmd->uc_name);
@@ -1140,17 +1137,13 @@ bool uc_split_args_iter(const char *arg, size_t arglen, size_t *end, char *buf,
}
/// split and quote args for <f-args>
-static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t argc, size_t *lenp)
+static char *uc_split_args(const char *arg, char **args, const size_t *arglens, size_t argc,
+ size_t *lenp)
{
- char *buf;
- char *p;
- char *q;
- int len;
-
// Precalculate length
- len = 2; // Initial and final quotes
+ int len = 2; // Initial and final quotes
if (args == NULL) {
- p = arg;
+ const char *p = arg;
while (*p) {
if (p[0] == '\\' && p[1] == '\\') {
@@ -1177,7 +1170,7 @@ static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t
}
} else {
for (size_t i = 0; i < argc; i++) {
- p = args[i];
+ const char *p = args[i];
const char *arg_end = args[i] + arglens[i];
while (p < arg_end) {
@@ -1198,13 +1191,13 @@ static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t
}
}
- buf = xmalloc((size_t)len + 1);
+ char *buf = xmalloc((size_t)len + 1);
- q = buf;
+ char *q = buf;
*q++ = '"';
if (args == NULL) {
- p = arg;
+ const char *p = arg;
while (*p) {
if (p[0] == '\\' && p[1] == '\\') {
*q++ = '\\';
@@ -1226,12 +1219,12 @@ static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t
*q++ = ' ';
*q++ = '"';
} else {
- mb_copy_char((const char **)&p, &q);
+ mb_copy_char(&p, &q);
}
}
} else {
for (size_t i = 0; i < argc; i++) {
- p = args[i];
+ const char *p = args[i];
const char *arg_end = args[i] + arglens[i];
while (p < arg_end) {
@@ -1239,7 +1232,7 @@ static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t
*q++ = '\\';
*q++ = *p++;
} else {
- mb_copy_char((const char **)&p, &q);
+ mb_copy_char(&p, &q);
}
}
if (i != argc - 1) {
@@ -1540,13 +1533,16 @@ static size_t uc_check_code(char *code, size_t len, char *buf, ucmd_T *cmd, exar
case ct_RANGE:
case ct_COUNT: {
char num_buf[20];
- long num = (type == ct_LINE1) ? eap->line1 :
- (type == ct_LINE2) ? eap->line2 :
- (type == ct_RANGE) ? eap->addr_count :
- (eap->addr_count > 0) ? eap->line2 : cmd->uc_def;
+ int64_t num = type == ct_LINE1
+ ? eap->line1
+ : (type == ct_LINE2
+ ? eap->line2
+ : (type == ct_RANGE
+ ? eap->addr_count
+ : (eap->addr_count > 0 ? eap->line2 : cmd->uc_def)));
size_t num_len;
- snprintf(num_buf, sizeof(num_buf), "%" PRId64, (int64_t)num);
+ snprintf(num_buf, sizeof(num_buf), "%" PRId64, num);
num_len = strlen(num_buf);
result = num_len;
@@ -1611,14 +1607,7 @@ static size_t uc_check_code(char *code, size_t len, char *buf, ucmd_T *cmd, exar
int do_ucmd(exarg_T *eap, bool preview)
{
- char *buf;
- char *p;
- char *q;
-
- char *start;
char *end = NULL;
- char *ksp;
- size_t len, totlen;
size_t split_len = 0;
char *split_buf = NULL;
@@ -1627,7 +1616,7 @@ int do_ucmd(exarg_T *eap, bool preview)
if (eap->cmdidx == CMD_USER) {
cmd = USER_CMD(eap->useridx);
} else {
- cmd = USER_CMD_GA(&curbuf->b_ucmds, eap->useridx);
+ cmd = USER_CMD_GA(&prevwin_curwin()->w_buffer->b_ucmds, eap->useridx);
}
if (preview) {
@@ -1643,18 +1632,19 @@ int do_ucmd(exarg_T *eap, bool preview)
// Replace <> in the command by the arguments.
// First round: "buf" is NULL, compute length, allocate "buf".
// Second round: copy result into "buf".
- buf = NULL;
- for (;;) {
- p = cmd->uc_rep; // source
- q = buf; // destination
- totlen = 0;
-
- for (;;) {
- start = vim_strchr(p, '<');
+ char *buf = NULL;
+ while (true) {
+ char *p = cmd->uc_rep; // source
+ char *q = buf; // destination
+ size_t totlen = 0;
+
+ while (true) {
+ char *start = vim_strchr(p, '<');
if (start != NULL) {
end = vim_strchr(start + 1, '>');
}
if (buf != NULL) {
+ char *ksp;
for (ksp = p; *ksp != NUL && (uint8_t)(*ksp) != K_SPECIAL; ksp++) {}
if ((uint8_t)(*ksp) == K_SPECIAL
&& (start == NULL || ksp < start || end == NULL)
@@ -1662,7 +1652,7 @@ int do_ucmd(exarg_T *eap, bool preview)
// K_SPECIAL has been put in the buffer as K_SPECIAL
// KS_SPECIAL KE_FILLER, like for mappings, but
// do_cmdline() doesn't handle that, so convert it back.
- len = (size_t)(ksp - p);
+ size_t len = (size_t)(ksp - p);
if (len > 0) {
memmove(q, p, len);
q += len;
@@ -1682,7 +1672,7 @@ int do_ucmd(exarg_T *eap, bool preview)
end++;
// Take everything up to the '<'
- len = (size_t)(start - p);
+ size_t len = (size_t)(start - p);
if (buf == NULL) {
totlen += len;
} else {
@@ -1751,8 +1741,8 @@ Dictionary commands_array(buf_T *buf)
Dictionary d = ARRAY_DICT_INIT;
ucmd_T *cmd = USER_CMD_GA(gap, i);
- PUT(d, "name", STRING_OBJ(cstr_to_string((char *)cmd->uc_name)));
- PUT(d, "definition", STRING_OBJ(cstr_to_string((char *)cmd->uc_rep)));
+ PUT(d, "name", CSTR_TO_OBJ(cmd->uc_name));
+ PUT(d, "definition", CSTR_TO_OBJ(cmd->uc_rep));
PUT(d, "script_id", INTEGER_OBJ(cmd->uc_script_ctx.sc_sid));
PUT(d, "bang", BOOLEAN_OBJ(!!(cmd->uc_argt & EX_BANG)));
PUT(d, "bar", BOOLEAN_OBJ(!!(cmd->uc_argt & EX_TRLBAR)));
@@ -1772,21 +1762,21 @@ Dictionary commands_array(buf_T *buf)
case (EX_EXTRA | EX_NOSPC | EX_NEEDARG):
arg[0] = '1'; break;
}
- PUT(d, "nargs", STRING_OBJ(cstr_to_string(arg)));
+ PUT(d, "nargs", CSTR_TO_OBJ(arg));
char *cmd_compl = get_command_complete(cmd->uc_compl);
PUT(d, "complete", (cmd_compl == NULL
- ? NIL : STRING_OBJ(cstr_to_string(cmd_compl))));
+ ? NIL : CSTR_TO_OBJ(cmd_compl)));
PUT(d, "complete_arg", cmd->uc_compl_arg == NULL
- ? NIL : STRING_OBJ(cstr_to_string((char *)cmd->uc_compl_arg)));
+ ? NIL : CSTR_TO_OBJ(cmd->uc_compl_arg));
Object obj = NIL;
if (cmd->uc_argt & EX_COUNT) {
if (cmd->uc_def >= 0) {
- snprintf(str, sizeof(str), "%" PRId64, (int64_t)cmd->uc_def);
- obj = STRING_OBJ(cstr_to_string(str)); // -count=N
+ snprintf(str, sizeof(str), "%" PRId64, cmd->uc_def);
+ obj = CSTR_TO_OBJ(str); // -count=N
} else {
- obj = STRING_OBJ(cstr_to_string("0")); // -count
+ obj = CSTR_TO_OBJ("0"); // -count
}
}
PUT(d, "count", obj);
@@ -1794,12 +1784,12 @@ Dictionary commands_array(buf_T *buf)
obj = NIL;
if (cmd->uc_argt & EX_RANGE) {
if (cmd->uc_argt & EX_DFLALL) {
- obj = STRING_OBJ(cstr_to_string("%")); // -range=%
+ obj = CSTR_TO_OBJ("%"); // -range=%
} else if (cmd->uc_def >= 0) {
- snprintf(str, sizeof(str), "%" PRId64, (int64_t)cmd->uc_def);
- obj = STRING_OBJ(cstr_to_string(str)); // -range=N
+ snprintf(str, sizeof(str), "%" PRId64, cmd->uc_def);
+ obj = CSTR_TO_OBJ(str); // -range=N
} else {
- obj = STRING_OBJ(cstr_to_string(".")); // -range
+ obj = CSTR_TO_OBJ("."); // -range
}
}
PUT(d, "range", obj);
@@ -1808,13 +1798,13 @@ Dictionary commands_array(buf_T *buf)
for (int j = 0; addr_type_complete[j].expand != ADDR_NONE; j++) {
if (addr_type_complete[j].expand != ADDR_LINES
&& addr_type_complete[j].expand == cmd->uc_addr_type) {
- obj = STRING_OBJ(cstr_to_string(addr_type_complete[j].name));
+ obj = CSTR_TO_OBJ(addr_type_complete[j].name);
break;
}
}
PUT(d, "addr", obj);
- PUT(rv, (char *)cmd->uc_name, DICTIONARY_OBJ(d));
+ PUT(rv, cmd->uc_name, DICTIONARY_OBJ(d));
}
return rv;
}