0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.0.1208: code is indented more than necessary

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes #11819)
This commit is contained in:
Yegappan Lakshmanan 2023-01-16 18:19:05 +00:00 committed by Bram Moolenaar
parent 450c7a97d1
commit a41e221935
12 changed files with 1318 additions and 1312 deletions

View File

@ -938,13 +938,13 @@ nb_partialremove(linenr_T lnum, colnr_T first, colnr_T last)
if (lastbyte >= oldlen)
lastbyte = oldlen - 1;
newtext = alloc(oldlen - (int)(lastbyte - first));
if (newtext != NULL)
{
mch_memmove(newtext, oldtext, first);
STRMOVE(newtext + first, oldtext + lastbyte + 1);
nbdebug((" NEW LINE %ld: %s\n", lnum, newtext));
ml_replace(lnum, newtext, FALSE);
}
if (newtext == NULL)
return;
mch_memmove(newtext, oldtext, first);
STRMOVE(newtext + first, oldtext + lastbyte + 1);
nbdebug((" NEW LINE %ld: %s\n", lnum, newtext));
ml_replace(lnum, newtext, FALSE);
}
/*
@ -960,12 +960,12 @@ nb_joinlines(linenr_T first, linenr_T other)
len_first = (int)STRLEN(ml_get(first));
len_other = (int)STRLEN(ml_get(other));
p = alloc(len_first + len_other + 1);
if (p != NULL)
{
mch_memmove(p, ml_get(first), len_first);
mch_memmove(p + len_first, ml_get(other), len_other + 1);
ml_replace(first, p, FALSE);
}
if (p == NULL)
return;
mch_memmove(p, ml_get(first), len_first);
mch_memmove(p + len_first, ml_get(other), len_other + 1);
ml_replace(first, p, FALSE);
}
#define SKIP_STOP 2
@ -2247,13 +2247,14 @@ nb_do_cmd(
static void
nb_set_curbuf(buf_T *buf)
{
if (curbuf != buf) {
if (buf_jump_open_win(buf) != NULL)
return;
if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf) != NULL)
return;
set_curbuf(buf, DOBUF_GOTO);
}
if (curbuf == buf)
return;
if (buf_jump_open_win(buf) != NULL)
return;
if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf) != NULL)
return;
set_curbuf(buf, DOBUF_GOTO);
}
/*
@ -2364,14 +2365,14 @@ nb_init_graphics(void)
{
static int did_init = FALSE;
if (!did_init)
{
coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
" ctermbg=LightCyan ctermfg=Black");
coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
if (did_init)
return;
did_init = TRUE;
}
coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
" ctermbg=LightCyan ctermfg=Black");
coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
did_init = TRUE;
}
/*
@ -2468,29 +2469,29 @@ netbeans_beval_cb(
if (!can_use_beval() || !NETBEANS_OPEN)
return;
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) != OK)
return;
// Send debugger request. Only when the text is of reasonable
// length.
if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
{
// Send debugger request. Only when the text is of reasonable
// length.
if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
buf = alloc(MAXPATHL * 2 + 25);
if (buf != NULL)
{
buf = alloc(MAXPATHL * 2 + 25);
if (buf != NULL)
p = nb_quote(text);
if (p != NULL)
{
p = nb_quote(text);
if (p != NULL)
{
vim_snprintf(buf, MAXPATHL * 2 + 25,
"0:balloonText=%d \"%s\"\n", r_cmdno, p);
vim_free(p);
}
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_beval_cb");
vim_free(buf);
vim_snprintf(buf, MAXPATHL * 2 + 25,
"0:balloonText=%d \"%s\"\n", r_cmdno, p);
vim_free(p);
}
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_beval_cb");
vim_free(buf);
}
vim_free(text);
}
vim_free(text);
}
#endif
@ -2555,12 +2556,12 @@ set_ref_in_nb_channel(int copyID)
int abort = FALSE;
typval_T tv;
if (nb_channel != NULL)
{
tv.v_type = VAR_CHANNEL;
tv.vval.v_channel = nb_channel;
abort = set_ref_in_item(&tv, copyID, NULL, NULL);
}
if (nb_channel == NULL)
return FALSE;
tv.v_type = VAR_CHANNEL;
tv.vval.v_channel = nb_channel;
abort = set_ref_in_item(&tv, copyID, NULL, NULL);
return abort;
}
#endif
@ -2827,22 +2828,22 @@ netbeans_button_release(int button)
bufno = nb_getbufno(curbuf);
if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
{
int col = mouse_col - curwin->w_wincol
- ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
long off = pos2off(curbuf, &curwin->w_cursor);
if (bufno < 0 || curwin == NULL || curwin->w_buffer != curbuf)
return;
// sync the cursor position
sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release[newDotAndMark]");
int col = mouse_col - curwin->w_wincol
- ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
long off = pos2off(curbuf, &curwin->w_cursor);
sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, r_cmdno,
button, (long)curwin->w_cursor.lnum, col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release");
}
// sync the cursor position
sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release[newDotAndMark]");
sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, r_cmdno,
button, (long)curwin->w_cursor.lnum, col);
nbdebug(("EVT: %s", buf));
nb_send(buf, "netbeans_button_release");
}
@ -3308,29 +3309,27 @@ get_buf_size(buf_T *bufp)
if (bufp->b_ml.ml_flags & ML_EMPTY)
return 0;
if (get_fileformat(bufp) == EOL_DOS)
eol_size = 2;
else
eol_size = 1;
for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
{
if (get_fileformat(bufp) == EOL_DOS)
eol_size = 2;
else
eol_size = 1;
for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE))
+ eol_size;
// Check for a CTRL-C every 100000 characters
if (char_count > last_check)
{
char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE))
+ eol_size;
// Check for a CTRL-C every 100000 characters
if (char_count > last_check)
{
ui_breakcheck();
if (got_int)
return char_count;
last_check = char_count + 100000L;
}
ui_breakcheck();
if (got_int)
return char_count;
last_check = char_count + 100000L;
}
// Correction for when last line doesn't have an EOL.
if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
char_count -= eol_size;
}
// Correction for when last line doesn't have an EOL.
if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
char_count -= eol_size;
return char_count;
}
@ -3393,12 +3392,12 @@ pos2off(buf_T *buf, pos_T *pos)
{
long offset = 0;
if (!(buf->b_ml.ml_flags & ML_EMPTY))
{
if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
return 0;
offset += pos->col;
}
if (buf->b_ml.ml_flags & ML_EMPTY)
return 0;
if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
return 0;
offset += pos->col;
return offset;
}

File diff suppressed because it is too large Load Diff

View File

@ -989,11 +989,11 @@ mb_adjust_opend(oparg_T *oap)
{
char_u *p;
if (oap->inclusive)
{
p = ml_get(oap->end.lnum);
oap->end.col += mb_tail_off(p, p + oap->end.col);
}
if (!oap->inclusive)
return;
p = ml_get(oap->end.lnum);
oap->end.col += mb_tail_off(p, p + oap->end.col);
}
/*
@ -1869,22 +1869,23 @@ adjust_cursor_eol(void)
{
unsigned int cur_ve_flags = get_ve_flags();
if (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL
&& (cur_ve_flags & VE_ONEMORE) == 0
&& !(restart_edit || (State & MODE_INSERT)))
int adj_cursor = (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL
&& (cur_ve_flags & VE_ONEMORE) == 0
&& !(restart_edit || (State & MODE_INSERT)));
if (!adj_cursor)
return;
// Put the cursor on the last character in the line.
dec_cursor();
if (cur_ve_flags == VE_ALL)
{
// Put the cursor on the last character in the line.
dec_cursor();
colnr_T scol, ecol;
if (cur_ve_flags == VE_ALL)
{
colnr_T scol, ecol;
// Coladd is set to the width of the last character.
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
curwin->w_cursor.coladd = ecol - scol + 1;
}
// Coladd is set to the width of the last character.
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
curwin->w_cursor.coladd = ecol - scol + 1;
}
}
@ -2235,12 +2236,12 @@ reset_lbr(void)
static void
restore_lbr(int lbr_saved)
{
if (!curwin->w_p_lbr && lbr_saved)
{
// changing 'linebreak' may require w_virtcol to be updated
curwin->w_p_lbr = TRUE;
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
}
if (curwin->w_p_lbr || !lbr_saved)
return;
// changing 'linebreak' may require w_virtcol to be updated
curwin->w_p_lbr = TRUE;
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
}
#endif

View File

@ -672,17 +672,17 @@ set_string_default_esc(char *name, char_u *val, int escape)
p = vim_strsave_escaped(val, (char_u *)" ");
else
p = vim_strsave(val);
if (p != NULL) // we don't want a NULL
{
opt_idx = findoption((char_u *)name);
if (opt_idx >= 0)
{
if (options[opt_idx].flags & P_DEF_ALLOCED)
vim_free(options[opt_idx].def_val[VI_DEFAULT]);
options[opt_idx].def_val[VI_DEFAULT] = p;
options[opt_idx].flags |= P_DEF_ALLOCED;
}
}
if (p == NULL) // we don't want a NULL
return;
opt_idx = findoption((char_u *)name);
if (opt_idx < 0)
return;
if (options[opt_idx].flags & P_DEF_ALLOCED)
vim_free(options[opt_idx].def_val[VI_DEFAULT]);
options[opt_idx].def_val[VI_DEFAULT] = p;
options[opt_idx].flags |= P_DEF_ALLOCED;
}
void
@ -1112,31 +1112,31 @@ set_helplang_default(char_u *lang)
if (lang == NULL || STRLEN(lang) < 2) // safety check
return;
idx = findoption((char_u *)"hlg");
if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
if (idx < 0 || (options[idx].flags & P_WAS_SET))
return;
if (options[idx].flags & P_ALLOCED)
free_string_option(p_hlg);
p_hlg = vim_strsave(lang);
if (p_hlg == NULL)
p_hlg = empty_option;
else
{
if (options[idx].flags & P_ALLOCED)
free_string_option(p_hlg);
p_hlg = vim_strsave(lang);
if (p_hlg == NULL)
p_hlg = empty_option;
else
// zh_CN becomes "cn", zh_TW becomes "tw"
if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
{
// zh_CN becomes "cn", zh_TW becomes "tw"
if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
{
p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
}
// any C like setting, such as C.UTF-8, becomes "en"
else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
{
p_hlg[0] = 'e';
p_hlg[1] = 'n';
}
p_hlg[2] = NUL;
p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
}
options[idx].flags |= P_ALLOCED;
// any C like setting, such as C.UTF-8, becomes "en"
else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
{
p_hlg[0] = 'e';
p_hlg[1] = 'n';
}
p_hlg[2] = NUL;
}
options[idx].flags |= P_ALLOCED;
}
#endif
@ -1171,17 +1171,19 @@ set_title_defaults(void)
p_title = val;
}
idx1 = findoption((char_u *)"icon");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
if (idx1 < 0 || (options[idx1].flags & P_WAS_SET))
{
#ifdef FEAT_GUI
if (gui.starting || gui.in_use)
val = TRUE;
else
#endif
val = mch_can_restore_icon();
options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
p_icon = val;
return;
}
#ifdef FEAT_GUI
if (gui.starting || gui.in_use)
val = TRUE;
else
#endif
val = mch_can_restore_icon();
options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
p_icon = val;
}
void
@ -7084,12 +7086,11 @@ reset_option_was_set(char_u *name)
{
int idx = findoption(name);
if (idx >= 0)
{
options[idx].flags &= ~P_WAS_SET;
return OK;
}
return FAIL;
if (idx < 0)
return FAIL;
options[idx].flags &= ~P_WAS_SET;
return OK;
}
/*

View File

@ -155,42 +155,42 @@ trigger_optionset_string(
char_u *newval)
{
// Don't do this recursively.
if (oldval != NULL && newval != NULL
&& *get_vim_var_str(VV_OPTION_TYPE) == NUL)
{
char_u buf_type[7];
if (oldval == NULL || newval == NULL
|| *get_vim_var_str(VV_OPTION_TYPE) != NUL)
return;
sprintf((char *)buf_type, "%s",
char_u buf_type[7];
sprintf((char *)buf_type, "%s",
(opt_flags & OPT_LOCAL) ? "local" : "global");
set_vim_var_string(VV_OPTION_OLD, oldval, -1);
set_vim_var_string(VV_OPTION_NEW, newval, -1);
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
if (opt_flags & OPT_LOCAL)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
}
if (opt_flags & OPT_GLOBAL)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
}
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
}
if (opt_flags & OPT_MODELINE)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
}
apply_autocmds(EVENT_OPTIONSET,
get_option_fullname(opt_idx), NULL, FALSE,
NULL);
reset_v_option_vars();
set_vim_var_string(VV_OPTION_OLD, oldval, -1);
set_vim_var_string(VV_OPTION_NEW, newval, -1);
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
if (opt_flags & OPT_LOCAL)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
}
if (opt_flags & OPT_GLOBAL)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
}
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
}
if (opt_flags & OPT_MODELINE)
{
set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
}
apply_autocmds(EVENT_OPTIONSET,
get_option_fullname(opt_idx), NULL, FALSE,
NULL);
reset_v_option_vars();
}
#endif
@ -387,45 +387,45 @@ set_string_option_direct(
return;
s = vim_strsave(val);
if (s != NULL)
if (s == NULL)
return;
varp = (char_u **)get_option_varp_scope(idx,
both ? OPT_LOCAL : opt_flags);
if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
free_string_option(*varp);
*varp = s;
// For buffer/window local option may also set the global value.
if (both)
set_string_option_global(idx, varp);
set_option_flag(idx, P_ALLOCED);
// When setting both values of a global option with a local value,
// make the local value empty, so that the global value is used.
if (is_global_local_option(idx) && both)
{
varp = (char_u **)get_option_varp_scope(idx,
both ? OPT_LOCAL : opt_flags);
if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
free_string_option(*varp);
*varp = s;
// For buffer/window local option may also set the global value.
if (both)
set_string_option_global(idx, varp);
set_option_flag(idx, P_ALLOCED);
// When setting both values of a global option with a local value,
// make the local value empty, so that the global value is used.
if (is_global_local_option(idx) && both)
{
free_string_option(*varp);
*varp = empty_option;
}
# ifdef FEAT_EVAL
if (set_sid != SID_NONE)
{
sctx_T script_ctx;
if (set_sid == 0)
script_ctx = current_sctx;
else
{
script_ctx.sc_sid = set_sid;
script_ctx.sc_seq = 0;
script_ctx.sc_lnum = 0;
script_ctx.sc_version = 1;
}
set_option_sctx_idx(idx, opt_flags, script_ctx);
}
# endif
free_string_option(*varp);
*varp = empty_option;
}
# ifdef FEAT_EVAL
if (set_sid != SID_NONE)
{
sctx_T script_ctx;
if (set_sid == 0)
script_ctx = current_sctx;
else
{
script_ctx.sc_sid = set_sid;
script_ctx.sc_seq = 0;
script_ctx.sc_lnum = 0;
script_ctx.sc_version = 1;
}
set_option_sctx_idx(idx, opt_flags, script_ctx);
}
# endif
}
/*
@ -507,54 +507,54 @@ set_string_option(
return NULL;
s = vim_strsave(value == NULL ? (char_u *)"" : value);
if (s != NULL)
if (s == NULL)
return NULL;
varp = (char_u **)get_option_varp_scope(opt_idx,
(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
? (is_global_local_option(opt_idx)
? OPT_GLOBAL : OPT_LOCAL)
: opt_flags);
oldval = *varp;
#if defined(FEAT_EVAL)
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
{
varp = (char_u **)get_option_varp_scope(opt_idx,
(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
? (is_global_local_option(opt_idx)
? OPT_GLOBAL : OPT_LOCAL)
: opt_flags);
oldval = *varp;
#if defined(FEAT_EVAL)
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
{
oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL);
oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
}
#endif
*varp = s;
#if defined(FEAT_EVAL)
if (!starting
# ifdef FEAT_CRYPT
&& !is_crypt_key_option(opt_idx)
# endif
)
{
if (oldval_l != NULL)
saved_oldval_l = vim_strsave(oldval_l);
if (oldval_g != NULL)
saved_oldval_g = vim_strsave(oldval_g);
saved_oldval = vim_strsave(oldval);
saved_newval = vim_strsave(s);
}
#endif
if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL,
opt_flags, &value_checked)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE, value_checked);
#if defined(FEAT_EVAL)
// call autocommand after handling side effects
if (errmsg == NULL)
trigger_optionset_string(opt_idx, opt_flags,
saved_oldval, saved_oldval_l,
saved_oldval_g, saved_newval);
vim_free(saved_oldval);
vim_free(saved_oldval_l);
vim_free(saved_oldval_g);
vim_free(saved_newval);
#endif
oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL);
oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
}
#endif
*varp = s;
#if defined(FEAT_EVAL)
if (!starting
# ifdef FEAT_CRYPT
&& !is_crypt_key_option(opt_idx)
# endif
)
{
if (oldval_l != NULL)
saved_oldval_l = vim_strsave(oldval_l);
if (oldval_g != NULL)
saved_oldval_g = vim_strsave(oldval_g);
saved_oldval = vim_strsave(oldval);
saved_newval = vim_strsave(s);
}
#endif
if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL,
opt_flags, &value_checked)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE, value_checked);
#if defined(FEAT_EVAL)
// call autocommand after handling side effects
if (errmsg == NULL)
trigger_optionset_string(opt_idx, opt_flags,
saved_oldval, saved_oldval_l,
saved_oldval_g, saved_newval);
vim_free(saved_oldval);
vim_free(saved_oldval_l);
vim_free(saved_oldval_g);
vim_free(saved_newval);
#endif
return errmsg;
}

View File

@ -234,13 +234,13 @@ mch_delay(long msec, int flags)
void Delay(long);
#endif
if (msec > 0)
{
if (flags & MCH_DELAY_IGNOREINPUT)
Delay(msec / 20L); // Delay works with 20 msec intervals
else
WaitForChar(raw_in, msec * 1000L);
}
if (msec <= 0)
return;
if (flags & MCH_DELAY_IGNOREINPUT)
Delay(msec / 20L); // Delay works with 20 msec intervals
else
WaitForChar(raw_in, msec * 1000L);
}
/*
@ -577,18 +577,18 @@ fname_case(
size_t flen;
fib = get_fib(name);
if (fib != NULL)
{
flen = STRLEN(name);
// TODO: Check if this fix applies to AmigaOS < 4 too.
if (fib == NULL)
return;
flen = STRLEN(name);
// TODO: Check if this fix applies to AmigaOS < 4 too.
#ifdef __amigaos4__
if (fib->fib_DirEntryType == ST_ROOT)
strcat(fib->fib_FileName, ":");
if (fib->fib_DirEntryType == ST_ROOT)
strcat(fib->fib_FileName, ":");
#endif
if (flen == strlen(fib->fib_FileName)) // safety check
mch_memmove(name, fib->fib_FileName, flen);
free_fib(fib);
}
if (flen == strlen(fib->fib_FileName)) // safety check
mch_memmove(name, fib->fib_FileName, flen);
free_fib(fib);
}
/*
@ -609,17 +609,17 @@ get_fib(char_u *fname)
#else
fib = ALLOC_ONE(struct FileInfoBlock);
#endif
if (fib != NULL)
if (fib == NULL)
return;
flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
if (flock == (BPTR)NULL || !Examine(flock, fib))
{
flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
if (flock == (BPTR)NULL || !Examine(flock, fib))
{
free_fib(fib); // in case of an error the memory is freed here
fib = NULL;
}
if (flock)
UnLock(flock);
free_fib(fib); // in case of an error the memory is freed here
fib = NULL;
}
if (flock)
UnLock(flock);
return fib;
}
@ -815,11 +815,11 @@ mch_getperm(char_u *name)
long retval = -1;
fib = get_fib(name);
if (fib != NULL)
{
retval = fib->fib_Protection;
free_fib(fib);
}
if (fib == NULL)
return -1;
retval = fib->fib_Protection;
free_fib(fib);
return retval;
}
@ -856,15 +856,15 @@ mch_isdir(char_u *name)
int retval = FALSE;
fib = get_fib(name);
if (fib != NULL)
{
if (fib == NULL)
return FALSE;
#ifdef __amigaos4__
retval = (FIB_IS_DRAWER(fib)) ? TRUE : FALSE;
retval = (FIB_IS_DRAWER(fib)) ? TRUE : FALSE;
#else
retval = ((fib->fib_DirEntryType >= 0) ? TRUE : FALSE);
retval = ((fib->fib_DirEntryType >= 0) ? TRUE : FALSE);
#endif
free_fib(fib);
}
free_fib(fib);
return retval;
}
@ -877,12 +877,11 @@ mch_mkdir(char_u *name)
BPTR lock;
lock = CreateDir(name);
if (lock != NULL)
{
UnLock(lock);
return 0;
}
return -1;
if (lock == NULL)
return -1;
UnLock(lock);
return 0;
}
/*
@ -1173,17 +1172,17 @@ out:
void
mch_set_shellsize(void)
{
if (term_console)
{
size_set = TRUE;
out_char(CSI);
out_num((long)Rows);
out_char('t');
out_char(CSI);
out_num((long)Columns);
out_char('u');
out_flush();
}
if (!term_console)
return;
size_set = TRUE;
out_char(CSI);
out_num((long)Rows);
out_char('t');
out_char(CSI);
out_num((long)Columns);
out_char('u');
out_flush();
}
/*

View File

@ -568,28 +568,28 @@ mac_utf8_to_utf16(
void
mac_lang_init(void)
{
if (mch_getenv((char_u *)"LANG") == NULL)
{
char buf[50];
if (mch_getenv((char_u *)"LANG") != NULL)
return;
// $LANG is not set, either because it was unset or Vim was started
// from the Dock. Query the system locale.
if (LocaleRefGetPartString(NULL,
kLocaleLanguageMask | kLocaleLanguageVariantMask |
kLocaleRegionMask | kLocaleRegionVariantMask,
sizeof(buf) - 10, buf) == noErr && *buf)
{
if (strcasestr(buf, "utf-8") == NULL)
strcat(buf, ".UTF-8");
vim_setenv((char_u *)"LANG", (char_u *)buf);
char buf[50];
// $LANG is not set, either because it was unset or Vim was started
// from the Dock. Query the system locale.
if (LocaleRefGetPartString(NULL,
kLocaleLanguageMask | kLocaleLanguageVariantMask |
kLocaleRegionMask | kLocaleRegionVariantMask,
sizeof(buf) - 10, buf) == noErr && *buf)
{
if (strcasestr(buf, "utf-8") == NULL)
strcat(buf, ".UTF-8");
vim_setenv((char_u *)"LANG", (char_u *)buf);
# ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "");
setlocale(LC_ALL, "");
# endif
# if defined(LC_NUMERIC)
// Make sure strtod() uses a decimal point, not a comma.
setlocale(LC_NUMERIC, "C");
// Make sure strtod() uses a decimal point, not a comma.
setlocale(LC_NUMERIC, "C");
# endif
}
}
}
#endif // MACOS_CONVERT

View File

@ -835,24 +835,24 @@ check_str_len(char_u *str)
GetSystemInfo(&si);
// get memory information
if (VirtualQuery(str, &mbi, sizeof(mbi)))
{
// pre cast these (typing savers)
long_u dwStr = (long_u)str;
long_u dwBaseAddress = (long_u)mbi.BaseAddress;
if (!VirtualQuery(str, &mbi, sizeof(mbi)))
return 0;
// get start address of page that str is on
long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize;
// pre cast these (typing savers)
long_u dwStr = (long_u)str;
long_u dwBaseAddress = (long_u)mbi.BaseAddress;
// get length from str to end of page
long_u pageLength = si.dwPageSize - (dwStr - strPage);
// get start address of page that str is on
long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize;
for (p = str; !IsBadReadPtr(p, (UINT)pageLength);
p += pageLength, pageLength = si.dwPageSize)
for (i = 0; i < pageLength; ++i, ++length)
if (p[i] == NUL)
return length + 1;
}
// get length from str to end of page
long_u pageLength = si.dwPageSize - (dwStr - strPage);
for (p = str; !IsBadReadPtr(p, (UINT)pageLength);
p += pageLength, pageLength = si.dwPageSize)
for (i = 0; i < pageLength; ++i, ++length)
if (p[i] == NUL)
return length + 1;
return 0;
}
@ -1213,43 +1213,43 @@ PrintHookProc(
RECT rc, rcDlg, rcOwner;
PRINTDLGW *pPD;
if (uiMsg == WM_INITDIALOG)
{
// Get the owner window and dialog box rectangles.
if ((hwndOwner = GetParent(hDlg)) == NULL)
hwndOwner = GetDesktopWindow();
if (uiMsg != WM_INITDIALOG)
return FALSE;
GetWindowRect(hwndOwner, &rcOwner);
GetWindowRect(hDlg, &rcDlg);
CopyRect(&rc, &rcOwner);
// Get the owner window and dialog box rectangles.
if ((hwndOwner = GetParent(hDlg)) == NULL)
hwndOwner = GetDesktopWindow();
// Offset the owner and dialog box rectangles so that
// right and bottom values represent the width and
// height, and then offset the owner again to discard
// space taken up by the dialog box.
GetWindowRect(hwndOwner, &rcOwner);
GetWindowRect(hDlg, &rcDlg);
CopyRect(&rc, &rcOwner);
OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
OffsetRect(&rc, -rc.left, -rc.top);
OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
// Offset the owner and dialog box rectangles so that
// right and bottom values represent the width and
// height, and then offset the owner again to discard
// space taken up by the dialog box.
// The new position is the sum of half the remaining
// space and the owner's original position.
OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
OffsetRect(&rc, -rc.left, -rc.top);
OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
SetWindowPos(hDlg,
HWND_TOP,
rcOwner.left + (rc.right / 2),
rcOwner.top + (rc.bottom / 2),
0, 0, // ignores size arguments
SWP_NOSIZE);
// The new position is the sum of half the remaining
// space and the owner's original position.
// tackle the printdlg copiesctrl problem
pPD = (PRINTDLGW *)lParam;
pPD->nCopies = (WORD)pPD->lCustData;
SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE );
// Bring the window to top
BringWindowToTop(GetParent(hDlg));
SetForegroundWindow(hDlg);
}
SetWindowPos(hDlg,
HWND_TOP,
rcOwner.left + (rc.right / 2),
rcOwner.top + (rc.bottom / 2),
0, 0, // ignores size arguments
SWP_NOSIZE);
// tackle the printdlg copiesctrl problem
pPD = (PRINTDLGW *)lParam;
pPD->nCopies = (WORD)pPD->lCustData;
SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE );
// Bring the window to top
BringWindowToTop(GetParent(hDlg));
SetForegroundWindow(hDlg);
return FALSE;
}
@ -1571,29 +1571,27 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
return TRUE;
init_fail_dlg:
DWORD err = CommDlgExtendedError();
if (err)
{
DWORD err = CommDlgExtendedError();
char_u *buf;
if (err)
{
char_u *buf;
// I suspect FormatMessage() doesn't work for values returned by
// CommDlgExtendedError(). What does?
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, 0, (LPTSTR)(&buf), 0, NULL);
semsg(_(e_print_error_str),
buf == NULL ? (char_u *)_("Unknown") : buf);
LocalFree((LPVOID)(buf));
}
else
msg_clr_eos(); // Maybe canceled
mch_print_cleanup();
return FALSE;
// I suspect FormatMessage() doesn't work for values returned by
// CommDlgExtendedError(). What does?
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, 0, (LPTSTR)(&buf), 0, NULL);
semsg(_(e_print_error_str),
buf == NULL ? (char_u *)_("Unknown") : buf);
LocalFree((LPVOID)(buf));
}
else
msg_clr_eos(); // Maybe canceled
mch_print_cleanup();
return FALSE;
}
@ -1999,11 +1997,11 @@ serverSendEnc(HWND target)
static void
CleanUpMessaging(void)
{
if (message_window != 0)
{
DestroyWindow(message_window);
message_window = 0;
}
if (message_window == 0)
return;
DestroyWindow(message_window);
message_window = 0;
}
static int save_reply(HWND server, char_u *reply, int expr);

View File

@ -67,38 +67,38 @@ clip_mch_request_selection(Clipboard_T *cbd)
char_u *clip_text = NULL;
cbdata = PhClipboardPasteStart(PhInputGroup(NULL));
if (cbdata != NULL)
if (cbdata == NULL)
return;
// Look for the vim specific clip first
clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM);
if (clip_header != NULL && clip_header->data != NULL)
{
// Look for the vim specific clip first
clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM);
if (clip_header != NULL && clip_header->data != NULL)
switch(*(char *) clip_header->data)
{
switch(*(char *) clip_header->data)
{
default: // fallthrough to line type
case 'L': type = MLINE; break;
case 'C': type = MCHAR; break;
case 'B': type = MBLOCK; break;
}
is_type_set = TRUE;
default: // fallthrough to line type
case 'L': type = MLINE; break;
case 'C': type = MCHAR; break;
case 'B': type = MBLOCK; break;
}
// Try for just normal text
clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT);
if (clip_header != NULL)
{
clip_text = clip_header->data;
clip_length = clip_header->length - 1;
if (clip_text != NULL && is_type_set == FALSE)
type = MAUTO;
}
if ((clip_text != NULL) && (clip_length > 0))
clip_yank_selection(type, clip_text, clip_length, cbd);
PhClipboardPasteFinish(cbdata);
is_type_set = TRUE;
}
// Try for just normal text
clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT);
if (clip_header != NULL)
{
clip_text = clip_header->data;
clip_length = clip_header->length - 1;
if (clip_text != NULL && is_type_set == FALSE)
type = MAUTO;
}
if ((clip_text != NULL) && (clip_length > 0))
clip_yank_selection(type, clip_text, clip_length, cbd);
PhClipboardPasteFinish(cbdata);
}
void

View File

@ -780,16 +780,16 @@ get_stack_limit(void)
int
mch_stackcheck(char *p)
{
if (stack_limit != NULL)
if (stack_limit == NULL)
return OK;
if (stack_grows_downwards)
{
if (stack_grows_downwards)
{
if (p < stack_limit)
return FAIL;
}
else if (p > stack_limit)
if (p < stack_limit)
return FAIL;
}
else if (p > stack_limit)
return FAIL;
return OK;
}
#endif
@ -837,25 +837,25 @@ static char *signal_stack;
static void
init_signal_stack(void)
{
if (signal_stack != NULL)
{
if (signal_stack == NULL)
return;
# ifdef HAVE_SIGALTSTACK
# ifdef HAVE_SS_BASE
sigstk.ss_base = signal_stack;
sigstk.ss_base = signal_stack;
# else
sigstk.ss_sp = signal_stack;
sigstk.ss_sp = signal_stack;
# endif
sigstk.ss_size = get_signal_stack_size();
sigstk.ss_flags = 0;
(void)sigaltstack(&sigstk, NULL);
sigstk.ss_size = get_signal_stack_size();
sigstk.ss_flags = 0;
(void)sigaltstack(&sigstk, NULL);
# else
sigstk.ss_sp = signal_stack;
if (stack_grows_downwards)
sigstk.ss_sp += get_signal_stack_size() - 1;
sigstk.ss_onstack = 0;
(void)sigstack(&sigstk, NULL);
sigstk.ss_sp = signal_stack;
if (stack_grows_downwards)
sigstk.ss_sp += get_signal_stack_size() - 1;
sigstk.ss_onstack = 0;
(void)sigstack(&sigstk, NULL);
# endif
}
}
#endif
@ -2020,91 +2020,90 @@ get_x11_thing(
int retval = FALSE;
Status status;
if (get_x11_windis() == OK)
if (get_x11_windis() != OK)
return FALSE;
// Get window/icon name if any
if (get_title)
status = XGetWMName(x11_display, x11_window, &text_prop);
else
status = XGetWMIconName(x11_display, x11_window, &text_prop);
/*
* If terminal is xterm, then x11_window may be a child window of the
* outer xterm window that actually contains the window/icon name, so
* keep traversing up the tree until a window with a title/icon is
* found.
*/
// Previously this was only done for xterm and alike. I don't see a
// reason why it would fail for other terminal emulators.
// if (term_is_xterm)
Window root;
Window parent;
Window win = x11_window;
Window *children;
unsigned int num_children;
while (!status || text_prop.value == NULL)
{
// Get window/icon name if any
if (!XQueryTree(x11_display, win, &root, &parent, &children,
&num_children))
break;
if (children)
XFree((void *)children);
if (parent == root || parent == 0)
break;
win = parent;
if (get_title)
status = XGetWMName(x11_display, x11_window, &text_prop);
status = XGetWMName(x11_display, win, &text_prop);
else
status = XGetWMIconName(x11_display, x11_window, &text_prop);
status = XGetWMIconName(x11_display, win, &text_prop);
}
/*
* If terminal is xterm, then x11_window may be a child window of the
* outer xterm window that actually contains the window/icon name, so
* keep traversing up the tree until a window with a title/icon is
* found.
*/
// Previously this was only done for xterm and alike. I don't see a
// reason why it would fail for other terminal emulators.
// if (term_is_xterm)
if (status && text_prop.value != NULL)
{
retval = TRUE;
if (!test_only)
{
Window root;
Window parent;
Window win = x11_window;
Window *children;
unsigned int num_children;
while (!status || text_prop.value == NULL)
if (get_title)
vim_free(oldtitle);
else
vim_free(oldicon);
if (text_prop.encoding == XA_STRING && !has_mbyte)
{
if (!XQueryTree(x11_display, win, &root, &parent, &children,
&num_children))
break;
if (children)
XFree((void *)children);
if (parent == root || parent == 0)
break;
win = parent;
if (get_title)
status = XGetWMName(x11_display, win, &text_prop);
oldtitle = vim_strsave((char_u *)text_prop.value);
else
status = XGetWMIconName(x11_display, win, &text_prop);
oldicon = vim_strsave((char_u *)text_prop.value);
}
}
if (status && text_prop.value != NULL)
{
retval = TRUE;
if (!test_only)
else
{
if (get_title)
vim_free(oldtitle);
char **cl;
Status transform_status;
int n = 0;
transform_status = XmbTextPropertyToTextList(x11_display,
&text_prop,
&cl, &n);
if (transform_status >= Success && n > 0 && cl[0])
{
if (get_title)
oldtitle = vim_strsave((char_u *) cl[0]);
else
oldicon = vim_strsave((char_u *) cl[0]);
XFreeStringList(cl);
}
else
vim_free(oldicon);
if (text_prop.encoding == XA_STRING && !has_mbyte)
{
if (get_title)
oldtitle = vim_strsave((char_u *)text_prop.value);
else
oldicon = vim_strsave((char_u *)text_prop.value);
}
else
{
char **cl;
Status transform_status;
int n = 0;
transform_status = XmbTextPropertyToTextList(x11_display,
&text_prop,
&cl, &n);
if (transform_status >= Success && n > 0 && cl[0])
{
if (get_title)
oldtitle = vim_strsave((char_u *) cl[0]);
else
oldicon = vim_strsave((char_u *) cl[0]);
XFreeStringList(cl);
}
else
{
if (get_title)
oldtitle = vim_strsave((char_u *)text_prop.value);
else
oldicon = vim_strsave((char_u *)text_prop.value);
}
}
}
XFree((void *)text_prop.value);
}
XFree((void *)text_prop.value);
}
return retval;
}
@ -2772,52 +2771,52 @@ fname_case(
DIR *dirp;
struct dirent *dp;
if (mch_lstat((char *)name, &st) >= 0)
if (mch_lstat((char *)name, &st) < 0)
return;
// Open the directory where the file is located.
slash = vim_strrchr(name, '/');
if (slash == NULL)
{
// Open the directory where the file is located.
slash = vim_strrchr(name, '/');
if (slash == NULL)
{
dirp = opendir(".");
tail = name;
}
else
{
*slash = NUL;
dirp = opendir((char *)name);
*slash = '/';
tail = slash + 1;
}
dirp = opendir(".");
tail = name;
}
else
{
*slash = NUL;
dirp = opendir((char *)name);
*slash = '/';
tail = slash + 1;
}
if (dirp != NULL)
if (dirp == NULL)
return;
while ((dp = readdir(dirp)) != NULL)
{
// Only accept names that differ in case and are the same byte
// length. TODO: accept different length name.
if (STRICMP(tail, dp->d_name) == 0
&& STRLEN(tail) == STRLEN(dp->d_name))
{
while ((dp = readdir(dirp)) != NULL)
char_u newname[MAXPATHL + 1];
struct stat st2;
// Verify the inode is equal.
vim_strncpy(newname, name, MAXPATHL);
vim_strncpy(newname + (tail - name), (char_u *)dp->d_name,
MAXPATHL - (tail - name));
if (mch_lstat((char *)newname, &st2) >= 0
&& st.st_ino == st2.st_ino
&& st.st_dev == st2.st_dev)
{
// Only accept names that differ in case and are the same byte
// length. TODO: accept different length name.
if (STRICMP(tail, dp->d_name) == 0
&& STRLEN(tail) == STRLEN(dp->d_name))
{
char_u newname[MAXPATHL + 1];
struct stat st2;
// Verify the inode is equal.
vim_strncpy(newname, name, MAXPATHL);
vim_strncpy(newname + (tail - name), (char_u *)dp->d_name,
MAXPATHL - (tail - name));
if (mch_lstat((char *)newname, &st2) >= 0
&& st.st_ino == st2.st_ino
&& st.st_dev == st2.st_dev)
{
STRCPY(tail, dp->d_name);
break;
}
}
STRCPY(tail, dp->d_name);
break;
}
closedir(dirp);
}
}
closedir(dirp);
}
#endif
@ -2902,46 +2901,46 @@ mch_copy_sec(char_u *from_file, char_u *to_file)
if (selinux_enabled == -1)
selinux_enabled = is_selinux_enabled();
if (selinux_enabled > 0)
if (selinux_enabled <= 0)
return;
// Use "char *" instead of "security_context_t" to avoid a deprecation
// warning.
char *from_context = NULL;
char *to_context = NULL;
if (getfilecon((char *)from_file, &from_context) < 0)
{
// Use "char *" instead of "security_context_t" to avoid a deprecation
// warning.
char *from_context = NULL;
char *to_context = NULL;
if (getfilecon((char *)from_file, &from_context) < 0)
{
// If the filesystem doesn't support extended attributes,
// the original had no special security context and the
// target cannot have one either.
if (errno == EOPNOTSUPP)
return;
msg_puts(_("\nCould not get security context for "));
msg_outtrans(from_file);
msg_putchar('\n');
// If the filesystem doesn't support extended attributes,
// the original had no special security context and the
// target cannot have one either.
if (errno == EOPNOTSUPP)
return;
}
if (getfilecon((char *)to_file, &to_context) < 0)
msg_puts(_("\nCould not get security context for "));
msg_outtrans(from_file);
msg_putchar('\n');
return;
}
if (getfilecon((char *)to_file, &to_context) < 0)
{
msg_puts(_("\nCould not get security context for "));
msg_outtrans(to_file);
msg_putchar('\n');
freecon (from_context);
return ;
}
if (strcmp(from_context, to_context) != 0)
{
if (setfilecon((char *)to_file, from_context) < 0)
{
msg_puts(_("\nCould not get security context for "));
msg_puts(_("\nCould not set security context for "));
msg_outtrans(to_file);
msg_putchar('\n');
freecon (from_context);
return ;
}
if (strcmp(from_context, to_context) != 0)
{
if (setfilecon((char *)to_file, from_context) < 0)
{
msg_puts(_("\nCould not set security context for "));
msg_outtrans(to_file);
msg_putchar('\n');
}
}
freecon(to_context);
freecon(from_context);
}
freecon(to_context);
freecon(from_context);
}
#endif // HAVE_SELINUX
@ -3549,21 +3548,21 @@ mch_tcgetattr(int fd, void *term)
int retval = -1;
tty_fd = get_tty_fd(fd);
if (tty_fd >= 0)
{
if (tty_fd < 0)
return -1;
#ifdef NEW_TTY_SYSTEM
# ifdef HAVE_TERMIOS_H
retval = tcgetattr(tty_fd, (struct termios *)term);
retval = tcgetattr(tty_fd, (struct termios *)term);
# else
retval = ioctl(tty_fd, TCGETA, (struct termio *)term);
retval = ioctl(tty_fd, TCGETA, (struct termio *)term);
# endif
#else
// for "old" tty systems
retval = ioctl(tty_fd, TIOCGETP, (struct sgttyb *)term);
// for "old" tty systems
retval = ioctl(tty_fd, TIOCGETP, (struct sgttyb *)term);
#endif
if (tty_fd != fd)
close(tty_fd);
}
if (tty_fd != fd)
close(tty_fd);
return retval;
}
@ -3682,18 +3681,18 @@ get_stty(void)
char_u buf[2];
char_u *p;
if (get_tty_info(read_cmd_fd, &info) == OK)
{
intr_char = info.interrupt;
buf[0] = info.backspace;
buf[1] = NUL;
add_termcode((char_u *)"kb", buf, FALSE);
if (get_tty_info(read_cmd_fd, &info) != OK)
return;
// If <BS> and <DEL> are now the same, redefine <DEL>.
p = find_termcode((char_u *)"kD");
if (p != NULL && p[0] == buf[0] && p[1] == buf[1])
do_fixdel(NULL);
}
intr_char = info.interrupt;
buf[0] = info.backspace;
buf[1] = NUL;
add_termcode((char_u *)"kb", buf, FALSE);
// If <BS> and <DEL> are now the same, redefine <DEL>.
p = find_termcode((char_u *)"kD");
if (p != NULL && p[0] == buf[0] && p[1] == buf[1])
do_fixdel(NULL);
}
/*
@ -4160,30 +4159,30 @@ mch_report_winsize(int fd, int rows, int cols)
int retval = -1;
tty_fd = get_tty_fd(fd);
if (tty_fd >= 0)
{
if (tty_fd < 0)
return FAIL;
# if defined(TIOCSWINSZ)
struct winsize ws;
struct winsize ws;
ws.ws_col = cols;
ws.ws_row = rows;
ws.ws_xpixel = cols * 5;
ws.ws_ypixel = rows * 10;
retval = ioctl(tty_fd, TIOCSWINSZ, &ws);
ch_log(NULL, "ioctl(TIOCSWINSZ) %s",
retval == 0 ? "success" : "failed");
ws.ws_col = cols;
ws.ws_row = rows;
ws.ws_xpixel = cols * 5;
ws.ws_ypixel = rows * 10;
retval = ioctl(tty_fd, TIOCSWINSZ, &ws);
ch_log(NULL, "ioctl(TIOCSWINSZ) %s",
retval == 0 ? "success" : "failed");
# elif defined(TIOCSSIZE)
struct ttysize ts;
struct ttysize ts;
ts.ts_cols = cols;
ts.ts_lines = rows;
retval = ioctl(tty_fd, TIOCSSIZE, &ts);
ch_log(NULL, "ioctl(TIOCSSIZE) %s",
retval == 0 ? "success" : "failed");
ts.ts_cols = cols;
ts.ts_lines = rows;
retval = ioctl(tty_fd, TIOCSSIZE, &ts);
ch_log(NULL, "ioctl(TIOCSSIZE) %s",
retval == 0 ? "success" : "failed");
# endif
if (tty_fd != fd)
close(tty_fd);
}
if (tty_fd != fd)
close(tty_fd);
return retval == 0 ? OK : FAIL;
}
#endif
@ -4362,28 +4361,28 @@ open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **name1, char_u **name2)
*name2 = NULL;
*pty_master_fd = mch_openpty(&tty_name); // open pty
if (*pty_master_fd >= 0)
{
// Leaving out O_NOCTTY may lead to waitpid() always returning
// 0 on Mac OS X 10.7 thereby causing freezes. Let's assume
// adding O_NOCTTY always works when defined.
if (*pty_master_fd < 0)
return;
// Leaving out O_NOCTTY may lead to waitpid() always returning
// 0 on Mac OS X 10.7 thereby causing freezes. Let's assume
// adding O_NOCTTY always works when defined.
#ifdef O_NOCTTY
*pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0);
*pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0);
#else
*pty_slave_fd = open(tty_name, O_RDWR | O_EXTRA, 0);
*pty_slave_fd = open(tty_name, O_RDWR | O_EXTRA, 0);
#endif
if (*pty_slave_fd < 0)
{
close(*pty_master_fd);
*pty_master_fd = -1;
}
else
{
if (name1 != NULL)
*name1 = vim_strsave((char_u *)tty_name);
if (name2 != NULL)
*name2 = vim_strsave((char_u *)tty_name);
}
if (*pty_slave_fd < 0)
{
close(*pty_master_fd);
*pty_master_fd = -1;
}
else
{
if (name1 != NULL)
*name1 = vim_strsave((char_u *)tty_name);
if (name2 != NULL)
*name2 = vim_strsave((char_u *)tty_name);
}
}
#endif
@ -7250,29 +7249,28 @@ gpm_open(void)
return 0;
#endif
if (!gpm_flag)
if (gpm_flag)
return 1; // already open
gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN);
gpm_connect.defaultMask = ~GPM_HARD;
// Default handling for mouse move
gpm_connect.minMod = 0; // Handle any modifier keys
gpm_connect.maxMod = 0xffff;
if (Gpm_Open(&gpm_connect, 0) > 0)
{
gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN);
gpm_connect.defaultMask = ~GPM_HARD;
// Default handling for mouse move
gpm_connect.minMod = 0; // Handle any modifier keys
gpm_connect.maxMod = 0xffff;
if (Gpm_Open(&gpm_connect, 0) > 0)
{
// gpm library tries to handling TSTP causes
// problems. Anyways, we close connection to Gpm whenever
// we are going to suspend or starting an external process
// so we shouldn't have problem with this
// gpm library tries to handling TSTP causes
// problems. Anyways, we close connection to Gpm whenever
// we are going to suspend or starting an external process
// so we shouldn't have problem with this
# ifdef SIGTSTP
signal(SIGTSTP, restricted ? SIG_IGN : (void (*)())sig_tstp);
signal(SIGTSTP, restricted ? SIG_IGN : (void (*)())sig_tstp);
# endif
return 1; // succeed
}
if (gpm_fd == -2)
Gpm_Close(); // We don't want to talk to xterm via gpm
return 0;
return 1; // succeed
}
return 1; // already open
if (gpm_fd == -2)
Gpm_Close(); // We don't want to talk to xterm via gpm
return 0;
}
/*
@ -7395,14 +7393,13 @@ sysmouse_open(void)
mouse.operation = MOUSE_MODE;
mouse.u.mode.mode = 0;
mouse.u.mode.signal = SIGUSR2;
if (ioctl(1, CONS_MOUSECTL, &mouse) != -1)
{
signal(SIGUSR2, (void (*)())sig_sysmouse);
mouse.operation = MOUSE_SHOW;
ioctl(1, CONS_MOUSECTL, &mouse);
return OK;
}
return FAIL;
if (ioctl(1, CONS_MOUSECTL, &mouse) == -1)
return FAIL;
signal(SIGUSR2, (void (*)())sig_sysmouse);
mouse.operation = MOUSE_SHOW;
ioctl(1, CONS_MOUSECTL, &mouse);
return OK;
}
/*
@ -8243,14 +8240,14 @@ xsmp_init(void)
void
xsmp_close(void)
{
if (xsmp_icefd != -1)
{
SmcCloseConnection(xsmp.smcconn, 0, NULL);
if (xsmp.clientid != NULL)
free(xsmp.clientid);
xsmp.clientid = NULL;
xsmp_icefd = -1;
}
if (xsmp_icefd == -1)
return;
SmcCloseConnection(xsmp.smcconn, 0, NULL);
if (xsmp.clientid != NULL)
free(xsmp.clientid);
xsmp.clientid = NULL;
xsmp_icefd = -1;
}
#endif // USE_XSMP
@ -8348,11 +8345,11 @@ start_timeout(long msec)
void
delete_timer(void)
{
if (timer_created)
{
timer_delete(timer_id);
timer_created = FALSE;
}
if (!timer_created)
return;
timer_delete(timer_id);
timer_created = FALSE;
}
# else // HAVE_TIMER_CREATE

View File

@ -278,15 +278,15 @@ get_build_number(void)
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
hNtdll = GetModuleHandle("ntdll.dll");
if (hNtdll != NULL)
{
pRtlGetVersion =
(PfnRtlGetVersion)GetProcAddress(hNtdll, "RtlGetVersion");
pRtlGetVersion(&osver);
ver = MAKE_VER(min(osver.dwMajorVersion, 255),
min(osver.dwMinorVersion, 255),
min(osver.dwBuildNumber, 32767));
}
if (hNtdll == NULL)
return ver;
pRtlGetVersion =
(PfnRtlGetVersion)GetProcAddress(hNtdll, "RtlGetVersion");
pRtlGetVersion(&osver);
ver = MAKE_VER(min(osver.dwMajorVersion, 255),
min(osver.dwMinorVersion, 255),
min(osver.dwBuildNumber, 32767));
return ver;
}
@ -478,29 +478,29 @@ get_exe_name(void)
exe_name = FullName_save((char_u *)temp, FALSE);
}
if (exe_path == NULL && exe_name != NULL)
if (exe_path != NULL || exe_name == NULL)
return;
exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
if (exe_path == NULL)
return;
// Append our starting directory to $PATH, so that when doing
// "!xxd" it's found in our starting directory. Needed because
// SearchPath() also looks there.
p = mch_getenv("PATH");
if (p == NULL
|| STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN)
{
exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
if (exe_path != NULL)
if (p == NULL || *p == NUL)
temp[0] = NUL;
else
{
// Append our starting directory to $PATH, so that when doing
// "!xxd" it's found in our starting directory. Needed because
// SearchPath() also looks there.
p = mch_getenv("PATH");
if (p == NULL
|| STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN)
{
if (p == NULL || *p == NUL)
temp[0] = NUL;
else
{
STRCPY(temp, p);
STRCAT(temp, ";");
}
STRCAT(temp, exe_path);
vim_setenv((char_u *)"PATH", (char_u *)temp);
}
STRCPY(temp, p);
STRCAT(temp, ";");
}
STRCAT(temp, exe_path);
vim_setenv((char_u *)"PATH", (char_u *)temp);
}
}
@ -533,27 +533,27 @@ vimLoadLib(const char *name)
// No need to load any library when registering OLE.
if (found_register_arg)
return dll;
return NULL;
// NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
// vimLoadLib() recursively, which causes a stack overflow.
if (exe_path == NULL)
get_exe_name();
if (exe_path != NULL)
{
WCHAR old_dirw[MAXPATHL];
if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0)
{
// Change directory to where the executable is, both to make
// sure we find a .dll there and to avoid looking for a .dll
// in the current directory.
SetCurrentDirectory((LPCSTR)exe_path);
dll = LoadLibrary(name);
SetCurrentDirectoryW(old_dirw);
return dll;
}
}
if (exe_path == NULL)
return NULL;
WCHAR old_dirw[MAXPATHL];
if (GetCurrentDirectoryW(MAXPATHL, old_dirw) == 0)
return NULL;
// Change directory to where the executable is, both to make
// sure we find a .dll there and to avoid looking for a .dll
// in the current directory.
SetCurrentDirectory((LPCSTR)exe_path);
dll = LoadLibrary(name);
SetCurrentDirectoryW(old_dirw);
return dll;
}
@ -907,31 +907,31 @@ PlatformId(void)
{
static int done = FALSE;
if (!done)
{
OSVERSIONINFO ovi;
if (done)
return;
ovi.dwOSVersionInfoSize = sizeof(ovi);
GetVersionEx(&ovi);
OSVERSIONINFO ovi;
ovi.dwOSVersionInfoSize = sizeof(ovi);
GetVersionEx(&ovi);
#ifdef FEAT_EVAL
vim_snprintf(windowsVersion, sizeof(windowsVersion), "%d.%d",
(int)ovi.dwMajorVersion, (int)ovi.dwMinorVersion);
vim_snprintf(windowsVersion, sizeof(windowsVersion), "%d.%d",
(int)ovi.dwMajorVersion, (int)ovi.dwMinorVersion);
#endif
if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2)
|| ovi.dwMajorVersion > 6)
win8_or_later = TRUE;
if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2)
|| ovi.dwMajorVersion > 6)
win8_or_later = TRUE;
if ((ovi.dwMajorVersion == 10 && ovi.dwBuildNumber >= 19045)
|| ovi.dwMajorVersion > 10)
win10_22H2_or_later = TRUE;
if ((ovi.dwMajorVersion == 10 && ovi.dwBuildNumber >= 19045)
|| ovi.dwMajorVersion > 10)
win10_22H2_or_later = TRUE;
#ifdef HAVE_ACL
// Enable privilege for getting or setting SACLs.
win32_enable_privilege(SE_SECURITY_NAME, TRUE);
// Enable privilege for getting or setting SACLs.
win32_enable_privilege(SE_SECURITY_NAME, TRUE);
#endif
done = TRUE;
}
done = TRUE;
}
#ifdef _MSC_VER
# pragma warning(pop)
@ -3051,40 +3051,38 @@ FitConsoleWindow(
COORD dwWindowSize;
BOOL NeedAdjust = FALSE;
if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
{
/*
* A buffer resize will fail if the current console window does
* not lie completely within that buffer. To avoid this, we might
* have to move and possibly shrink the window.
*/
if (csbi.srWindow.Right >= dwBufferSize.X)
{
dwWindowSize.X = SRWIDTH(csbi.srWindow);
if (dwWindowSize.X > dwBufferSize.X)
dwWindowSize.X = dwBufferSize.X;
csbi.srWindow.Right = dwBufferSize.X - 1;
csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X;
NeedAdjust = TRUE;
}
if (csbi.srWindow.Bottom >= dwBufferSize.Y)
{
dwWindowSize.Y = SRHEIGHT(csbi.srWindow);
if (dwWindowSize.Y > dwBufferSize.Y)
dwWindowSize.Y = dwBufferSize.Y;
csbi.srWindow.Bottom = dwBufferSize.Y - 1;
csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y;
NeedAdjust = TRUE;
}
if (NeedAdjust && WantAdjust)
{
if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow))
return FALSE;
}
return TRUE;
}
if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
return FALSE;
return FALSE;
/*
* A buffer resize will fail if the current console window does
* not lie completely within that buffer. To avoid this, we might
* have to move and possibly shrink the window.
*/
if (csbi.srWindow.Right >= dwBufferSize.X)
{
dwWindowSize.X = SRWIDTH(csbi.srWindow);
if (dwWindowSize.X > dwBufferSize.X)
dwWindowSize.X = dwBufferSize.X;
csbi.srWindow.Right = dwBufferSize.X - 1;
csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X;
NeedAdjust = TRUE;
}
if (csbi.srWindow.Bottom >= dwBufferSize.Y)
{
dwWindowSize.Y = SRHEIGHT(csbi.srWindow);
if (dwWindowSize.Y > dwBufferSize.Y)
dwWindowSize.Y = dwBufferSize.Y;
csbi.srWindow.Bottom = dwBufferSize.Y - 1;
csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y;
NeedAdjust = TRUE;
}
if (NeedAdjust && WantAdjust)
{
if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow))
return FALSE;
}
return TRUE;
}
typedef struct ConsoleBufferStruct
@ -3674,17 +3672,15 @@ mch_get_host_name(
WCHAR wszHostName[256 + 1];
DWORD wcch = ARRAY_LENGTH(wszHostName);
if (GetComputerNameW(wszHostName, &wcch))
{
char_u *p = utf16_to_enc(wszHostName, NULL);
if (!GetComputerNameW(wszHostName, &wcch))
return;
if (p != NULL)
{
vim_strncpy(s, p, len - 1);
vim_free(p);
return;
}
}
char_u *p = utf16_to_enc(wszHostName, NULL);
if (p == NULL)
return;
vim_strncpy(s, p, len - 1);
vim_free(p);
}
@ -3732,32 +3728,31 @@ mch_dirname(
* But the Win32s known bug list says that getcwd() doesn't work
* so use the Win32 system call instead. <Negri>
*/
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0)
if (GetCurrentDirectoryW(_MAX_PATH, wbuf) == 0)
return FAIL;
WCHAR wcbuf[_MAX_PATH + 1];
char_u *p = NULL;
if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0)
{
WCHAR wcbuf[_MAX_PATH + 1];
char_u *p = NULL;
if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0)
p = utf16_to_enc(wcbuf, NULL);
if (STRLEN(p) >= (size_t)len)
{
p = utf16_to_enc(wcbuf, NULL);
if (STRLEN(p) >= (size_t)len)
{
// long path name is too long, fall back to short one
vim_free(p);
p = NULL;
}
}
if (p == NULL)
p = utf16_to_enc(wbuf, NULL);
if (p != NULL)
{
vim_strncpy(buf, p, len - 1);
// long path name is too long, fall back to short one
vim_free(p);
return OK;
p = NULL;
}
}
return FAIL;
if (p == NULL)
p = utf16_to_enc(wbuf, NULL);
if (p == NULL)
return FAIL;
vim_strncpy(buf, p, len - 1);
vim_free(p);
return OK;
}
/*
@ -3974,14 +3969,14 @@ win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info)
NULL); // handle to template file
vim_free(wn);
if (hFile != INVALID_HANDLE_VALUE)
{
if (GetFileInformationByHandle(hFile, info) != 0)
res = FILEINFO_OK;
else
res = FILEINFO_INFO_FAIL;
CloseHandle(hFile);
}
if (hFile == INVALID_HANDLE_VALUE)
return FILEINFO_READ_FAIL;
if (GetFileInformationByHandle(hFile, info) != 0)
res = FILEINFO_OK;
else
res = FILEINFO_INFO_FAIL;
CloseHandle(hFile);
return res;
}
@ -6170,12 +6165,12 @@ mch_signal_job(job_T *job, char_u *how)
void
mch_clear_job(job_T *job)
{
if (job->jv_status != JOB_FAILED)
{
if (job->jv_job_object != NULL)
CloseHandle(job->jv_job_object);
CloseHandle(job->jv_proc_info.hProcess);
}
if (job->jv_status == JOB_FAILED)
return;
if (job->jv_job_object != NULL)
CloseHandle(job->jv_job_object);
CloseHandle(job->jv_proc_info.hProcess);
}
#endif
@ -7988,32 +7983,32 @@ load_ntdll(void)
{
static int loaded = -1;
if (loaded == -1)
if (loaded != -1)
return (BOOL) loaded;
HMODULE hNtdll = GetModuleHandle("ntdll.dll");
if (hNtdll != NULL)
{
HMODULE hNtdll = GetModuleHandle("ntdll.dll");
if (hNtdll != NULL)
{
pNtOpenFile = (PfnNtOpenFile) GetProcAddress(hNtdll, "NtOpenFile");
pNtClose = (PfnNtClose) GetProcAddress(hNtdll, "NtClose");
pNtSetEaFile = (PfnNtSetEaFile)
GetProcAddress(hNtdll, "NtSetEaFile");
pNtQueryEaFile = (PfnNtQueryEaFile)
GetProcAddress(hNtdll, "NtQueryEaFile");
pNtQueryInformationFile = (PfnNtQueryInformationFile)
GetProcAddress(hNtdll, "NtQueryInformationFile");
pRtlInitUnicodeString = (PfnRtlInitUnicodeString)
GetProcAddress(hNtdll, "RtlInitUnicodeString");
}
if (pNtOpenFile == NULL
|| pNtClose == NULL
|| pNtSetEaFile == NULL
|| pNtQueryEaFile == NULL
|| pNtQueryInformationFile == NULL
|| pRtlInitUnicodeString == NULL)
loaded = FALSE;
else
loaded = TRUE;
pNtOpenFile = (PfnNtOpenFile) GetProcAddress(hNtdll, "NtOpenFile");
pNtClose = (PfnNtClose) GetProcAddress(hNtdll, "NtClose");
pNtSetEaFile = (PfnNtSetEaFile)
GetProcAddress(hNtdll, "NtSetEaFile");
pNtQueryEaFile = (PfnNtQueryEaFile)
GetProcAddress(hNtdll, "NtQueryEaFile");
pNtQueryInformationFile = (PfnNtQueryInformationFile)
GetProcAddress(hNtdll, "NtQueryInformationFile");
pRtlInitUnicodeString = (PfnRtlInitUnicodeString)
GetProcAddress(hNtdll, "RtlInitUnicodeString");
}
if (pNtOpenFile == NULL
|| pNtClose == NULL
|| pNtSetEaFile == NULL
|| pNtQueryEaFile == NULL
|| pNtQueryInformationFile == NULL
|| pRtlInitUnicodeString == NULL)
loaded = FALSE;
else
loaded = TRUE;
return (BOOL) loaded;
}
@ -8190,11 +8185,11 @@ get_cmd_argsW(char ***argvp)
void
free_cmd_argsW(void)
{
if (ArglistW != NULL)
{
GlobalFree(ArglistW);
ArglistW = NULL;
}
if (ArglistW == NULL)
return;
GlobalFree(ArglistW);
ArglistW = NULL;
}
/*
@ -8899,20 +8894,20 @@ resize_console_buf(void)
COORD coord;
SMALL_RECT newsize;
if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
{
coord.X = SRWIDTH(csbi.srWindow);
coord.Y = SRHEIGHT(csbi.srWindow);
SetConsoleScreenBufferSize(g_hConOut, coord);
if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi))
return;
newsize.Left = 0;
newsize.Top = 0;
newsize.Right = coord.X - 1;
newsize.Bottom = coord.Y - 1;
SetConsoleWindowInfo(g_hConOut, TRUE, &newsize);
coord.X = SRWIDTH(csbi.srWindow);
coord.Y = SRHEIGHT(csbi.srWindow);
SetConsoleScreenBufferSize(g_hConOut, coord);
SetConsoleScreenBufferSize(g_hConOut, coord);
}
newsize.Left = 0;
newsize.Top = 0;
newsize.Right = coord.X - 1;
newsize.Bottom = coord.Y - 1;
SetConsoleWindowInfo(g_hConOut, TRUE, &newsize);
SetConsoleScreenBufferSize(g_hConOut, coord);
}
#endif
@ -8926,14 +8921,14 @@ GetWin32Error(void)
NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL);
if (oldmsg != NULL)
LocalFree(oldmsg);
if (msg != NULL)
{
// remove trailing \r\n
char *pcrlf = strstr(msg, "\r\n");
if (pcrlf != NULL)
*pcrlf = '\0';
oldmsg = msg;
}
if (msg == NULL)
return NULL;
// remove trailing \r\n
char *pcrlf = strstr(msg, "\r\n");
if (pcrlf != NULL)
*pcrlf = '\0';
oldmsg = msg;
return msg;
}

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1208,
/**/
1207,
/**/