ex_cmds: port cmd_addr_T and ADDR_NONE (#13492)

Patch 8.1.1241 is too hard to port in 1 commit.
https://github.com/neovim/neovim/pull/13079 is too hard to review
and seems to be blocked.

Use 'int' type for some  addr variables to suppress 'switch/case' warnings.
This commit is contained in:
Jan Edmund Lazo
2020-12-10 19:48:18 -05:00
committed by GitHub
parent 52e660e857
commit a92dbf49bf
4 changed files with 589 additions and 574 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -67,15 +67,18 @@
#define FILE1 (FILES | NOSPC) // 1 file allowed, defaults to current file #define FILE1 (FILES | NOSPC) // 1 file allowed, defaults to current file
// values for cmd_addr_type // values for cmd_addr_type
#define ADDR_LINES 0 typedef enum {
#define ADDR_WINDOWS 1 ADDR_LINES, // buffer line numbers
#define ADDR_ARGUMENTS 2 ADDR_WINDOWS, // window number
#define ADDR_LOADED_BUFFERS 3 ADDR_ARGUMENTS, // argument number
#define ADDR_BUFFERS 4 ADDR_LOADED_BUFFERS, // buffer number of loaded buffer
#define ADDR_TABS 5 ADDR_BUFFERS, // buffer number
#define ADDR_TABS_RELATIVE 6 // Tab page that only relative ADDR_TABS, // tab page number
#define ADDR_QUICKFIX 7 ADDR_TABS_RELATIVE, // Tab page that only relative
#define ADDR_OTHER 99 ADDR_QUICKFIX, // quickfix list entry number
ADDR_OTHER, // something else
ADDR_NONE // no range used
} cmd_addr_T;
typedef struct exarg exarg_T; typedef struct exarg exarg_T;
@@ -93,7 +96,7 @@ typedef struct cmdname {
char_u *cmd_name; ///< Name of the command. char_u *cmd_name; ///< Name of the command.
ex_func_T cmd_func; ///< Function with implementation of this command. ex_func_T cmd_func; ///< Function with implementation of this command.
uint32_t cmd_argt; ///< Relevant flags from the declared above. uint32_t cmd_argt; ///< Relevant flags from the declared above.
int cmd_addr_type; ///< Flag for address type cmd_addr_T cmd_addr_type; ///< Flag for address type
} CommandDefinition; } CommandDefinition;
// A list used for saving values of "emsg_silent". Used by ex_try() to save the // A list used for saving values of "emsg_silent". Used by ex_try() to save the

View File

