forked from aniani/vim
patch 9.0.0601: too much indent
Problem: Too much indent. Solution: Return out early from a funtion. (Yegappan Lakshmanan, close #11238)
This commit is contained in:
committed by
Bram Moolenaar
parent
d324742292
commit
368aa69088
321
src/beval.c
321
src/beval.c
@@ -39,94 +39,94 @@ find_word_under_cursor(
|
|||||||
|
|
||||||
*textp = NULL;
|
*textp = NULL;
|
||||||
wp = mouse_find_win(&row, &col, FAIL_POPUP);
|
wp = mouse_find_win(&row, &col, FAIL_POPUP);
|
||||||
if (wp != NULL && row >= 0 && row < wp->w_height && col < wp->w_width)
|
if (wp == NULL || row < 0 || row >= wp->w_height || col >= wp->w_width)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
// Found a window and the cursor is in the text. Now find the line
|
||||||
|
// number.
|
||||||
|
if (mouse_comp_pos(wp, &row, &col, &lnum, NULL))
|
||||||
|
return FAIL; // position is below the last line
|
||||||
|
|
||||||
|
// Not past end of the file.
|
||||||
|
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
||||||
|
if (col > win_linetabsize(wp, lnum, lbuf, (colnr_T)MAXCOL))
|
||||||
|
return FAIL; // past end of line
|
||||||
|
|
||||||
|
// Not past end of line.
|
||||||
|
if (getword)
|
||||||
{
|
{
|
||||||
// Found a window and the cursor is in the text. Now find the line
|
// For Netbeans we get the relevant part of the line
|
||||||
// number.
|
// instead of the whole line.
|
||||||
if (!mouse_comp_pos(wp, &row, &col, &lnum, NULL))
|
int len;
|
||||||
|
pos_T *spos = NULL, *epos = NULL;
|
||||||
|
|
||||||
|
if (VIsual_active)
|
||||||
{
|
{
|
||||||
// Not past end of the file.
|
if (LT_POS(VIsual, curwin->w_cursor))
|
||||||
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
|
||||||
if (col <= win_linetabsize(wp, lnum, lbuf, (colnr_T)MAXCOL))
|
|
||||||
{
|
{
|
||||||
// Not past end of line.
|
spos = &VIsual;
|
||||||
if (getword)
|
epos = &curwin->w_cursor;
|
||||||
{
|
}
|
||||||
// For Netbeans we get the relevant part of the line
|
else
|
||||||
// instead of the whole line.
|
{
|
||||||
int len;
|
spos = &curwin->w_cursor;
|
||||||
pos_T *spos = NULL, *epos = NULL;
|
epos = &VIsual;
|
||||||
|
|
||||||
if (VIsual_active)
|
|
||||||
{
|
|
||||||
if (LT_POS(VIsual, curwin->w_cursor))
|
|
||||||
{
|
|
||||||
spos = &VIsual;
|
|
||||||
epos = &curwin->w_cursor;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
spos = &curwin->w_cursor;
|
|
||||||
epos = &VIsual;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
col = vcol2col(wp, lnum, col);
|
|
||||||
scol = col;
|
|
||||||
|
|
||||||
if (VIsual_active
|
|
||||||
&& wp->w_buffer == curwin->w_buffer
|
|
||||||
&& (lnum == spos->lnum
|
|
||||||
? col >= (int)spos->col
|
|
||||||
: lnum > spos->lnum)
|
|
||||||
&& (lnum == epos->lnum
|
|
||||||
? col <= (int)epos->col
|
|
||||||
: lnum < epos->lnum))
|
|
||||||
{
|
|
||||||
// Visual mode and pointing to the line with the
|
|
||||||
// Visual selection: return selected text, with a
|
|
||||||
// maximum of one line.
|
|
||||||
if (spos->lnum != epos->lnum || spos->col == epos->col)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE);
|
|
||||||
len = epos->col - spos->col;
|
|
||||||
if (*p_sel != 'e')
|
|
||||||
len += mb_ptr2len(lbuf + epos->col);
|
|
||||||
lbuf = vim_strnsave(lbuf + spos->col, len);
|
|
||||||
lnum = spos->lnum;
|
|
||||||
col = spos->col;
|
|
||||||
scol = col;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Find the word under the cursor.
|
|
||||||
++emsg_off;
|
|
||||||
len = find_ident_at_pos(wp, lnum, (colnr_T)col,
|
|
||||||
&lbuf, &scol, flags);
|
|
||||||
--emsg_off;
|
|
||||||
if (len == 0)
|
|
||||||
return FAIL;
|
|
||||||
lbuf = vim_strnsave(lbuf, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
scol = col;
|
|
||||||
|
|
||||||
if (winp != NULL)
|
|
||||||
*winp = wp;
|
|
||||||
if (lnump != NULL)
|
|
||||||
*lnump = lnum;
|
|
||||||
*textp = lbuf;
|
|
||||||
if (colp != NULL)
|
|
||||||
*colp = col;
|
|
||||||
if (startcolp != NULL)
|
|
||||||
*startcolp = scol;
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
col = vcol2col(wp, lnum, col);
|
||||||
|
scol = col;
|
||||||
|
|
||||||
|
if (VIsual_active
|
||||||
|
&& wp->w_buffer == curwin->w_buffer
|
||||||
|
&& (lnum == spos->lnum
|
||||||
|
? col >= (int)spos->col
|
||||||
|
: lnum > spos->lnum)
|
||||||
|
&& (lnum == epos->lnum
|
||||||
|
? col <= (int)epos->col
|
||||||
|
: lnum < epos->lnum))
|
||||||
|
{
|
||||||
|
// Visual mode and pointing to the line with the
|
||||||
|
// Visual selection: return selected text, with a
|
||||||
|
// maximum of one line.
|
||||||
|
if (spos->lnum != epos->lnum || spos->col == epos->col)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE);
|
||||||
|
len = epos->col - spos->col;
|
||||||
|
if (*p_sel != 'e')
|
||||||
|
len += mb_ptr2len(lbuf + epos->col);
|
||||||
|
lbuf = vim_strnsave(lbuf + spos->col, len);
|
||||||
|
lnum = spos->lnum;
|
||||||
|
col = spos->col;
|
||||||
|
scol = col;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Find the word under the cursor.
|
||||||
|
++emsg_off;
|
||||||
|
len = find_ident_at_pos(wp, lnum, (colnr_T)col,
|
||||||
|
&lbuf, &scol, flags);
|
||||||
|
--emsg_off;
|
||||||
|
if (len == 0)
|
||||||
|
return FAIL;
|
||||||
|
lbuf = vim_strnsave(lbuf, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FAIL;
|
else
|
||||||
|
scol = col;
|
||||||
|
|
||||||
|
if (winp != NULL)
|
||||||
|
*winp = wp;
|
||||||
|
if (lnump != NULL)
|
||||||
|
*lnump = lnum;
|
||||||
|
*textp = lbuf;
|
||||||
|
if (colp != NULL)
|
||||||
|
*colp = col;
|
||||||
|
if (startcolp != NULL)
|
||||||
|
*startcolp = scol;
|
||||||
|
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -220,6 +220,92 @@ can_use_beval(void)
|
|||||||
) && msg_scrolled == 0;
|
) && msg_scrolled == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ifdef FEAT_EVAL
|
||||||
|
/*
|
||||||
|
* Evaluate the expression 'bexpr' and set the text in the balloon 'beval'.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
bexpr_eval(
|
||||||
|
BalloonEval *beval,
|
||||||
|
char_u *bexpr,
|
||||||
|
win_T *wp,
|
||||||
|
linenr_T lnum,
|
||||||
|
int col,
|
||||||
|
char_u *text)
|
||||||
|
{
|
||||||
|
win_T *cw;
|
||||||
|
long winnr = 0;
|
||||||
|
buf_T *save_curbuf;
|
||||||
|
int use_sandbox;
|
||||||
|
static char_u *result = NULL;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
sctx_T save_sctx = current_sctx;
|
||||||
|
|
||||||
|
// Convert window pointer to number.
|
||||||
|
for (cw = firstwin; cw != wp; cw = cw->w_next)
|
||||||
|
++winnr;
|
||||||
|
|
||||||
|
set_vim_var_nr(VV_BEVAL_BUFNR, (long)wp->w_buffer->b_fnum);
|
||||||
|
set_vim_var_nr(VV_BEVAL_WINNR, winnr);
|
||||||
|
set_vim_var_nr(VV_BEVAL_WINID, wp->w_id);
|
||||||
|
set_vim_var_nr(VV_BEVAL_LNUM, (long)lnum);
|
||||||
|
set_vim_var_nr(VV_BEVAL_COL, (long)(col + 1));
|
||||||
|
set_vim_var_string(VV_BEVAL_TEXT, text, -1);
|
||||||
|
vim_free(text);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Temporarily change the curbuf, so that we can determine whether
|
||||||
|
* the buffer-local balloonexpr option was set insecurely.
|
||||||
|
*/
|
||||||
|
save_curbuf = curbuf;
|
||||||
|
curbuf = wp->w_buffer;
|
||||||
|
use_sandbox = was_set_insecurely((char_u *)"balloonexpr",
|
||||||
|
*curbuf->b_p_bexpr == NUL ? 0 : OPT_LOCAL);
|
||||||
|
curbuf = save_curbuf;
|
||||||
|
if (use_sandbox)
|
||||||
|
++sandbox;
|
||||||
|
++textlock;
|
||||||
|
|
||||||
|
if (bexpr == p_bexpr)
|
||||||
|
{
|
||||||
|
sctx_T *sp = get_option_sctx("balloonexpr");
|
||||||
|
|
||||||
|
if (sp != NULL)
|
||||||
|
current_sctx = *sp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
current_sctx = curbuf->b_p_script_ctx[BV_BEXPR];
|
||||||
|
|
||||||
|
vim_free(result);
|
||||||
|
result = eval_to_string(bexpr, TRUE);
|
||||||
|
|
||||||
|
// Remove one trailing newline, it is added when the result was a
|
||||||
|
// list and it's hardly ever useful. If the user really wants a
|
||||||
|
// trailing newline he can add two and one remains.
|
||||||
|
if (result != NULL)
|
||||||
|
{
|
||||||
|
len = STRLEN(result);
|
||||||
|
if (len > 0 && result[len - 1] == NL)
|
||||||
|
result[len - 1] = NUL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use_sandbox)
|
||||||
|
--sandbox;
|
||||||
|
--textlock;
|
||||||
|
current_sctx = save_sctx;
|
||||||
|
|
||||||
|
set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
|
||||||
|
if (result != NULL && result[0] != NUL)
|
||||||
|
post_balloon(beval, result, NULL);
|
||||||
|
|
||||||
|
// The 'balloonexpr' evaluation may show something on the screen
|
||||||
|
// that requires a screen update.
|
||||||
|
if (must_redraw)
|
||||||
|
redraw_after_callback(FALSE, FALSE);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Common code, invoked when the mouse is resting for a moment.
|
* Common code, invoked when the mouse is resting for a moment.
|
||||||
*/
|
*/
|
||||||
@@ -229,15 +315,9 @@ general_beval_cb(BalloonEval *beval, int state UNUSED)
|
|||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
int col;
|
int col;
|
||||||
int use_sandbox;
|
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
char_u *text;
|
char_u *text;
|
||||||
static char_u *result = NULL;
|
|
||||||
long winnr = 0;
|
|
||||||
char_u *bexpr;
|
char_u *bexpr;
|
||||||
buf_T *save_curbuf;
|
|
||||||
size_t len;
|
|
||||||
win_T *cw;
|
|
||||||
#endif
|
#endif
|
||||||
static int recursive = FALSE;
|
static int recursive = FALSE;
|
||||||
|
|
||||||
@@ -259,70 +339,7 @@ general_beval_cb(BalloonEval *beval, int state UNUSED)
|
|||||||
: wp->w_buffer->b_p_bexpr;
|
: wp->w_buffer->b_p_bexpr;
|
||||||
if (*bexpr != NUL)
|
if (*bexpr != NUL)
|
||||||
{
|
{
|
||||||
sctx_T save_sctx = current_sctx;
|
bexpr_eval(beval, bexpr, wp, lnum, col, text);
|
||||||
|
|
||||||
// Convert window pointer to number.
|
|
||||||
for (cw = firstwin; cw != wp; cw = cw->w_next)
|
|
||||||
++winnr;
|
|
||||||
|
|
||||||
set_vim_var_nr(VV_BEVAL_BUFNR, (long)wp->w_buffer->b_fnum);
|
|
||||||
set_vim_var_nr(VV_BEVAL_WINNR, winnr);
|
|
||||||
set_vim_var_nr(VV_BEVAL_WINID, wp->w_id);
|
|
||||||
set_vim_var_nr(VV_BEVAL_LNUM, (long)lnum);
|
|
||||||
set_vim_var_nr(VV_BEVAL_COL, (long)(col + 1));
|
|
||||||
set_vim_var_string(VV_BEVAL_TEXT, text, -1);
|
|
||||||
vim_free(text);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Temporarily change the curbuf, so that we can determine whether
|
|
||||||
* the buffer-local balloonexpr option was set insecurely.
|
|
||||||
*/
|
|
||||||
save_curbuf = curbuf;
|
|
||||||
curbuf = wp->w_buffer;
|
|
||||||
use_sandbox = was_set_insecurely((char_u *)"balloonexpr",
|
|
||||||
*curbuf->b_p_bexpr == NUL ? 0 : OPT_LOCAL);
|
|
||||||
curbuf = save_curbuf;
|
|
||||||
if (use_sandbox)
|
|
||||||
++sandbox;
|
|
||||||
++textlock;
|
|
||||||
|
|
||||||
if (bexpr == p_bexpr)
|
|
||||||
{
|
|
||||||
sctx_T *sp = get_option_sctx("balloonexpr");
|
|
||||||
|
|
||||||
if (sp != NULL)
|
|
||||||
current_sctx = *sp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
current_sctx = curbuf->b_p_script_ctx[BV_BEXPR];
|
|
||||||
|
|
||||||
vim_free(result);
|
|
||||||
result = eval_to_string(bexpr, TRUE);
|
|
||||||
|
|
||||||
// Remove one trailing newline, it is added when the result was a
|
|
||||||
// list and it's hardly ever useful. If the user really wants a
|
|
||||||
// trailing newline he can add two and one remains.
|
|
||||||
if (result != NULL)
|
|
||||||
{
|
|
||||||
len = STRLEN(result);
|
|
||||||
if (len > 0 && result[len - 1] == NL)
|
|
||||||
result[len - 1] = NUL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (use_sandbox)
|
|
||||||
--sandbox;
|
|
||||||
--textlock;
|
|
||||||
current_sctx = save_sctx;
|
|
||||||
|
|
||||||
set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
|
|
||||||
if (result != NULL && result[0] != NUL)
|
|
||||||
post_balloon(beval, result, NULL);
|
|
||||||
|
|
||||||
// The 'balloonexpr' evaluation may show something on the screen
|
|
||||||
// that requires a screen update.
|
|
||||||
if (must_redraw)
|
|
||||||
redraw_after_callback(FALSE, FALSE);
|
|
||||||
|
|
||||||
recursive = FALSE;
|
recursive = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
188
src/blob.c
188
src/blob.c
@@ -60,29 +60,31 @@ rettv_blob_set(typval_T *rettv, blob_T *b)
|
|||||||
int
|
int
|
||||||
blob_copy(blob_T *from, typval_T *to)
|
blob_copy(blob_T *from, typval_T *to)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int len;
|
||||||
|
|
||||||
to->v_type = VAR_BLOB;
|
to->v_type = VAR_BLOB;
|
||||||
to->v_lock = 0;
|
to->v_lock = 0;
|
||||||
if (from == NULL)
|
if (from == NULL)
|
||||||
to->vval.v_blob = NULL;
|
|
||||||
else if (rettv_blob_alloc(to) == FAIL)
|
|
||||||
ret = FAIL;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
int len = from->bv_ga.ga_len;
|
to->vval.v_blob = NULL;
|
||||||
|
return OK;
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
to->vval.v_blob->bv_ga.ga_data =
|
|
||||||
vim_memsave(from->bv_ga.ga_data, len);
|
|
||||||
if (to->vval.v_blob->bv_ga.ga_data == NULL)
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
to->vval.v_blob->bv_ga.ga_len = len;
|
|
||||||
to->vval.v_blob->bv_ga.ga_maxlen = len;
|
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
if (rettv_blob_alloc(to) == FAIL)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
len = from->bv_ga.ga_len;
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
to->vval.v_blob->bv_ga.ga_data =
|
||||||
|
vim_memsave(from->bv_ga.ga_data, len);
|
||||||
|
if (to->vval.v_blob->bv_ga.ga_data == NULL)
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
to->vval.v_blob->bv_ga.ga_len = len;
|
||||||
|
to->vval.v_blob->bv_ga.ga_maxlen = len;
|
||||||
|
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -280,6 +282,93 @@ failed:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns a slice of 'blob' from index 'n1' to 'n2' in 'rettv'. The length of
|
||||||
|
* the blob is 'len'. Returns an empty blob if the indexes are out of range.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
blob_slice(
|
||||||
|
blob_T *blob,
|
||||||
|
long len,
|
||||||
|
varnumber_T n1,
|
||||||
|
varnumber_T n2,
|
||||||
|
int exclusive,
|
||||||
|
typval_T *rettv)
|
||||||
|
{
|
||||||
|
if (n1 < 0)
|
||||||
|
{
|
||||||
|
n1 = len + n1;
|
||||||
|
if (n1 < 0)
|
||||||
|
n1 = 0;
|
||||||
|
}
|
||||||
|
if (n2 < 0)
|
||||||
|
n2 = len + n2;
|
||||||
|
else if (n2 >= len)
|
||||||
|
n2 = len - (exclusive ? 0 : 1);
|
||||||
|
if (exclusive)
|
||||||
|
--n2;
|
||||||
|
if (n1 >= len || n2 < 0 || n1 > n2)
|
||||||
|
{
|
||||||
|
clear_tv(rettv);
|
||||||
|
rettv->v_type = VAR_BLOB;
|
||||||
|
rettv->vval.v_blob = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blob_T *new_blob = blob_alloc();
|
||||||
|
long i;
|
||||||
|
|
||||||
|
if (new_blob != NULL)
|
||||||
|
{
|
||||||
|
if (ga_grow(&new_blob->bv_ga, n2 - n1 + 1) == FAIL)
|
||||||
|
{
|
||||||
|
blob_free(new_blob);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
new_blob->bv_ga.ga_len = n2 - n1 + 1;
|
||||||
|
for (i = n1; i <= n2; i++)
|
||||||
|
blob_set(new_blob, i - n1, blob_get(blob, i));
|
||||||
|
|
||||||
|
clear_tv(rettv);
|
||||||
|
rettv_blob_set(rettv, new_blob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the byte value in 'blob' at index 'idx' in 'rettv'. If the index is
|
||||||
|
* too big or negative that is an error. The length of the blob is 'len'.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
blob_index(
|
||||||
|
blob_T *blob,
|
||||||
|
int len,
|
||||||
|
varnumber_T idx,
|
||||||
|
typval_T *rettv)
|
||||||
|
{
|
||||||
|
// The resulting variable is a byte value.
|
||||||
|
// If the index is too big or negative that is an error.
|
||||||
|
if (idx < 0)
|
||||||
|
idx = len + idx;
|
||||||
|
if (idx < len && idx >= 0)
|
||||||
|
{
|
||||||
|
int v = blob_get(blob, idx);
|
||||||
|
|
||||||
|
clear_tv(rettv);
|
||||||
|
rettv->v_type = VAR_NUMBER;
|
||||||
|
rettv->vval.v_number = v;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
semsg(_(e_blob_index_out_of_range_nr), idx);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
blob_slice_or_index(
|
blob_slice_or_index(
|
||||||
blob_T *blob,
|
blob_T *blob,
|
||||||
@@ -289,71 +378,12 @@ blob_slice_or_index(
|
|||||||
int exclusive,
|
int exclusive,
|
||||||
typval_T *rettv)
|
typval_T *rettv)
|
||||||
{
|
{
|
||||||
long len = blob_len(blob);
|
long len = blob_len(blob);
|
||||||
|
|
||||||
if (is_range)
|
if (is_range)
|
||||||
{
|
return blob_slice(blob, len, n1, n2, exclusive, rettv);
|
||||||
// The resulting variable is a sub-blob. If the indexes
|
|
||||||
// are out of range the result is empty.
|
|
||||||
if (n1 < 0)
|
|
||||||
{
|
|
||||||
n1 = len + n1;
|
|
||||||
if (n1 < 0)
|
|
||||||
n1 = 0;
|
|
||||||
}
|
|
||||||
if (n2 < 0)
|
|
||||||
n2 = len + n2;
|
|
||||||
else if (n2 >= len)
|
|
||||||
n2 = len - (exclusive ? 0 : 1);
|
|
||||||
if (exclusive)
|
|
||||||
--n2;
|
|
||||||
if (n1 >= len || n2 < 0 || n1 > n2)
|
|
||||||
{
|
|
||||||
clear_tv(rettv);
|
|
||||||
rettv->v_type = VAR_BLOB;
|
|
||||||
rettv->vval.v_blob = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
blob_T *new_blob = blob_alloc();
|
|
||||||
long i;
|
|
||||||
|
|
||||||
if (new_blob != NULL)
|
|
||||||
{
|
|
||||||
if (ga_grow(&new_blob->bv_ga, n2 - n1 + 1) == FAIL)
|
|
||||||
{
|
|
||||||
blob_free(new_blob);
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
new_blob->bv_ga.ga_len = n2 - n1 + 1;
|
|
||||||
for (i = n1; i <= n2; i++)
|
|
||||||
blob_set(new_blob, i - n1, blob_get(blob, i));
|
|
||||||
|
|
||||||
clear_tv(rettv);
|
|
||||||
rettv_blob_set(rettv, new_blob);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return blob_index(blob, len, n1, rettv);
|
||||||
// The resulting variable is a byte value.
|
|
||||||
// If the index is too big or negative that is an error.
|
|
||||||
if (n1 < 0)
|
|
||||||
n1 = len + n1;
|
|
||||||
if (n1 < len && n1 >= 0)
|
|
||||||
{
|
|
||||||
int v = blob_get(blob, n1);
|
|
||||||
|
|
||||||
clear_tv(rettv);
|
|
||||||
rettv->v_type = VAR_NUMBER;
|
|
||||||
rettv->vval.v_number = v;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
semsg(_(e_blob_index_out_of_range_nr), n1);
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -699,6 +699,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
601,
|
||||||
/**/
|
/**/
|
||||||
600,
|
600,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user