aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2023-02-11 10:24:46 +0100
committerGitHub <noreply@github.com>2023-02-11 10:24:46 +0100
commitc8c930ea785aa393ebc819139913a9e05f0ccd45 (patch)
tree7ec328fa4a13dbac9a71361e6036c4d1952f9c10 /src
parentc9b0fe1f41ebaa6815a69ac614a5b2d1bab6f720 (diff)
downloadrneovim-c8c930ea785aa393ebc819139913a9e05f0ccd45.tar.gz
rneovim-c8c930ea785aa393ebc819139913a9e05f0ccd45.tar.bz2
rneovim-c8c930ea785aa393ebc819139913a9e05f0ccd45.zip
refactor: reduce scope of locals as per the style guide (#22206)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/arglist.c9
-rw-r--r--src/nvim/cmdhist.c20
-rw-r--r--src/nvim/edit.c70
-rw-r--r--src/nvim/ex_cmds.c22
-rw-r--r--src/nvim/ex_cmds2.c10
-rw-r--r--src/nvim/ex_eval.c68
-rw-r--r--src/nvim/ex_getln.c24
-rw-r--r--src/nvim/ex_session.c14
-rw-r--r--src/nvim/file_search.c6
-rw-r--r--src/nvim/getchar.c25
-rw-r--r--src/nvim/help.c13
-rw-r--r--src/nvim/indent.c29
-rw-r--r--src/nvim/mapping.c10
-rw-r--r--src/nvim/mbyte.c44
-rw-r--r--src/nvim/mouse.c43
-rw-r--r--src/nvim/ops.c104
-rw-r--r--src/nvim/popupmenu.c22
-rw-r--r--src/nvim/profile.c13
-rw-r--r--src/nvim/spell.c7
-rw-r--r--src/nvim/spellfile.c81
-rw-r--r--src/nvim/window.c3
21 files changed, 240 insertions, 397 deletions
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c
index c6a4be7e13..3882b98c2c 100644
--- a/src/nvim/arglist.c
+++ b/src/nvim/arglist.c
@@ -619,8 +619,6 @@ void ex_argument(exarg_T *eap)
/// Edit file "argn" of the argument lists.
void do_argfile(exarg_T *eap, int argn)
{
- int other;
- char *p;
int old_arg_idx = curwin->w_arg_idx;
if (argn < 0 || argn >= ARGCOUNT) {
@@ -646,9 +644,9 @@ void do_argfile(exarg_T *eap, int argn)
} else {
// if 'hidden' set, only check for changed file when re-editing
// the same buffer
- other = true;
+ int other = true;
if (buf_hide(curbuf)) {
- p = fix_fname(alist_name(&ARGLIST[argn]));
+ char *p = fix_fname(alist_name(&ARGLIST[argn]));
other = otherfile(p);
xfree(p);
}
@@ -683,8 +681,6 @@ void do_argfile(exarg_T *eap, int argn)
/// ":next", and commands that behave like it.
void ex_next(exarg_T *eap)
{
- int i;
-
// check for changed buffer now, if this fails the argument list is not
// redefined.
if (buf_hide(curbuf)
@@ -692,6 +688,7 @@ void ex_next(exarg_T *eap)
|| !check_changed(curbuf, CCGD_AW
| (eap->forceit ? CCGD_FORCEIT : 0)
| CCGD_EXCMD)) {
+ int i;
if (*eap->arg != NUL) { // redefine file list
if (do_arglist(eap->arg, AL_SET, 0, true) == FAIL) {
return;
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index 2df82d9355..c2928eb9c4 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -368,7 +368,6 @@ static int get_history_idx(int histype)
static int calc_hist_idx(int histype, int num)
{
int i;
- int wrapped = false;
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT
|| (i = hisidx[histype]) < 0 || num == 0) {
@@ -377,6 +376,7 @@ static int calc_hist_idx(int histype, int num)
histentry_T *hist = history[histype];
if (num > 0) {
+ int wrapped = false;
while (hist[i].hisnum > num) {
if (--i < 0) {
if (wrapped) {
@@ -568,14 +568,12 @@ void f_histdel(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "histget()" function
void f_histget(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- HistoryType type;
- int idx;
-
const char *const str = tv_get_string_chk(&argvars[0]); // NULL on type error
if (str == NULL) {
rettv->vval.v_string = NULL;
} else {
- type = get_histtype(str, strlen(str), false);
+ int idx;
+ HistoryType type = get_histtype(str, strlen(str), false);
if (argvars[1].v_type == VAR_UNKNOWN) {
idx = get_history_idx(type);
} else {
@@ -603,13 +601,11 @@ void f_histnr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// :history command - print a history
void ex_history(exarg_T *eap)
{
- histentry_T *hist;
int histype1 = HIST_CMD;
int histype2 = HIST_CMD;
int hisidx1 = 1;
int hisidx2 = -1;
- int idx;
- int i, j, k;
+ int i;
char *end;
char *arg = eap->arg;
@@ -649,10 +645,10 @@ void ex_history(exarg_T *eap)
assert(history_names[histype1] != NULL);
STRCAT(STRCAT(IObuff, history_names[histype1]), " history");
msg_puts_title(IObuff);
- idx = hisidx[histype1];
- hist = history[histype1];
- j = hisidx1;
- k = hisidx2;
+ int idx = hisidx[histype1];
+ histentry_T *hist = history[histype1];
+ int j = hisidx1;
+ int k = hisidx2;
if (j < 0) {
j = (-j > hislen) ? 0 : hist[(hislen + j + idx + 1) % hislen].hisnum;
}
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 96df6a3044..4fe1c08974 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -558,10 +558,9 @@ static int insert_execute(VimState *state, int key)
if (ins_compl_accept_char(s->c)) {
// Trigger InsertCharPre.
char *str = do_insert_char_pre(s->c);
- char *p;
if (str != NULL) {
- for (p = str; *p != NUL; MB_PTR_ADV(p)) {
+ for (char *p = str; *p != NUL; MB_PTR_ADV(p)) {
ins_compl_addleader(utf_ptr2char(p));
}
xfree(str);
@@ -1122,12 +1121,11 @@ normalchar:
if (!p_paste) {
// Trigger InsertCharPre.
char *str = do_insert_char_pre(s->c);
- char *p;
if (str != NULL) {
if (*str != NUL && stop_arrow() != FAIL) {
// Insert the new value of v:char literally.
- for (p = str; *p != NUL; MB_PTR_ADV(p)) {
+ for (char *p = str; *p != NUL; MB_PTR_ADV(p)) {
s->c = utf_ptr2char(p);
if (s->c == CAR || s->c == K_KENTER || s->c == NL) {
ins_eol(s->c);
@@ -1410,9 +1408,8 @@ static int pc_col;
void edit_putchar(int c, bool highlight)
{
- int attr;
-
if (curwin->w_grid_alloc.chars != NULL || default_grid.chars != NULL) {
+ int attr;
update_topline(curwin); // just in case w_topline isn't valid
validate_cursor();
if (highlight) {
@@ -1583,7 +1580,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
int start_col;
colnr_T vc;
colnr_T orig_col = 0; // init for GCC
- char *new_line, *orig_line = NULL; // init for GCC
+ char *orig_line = NULL; // init for GCC
// MODE_VREPLACE state needs to know what the line was like before changing
if (State & VREPLACE_FLAG) {
@@ -1742,7 +1739,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
// then put it back again the way we wanted it.
if (State & VREPLACE_FLAG) {
// Save new line
- new_line = xstrdup(get_cursor_line_ptr());
+ char *new_line = xstrdup(get_cursor_line_ptr());
// We only put back the new line up to the cursor
new_line[curwin->w_cursor.col] = NUL;
@@ -1949,9 +1946,6 @@ int get_literal(bool no_simplify)
/// @param ctrlv `c` was typed after CTRL-V
static void insert_special(int c, int allow_modmask, int ctrlv)
{
- char *p;
- int len;
-
// Special function key, translate into "<Key>". Up to the last '>' is
// inserted with ins_str(), so as not to replace characters in replace
// mode.
@@ -1961,8 +1955,8 @@ static void insert_special(int c, int allow_modmask, int ctrlv)
allow_modmask = true;
}
if (IS_SPECIAL(c) || (mod_mask && allow_modmask)) {
- p = (char *)get_special_key_name(c, mod_mask);
- len = (int)strlen(p);
+ char *p = (char *)get_special_key_name(c, mod_mask);
+ int len = (int)strlen(p);
c = (uint8_t)p[len - 1];
if (len > 2) {
if (stop_arrow() == FAIL) {
@@ -2294,7 +2288,6 @@ int stop_arrow(void)
/// @param nomove <c-\><c-o>, don't move cursor
static void stop_insert(pos_T *end_insert_pos, int esc, int nomove)
{
- int cc;
char *ptr;
stop_redo_ins();
@@ -2314,6 +2307,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove)
}
if (!arrow_used && end_insert_pos != NULL) {
+ int cc;
// Auto-format now. It may seem strange to do this when stopping an
// insertion (or moving the cursor), but it's required when appending
// a line and having it end in a space. But only do it when something
@@ -2883,7 +2877,6 @@ static void mb_replace_pop_ins(int cc)
int n;
char_u buf[MB_MAXBYTES + 1];
int i;
- int c;
if ((n = MB_BYTE2LEN(cc)) > 1) {
buf[0] = (char_u)cc;
@@ -2897,7 +2890,7 @@ static void mb_replace_pop_ins(int cc)
// Handle composing chars.
for (;;) {
- c = replace_pop();
+ int c = replace_pop();
if (c == -1) { // stack empty
break;
}
@@ -2943,17 +2936,13 @@ static void replace_flush(void)
static void replace_do_bs(int limit_col)
{
int cc;
- int orig_len = 0;
- int ins_len;
- int orig_vcols = 0;
colnr_T start_vcol;
- char *p;
- int i;
- int vcol;
const int l_State = State;
cc = replace_pop();
if (cc > 0) {
+ int orig_len = 0;
+ int orig_vcols = 0;
if (l_State & VREPLACE_FLAG) {
// Get the number of screen cells used by the character we are
// going to delete.
@@ -2969,10 +2958,10 @@ static void replace_do_bs(int limit_col)
if (l_State & VREPLACE_FLAG) {
// Get the number of screen cells used by the inserted characters
- p = get_cursor_pos_ptr();
- ins_len = (int)strlen(p) - orig_len;
- vcol = start_vcol;
- for (i = 0; i < ins_len; i++) {
+ char *p = get_cursor_pos_ptr();
+ int ins_len = (int)strlen(p) - orig_len;
+ int vcol = start_vcol;
+ for (int i = 0; i < ins_len; i++) {
vcol += win_chartabsize(curwin, p + i, vcol);
i += utfc_ptr2len(p) - 1;
}
@@ -3786,14 +3775,11 @@ static void ins_bs_one(colnr_T *vcolp)
static bool ins_bs(int c, int mode, int *inserted_space_p)
FUNC_ATTR_NONNULL_ARG(3)
{
- linenr_T lnum;
int cc;
int temp = 0; // init for GCC
colnr_T save_col;
- colnr_T mincol;
bool did_backspace = false;
int in_indent;
- int oldState;
int cpc[MAX_MCO]; // composing characters
bool call_fix_indent = false;
@@ -3844,7 +3830,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
// Delete newline!
if (curwin->w_cursor.col == 0) {
- lnum = Insstart.lnum;
+ linenr_T lnum = Insstart.lnum;
if (curwin->w_cursor.lnum == lnum || revins_on) {
if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
(linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) {
@@ -3900,7 +3886,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
// Do the next ins_char() in MODE_NORMAL state, to
// prevent ins_char() from replacing characters and
// avoiding showmatch().
- oldState = State;
+ int oldState = State;
State = MODE_NORMAL;
// restore characters (blanks) deleted after cursor
while (cc > 0) {
@@ -3920,7 +3906,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
if (revins_on) { // put cursor on last inserted char
dec_cursor();
}
- mincol = 0;
+ colnr_T mincol = 0;
// keep indent
if (mode == BACKSPACE_LINE
&& (curbuf->b_p_ai || cindent_on())
@@ -3944,7 +3930,6 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
&& (*(get_cursor_pos_ptr() - 1) == TAB
|| (*(get_cursor_pos_ptr() - 1) == ' '
&& (!*inserted_space_p || arrow_used)))))) {
- int ts;
colnr_T vcol;
colnr_T want_vcol;
colnr_T start_vcol;
@@ -3959,7 +3944,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
inc_cursor();
if (p_sta && in_indent) {
- ts = get_sw_value(curbuf);
+ int ts = get_sw_value(curbuf);
want_vcol = (want_vcol / ts) * ts;
} else {
want_vcol = tabstop_start(want_vcol,
@@ -3999,7 +3984,6 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
}
} else {
// Delete up to starting point, start of line or previous word.
- int prev_cclass = 0;
int cclass = mb_get_class(get_cursor_pos_ptr());
do {
@@ -4008,7 +3992,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
}
cc = gchar_cursor();
// look multi-byte character class
- prev_cclass = cclass;
+ int prev_cclass = cclass;
cclass = mb_get_class(get_cursor_pos_ptr());
if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word?
mode = BACKSPACE_WORD_NOT_SPACE;
@@ -4425,7 +4409,6 @@ static void ins_pagedown(void)
static bool ins_tab(void)
FUNC_ATTR_WARN_UNUSED_RESULT
{
- int i;
int temp;
if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum) {
@@ -4501,6 +4484,7 @@ static bool ins_tab(void)
if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0
|| get_sts_value() > 0
|| (p_sta && ind))) {
+ int i;
char *ptr;
char *saved_line = NULL; // init for GCC
pos_T pos;
@@ -4690,7 +4674,6 @@ bool ins_eol(int c)
static int ins_digraph(void)
{
int c;
- int cc;
bool did_putchar = false;
pc_status = PC_STATUS_UNSET;
@@ -4736,7 +4719,7 @@ static int ins_digraph(void)
}
no_mapping++;
allow_keys++;
- cc = plain_vgetc();
+ int cc = plain_vgetc();
no_mapping--;
allow_keys--;
if (did_putchar) {
@@ -4835,13 +4818,14 @@ static int ins_ctrl_ey(int tc)
// Used when inserting a "normal" character.
static void ins_try_si(int c)
{
- pos_T *pos, old_pos;
- char *ptr;
- int i;
- bool temp;
+ pos_T *pos;
// do some very smart indenting when entering '{' or '}'
if (((did_si || can_si_back) && c == '{') || (can_si && c == '}' && inindent(0))) {
+ pos_T old_pos;
+ char *ptr;
+ int i;
+ bool temp;
// for '}' set indent equal to indent of line containing matching '{'
if (c == '}' && (pos = findmatch(NULL, '{')) != NULL) {
old_pos = curwin->w_cursor;
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index ae7abfc5e7..da78861d87 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -724,7 +724,6 @@ sortend:
/// @return FAIL for failure, OK otherwise
int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
{
- char *str;
linenr_T l;
linenr_T extra; // Num lines added before line1
linenr_T num_lines; // Num lines moved
@@ -761,7 +760,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
return FAIL;
}
for (extra = 0, l = line1; l <= line2; l++) {
- str = xstrdup(ml_get(l + extra));
+ char *str = xstrdup(ml_get(l + extra));
ml_append(dest + l - line1, str, (colnr_T)0, false);
xfree(str);
if (dest < line1) {
@@ -875,10 +874,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
/// ":copy"
void ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
{
- linenr_T count;
- char *p;
-
- count = line2 - line1 + 1;
+ linenr_T count = line2 - line1 + 1;
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
curbuf->b_op_start.lnum = n + 1;
curbuf->b_op_end.lnum = n + count;
@@ -902,7 +898,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
while (line1 <= line2) {
// need to use xstrdup() because the line will be unlocked within
// ml_append()
- p = xstrdup(ml_get(line1));
+ char *p = xstrdup(ml_get(line1));
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false);
xfree(p);
@@ -952,7 +948,6 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out
char *t;
char *p;
char *trailarg;
- size_t len;
int scroll_save = msg_scroll;
//
@@ -975,7 +970,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out
// Skip leading white space to avoid a strange error with some shells.
trailarg = skipwhite(arg);
do {
- len = strlen(trailarg) + 1;
+ size_t len = strlen(trailarg) + 1;
if (newcmd != NULL) {
len += strlen(newcmd);
}
@@ -2736,7 +2731,6 @@ void ex_append(exarg_T *eap)
linenr_T lnum = eap->line2;
int indent = 0;
char *p;
- int vcol;
int empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
// the ! flag toggles autoindent
@@ -2803,7 +2797,7 @@ void ex_append(exarg_T *eap)
}
// Look for the "." after automatic indent.
- vcol = 0;
+ int vcol = 0;
for (p = theline; indent > vcol; p++) {
if (*p == ' ') {
vcol++;
@@ -4339,7 +4333,6 @@ static void global_exe_one(char *const cmd, const linenr_T lnum)
void ex_global(exarg_T *eap)
{
linenr_T lnum; // line number according to old situation
- int ndone = 0;
int type; // first char of cmd: 'v' or 'g'
char *cmd; // command argument
@@ -4411,6 +4404,7 @@ void ex_global(exarg_T *eap)
global_exe_one(cmd, lnum);
}
} else {
+ int ndone = 0;
// pass 1: set marks for each (not) matching line
for (lnum = eap->line1; lnum <= eap->line2 && !got_int; lnum++) {
// a match on this line?
@@ -4687,8 +4681,6 @@ int ex_substitute_preview(exarg_T *eap, long cmdpreview_ns, handle_T cmdpreview_
/// @return a pointer to the char just past the pattern plus flags.
char *skip_vimgrep_pat(char *p, char **s, int *flags)
{
- int c;
-
if (vim_isIDc((uint8_t)(*p))) {
// ":vimgrep pattern fname"
if (s != NULL) {
@@ -4703,7 +4695,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags)
if (s != NULL) {
*s = p + 1;
}
- c = (uint8_t)(*p);
+ int c = (uint8_t)(*p);
p = skip_regexp(p + 1, c, true);
if (*p != c) {
return NULL;
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index d08823bc30..c777efb445 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -446,12 +446,9 @@ int buf_write_all(buf_T *buf, int forceit)
/// ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo"
void ex_listdo(exarg_T *eap)
{
- int i;
win_T *wp;
tabpage_T *tp;
- int next_fnum = 0;
char *save_ei = NULL;
- char *p_shm_save;
if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) {
// Don't do syntax HL autocommands. Skipping the syntax file is a
@@ -469,7 +466,9 @@ void ex_listdo(exarg_T *eap)
|| !check_changed(curbuf, CCGD_AW
| (eap->forceit ? CCGD_FORCEIT : 0)
| CCGD_EXCMD)) {
- i = 0;
+ int next_fnum = 0;
+ char *p_shm_save;
+ int i = 0;
// start at the eap->line1 argument/window/buffer
wp = firstwin;
tp = first_tabpage;
@@ -762,14 +761,13 @@ void ex_compiler(exarg_T *eap)
/// ":checktime [buffer]"
void ex_checktime(exarg_T *eap)
{
- buf_T *buf;
int save_no_check_timestamps = no_check_timestamps;
no_check_timestamps = 0;
if (eap->addr_count == 0) { // default is all buffers
check_timestamps(false);
} else {
- buf = buflist_findnr((int)eap->line2);
+ buf_T *buf = buflist_findnr((int)eap->line2);
if (buf != NULL) { // cannot happen?
(void)buf_check_timestamp(buf);
}
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index f76e60f6c5..2c578564bc 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -278,9 +278,8 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore)
/// Free a "msg_list" and the messages it contains.
static void free_msglist(msglist_T *l)
{
- msglist_T *messages, *next;
-
- messages = l;
+ msglist_T *next;
+ msglist_T *messages = l;
while (messages != NULL) {
next = messages->next;
xfree(messages->msg);
@@ -379,9 +378,10 @@ int do_intthrow(cstack_T *cstack)
char *get_exception_string(void *value, except_type_T type, char *cmdname, int *should_free)
{
char *ret, *mesg;
- char *p, *val;
if (type == ET_ERROR) {
+ char *p;
+ char *val;
*should_free = true;
mesg = ((msglist_T *)value)->throw_msg;
if (cmdname != NULL && *cmdname != NUL) {
@@ -441,9 +441,6 @@ char *get_exception_string(void *value, except_type_T type, char *cmdname, int *
/// exception.
static int throw_exception(void *value, except_type_T type, char *cmdname)
{
- except_T *excp;
- int should_free;
-
// Disallow faking Interrupt or error exceptions as user exceptions. They
// would be treated differently from real interrupt or error exceptions
// when no active try block is found, see do_cmdline().
@@ -456,7 +453,7 @@ static int throw_exception(void *value, except_type_T type, char *cmdname)
}
}
- excp = xmalloc(sizeof(except_T));
+ except_T *excp = xmalloc(sizeof(except_T));
if (type == ET_ERROR) {
// Store the original message and prefix the exception value with
@@ -464,6 +461,7 @@ static int throw_exception(void *value, except_type_T type, char *cmdname)
excp->messages = (msglist_T *)value;
}
+ int should_free;
excp->value = get_exception_string(value, type, cmdname, &should_free);
if (excp->value == NULL && should_free) {
goto nomem;
@@ -525,8 +523,6 @@ fail:
/// caught and the catch clause has been ended normally.
static void discard_exception(except_T *excp, bool was_finished)
{
- char *saved_IObuff;
-
if (current_exception == excp) {
current_exception = NULL;
}
@@ -538,7 +534,7 @@ static void discard_exception(except_T *excp, bool was_finished)
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
- saved_IObuff = xstrdup(IObuff);
+ char *saved_IObuff = xstrdup(IObuff);
if (debug_break_level > 0) {
msg_silent = false; // display messages
} else {
@@ -677,7 +673,6 @@ static void report_pending(int action, int pending, void *value)
{
char *mesg;
char *s;
- int save_msg_silent;
assert(value || !(pending & CSTP_THROW));
@@ -727,7 +722,7 @@ static void report_pending(int action, int pending, void *value)
}
}
- save_msg_silent = msg_silent;
+ int save_msg_silent = msg_silent;
if (debug_break_level > 0) {
msg_silent = false; // display messages
}
@@ -806,8 +801,6 @@ void ex_eval(exarg_T *eap)
/// Handle ":if".
void ex_if(exarg_T *eap)
{
- int skip;
- int result;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) {
@@ -816,10 +809,10 @@ void ex_if(exarg_T *eap)
cstack->cs_idx++;
cstack->cs_flags[cstack->cs_idx] = 0;
- skip = CHECK_SKIP;
+ int skip = CHECK_SKIP;
bool error;
- result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip);
+ int result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip);
if (!skip && !error) {
if (result) {
@@ -860,7 +853,6 @@ void ex_endif(exarg_T *eap)
/// Handle ":else" and ":elseif".
void ex_else(exarg_T *eap)
{
- bool result = false;
cstack_T *const cstack = eap->cstack;
bool skip = CHECK_SKIP;
@@ -907,6 +899,7 @@ void ex_else(exarg_T *eap)
}
if (eap->cmdidx == CMD_elseif) {
+ bool result = false;
bool error;
// When skipping we ignore most errors, but a missing expression is
// wrong, perhaps it should have been "else".
@@ -941,13 +934,12 @@ void ex_else(exarg_T *eap)
void ex_while(exarg_T *eap)
{
bool error;
- int skip;
- int result;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = _("E585: :while/:for nesting too deep");
} else {
+ int result;
// The loop flag is set when we have jumped back from the matching
// ":endwhile" or ":endfor". When not set, need to initialise this
// cstack entry.
@@ -959,7 +951,7 @@ void ex_while(exarg_T *eap)
cstack->cs_flags[cstack->cs_idx] =
eap->cmdidx == CMD_while ? CSF_WHILE : CSF_FOR;
- skip = CHECK_SKIP;
+ int skip = CHECK_SKIP;
if (eap->cmdidx == CMD_while) {
// ":while bool-expr"
result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip);
@@ -1013,7 +1005,6 @@ void ex_while(exarg_T *eap)
/// Handle ":continue"
void ex_continue(exarg_T *eap)
{
- int idx;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
@@ -1023,7 +1014,7 @@ void ex_continue(exarg_T *eap)
// conditional not in its finally clause (which is then to be executed
// next). Therefore, deactivate all conditionals except the ":while"
// itself (if reached).
- idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, false);
+ int idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, false);
assert(idx >= 0);
if (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR)) {
rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel);
@@ -1043,7 +1034,6 @@ void ex_continue(exarg_T *eap)
/// Handle ":break"
void ex_break(exarg_T *eap)
{
- int idx;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
@@ -1053,7 +1043,7 @@ void ex_break(exarg_T *eap)
// conditional not in its finally clause (which is then to be
// executed next) is found. In the latter case, make the ":break"
// pending for execution at the ":endtry".
- idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, true);
+ int idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, true);
if (idx >= 0 && !(cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) {
cstack->cs_pending[idx] = CSTP_BREAK;
report_make_pending(CSTP_BREAK, NULL);
@@ -1065,10 +1055,8 @@ void ex_break(exarg_T *eap)
void ex_endwhile(exarg_T *eap)
{
cstack_T *const cstack = eap->cstack;
- int idx;
char *err;
int csf;
- int fl;
if (eap->cmdidx == CMD_endwhile) {
err = e_while;
@@ -1081,7 +1069,7 @@ void ex_endwhile(exarg_T *eap)
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = _(err);
} else {
- fl = cstack->cs_flags[cstack->cs_idx];
+ int fl = cstack->cs_flags[cstack->cs_idx];
if (!(fl & csf)) {
// If we are in a ":while" or ":for" but used the wrong endloop
// command, do not rewind to the next enclosing ":for"/":while".
@@ -1098,6 +1086,7 @@ void ex_endwhile(exarg_T *eap)
eap->errmsg = _(e_endtry);
}
// Try to find the matching ":while" and report what's missing.
+ int idx;
for (idx = cstack->cs_idx; idx > 0; idx--) {
fl = cstack->cs_flags[idx];
if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) {
@@ -1163,7 +1152,6 @@ void ex_throw(exarg_T *eap)
/// used for rethrowing an uncaught exception.
void do_throw(cstack_T *cstack)
{
- int idx;
int inactivate_try = false;
//
@@ -1187,7 +1175,7 @@ void do_throw(cstack_T *cstack)
got_int = false;
}
#endif
- idx = cleanup_conditionals(cstack, 0, inactivate_try);
+ int idx = cleanup_conditionals(cstack, 0, inactivate_try);
if (idx >= 0) {
// If this try conditional is active and we are before its first
// ":catch", set THROWN so that the ":catch" commands will check
@@ -1220,7 +1208,6 @@ void do_throw(cstack_T *cstack)
/// Handle ":try"
void ex_try(exarg_T *eap)
{
- int skip;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) {
@@ -1231,7 +1218,7 @@ void ex_try(exarg_T *eap)
cstack->cs_flags[cstack->cs_idx] = CSF_TRY;
cstack->cs_pending[cstack->cs_idx] = CSTP_NONE;
- skip = CHECK_SKIP;
+ int skip = CHECK_SKIP;
if (!skip) {
// Set ACTIVE and TRUE. TRUE means that the corresponding ":catch"
@@ -1271,12 +1258,9 @@ void ex_catch(exarg_T *eap)
int idx = 0;
bool give_up = false;
bool skip = false;
- bool caught = false;
char *end;
- char save_char = 0;
char *save_cpo;
regmatch_T regmatch;
- int prev_got_int;
cstack_T *const cstack = eap->cstack;
char *pat;
@@ -1319,6 +1303,7 @@ void ex_catch(exarg_T *eap)
}
if (!give_up) {
+ bool caught = false;
// Don't do something when no exception has been thrown or when the
// corresponding try block never got active (because of an inactive
// surrounding conditional or after an error or interrupt or throw).
@@ -1344,6 +1329,7 @@ void ex_catch(exarg_T *eap)
// the original exception, replace it by an interrupt exception,
// and don't catch it in this try block.
if (!dbg_check_skipped(eap) || !do_intthrow(cstack)) {
+ char save_char = 0;
// Terminate the pattern and avoid the 'l' flag in 'cpoptions'
// while compiling it.
if (end != NULL) {
@@ -1365,12 +1351,11 @@ void ex_catch(exarg_T *eap)
if (regmatch.regprog == NULL) {
semsg(_(e_invarg2), pat);
} else {
- //
// Save the value of got_int and reset it. We don't want
// a previous interruption cancel matching, only hitting
// CTRL-C while matching should abort it.
- //
- prev_got_int = got_int;
+
+ int prev_got_int = got_int;
got_int = false;
caught = vim_regexec_nl(&regmatch, current_exception->value, (colnr_T)0);
got_int |= prev_got_int;
@@ -1415,7 +1400,6 @@ void ex_catch(exarg_T *eap)
void ex_finally(exarg_T *eap)
{
int idx;
- int skip = false;
int pending = CSTP_NONE;
cstack_T *const cstack = eap->cstack;
@@ -1451,7 +1435,7 @@ void ex_finally(exarg_T *eap)
// ":finally". After every other error (did_emsg or the conditional
// errors detected above) or after an interrupt (got_int) or an
// exception (did_throw), the finally clause must be executed.
- skip = !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE);
+ int skip = !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE);
if (!skip) {
// When debugging or a breakpoint was encountered, display the
@@ -1985,14 +1969,12 @@ void ex_endfunction(exarg_T *eap)
/// @return true if the string "p" looks like a ":while" or ":for" command.
int has_loop_cmd(char *p)
{
- int len;
-
// skip modifiers, white space and ':'
for (;;) {
while (*p == ' ' || *p == '\t' || *p == ':') {
p++;
}
- len = modifier_len(p);
+ int len = modifier_len(p);
if (len == 0) {
break;
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index eadeb839de..95564da7cb 100644
--- a/