@@ -85,7 +85,7 @@ typedef struct ucmd {
char_u *uc_rep; // The command's replacement string char_u *uc_rep; // The command's replacement string
long uc_def; // The default value for a range/count long uc_def; // The default value for a range/count
int uc_compl; // completion type int uc_compl; // completion type
int uc_addr_type; // The command's address type cmd_addr_T uc_addr_type; // The command's address type
sctx_T uc_script_ctx; // SCTX where the command was defined sctx_T uc_script_ctx; // SCTX where the command was defined
char_u *uc_compl_arg; // completion argument if any char_u *uc_compl_arg; // completion argument if any
} ucmd_T; } ucmd_T;
@@ -1734,6 +1734,9 @@ static char_u * do_one_cmd(char_u **cmdlinep,
ea.line2 = 1; ea.line2 = 1;
} }
break; break;
case ADDR_NONE:
IEMSG(_("INTERNAL: Cannot use DFLALL with ADDR_NONE"));
break;
} }
} }
@@ -2347,6 +2350,9 @@ int parse_cmd_address(exarg_T *eap, char_u **errormsg, bool silent)
case ADDR_QUICKFIX: case ADDR_QUICKFIX:
eap->line2 = qf_get_cur_valid_idx(eap); eap->line2 = qf_get_cur_valid_idx(eap);
break; break;
case ADDR_NONE:
// Will give an error later if a range is found.
break;
} }
eap->cmd = skipwhite(eap->cmd); eap->cmd = skipwhite(eap->cmd);
lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent, lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent,
@@ -2412,6 +2418,9 @@ int parse_cmd_address(exarg_T *eap, char_u **errormsg, bool silent)
eap->line2 = 1; eap->line2 = 1;
} }
break; break;
case ADDR_NONE:
// Will give an error later if a range is found.
break;
} }
eap->addr_count++; eap->addr_count++;
} else if (*eap->cmd == '*') { } else if (*eap->cmd == '*') {
@@ -3698,12 +3707,14 @@ char_u *skip_range(
// Return MAXLNUM when no Ex address was found. // Return MAXLNUM when no Ex address was found.
static linenr_T get_address(exarg_T *eap, static linenr_T get_address(exarg_T *eap,
char_u **ptr, char_u **ptr,
int addr_type, // flag: one of ADDR_LINES, ... cmd_addr_T addr_type_arg,
int skip, // only skip the address, don't use it int skip, // only skip the address, don't use it
bool silent, // no errors or side effects bool silent, // no errors or side effects
int to_other_file, // flag: may jump to other file int to_other_file, // flag: may jump to other file
int address_count) // 1 for first, >1 after comma int address_count) // 1 for first, >1 after comma
FUNC_ATTR_NONNULL_ALL
{ {
const int addr_type = addr_type_arg;
int c; int c;
int i; int i;
long n; long n;
@@ -3737,6 +3748,7 @@ static linenr_T get_address(exarg_T *eap,
lnum = CURRENT_TAB_NR; lnum = CURRENT_TAB_NR;
break; break;
case ADDR_TABS_RELATIVE: case ADDR_TABS_RELATIVE:
case ADDR_NONE:
EMSG(_(e_invrange)); EMSG(_(e_invrange));
cmd = NULL; cmd = NULL;
goto error; goto error;
@@ -3776,6 +3788,7 @@ static linenr_T get_address(exarg_T *eap,
lnum = LAST_TAB_NR; lnum = LAST_TAB_NR;
break; break;
case ADDR_TABS_RELATIVE: case ADDR_TABS_RELATIVE:
case ADDR_NONE:
EMSG(_(e_invrange)); EMSG(_(e_invrange));
cmd = NULL; cmd = NULL;
goto error; goto error;
@@ -3938,6 +3951,8 @@ static linenr_T get_address(exarg_T *eap,
case ADDR_QUICKFIX: case ADDR_QUICKFIX:
lnum = qf_get_cur_valid_idx(eap); lnum = qf_get_cur_valid_idx(eap);
break; break;
case ADDR_NONE:
break;
} }
} }
@@ -4089,6 +4104,9 @@ static char_u *invalid_range(exarg_T *eap)
return (char_u *)_(e_invrange); return (char_u *)_(e_invrange);
} }
break; break;
case ADDR_NONE:
// Will give an error elsewhere.
break;
} }
} }
return NULL; return NULL;
@@ -4957,7 +4975,8 @@ char_u *get_command_name(expand_T *xp, int idx)
static int uc_add_command(char_u *name, size_t name_len, char_u *rep, static int uc_add_command(char_u *name, size_t name_len, char_u *rep,
uint32_t argt, long def, int flags, int compl, uint32_t argt, long def, int flags, int compl,
char_u *compl_arg, int addr_type, int force) char_u *compl_arg, cmd_addr_T addr_type, bool force)
FUNC_ATTR_NONNULL_ARG(1, 3)
{ {
ucmd_T *cmd = NULL; ucmd_T *cmd = NULL;
char_u *p; char_u *p;
@@ -5049,7 +5068,7 @@ fail:
static struct { static struct {
int expand; cmd_addr_T expand;
char *name; char *name;
char *shortname; char *shortname;
} addr_type_complete[] = } addr_type_complete[] =
@@ -5062,7 +5081,7 @@ static struct {
{ ADDR_WINDOWS, "windows", "win" }, { ADDR_WINDOWS, "windows", "win" },
{ ADDR_QUICKFIX, "quickfix", "qf" }, { ADDR_QUICKFIX, "quickfix", "qf" },
{ ADDR_OTHER, "other", "?" }, { ADDR_OTHER, "other", "?" },
{ -1, NULL, NULL } { ADDR_NONE, NULL, NULL }
}; };
/* /*
@@ -5236,7 +5255,7 @@ static void uc_list(char_u *name, size_t name_len)
} while (len < 8 - over); } while (len < 8 - over);
// Address Type // Address Type
for (j = 0; addr_type_complete[j].expand != -1; j++) { for (j = 0; addr_type_complete[j].expand != ADDR_NONE; j++) {
if (addr_type_complete[j].expand != ADDR_LINES if (addr_type_complete[j].expand != ADDR_LINES
&& addr_type_complete[j].expand == cmd->uc_addr_type) { && addr_type_complete[j].expand == cmd->uc_addr_type) {
STRCPY(IObuff + len, addr_type_complete[j].shortname); STRCPY(IObuff + len, addr_type_complete[j].shortname);
@@ -5284,7 +5303,8 @@ static void uc_list(char_u *name, size_t name_len)
static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def, static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def,
int *flags, int *complp, char_u **compl_arg, int *flags, int *complp, char_u **compl_arg,
int *addr_type_arg) cmd_addr_T *addr_type_arg)
FUNC_ATTR_NONNULL_ALL
{ {
char_u *p; char_u *p;
@@ -5421,7 +5441,7 @@ static void ex_command(exarg_T *eap)
int flags = 0; int flags = 0;
int compl = EXPAND_NOTHING; int compl = EXPAND_NOTHING;
char_u *compl_arg = NULL; char_u *compl_arg = NULL;
int addr_type_arg = ADDR_LINES; cmd_addr_T addr_type_arg = ADDR_LINES;
int has_attr = (eap->arg[0] == '-'); int has_attr = (eap->arg[0] == '-');
int name_len; int name_len;
@@ -6080,11 +6100,12 @@ char_u *get_user_cmd_complete(expand_T *xp, int idx)
* Parse address type argument * Parse address type argument
*/ */
int parse_addr_type_arg(char_u *value, int vallen, uint32_t *argt, int parse_addr_type_arg(char_u *value, int vallen, uint32_t *argt,
int *addr_type_arg) cmd_addr_T *addr_type_arg)
FUNC_ATTR_NONNULL_ALL
{ {
int i, a, b; int i, a, b;
for (i = 0; addr_type_complete[i].expand != -1; i++) { for (i = 0; addr_type_complete[i].expand != ADDR_NONE; i++) {
a = (int)STRLEN(addr_type_complete[i].name) == vallen; a = (int)STRLEN(addr_type_complete[i].name) == vallen;
b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0; b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0;
if (a && b) { if (a && b) {
@@ -6093,7 +6114,7 @@ int parse_addr_type_arg(char_u *value, int vallen, uint32_t *argt,
} }
} }
if (addr_type_complete[i].expand == -1) { if (addr_type_complete[i].expand == ADDR_NONE) {
char_u *err = value; char_u *err = value;
for (i = 0; err[i] != NUL && !ascii_iswhite(err[i]); i++) {} for (i = 0; err[i] != NUL && !ascii_iswhite(err[i]); i++) {}
@@ -6117,6 +6138,7 @@ int parse_addr_type_arg(char_u *value, int vallen, uint32_t *argt,
*/ */
int parse_compl_arg(const char_u *value, int vallen, int *complp, int parse_compl_arg(const char_u *value, int vallen, int *complp,
uint32_t *argt, char_u **compl_arg) uint32_t *argt, char_u **compl_arg)
FUNC_ATTR_NONNULL_ALL
{ {
const char_u *arg = NULL; const char_u *arg = NULL;
size_t arglen = 0; size_t arglen = 0;
@@ -9489,7 +9511,7 @@ Dictionary commands_array(buf_T *buf)
PUT(d, "range", obj); PUT(d, "range", obj);
obj = NIL; obj = NIL;
for (int j = 0; addr_type_complete[j].expand != -1; j++) { for (int j = 0; addr_type_complete[j].expand != ADDR_NONE; j++) {
if (addr_type_complete[j].expand != ADDR_LINES if (addr_type_complete[j].expand != ADDR_LINES
&& addr_type_complete[j].expand == cmd->uc_addr_type) { && addr_type_complete[j].expand == cmd->uc_addr_type) {
obj = STRING_OBJ(cstr_to_string(addr_type_complete[j].name)); obj = STRING_OBJ(cstr_to_string(addr_type_complete[j].name));

View File

@@ -62,7 +62,7 @@ for _, cmd in ipairs(defs) do
.cmd_name = (char_u *) "%s", .cmd_name = (char_u *) "%s",
.cmd_func = (ex_func_T)&%s, .cmd_func = (ex_func_T)&%s,
.cmd_argt = %uL, .cmd_argt = %uL,
.cmd_addr_type = %i .cmd_addr_type = %s
}, },
]], enumname, cmd.command, cmd.func, cmd.flags, cmd.addr_type)) ]], enumname, cmd.command, cmd.func, cmd.flags, cmd.addr_type))
end end