summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/job.c100
-rw-r--r--src/list.c222
-rw-r--r--src/locale.c47
-rw-r--r--src/main.c49
-rw-r--r--src/map.c55
-rw-r--r--src/mark.c46
-rw-r--r--src/match.c54
-rw-r--r--src/mbyte.c138
-rw-r--r--src/memfile.c28
-rw-r--r--src/memline.c86
-rw-r--r--src/menu.c106
-rw-r--r--src/message.c136
-rw-r--r--src/misc1.c80
-rw-r--r--src/misc2.c80
-rw-r--r--src/move.c119
-rw-r--r--src/version.c2
16 files changed, 675 insertions, 673 deletions
diff --git a/src/job.c b/src/job.c
index ba5eec0f1..ddfc8ef3c 100644
--- a/src/job.c
+++ b/src/job.c
@@ -793,11 +793,11 @@ job_free_job(job_T *job)
static void
job_free(job_T *job)
{
- if (!in_free_unref_items)
- {
- job_free_contents(job);
- job_free_job(job);
- }
+ if (in_free_unref_items)
+ return;
+
+ job_free_contents(job);
+ job_free_job(job);
}
static job_T *jobs_to_free = NULL;
@@ -1087,28 +1087,28 @@ set_ref_in_job(int copyID)
void
job_unref(job_T *job)
{
- if (job != NULL && --job->jv_refcount <= 0)
+ if (job == NULL || --job->jv_refcount > 0)
+ return;
+
+ // Do not free the job if there is a channel where the close callback
+ // may get the job info.
+ if (job_channel_still_useful(job))
+ return;
+
+ // Do not free the job when it has not ended yet and there is a
+ // "stoponexit" flag or an exit callback.
+ if (!job_need_end_check(job))
{
- // Do not free the job if there is a channel where the close callback
- // may get the job info.
- if (!job_channel_still_useful(job))
- {
- // Do not free the job when it has not ended yet and there is a
- // "stoponexit" flag or an exit callback.
- if (!job_need_end_check(job))
- {
- job_free(job);
- }
- else if (job->jv_channel != NULL)
- {
- // Do remove the link to the channel, otherwise it hangs
- // around until Vim exits. See job_free() for refcount.
- ch_log(job->jv_channel, "detaching channel from job");
- job->jv_channel->ch_job = NULL;
- channel_unref(job->jv_channel);
- job->jv_channel = NULL;
- }
- }
+ job_free(job);
+ }
+ else if (job->jv_channel != NULL)
+ {
+ // Do remove the link to the channel, otherwise it hangs
+ // around until Vim exits. See job_free() for refcount.
+ ch_log(job->jv_channel, "detaching channel from job");
+ job->jv_channel->ch_job = NULL;
+ channel_unref(job->jv_channel);
+ job->jv_channel = NULL;
}
}
@@ -1157,18 +1157,18 @@ job_alloc(void)
job_T *job;
job = ALLOC_CLEAR_ONE(job_T);
- if (job != NULL)
- {
- job->jv_refcount = 1;
- job->jv_stoponexit = vim_strsave((char_u *)"term");
+ if (job == NULL)
+ return NULL;
- if (first_job != NULL)
- {
- first_job->jv_prev = job;
- job->jv_next = first_job;
- }
- first_job = job;
+ job->jv_refcount = 1;
+ job->jv_stoponexit = vim_strsave((char_u *)"term");
+
+ if (first_job != NULL)
+ {
+ first_job->jv_prev = job;
+ job->jv_next = first_job;
}
+ first_job = job;
return job;
}
@@ -1803,13 +1803,13 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv)
return;
job = get_job_arg(&argvars[0]);
- if (job != NULL)
- {
- rettv->v_type = VAR_CHANNEL;
- rettv->vval.v_channel = job->jv_channel;
- if (job->jv_channel != NULL)
- ++job->jv_channel->ch_refcount;
- }
+ if (job == NULL)
+ return;
+
+ rettv->v_type = VAR_CHANNEL;
+ rettv->vval.v_channel = job->jv_channel;
+ if (job->jv_channel != NULL)
+ ++job->jv_channel->ch_refcount;
}
/*
@@ -1855,13 +1855,13 @@ job_info(job_T *job, dict_T *dict)
#endif
l = list_alloc();
- if (l != NULL)
- {
- dict_add_list(dict, "cmd", l);
- if (job->jv_argv != NULL)
- for (i = 0; job->jv_argv[i] != NULL; i++)
- list_append_string(l, (char_u *)job->jv_argv[i], -1);
- }
+ if (l == NULL)
+ return;
+
+ dict_add_list(dict, "cmd", l);
+ if (job->jv_argv != NULL)
+ for (i = 0; job->jv_argv[i] != NULL; i++)
+ list_append_string(l, (char_u *)job->jv_argv[i], -1);
}
/*
diff --git a/src/list.c b/src/list.c
index 8f228a1ae..71184547e 100644
--- a/src/list.c
+++ b/src/list.c
@@ -124,27 +124,27 @@ list_alloc_with_items(int count)
list_init(l);
- if (count > 0)
- {
- listitem_T *li = (listitem_T *)(l + 1);
- int i;
+ if (count <= 0)
+ return l;
- l->lv_len = count;
- l->lv_with_items = count;
- l->lv_first = li;
- l->lv_u.mat.lv_last = li + count - 1;
- for (i = 0; i < count; ++i)
- {
- if (i == 0)
- li->li_prev = NULL;
- else
- li->li_prev = li - 1;
- if (i == count - 1)
- li->li_next = NULL;
- else
- li->li_next = li + 1;
- ++li;
- }
+ listitem_T *li = (listitem_T *)(l + 1);
+ int i;
+
+ l->lv_len = count;
+ l->lv_with_items = count;
+ l->lv_first = li;
+ l->lv_u.mat.lv_last = li + count - 1;
+ for (i = 0; i < count; ++i)
+ {
+ if (i == 0)
+ li->li_prev = NULL;
+ else
+ li->li_prev = li - 1;
+ if (i == count - 1)
+ li->li_next = NULL;
+ else
+ li->li_next = li + 1;
+ ++li;
}
return l;
@@ -297,11 +297,11 @@ list_free_items(int copyID)
void
list_free(list_T *l)
{
- if (!in_free_unref_items)
- {
- list_free_contents(l);
- list_free_list(l);
- }
+ if (in_free_unref_items)
+ return;
+
+ list_free_contents(l);
+ list_free_list(l);
}
/*
@@ -540,13 +540,13 @@ list_find_index(list_T *l, long *idx)
{
listitem_T *li = list_find(l, *idx);
- if (li == NULL)
+ if (li != NULL)
+ return li;
+
+ if (*idx < 0)
{
- if (*idx < 0)
- {
- *idx = 0;
- li = list_find(l, *idx);
- }
+ *idx = 0;
+ li = list_find(l, *idx);
}
return li;
}
@@ -772,21 +772,21 @@ check_range_index_one(list_T *l, long *n1, int can_append, int quiet)
long orig_n1 = *n1;
listitem_T *li = list_find_index(l, n1);
+ if (li != NULL)
+ return li;
+
+ // Vim9: Allow for adding an item at the end.
+ if (can_append && in_vim9script()
+ && *n1 == l->lv_len && l->lv_lock == 0)
+ {
+ list_append_number(l, 0);
+ li = list_find_index(l, n1);
+ }
if (li == NULL)
{
- // Vim9: Allow for adding an item at the end.
- if (can_append && in_vim9script()
- && *n1 == l->lv_len && l->lv_lock == 0)
- {
- list_append_number(l, 0);
- li = list_find_index(l, n1);
- }
- if (li == NULL)
- {
- if (!quiet)
- semsg(_(e_list_index_out_of_range_nr), orig_n1);
- return NULL;
- }
+ if (!quiet)
+ semsg(_(e_list_index_out_of_range_nr), orig_n1);
+ return NULL;
}
return li;
}
@@ -1286,45 +1286,45 @@ list_copy(list_T *orig, int deep, int top, int copyID)
return NULL;
copy = list_alloc();
- if (copy != NULL)
+ if (copy == NULL)
+ return NULL;
+
+ if (orig->lv_type == NULL || top || deep)
+ copy->lv_type = NULL;
+ else
+ copy->lv_type = alloc_type(orig->lv_type);
+ if (copyID != 0)
{
- if (orig->lv_type == NULL || top || deep)
- copy->lv_type = NULL;
- else
- copy->lv_type = alloc_type(orig->lv_type);
- if (copyID != 0)
- {
- // Do this before adding the items, because one of the items may
- // refer back to this list.
- orig->lv_copyID = copyID;
- orig->lv_copylist = copy;
- }
- CHECK_LIST_MATERIALIZE(orig);
- for (item = orig->lv_first; item != NULL && !got_int;
- item = item->li_next)
+ // Do this before adding the items, because one of the items may
+ // refer back to this list.
+ orig->lv_copyID = copyID;
+ orig->lv_copylist = copy;
+ }
+ CHECK_LIST_MATERIALIZE(orig);
+ for (item = orig->lv_first; item != NULL && !got_int;
+ item = item->li_next)
+ {
+ ni = listitem_alloc();
+ if (ni == NULL)
+ break;
+ if (deep)
{
- ni = listitem_alloc();
- if (ni == NULL)
- break;
- if (deep)
+ if (item_copy(&item->li_tv, &ni->li_tv,
+ deep, FALSE, copyID) == FAIL)
{
- if (item_copy(&item->li_tv, &ni->li_tv,
- deep, FALSE, copyID) == FAIL)
- {
- vim_free(ni);
- break;
- }
+ vim_free(ni);
+ break;
}
- else
- copy_tv(&item->li_tv, &ni->li_tv);
- list_append(copy, ni);
- }
- ++copy->lv_refcount;
- if (item != NULL)
- {
- list_unref(copy);
- copy = NULL;
}
+ else
+ copy_tv(&item->li_tv, &ni->li_tv);
+ list_append(copy, ni);
+ }
+ ++copy->lv_refcount;
+ if (item != NULL)
+ {
+ list_unref(copy);
+ copy = NULL;
}
return copy;
@@ -1491,17 +1491,17 @@ list_join(
retval = list_join_inner(gap, l, sep, echo_style, restore_copyID,
copyID, &join_ga);
+ if (join_ga.ga_data == NULL)
+ return retval;
+
// Dispose each item in join_ga.
- if (join_ga.ga_data != NULL)
+ p = (join_T *)join_ga.ga_data;
+ for (i = 0; i < join_ga.ga_len; ++i)
{
- p = (join_T *)join_ga.ga_data;
- for (i = 0; i < join_ga.ga_len; ++i)
- {
- vim_free(p->tofree);
- ++p;
- }
- ga_clear(&join_ga);
+ vim_free(p->tofree);
+ ++p;
}
+ ga_clear(&join_ga);
return retval;
}
@@ -2560,36 +2560,36 @@ filter_map(typval_T *argvars, typval_T *rettv, filtermap_T filtermap)
// message. Avoid a misleading error message for an empty string that
// was not passed as argument.
expr = &argvars[1];
- if (expr->v_type != VAR_UNKNOWN)
- {
- typval_T save_val;
- typval_T save_key;
+ if (expr->v_type == VAR_UNKNOWN)
+ return;
+
+ typval_T save_val;
+ typval_T save_key;
- prepare_vimvar(VV_VAL, &save_val);
- prepare_vimvar(VV_KEY, &save_key);
+ prepare_vimvar(VV_VAL, &save_val);
+ prepare_vimvar(VV_KEY, &save_key);
- // We reset "did_emsg" to be able to detect whether an error
- // occurred during evaluation of the expression.
- save_did_emsg = did_emsg;
- did_emsg = FALSE;
+ // We reset "did_emsg" to be able to detect whether an error
+ // occurred during evaluation of the expression.
+ save_did_emsg = did_emsg;
+ did_emsg = FALSE;
- if (argvars[0].v_type == VAR_DICT)
- dict_filter_map(argvars[0].vval.v_dict, filtermap, type, func_name,
- arg_errmsg, expr, rettv);
- else if (argvars[0].v_type == VAR_BLOB)
- blob_filter_map(argvars[0].vval.v_blob, filtermap, expr, rettv);
- else if (argvars[0].v_type == VAR_STRING)
- string_filter_map(tv_get_string(&argvars[0]), filtermap, expr,
- rettv);
- else // argvars[0].v_type == VAR_LIST
- list_filter_map(argvars[0].vval.v_list, filtermap, type, func_name,
- arg_errmsg, expr, rettv);
+ if (argvars[0].v_type == VAR_DICT)
+ dict_filter_map(argvars[0].vval.v_dict, filtermap, type, func_name,
+ arg_errmsg, expr, rettv);
+ else if (argvars[0].v_type == VAR_BLOB)
+ blob_filter_map(argvars[0].vval.v_blob, filtermap, expr, rettv);
+ else if (argvars[0].v_type == VAR_STRING)
+ string_filter_map(tv_get_string(&argvars[0]), filtermap, expr,
+ rettv);
+ else // argvars[0].v_type == VAR_LIST
+ list_filter_map(argvars[0].vval.v_list, filtermap, type, func_name,
+ arg_errmsg, expr, rettv);
- restore_vimvar(VV_KEY, &save_key);
- restore_vimvar(VV_VAL, &save_val);
+ restore_vimvar(VV_KEY, &save_key);
+ restore_vimvar(VV_VAL, &save_val);
- did_emsg |= save_did_emsg;
- }
+ did_emsg |= save_did_emsg;
}
/*
diff --git a/src/locale.c b/src/locale.c
index d0378ffb5..ccdb479a8 100644
--- a/src/locale.c
+++ b/src/locale.c
@@ -151,20 +151,20 @@ get_mess_env(void)
char_u *p;
p = mch_getenv((char_u *)"LC_ALL");
- if (p == NULL || *p == NUL)
- {
- p = mch_getenv((char_u *)"LC_MESSAGES");
- if (p == NULL || *p == NUL)
- {
- p = mch_getenv((char_u *)"LANG");
- if (p != NULL && VIM_ISDIGIT(*p))
- p = NULL; // ignore something like "1043"
+ if (p != NULL && *p != NUL)
+ return p;
+
+ p = mch_getenv((char_u *)"LC_MESSAGES");
+ if (p != NULL && *p != NUL)
+ return p;
+
+ p = mch_getenv((char_u *)"LANG");
+ if (p != NULL && VIM_ISDIGIT(*p))
+ p = NULL; // ignore something like "1043"
# ifdef HAVE_GET_LOCALE_VAL
- if (p == NULL || *p == NUL)
- p = get_locale_val(LC_CTYPE);
+ if (p == NULL || *p == NUL)
+ p = get_locale_val(LC_CTYPE);
# endif
- }
- }
return p;
}
#endif
@@ -504,11 +504,11 @@ find_locales(void)
static void
init_locales(void)
{
- if (!did_init_locales)
- {
- did_init_locales = TRUE;
- locales = find_locales();
- }
+ if (did_init_locales)
+ return;
+
+ did_init_locales = TRUE;
+ locales = find_locales();
}
# if defined(EXITFREE) || defined(PROTO)
@@ -516,12 +516,13 @@ init_locales(void)
free_locales(void)
{
int i;
- if (locales != NULL)
- {
- for (i = 0; locales[i] != NULL; i++)
- vim_free(locales[i]);
- VIM_CLEAR(locales);
- }
+
+ if (locales == NULL)
+ return;
+
+ for (i = 0; locales[i] != NULL; i++)
+ vim_free(locales[i]);
+ VIM_CLEAR(locales);
}
# endif
diff --git a/src/main.c b/src/main.c
index 0299c61a7..d1c42ed12 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3099,23 +3099,23 @@ exe_pre_commands(mparm_T *parmp)
int i;
ESTACK_CHECK_DECLARATION
- if (cnt > 0)
- {
- curwin->w_cursor.lnum = 0; // just in case..
- estack_push(ETYPE_ARGS, (char_u *)_("pre-vimrc command line"), 0);
- ESTACK_CHECK_SETUP
+ if (cnt <= 0)
+ return;
+
+ curwin->w_cursor.lnum = 0; // just in case..
+ estack_push(ETYPE_ARGS, (char_u *)_("pre-vimrc command line"), 0);
+ ESTACK_CHECK_SETUP
# ifdef FEAT_EVAL
current_sctx.sc_sid = SID_CMDARG;
# endif
for (i = 0; i < cnt; ++i)
do_cmdline_cmd(cmds[i]);
- ESTACK_CHECK_NOW
+ ESTACK_CHECK_NOW
estack_pop();
# ifdef FEAT_EVAL
- current_sctx.sc_sid = 0;
+ current_sctx.sc_sid = 0;
# endif
- TIME_MSG("--cmd commands");
- }
+ TIME_MSG("--cmd commands");
}
/*
@@ -3369,28 +3369,27 @@ process_env(
ESTACK_CHECK_DECLARATION
- if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL)
- {
- if (is_viminit)
- vimrc_found(NULL, NULL);
- estack_push(ETYPE_ENV, env, 0);
- ESTACK_CHECK_SETUP
+ if ((initstr = mch_getenv(env)) == NULL || *initstr == NUL)
+ return FAIL;
+
+ if (is_viminit)
+ vimrc_found(NULL, NULL);
+ estack_push(ETYPE_ENV, env, 0);
+ ESTACK_CHECK_SETUP
save_current_sctx = current_sctx;
- current_sctx.sc_version = 1;
+ current_sctx.sc_version = 1;
#ifdef FEAT_EVAL
- current_sctx.sc_sid = SID_ENV;
- current_sctx.sc_seq = 0;
- current_sctx.sc_lnum = 0;
+ current_sctx.sc_sid = SID_ENV;
+ current_sctx.sc_seq = 0;
+ current_sctx.sc_lnum = 0;
#endif
- do_cmdline_cmd(initstr);
+ do_cmdline_cmd(initstr);
- ESTACK_CHECK_NOW
+ ESTACK_CHECK_NOW
estack_pop();
- current_sctx = save_current_sctx;
- return OK;
- }
- return FAIL;
+ current_sctx = save_current_sctx;
+ return OK;
}
#if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN)
diff --git a/src/map.c b/src/map.c
index a856b88e7..244636fdc 100644
--- a/src/map.c
+++ b/src/map.c
@@ -67,11 +67,11 @@ is_maphash_valid(void)
static void
validate_maphash(void)
{
- if (!maphash_valid)
- {
- CLEAR_FIELD(maphash);
- maphash_valid = TRUE;
- }
+ if (maphash_valid)
+ return;
+
+ CLEAR_FIELD(maphash);
+ maphash_valid = TRUE;
}
/*
@@ -581,8 +581,8 @@ do_map(
// needs to be freed later (*keys_buf and *arg_buf).
// replace_termcodes() also removes CTRL-Vs and sometimes backslashes.
// If something like <C-H> is simplified to 0x08 then mark it as simplified
- // and also add a n entry with a modifier, which will work when
- // modifyOtherKeys is working.
+ // and also add an entry with a modifier, which will work when using a key
+ // protocol.
if (haskey)
{
char_u *new_keys;
@@ -1843,32 +1843,33 @@ vim_strsave_escape_csi(char_u *p)
// illegal utf-8 byte:
// 0xc0 -> 0xc3 0x80 -> 0xc3 K_SPECIAL KS_SPECIAL KE_FILLER
res = alloc(STRLEN(p) * 4 + 1);
- if (res != NULL)
+ if (res == NULL)
+ return NULL;
+
+ d = res;
+ for (s = p; *s != NUL; )
{
- d = res;
- for (s = p; *s != NUL; )
- {
- if ((s[0] == K_SPECIAL
+ if ((s[0] == K_SPECIAL
#ifdef FEAT_GUI
|| (gui.in_use && s[0] == CSI)
#endif
- ) && s[1] != NUL && s[2] != NUL)
- {
- // Copy special key unmodified.
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- }
- else
- {
- // Add character, possibly multi-byte to destination, escaping
- // CSI and K_SPECIAL. Be careful, it can be an illegal byte!
- d = add_char2buf(PTR2CHAR(s), d);
- s += MB_CPTR2LEN(s);
- }
+ ) && s[1] != NUL && s[2] != NUL)
+ {
+ // Copy special key unmodified.
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ }
+ else
+ {
+ // Add character, possibly multi-byte to destination, escaping
+ // CSI and K_SPECIAL. Be careful, it can be an illegal byte!
+ d = add_char2buf(PTR2CHAR(s), d);
+ s += MB_CPTR2LEN(s);
}
- *d = NUL;
}
+ *d = NUL;
+
return res;
}
diff --git a/src/mark.c b/src/mark.c
index 584db033d..a7592e607 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -485,34 +485,34 @@ fname2fnum(xfmark_T *fm)
{
char_u *p;
- if (fm->fname != NULL)
- {
- /*
- * First expand "~/" in the file name to the home directory.
- * Don't expand the whole name, it may contain other '~' chars.
- */
- if (fm->fname[0] == '~' && (fm->fname[1] == '/'
+ if (fm->fname == NULL)
+ return;
+
+ /*
+ * First expand "~/" in the file name to the home directory.
+ * Don't expand the whole name, it may contain other '~' chars.
+ */
+ if (fm->fname[0] == '~' && (fm->fname[1] == '/'
#ifdef BACKSLASH_IN_FILENAME
- || fm->fname[1] == '\\'
+ || fm->fname[1] == '\\'
#endif
- ))
- {
- int len;
+ ))
+ {
+ int len;
- expand_env((char_u *)"~/", NameBuff, MAXPATHL);
- len = (int)STRLEN(NameBuff);
- vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1);
- }
- else
- vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1);
+ expand_env((char_u *)"~/", NameBuff, MAXPATHL);
+ len = (int)STRLEN(NameBuff);
+ vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1);
+ }
+ else
+ vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1);
- // Try to shorten the file name.
- mch_dirname(IObuff, IOSIZE);
- p = shorten_fname(NameBuff, IObuff);
+ // Try to shorten the file name.
+ mch_dirname(IObuff, IOSIZE);
+ p = shorten_fname(NameBuff, IObuff);
- // buflist_new() will call fmarks_check_names()
- (void)buflist_new(NameBuff, p, (linenr_T)1, 0);
- }
+ // buflist_new() will call fmarks_check_names()
+ (void)buflist_new(NameBuff, p, (linenr_T)1, 0);
}
/*
diff --git a/src/match.c b/src/match.c
index 6ac6513ca..f59c2066a 100644
--- a/src/match.c
+++ b/src/match.c
@@ -978,14 +978,14 @@ matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win)
if (dict_has_key(tv->vval.v_dict, "conceal"))
*conceal_char = dict_get_string(tv->vval.v_dict, "conceal", FALSE);
- if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL)
+ if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) == NULL)
+ return OK;
+
+ *win = find_win_by_nr_or_id(&di->di_tv);
+ if (*win == NULL)
{
- *win = find_win_by_nr_or_id(&di->di_tv);
- if (*win == NULL)
- {
- emsg(_(e_invalid_window_number));
- return FAIL;
- }
+ emsg(_(e_invalid_window_number));
+ return FAIL;
}
return OK;
@@ -1330,32 +1330,32 @@ f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
void
f_matcharg(typval_T *argvars UNUSED, typval_T *rettv)
{
- if (rettv_list_alloc(rettv) == OK)
- {
+ if (rettv_list_alloc(rettv) != OK)
+ return;
+
# ifdef FEAT_SEARCH_EXTRA
- int id;
- matchitem_T *m;
+ int id;
+ matchitem_T *m;
- if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
- return;
+ if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
+ return;
- id = (int)tv_get_number(&argvars[0]);
- if (id >= 1 && id <= 3)
+ id = (int)tv_get_number(&argvars[0]);
+ if (id >= 1 && id <= 3)
+ {
+ if ((m = get_match(curwin, id)) != NULL)
{
- if ((m = get_match(curwin, id)) != NULL)
- {
- list_append_string(rettv->vval.v_list,
- syn_id2name(m->mit_hlg_id), -1);
- list_append_string(rettv->vval.v_list, m->mit_pattern, -1);
- }
- else
- {
- list_append_string(rettv->vval.v_list, NULL, -1);
- list_append_string(rettv->vval.v_list, NULL, -1);
- }
+ list_append_string(rettv->vval.v_list,
+ syn_id2name(m->mit_hlg_id), -1);
+ list_append_string(rettv->vval.v_list, m->mit_pattern, -1);
+ }
+ else
+ {
+ list_append_string(rettv->vval.v_list, NULL, -1);
+ list_append_string(rettv->vval.v_list, NULL, -1);
}
-# endif
}
+# endif
}
/*
diff --git a/src/mbyte.c b/src/mbyte.c
index 1570cef23..07cd9c6e6 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -809,17 +809,17 @@ bomb_size(void)
void
remove_bom(char_u *s)
{
- if (enc_utf8)
- {
- char_u *p = s;
+ if (!enc_utf8)
+ return;
- while ((p = vim_strbyte(p, 0xef)) != NULL)
- {
- if (p[1] == 0xbb && p[2] == 0xbf)
- STRMOVE(p, p + 3);
- else
- ++p;
- }
+ char_u *p = s;
+
+ while ((p = vim_strbyte(p, 0xef)) != NULL)
+ {
+ if (p[1] == 0xbb && p[2] == 0xbf)
+ STRMOVE(p, p + 3);
+ else
+ ++p;
}
}
#endif
@@ -4590,56 +4590,56 @@ enc_canonize(char_u *enc)
// copy "enc" to allocated memory, with room for two '-'
r = alloc(STRLEN(enc) + 3);
- if (r != NULL)
+ if (r == NULL)
+ return NULL;
+
+ // Make it all lower case and replace '_' with '-'.
+ p = r;
+ for (s = enc; *s != NUL; ++s)
{
- // Make it all lower case and replace '_' with '-'.
- p = r;
- for (s = enc; *s != NUL; ++s)
- {
- if (*s == '_')
- *p++ = '-';
- else
- *p++ = TOLOWER_ASC(*s);
- }
- *p = NUL;
+ if (*s == '_')
+ *p++ = '-';
+ else
+ *p++ = TOLOWER_ASC(*s);
+ }
+ *p = NUL;
- // Skip "2byte-" and "8bit-".
- p = enc_skip(r);
+ // Skip "2byte-" and "8bit-".
+ p = enc_skip(r);
- // Change "microsoft-cp" to "cp". Used in some spell files.
- if (STRNCMP(p, "microsoft-cp", 12) == 0)
- STRMOVE(p, p + 10);
+ // Change "microsoft-cp" to "cp". Used in some spell files.
+ if (STRNCMP(p, "microsoft-cp", 12) == 0)
+ STRMOVE(p, p + 10);
- // "iso8859" -> "iso-8859"
- if (STRNCMP(p, "iso8859", 7) == 0)
- {
- STRMOVE(p + 4, p + 3);
- p[3] = '-';
- }
+ // "iso8859" -> "iso-8859"
+ if (STRNCMP(p, "iso8859", 7) == 0)
+ {
+ STRMOVE(p + 4, p + 3);
+ p[3] = '-';
+ }
- // "iso-8859n" -> "iso-8859-n"
- if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8]))
- {
- STRMOVE(p + 9, p + 8);
- p[8] = '-';
- }
+ // "iso-8859n" -> "iso-8859-n"
+ if (STRNCMP(p, "iso-8859", 8) == 0 && isdigit(p[8]))
+ {
+ STRMOVE(p + 9, p + 8);
+ p[8] = '-';
+ }
- // "latin-N" -> "latinN"
- if (STRNCMP(p, "latin-", 6) == 0)
- STRMOVE(p + 5, p + 6);
+ // "latin-N" -> "latinN"
+ if (STRNCMP(p, "latin-", 6) == 0)
+ STRMOVE(p + 5, p + 6);
- if (enc_canon_search(p) >= 0)
- {
- // canonical name can be used unmodified
- if (p != r)
- STRMOVE(r, p);
- }
- else if ((i = enc_alias_search(p)) >= 0)
- {
- // alias recognized, get canonical name
- vim_free(r);
- r = vim_strsave((char_u *)enc_canon_table[i].name);
- }
+ if (enc_canon_search(p) >= 0)
+ {
+ // canonical name can be used unmodified
+ if (p != r)
+ STRMOVE(r, p);
+ }
+ else if ((i = enc_alias_search(p)) >= 0)
+ {
+ // alias recognized, get canonical name
+ vim_free(r);
+ r = vim_strsave((char_u *)enc_canon_table[i].name);
}
return r;
}
@@ -5269,26 +5269,26 @@ convert_input_safe(
d = string_convert_ext(&input_conv, ptr, &dlen,
restp == NULL ? NULL : &unconvertlen);
- if (d != NULL)
+ if (d == NULL)
+ return dlen;
+
+ if (dlen <= maxlen)
{
- if (dlen <= maxlen)
+ if (unconvertlen > 0)
{
- if (unconvertlen > 0)
- {
- // Move the unconverted characters to allocated memory.
- *restp = alloc(unconvertlen);
- if (*restp != NULL)
- mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen);
- *restlenp = unconvertlen;
- }
- mch_memmove(ptr, d, dlen);
+ // Move the unconverted characters to allocated memory.
+ *restp = alloc(unconvertlen);
+ if (*restp != NULL)
+ mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen);
+ *restlenp = unconvertlen;
}
- else
- // result is too long, keep the unconverted text (the caller must
- // have done something wrong!)
- dlen = len;
- vim_free(d);
+ mch_memmove(ptr, d, dlen);
}
+ else
+ // result is too long, keep the unconverted text (the caller must
+ // have done something wrong!)
+ dlen = len;
+ vim_free(d);
return dlen;
}
diff --git a/src/memfile.c b/src/memfile.c
index 0d816f36d..e8cbe3169 100644
--- a/src/memfile.c
+++ b/src/memfile.c
@@ -879,16 +879,16 @@ mf_alloc_bhdr(memfile_T *mfp, int page_count)
{
bhdr_T *hp;
- if ((hp = ALLOC_ONE(bhdr_T)) != NULL)
+ if ((hp = ALLOC_ONE(bhdr_T)) == NULL)
+ return NULL;
+
+ if ((hp->bh_data = alloc((size_t)mfp->mf_page_size * page_count))
+ == NULL)
{
- if ((hp->bh_data = alloc((size_t)mfp->mf_page_size * page_count))
- == NULL)
- {
- vim_free(hp); // not enough memory
- return NULL;
- }
- hp->bh_page_count = page_count;
+ vim_free(hp); // not enough memory
+ return NULL;
}
+ hp->bh_page_count = page_count;
return hp;
}
@@ -1209,12 +1209,12 @@ mf_set_ffname(memfile_T *mfp)
void
mf_fullname(memfile_T *mfp)
{
- if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL)
- {
- vim_free(mfp->mf_fname);
- mfp->mf_fname = mfp->mf_ffname;
- mfp->mf_ffname = NULL;
- }
+ if (mfp == NULL || mfp->mf_fname == NULL || mfp->mf_ffname == NULL)
+ return;
+
+ vim_free(mfp->mf_fname);
+ mfp->mf_fname = mfp->mf_ffname;
+ mfp->mf_ffname = NULL;
}
/*
diff --git a/src/memline.c b/src/memline.c
index 48b17f558..7cbe559e6 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -422,21 +422,21 @@ error:
static void
ml_set_mfp_crypt(buf_T *buf)
{
- if (*buf->b_p_key != NUL)
- {
- int method_nr = crypt_get_method_nr(buf);
+ if (*buf->b_p_key == NUL)
+ return;
- if (method_nr > CRYPT_M_ZIP && method_nr < CRYPT_M_SOD)
- {
- // Generate a seed and store it in the memfile.
- sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0);
- }
-#ifdef FEAT_SODIUM
- else if (method_nr == CRYPT_M_SOD)
- crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed,
- MF_SEED_LEN);
- #endif
+ int method_nr = crypt_get_method_nr(buf);
+
+ if (method_nr > CRYPT_M_ZIP && method_nr < CRYPT_M_SOD)
+ {
+ // Generate a seed and store it in the memfile.
+ sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0);
}
+#ifdef FEAT_SODIUM
+ else if (method_nr == CRYPT_M_SOD)
+ crypt_sodium_randombytes_buf(buf->b_ml.ml_mfp->mf_seed,
+ MF_SEED_LEN);
+#endif
}
/*
@@ -2090,22 +2090,22 @@ make_percent_swname(char_u *dir, char_u *name)
char_u *d = NULL, *s, *f;
f = fix_fname(name != NULL ? name : (char_u *)"");
- if (f != NULL)
- {
- s = alloc(STRLEN(f) + 1);
- if (s != NULL)
- {
- STRCPY(s, f);
- for (d = s; *d != NUL; MB_PTR_ADV(d))
- if (vim_ispathsep(*d))
- *d = '%';
+ if (f == NULL)
+ return NULL;
- dir[STRLEN(dir) - 1] = NUL; // remove one trailing slash
- d = concat_fnames(dir, s, TRUE);
- vim_free(s);
- }
- vim_free(f);
+ s = alloc(STRLEN(f) + 1);
+ if (s != NULL)
+ {
+ STRCPY(s, f);
+ for (d = s; *d != NUL; MB_PTR_ADV(d))
+ if (vim_ispathsep(*d))
+ *d = '%';
+
+ dir[STRLEN(dir) - 1] = NUL; // remove one trailing slash
+ d = concat_fnames(dir, s, TRUE);
+ vim_free(s);
}
+ vim_free(f);
return d;
}
#endif
@@ -5473,24 +5473,24 @@ ml_decrypt_data(
int text_len;
cryptstate_T *state;
- if (dp->db_id == DATA_ID)
- {
- head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
- text_start = (char_u *)dp + dp->db_txt_start;
- text_len = dp->db_txt_end - dp->db_txt_start;
+ if (dp->db_id != DATA_ID)
+ return;
+
+ head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
+ text_start = (char_u *)dp + dp->db_txt_start;
+ text_len = dp->db_txt_end - dp->db_txt_start;
- if (head_end > text_start || dp->db_txt_start > size
- || dp->db_txt_end > size)
- return; // data was messed up
+ if (head_end > text_start || dp->db_txt_start > size
+ || dp->db_txt_end > size)
+ return; // data was messed up
- state = ml_crypt_prepare(mfp, offset, TRUE);
- if (state != NULL)
- {
- // Decrypt the text in place.
- crypt_decode_inplace(state, text_start, text_len, FALSE);
- crypt_free_state(state);
- }
- }
+ state = ml_crypt_prepare(mfp, offset, TRUE);
+ if (state == NULL)
+ return;
+
+ // Decrypt the text in place.
+ crypt_decode_inplace(state, text_start, text_len, FALSE);
+ crypt_free_state(state);
}
/*
diff --git a/src/menu.c b/src/menu.c
index 9209bf735..a543a5093 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1763,12 +1763,12 @@ popup_mode_name(char_u *name, int idx)
int i;
p = vim_strnsave(name, len + mode_chars_len);
- if (p != NULL)
- {
- mch_memmove(p + 5 + mode_chars_len, p + 5, (size_t)(len - 4));
- for (i = 0; i < mode_chars_len; ++i)
- p[5 + i] = menu_mode_chars[idx][i];
- }
+ if (p == NULL)
+ return NULL;
+
+ mch_memmove(p + 5 + mode_chars_len, p + 5, (size_t)(len - 4));
+ for (i = 0; i < mode_chars_len; ++i)
+ p[5 + i] = menu_mode_chars[idx][i];
return p;
}
@@ -2008,24 +2008,24 @@ show_popupmenu(void)
break;
// Only show a popup when it is defined and has entries
- if (menu != NULL && menu->children != NULL)
- {
+ if (menu == NULL || menu->children == NULL)
+ return;
+
# if defined(FEAT_GUI)
- if (gui.in_use)
- {
- // Update the menus now, in case the MenuPopup autocommand did
- // anything.
- gui_update_menus(0);
- gui_mch_show_popupmenu(menu);
- }
+ if (gui.in_use)
+ {
+ // Update the menus now, in case the MenuPopup autocommand did
+ // anything.
+ gui_update_menus(0);
+ gui_mch_show_popupmenu(menu);
+ }
# endif
# if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU)
- else
+ else
# endif
# if defined(FEAT_TERM_POPUP_MENU)
- pum_show_popupmenu(menu);
+ pum_show_popupmenu(menu);
# endif
- }
}
#endif
@@ -2255,39 +2255,39 @@ gui_add_tearoff(char_u *tearpath, int *pri_tab, int pri_idx)
vimmenu_T menuarg;
tbuf = alloc(5 + (unsigned int)STRLEN(tearpath));
- if (tbuf != NULL)
- {
- tbuf[0] = K_SPECIAL;
- tbuf[1] = K_SECOND(K_TEAROFF);
- tbuf[2] = K_THIRD(K_TEAROFF);
- STRCPY(tbuf + 3, tearpath);
- STRCAT(tbuf + 3, "\r");
+ if (tbuf == NULL)
+ return;
+
+ tbuf[0] = K_SPECIAL;
+ tbuf[1] = K_SECOND(K_TEAROFF);
+ tbuf[2] = K_THIRD(K_TEAROFF);
+ STRCPY(tbuf + 3, tearpath);
+ STRCAT(tbuf + 3, "\r");
- STRCAT(tearpath, ".");
- STRCAT(tearpath, TEAR_STRING);
+ STRCAT(tearpath, ".");
+ STRCAT(tearpath, TEAR_STRING);
- // Priority of tear-off is always 1
- t = pri_tab[pri_idx + 1];
- pri_tab[pri_idx + 1] = 1;
+ // Priority of tear-off is always 1
+ t = pri_tab[pri_idx + 1];
+ pri_tab[pri_idx + 1] = 1;
#ifdef FEAT_TOOLBAR
- menuarg.iconfile = NULL;
- menuarg.iconidx = -1;
- menuarg.icon_builtin = FALSE;
+ menuarg.iconfile = NULL;
+ menuarg.iconidx = -1;
+ menuarg.icon_builtin = FALSE;
#endif
- menuarg.noremap[0] = REMAP_NONE;
- menuarg.silent[0] = TRUE;
+ menuarg.noremap[0] = REMAP_NONE;
+ menuarg.silent[0] = TRUE;
- menuarg.modes = MENU_ALL_MODES;
- add_menu_path(tearpath, &menuarg, pri_tab, tbuf, FALSE);
+ menuarg.modes = MENU_ALL_MODES;
+ add_menu_path(tearpath, &menuarg, pri_tab, tbuf, FALSE);
- menuarg.modes = MENU_TIP_MODE;
- add_menu_path(tearpath, &menuarg, pri_tab,
- (char_u *)_("Tear off this menu"), FALSE);
+ menuarg.modes = MENU_TIP_MODE;
+ add_menu_path(tearpath, &menuarg, pri_tab,
+ (char_u *)_("Tear off this menu"), FALSE);
- pri_tab[pri_idx + 1] = t;
- vim_free(tbuf);
- }
+ pri_tab[pri_idx + 1] = t;
+ vim_free(tbuf);
}
/*
@@ -2789,16 +2789,16 @@ menutrans_lookup(char_u *name, int len)
name[len] = NUL;
dname = menu_text(name, NULL, NULL);
name[len] = i;
- if (dname != NULL)
- {
- for (i = 0; i < menutrans_ga.ga_len; ++i)
- if (STRICMP(dname, tp[i].from_noamp) == 0)
- {
- vim_free(dname);
- return tp[i].to;
- }
- vim_free(dname);
- }
+ if (dname == NULL)
+ return NULL;
+
+ for (i = 0; i < menutrans_ga.ga_len; ++i)
+ if (STRICMP(dname, tp[i].from_noamp) == 0)
+ {
+ vim_free(dname);
+ return tp[i].to;
+ }
+ vim_free(dname);
return NULL;
}
diff --git a/src/message.c b/src/message.c
index bb3517c94..d7b926357 100644
--- a/src/message.c
+++ b/src/message.c
@@ -375,15 +375,13 @@ smsg(const char *s, ...)
// give the raw message so the user at least gets a hint.
return msg((char *)s);
}
- else
- {
- va_list arglist;
- va_start(arglist, s);
- vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist);
- va_end(arglist);
- return msg((char *)IObuff);
- }
+ va_list arglist;
+
+ va_start(arglist, s);
+ vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist);
+ va_end(arglist);
+ return msg((char *)IObuff);
}
int
@@ -395,15 +393,13 @@ smsg_attr(int attr, const char *s, ...)
// give the raw message so the user at least gets a hint.
return msg_attr((char *)s, attr);
}
- else
- {
- va_list arglist;
- va_start(arglist, s);
- vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist);
- va_end(arglist);
- return msg_attr((char *)IObuff, attr);
- }
+ va_list arglist;
+
+ va_start(arglist, s);
+ vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist);
+ va_end(arglist);
+ return msg_attr((char *)IObuff, attr);
}
int
@@ -415,15 +411,13 @@ smsg_attr_keep(int attr, const char *s, ...)
// give the raw message so the user at least gets a hint.
return msg_attr_keep((char *)s, attr, TRUE);
}
- else
- {
- va_list arglist;
- va_start(arglist, s);
- vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist);
- va_end(arglist);
- return msg_attr_keep((char *)IObuff, attr, TRUE);
- }
+ va_list arglist;
+
+ va_start(arglist, s);
+ vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist);
+ va_end(arglist);
+ return msg_attr_keep((char *)IObuff, attr, TRUE);
}
#endif
@@ -834,16 +828,16 @@ semsg(const char *s, ...)
void
iemsg(char *s)
{
- if (!emsg_not_now())
- {
- emsg_core((char_u *)s);
+ if (emsg_not_now())
+ return;
+
+ emsg_core((char_u *)s);
#if defined(ABORT_ON_INTERNAL_ERROR) && defined(FEAT_EVAL)
- set_vim_var_string(VV_ERRMSG, (char_u *)s, -1);
- msg_putchar('\n'); // avoid overwriting the error message
- out_flush();
- abort();
+ set_vim_var_string(VV_ERRMSG, (char_u *)s, -1);
+ msg_putchar('\n'); // avoid overwriting the error message
+ out_flush();
+ abort();
#endif
- }
}
#ifndef PROTO // manual proto with __attribute__
@@ -856,29 +850,29 @@ iemsg(char *s)
void
siemsg(const char *s, ...)
{
- if (!emsg_not_now())
+ if (emsg_not_now())
+ return;
+
+ if (IObuff == NULL)
{
- if (IObuff == NULL)
- {
- // Very early in initialisation and already something wrong, just
- // give the raw message so the user at least gets a hint.
- emsg_core((char_u *)s);
- }
- else
- {
- va_list ap;
+ // Very early in initialisation and already something wrong, just
+ // give the raw message so the user at least gets a hint.
+ emsg_core((char_u *)s);
+ }
+ else
+ {
+ va_list ap;
- va_start(ap, s);
- vim_vsnprintf((char *)IObuff, IOSIZE, s, ap);
- va_end(ap);
- emsg_core(IObuff);
- }
+ va_start(ap, s);
+ vim_vsnprintf((char *)IObuff, IOSIZE, s, ap);
+ va_end(ap);
+ emsg_core(IObuff);
+ }
# ifdef ABORT_ON_INTERNAL_ERROR
- msg_putchar('\n'); // avoid overwriting the error message
- out_flush();
- abort();
+ msg_putchar('\n'); // avoid overwriting the error message
+ out_flush();
+ abort();
# endif
- }
}
#endif
@@ -1006,28 +1000,28 @@ add_msg_hist(
// allocate an entry and add the message at the end of the history
p = ALLOC_ONE(struct msg_hist);
- if (p != NULL)
+ if (p == NULL)
+ return;
+
+ if (len < 0)
+ len = (int)STRLEN(s);
+ // remove leading and trailing newlines
+ while (len > 0 && *s == '\n')
{
- if (len < 0)
- len = (int)STRLEN(s);
- // remove leading and trailing newlines
- while (len > 0 && *s == '\n')
- {
- ++s;
- --len;
- }
- while (len > 0 && s[len - 1] == '\n')
- --len;
- p->msg = vim_strnsave(s, len);
- p->next = NULL;
- p->attr = attr;
- if (last_msg_hist != NULL)
- last_msg_hist->next = p;
- last_msg_hist = p;
- if (first_msg_hist == NULL)
- first_msg_hist = last_msg_hist;
- ++msg_hist_len;
+ ++s;
+ --len;
}
+ while (len > 0 && s[len - 1] == '\n')
+ --len;
+ p->msg = vim_strnsave(s, len);
+ p->next = NULL;
+ p->attr = attr;
+ if (last_msg_hist != NULL)
+ last_msg_hist->next = p;
+ last_msg_hist = p;
+ if (first_msg_hist == NULL)
+ first_msg_hist = last_msg_hist;
+ ++msg_hist_len;
}
/*
diff --git a/src/misc1.c b/src/misc1.c
index c968bf67f..019bbaf8d 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -1119,59 +1119,59 @@ vim_beep(unsigned val)
called_vim_beep = TRUE;
#endif
- if (emsg_silent == 0 && !in_assert_fails)
+ if (emsg_silent != 0 || in_assert_fails)
+ return;
+
+ if (!((bo_flags & val) || (bo_flags & BO_ALL)))
{
- if (!((bo_flags & val) || (bo_flags & BO_ALL)))
- {
#ifdef ELAPSED_FUNC
- static int did_init = FALSE;
- static elapsed_T start_tv;
+ static int did_init = FALSE;
+ static elapsed_T start_tv;
- // Only beep once per half a second, otherwise a sequence of beeps
- // would freeze Vim.
- if (!did_init || ELAPSED_FUNC(start_tv) > 500)
- {
- did_init = TRUE;
- ELAPSED_INIT(start_tv);
+ // Only beep once per half a second, otherwise a sequence of beeps
+ // would freeze Vim.
+ if (!did_init || ELAPSED_FUNC(start_tv) > 500)
+ {
+ did_init = TRUE;
+ ELAPSED_INIT(start_tv);
#endif
- if (p_vb
+ if (p_vb
#ifdef FEAT_GUI
- // While the GUI is starting up the termcap is set for
- // the GUI but the output still goes to a terminal.
- && !(gui.in_use && gui.starting)
+ // While the GUI is starting up the termcap is set for
+ // the GUI but the output still goes to a terminal.
+ && !(gui.in_use && gui.starting)
#endif
- )
- {
- out_str_cf(T_VB);
+ )
+ {
+ out_str_cf(T_VB);
#ifdef FEAT_VTP
- // No restore color information, refresh the screen.
- if (has_vtp_working() != 0
+ // No restore color information, refresh the screen.
+ if (has_vtp_working() != 0
# ifdef FEAT_TERMGUICOLORS
- && (p_tgc || (!p_tgc && t_colors >= 256))
+ && (p_tgc || (!p_tgc && t_colors >= 256))
# endif
- )
- {
- redraw_later(UPD_CLEAR);
- update_screen(0);
- redrawcmd();
- }
-#endif
+ )
+ {
+ redraw_later(UPD_CLEAR);
+ update_screen(0);
+ redrawcmd();
}
- else
- out_char(BELL);
-#ifdef ELAPSED_FUNC
- }
#endif
+ }
+ else
+ out_char(BELL);
+#ifdef ELAPSED_FUNC
}
+#endif
+ }
- // When 'debug' contains "beep" produce a message. If we are sourcing
- // a script or executing a function give the user a hint where the beep
- // comes from.
- if (vim_strchr(p_debug, 'e') != NULL)
- {
- msg_source(HL_ATTR(HLF_W));
- msg_attr(_("Beep!"), HL_ATTR(HLF_W));
- }
+ // When 'debug' contains "beep" produce a message. If we are sourcing
+ // a script or executing a function give the user a hint where the beep
+ // comes from.
+ if (vim_strchr(p_debug, 'e') != NULL)
+ {
+ msg_source(HL_ATTR(HLF_W));
+ msg_attr(_("Beep!"), HL_ATTR(HLF_W));
}
}
diff --git a/src/misc2.c b/src/misc2.c
index 6ffd5aabd..87b1a15ed 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -1130,25 +1130,27 @@ simplify_key(int key, int *modifiers)
int key0;
int key1;
- if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT))
+ if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)))
+ return key;
+
+ // TAB is a special case
+ if (key == TAB && (*modifiers & MOD_MASK_SHIFT))
+ {
+ *modifiers &= ~MOD_MASK_SHIFT;
+ return K_S_TAB;
+ }
+ key0 = KEY2TERMCAP0(key);
+ key1 = KEY2TERMCAP1(key);
+ for (i = 0; modifier_keys_table[i] != NUL; i += MOD_KEYS_ENTRY_SIZE)
{
- // TAB is a special case
- if (key == TAB && (*modifiers & MOD_MASK_SHIFT))
+ if (key0 == modifier_keys_table[i + 3]
+ && key1 == modifier_keys_table[i + 4]
+ && (*modifiers & modifier_keys_table[i]))
{
- *modifiers &= ~MOD_MASK_SHIFT;
- return K_S_TAB;
+ *modifiers &= ~modifier_keys_table[i];
+ return TERMCAP2KEY(modifier_keys_table[i + 1],
+ modifier_keys_table[i + 2]);
}
- key0 = KEY2TERMCAP0(key);
- key1 = KEY2TERMCAP1(key);
- for (i = 0; modifier_keys_table[i] != NUL; i += MOD_KEYS_ENTRY_SIZE)
- if (key0 == modifier_keys_table[i + 3]
- && key1 == modifier_keys_table[i + 4]
- && (*modifiers & modifier_keys_table[i]))
- {
- *modifiers &= ~modifier_keys_table[i];
- return TERMCAP2KEY(modifier_keys_table[i + 1],
- modifier_keys_table[i + 2]);
- }
}
return key;
}
@@ -1537,22 +1539,22 @@ find_special_key(
int
may_adjust_key_for_ctrl(int modifiers, int key)
{
- if (modifiers & MOD_MASK_CTRL)
+ if (!(modifiers & MOD_MASK_CTRL))
+ return key;
+
+ if (ASCII_ISALPHA(key))
{
- if (ASCII_ISALPHA(key))
- {
#ifdef FEAT_TERMINAL
- check_no_reduce_keys(); // may update the no_reduce_keys flag
+ check_no_reduce_keys(); // may update the no_reduce_keys flag
#endif
- return no_reduce_keys == 0 ? TOUPPER_ASC(key) : key;
- }
- if (key == '2')
- return '@';
- if (key == '6')
- return '^';
- if (key == '-')
- return '_';
+ return no_reduce_keys == 0 ? TOUPPER_ASC(key) : key;
}
+ if (key == '2')
+ return '@';
+ if (key == '6')
+ return '^';
+ if (key == '-')
+ return '_';
return key;
}
@@ -2820,21 +2822,21 @@ read_string(FILE *fd, int cnt)
// allocate memory
str = alloc(cnt + 1);
- if (str != NULL)
+ if (str == NULL)
+ return NULL;
+
+ // Read the string. Quit when running into the EOF.
+ for (i = 0; i < cnt; ++i)
{
- // Read the string. Quit when running into the EOF.
- for (i = 0; i < cnt; ++i)
+ c = getc(fd);
+ if (c == EOF)
{
- c = getc(fd);
- if (c == EOF)
- {
- vim_free(str);
- return NULL;
- }
- str[i] = c;
+ vim_free(str);
+ return NULL;
}
- str[i] = NUL;
+ str[i] = c;
}
+ str[i] = NUL;
return str;
}
diff --git a/src/move.c b/src/move.c
index c7fbc9def..d3648df8b 100644
--- a/src/move.c
+++ b/src/move.c
@@ -244,15 +244,15 @@ skipcol_from_plines(win_T *wp, int plines_off)
static void
reset_skipcol(void)
{
- if (curwin->w_skipcol != 0)
- {
- curwin->w_skipcol = 0;
+ if (curwin->w_skipcol == 0)
+ return;
- // Should use the least expensive way that displays all that changed.
- // UPD_NOT_VALID is too expensive, UPD_REDRAW_TOP does not redraw
- // enough when the top line gets another screen line.
- redraw_later(UPD_SOME_VALID);
- }
+ curwin->w_skipcol = 0;
+
+ // Should use the least expensive way that displays all that changed.
+ // UPD_NOT_VALID is too expensive, UPD_REDRAW_TOP does not redraw
+ // enough when the top line gets another screen line.
+ redraw_later(UPD_SOME_VALID);
}
/*
@@ -980,17 +980,18 @@ validate_virtcol(void)
validate_virtcol_win(win_T *wp)
{
check_cursor_moved(wp);
- if (!(wp->w_valid & VALID_VIRTCOL))
- {
+
+ if (wp->w_valid & VALID_VIRTCOL)
+ return;
+
#ifdef FEAT_PROP_POPUP
- wp->w_virtcol_first_char = 0;
+ wp->w_virtcol_first_char = 0;
#endif
- getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
+ getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
#ifdef FEAT_SYN_HL
- redraw_for_cursorcolumn(wp);
+ redraw_for_cursorcolumn(wp);
#endif
- wp->w_valid |= VALID_VIRTCOL;
- }
+ wp->w_valid |= VALID_VIRTCOL;
}
/*
@@ -1000,20 +1001,21 @@ validate_virtcol_win(win_T *wp)
validate_cheight(void)
{
check_cursor_moved(curwin);
- if (!(curwin->w_valid & VALID_CHEIGHT))
- {
+
+ if (curwin->w_valid & VALID_CHEIGHT)
+ return;
+
#ifdef FEAT_DIFF
- if (curwin->w_cursor.lnum == curwin->w_topline)
- curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum)
- + curwin->w_topfill;
- else
+ if (curwin->w_cursor.lnum == curwin->w_topline)
+ curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum)
+ + curwin->w_topfill;
+ else
#endif
- curwin->w_cline_height = plines(curwin->w_cursor.lnum);
+ curwin->w_cline_height = plines(curwin->w_cursor.lnum);
#ifdef FEAT_FOLDING
- curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL);
+ curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL);
#endif
- curwin->w_valid |= VALID_CHEIGHT;
- }
+ curwin->w_valid |= VALID_CHEIGHT;
}
/*
@@ -1027,30 +1029,31 @@ validate_cursor_col(void)
int width;
validate_virtcol();
- if (!(curwin->w_valid & VALID_WCOL))
- {
- col = curwin->w_virtcol;
- off = curwin_col_off();
- col += off;
- width = curwin->w_width - off + curwin_col_off2();
- // long line wrapping, adjust curwin->w_wrow
- if (curwin->w_p_wrap
- && col >= (colnr_T)curwin->w_width
- && width > 0)
- // use same formula as what is used in curs_columns()
- col -= ((col - curwin->w_width) / width + 1) * width;
- if (col > (int)curwin->w_leftcol)
- col -= curwin->w_leftcol;
- else
- col = 0;
- curwin->w_wcol = col;
+ if (curwin->w_valid & VALID_WCOL)
+ return;
- curwin->w_valid |= VALID_WCOL;
+ col = curwin->w_virtcol;
+ off = curwin_col_off();
+ col += off;
+ width = curwin->w_width - off + curwin_col_off2();
+
+ // long line wrapping, adjust curwin->w_wrow
+ if (curwin->w_p_wrap
+ && col >= (colnr_T)curwin->w_width
+ && width > 0)
+ // use same formula as what is used in curs_columns()
+ col -= ((col - curwin->w_width) / width + 1) * width;
+ if (col > (int)curwin->w_leftcol)
+ col -= curwin->w_leftcol;
+ else
+ col = 0;
+ curwin->w_wcol = col;
+
+ curwin->w_valid |= VALID_WCOL;
#ifdef FEAT_PROP_POPUP
- curwin->w_flags &= ~WFLAG_WCOL_OFF_ADDED;
+ curwin->w_flags &= ~WFLAG_WCOL_OFF_ADDED;
#endif
- }
}
/*
@@ -1999,22 +2002,22 @@ check_topfill(
{
int n;
- if (wp->w_topfill > 0)
+ if (wp->w_topfill <= 0)
+ return;
+
+ n = plines_win_nofill(wp, wp->w_topline, TRUE);
+ if (wp->w_topfill + n > wp->w_height)
{
- n = plines_win_nofill(wp, wp->w_topline, TRUE);
- if (wp->w_topfill + n > wp->w_height)
+ if (down && wp->w_topline > 1)
{
- if (down && wp->w_topline > 1)
- {
- --wp->w_topline;
+ --wp->w_topline;
+ wp->w_topfill = 0;
+ }
+ else
+ {
+ wp->w_topfill = wp->w_height - n;
+ if (wp->w_topfill < 0)
wp->w_topfill = 0;
- }
- else
- {
- wp->w_topfill = wp->w_height - n;
- if (wp->w_topfill < 0)
- wp->w_topfill = 0;
- }
}
}
}
diff --git a/src/version.c b/src/version.c
index 7a028945b..33603ca1d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1196,
+/**/
1195,
/**/
1194,