Пример #1
0
/*
 * Implements the vi "^B" command.
 *
 * This command is like "forwpage", but it goes backwards.
 */
int
backpage(int f, int n)
{
    LINE *lp;
    int status;

    if ((n = full_pages(f, n)) < 0)
	return forwpage(f, -n);

    lp = curwp->w_line.l;
    if (lback(lp) != buf_head(curbp)) {
	while ((n -= line_height(curwp, lp)) >= 0
	       && lback(lp) != buf_head(curbp))
	    lp = lback(lp);
	curwp->w_line.l = lp;
	(void) gotoeos(FALSE, 1);
	curwp->w_flag |= WFHARD | WFMODE;
	status = TRUE;
    } else if (DOT.l != lp) {
	DOT.l = lp;
	curwp->w_flag |= WFHARD | WFMODE;
	status = TRUE;
    } else {
	status = FALSE;
    }
    return status;
}
Пример #2
0
/*
 * Implements the vi "^U" command.
 *
 * This command is like "forwpage", but it goes backwards.  It returns false
 * only if the cursor is on the first line of the buffer.
 *
 * Unlike vi, the OPT_CVMVAS option causes the repeat-count to be interpreted as
 * half-pages, rather than lines.
 */
int
backhpage(int f, int n)
{
    LINE *llp, *dlp;
    int status;

    if ((n = half_pages(f, n)) < 0)
	return forwhpage(f, -n);

    llp = curwp->w_line.l;
    dlp = DOT.l;
    if ((status = (lback(dlp) != buf_head(curbp))) == TRUE) {
	n -= line_height(curwp, dlp);
	while (lback(dlp) != buf_head(curbp)) {
	    llp = lback(llp);
	    dlp = lback(dlp);
	    if ((n -= line_height(curwp, dlp)) < 0)
		break;
	}
	curwp->w_line.l = llp;
	DOT.l = dlp;
	curwp->w_flag |= WFHARD | WFINS;
    }
    (void) firstnonwhite(FALSE, 1);
    return status;
}
Пример #3
0
/* ARGSUSED */
int
clear_match_attrs(int f GCC_UNUSED, int n GCC_UNUSED)
{
    int status;
    MARK origdot, origmark;

    if ((curbp->b_highlight & HILITE_ON) == 0)
	return TRUE;

    origdot = DOT;
    origmark = MK;

    DOT.l = lforw(buf_head(curbp));
    DOT.o = 0;
    MK.l = lback(buf_head(curbp));
    MK.o = llength(MK.l) - 1;
    videoattribute = VOWN_MATCHES;
    if ((status = attributeregion()) == TRUE) {
	DOT = origdot;
	MK = origmark;
	curbp->b_highlight = 0;
#if OPT_HILITEMATCH
	hilite_suppressed = TRUE;
#endif
    }
    return status;
}
Пример #4
0
/*
 * Implements the vi "^F" command.
 *
 * Scroll forward by a specified number of lines, or by a full page if no
 * argument.
 */
int
forwpage(int f, int n)
{
    LINE *lp;
    int status;

    if ((n = full_pages(f, n)) < 0)
	return backpage(f, -n);

    if ((status = (lforw(DOT.l) != buf_head(curbp))) == TRUE) {
	lp = curwp->w_line.l;
	n -= line_height(curwp, lp);
	while (lp != buf_head(curbp)) {
	    lp = lforw(lp);
	    if ((n -= line_height(curwp, lp)) < 0)
		break;
	}
	if (n < 0)
	    curwp->w_line.l = lp;
	DOT.l = lp;
	(void) firstnonwhite(FALSE, 1);
	curwp->w_flag |= WFHARD | WFMODE;
    }
    return status;
}
Пример #5
0
int
isns_authblock_decode(buf_t *bp, struct isns_authblk *auth)
{
	unsigned int	avail = buf_avail(bp);

	if (!buf_get32(bp, &auth->iab_bsd)
	 || !buf_get32(bp, &auth->iab_length)
	 || !buf_get64(bp, &auth->iab_timestamp)
	 || !buf_get32(bp, &auth->iab_spi_len))
		 return 0;

	/* Make sure the length specified by the auth block
	 * is reasonable. */
	if (auth->iab_length < ISNS_AUTHBLK_SIZE
	 || auth->iab_length > avail)
		return 0;

	/* This chops off any data trailing the auth block.
	 * It also makes sure that we detect if iab_length
	 * exceeds the amount of available data. */
	if (!buf_truncate(bp, auth->iab_length - ISNS_AUTHBLK_SIZE))
		return 0;

	auth->iab_spi = buf_head(bp);
	if (!buf_pull(bp, auth->iab_spi_len))
		return 0;

	auth->iab_sig = buf_head(bp);
	auth->iab_sig_len = buf_avail(bp);
	return 1;
}
Пример #6
0
/*
 * Move to a particular line (the argument).  Count from bottom of file if
 * argument is negative.
 */
int
vl_gotoline(int n)
{
    int status = TRUE;		/* status return */

    MARK odot;

    if (n == 0)			/* if a bogus argument...then leave */
	return (FALSE);

    odot = DOT;

    DOT.o = w_left_margin(curwp);
    if (n < 0) {
	DOT.l = lback(buf_head(curbp));
	status = backline(TRUE, -n - 1);
    } else {
	DOT.l = lforw(buf_head(curbp));
	status = forwline(TRUE, n - 1);
    }
    if (status != TRUE) {
	DOT = odot;
	return status;
    }
    (void) firstnonwhite(FALSE, 1);
    curwp->w_flag |= WFMOVE;
    return TRUE;
}
Пример #7
0
/* ARGSUSED */
int
gotoeob(int f GCC_UNUSED, int n GCC_UNUSED)
{
    DOT.l = lback(buf_head(curbp));
    curwp->w_flag |= WFMOVE;
    return firstnonwhite(FALSE, 1);
}
Пример #8
0
/* ARGSUSED */
int
gotomos(int f GCC_UNUSED, int n)
{
    LINE *last = DOT.l;
    LINE *lp, *head;
    int half = (curwp->w_ntrows + 1) / 2;

    head = buf_head(curbp);
    for (n = 0, lp = curwp->w_line.l; lp != head; lp = lforw(lp)) {
	if (n < half)
	    DOT.l = lp;
	if ((n += line_height(curwp, lp)) >= curwp->w_ntrows)
	    break;
    }
    if (n < curwp->w_ntrows) {	/* then we hit eof before eos */
	half = (n + 1) / 2;	/* go back up */
	for (n = 0, lp = curwp->w_line.l; lp != head; lp = lforw(lp)) {
	    DOT.l = lp;
	    if ((n += line_height(curwp, lp)) >= half)
		break;
	}
    }

    if (DOT.l != last)
	curwp->w_flag |= WFMOVE;
    return firstnonwhite(FALSE, 1);
}
Пример #9
0
/*
 * Implements the vi "k" command.
 *
 * This function is like "forwline", but goes backwards.
 */
int
backline(int f, int n)
{
    int rc;
    LINE *dlp;

    n = need_a_count(f, n, 1);

    if (n < 0) {
	rc = forwline(f, -n);
    } else if (is_first_line(DOT, curbp)) {
	/* cannot move up */
	rc = FALSE;
    } else {
	/* set the "goal" column if necessary */
	if (curgoal < 0)
	    curgoal = getccol(FALSE);

	/* loop upwards */
	dlp = DOT.l;
	while (n-- && lback(dlp) != buf_head(curbp))
	    dlp = lback(dlp);

	/* set dot */
	DOT.l = dlp;
	DOT.o = getgoal(dlp);
	curwp->w_flag |= WFMOVE;
	rc = TRUE;
    }
    return rc;
}
Пример #10
0
/* ARGSUSED */
int
gotobob(int f GCC_UNUSED, int n GCC_UNUSED)
{
    DOT.l = lforw(buf_head(curbp));
    DOT.o = w_left_margin(curwp);
    curwp->w_flag |= WFMOVE;
    return (TRUE);
}
Пример #11
0
/*
 * DSA signature generation and verification
 */
static void
isns_message_digest(EVP_MD_CTX *md, const buf_t *pdu,
		const struct isns_authblk *blk)
{
	uint64_t	stamp;

	EVP_DigestUpdate(md, buf_head(pdu), buf_avail(pdu));

	/* The RFC doesn't say which pieces of the
	 * message should be hashed.
	 * We make an educated guess.
	 */
	stamp = htonll(blk->iab_timestamp);
	EVP_DigestUpdate(md, &stamp, sizeof(stamp));
}
Пример #12
0
/*
 * Implements the vi "j" command.
 *
 * Move forward by full lines. If the number of lines to move is less than
 * zero, call the backward line function to actually do it. The last command
 * controls how the goal column is set.
 */
int
forwline(int f, int n)
{
    int rc;
    LINE *dlp;

    n = need_a_count(f, n, 1);

    if (n < 0) {
	rc = backline(f, -n);
    } else if (n == 0) {
	rc = TRUE;
    } else {

	/* set the "goal" column if necessary */
	if (curgoal < 0)
	    curgoal = getccol(FALSE);

	/* loop downwards */
	dlp = DOT.l;
	rc = TRUE;
	do {
	    LINE *nlp = lforw(dlp);
	    if (nlp == buf_head(curbp)) {
		rc = FALSE;
		break;
	    }
	    dlp = nlp;
	} while (--n != 0);

	if (rc) {
	    /* set dot */
	    DOT.l = dlp;
	    DOT.o = getgoal(dlp);
	    curwp->w_flag |= WFMOVE;
	}
    }
    return rc;
}
Пример #13
0
/*
 * Move the cursor backwards by "n" characters. If "n" is less than zero call
 * "forwchar" to actually do the move. Otherwise compute the new cursor
 * location. Error if you try and move out of the buffer. Set the flag if the
 * line pointer for dot changes.
 */
int
backchar(int f, int n)
{
    LINE *lp;

    n = need_a_count(f, n, 1);

    if (n < 0)
	return (forwchar(f, -n));
    while (n--) {
	if (DOT.o == w_left_margin(curwp)) {
	    if ((lp = lback(DOT.l)) == buf_head(curbp))
		return (FALSE);
	    DOT.l = lp;
	    DOT.o = llength(lp);
	    curwp->w_flag |= WFMOVE;
	} else {
	    DOT.o -= BytesBefore(DOT.l, DOT.o);
	}
    }
    return (TRUE);
}
Пример #14
0
/* push a deleted line onto the undo stack. */
void
toss_to_undo(LINE *lp)
{
    LINE *next;
    LINE *prev;
    int fc;

    TRACE2((T_CALLED "toss_to_undo(%p)\n", lp));
    if (needundocleanup)
	preundocleanup();

    pushline(lp, BACKSTK(curbp));

    next = lforw(lp);

    /* need to save a dot -- either the next line or
       the previous one */
    if (next == buf_head(curbp)) {
	prev = lback(lp);
	FORWDOT(curbp).l = prev;
	fc = firstchar(prev);
	if (fc < 0)		/* all white */
	    FORWDOT(curbp).o = llength(prev) - 1;
	else
	    FORWDOT(curbp).o = fc;
    } else {
	FORWDOT(curbp).l = next;
	fc = firstchar(next);
	if (fc < 0)		/* all white */
	    FORWDOT(curbp).o = b_left_margin(curbp);
	else
	    FORWDOT(curbp).o = fc;
    }

    dumpuline(lp);
    return2Void();
}
Пример #15
0
static void
skipblanksf(void)
{
    while (lforw(DOT.l) != buf_head(curbp) && is_empty_line(DOT))
	DOT.l = lforw(DOT.l);
}
Пример #16
0
void
attrib_matches(void)
{
#if OPT_HILITEMATCH
    MARK origdot;
    MARK nextdot;
    int status;
    REGIONSHAPE oregionshape = regionshape;
    VIDEO_ATTR vattr;

    assert(curwp != 0);

    ignorecase = window_b_val(curwp, MDIGNCASE);

    if (!need_to_rehilite())
	return;

    if (tb_length(searchpat) == 0 || gregexp == NULL)
	return;

/* #define track_hilite 1 */
#ifdef track_hilite
    mlwrite("rehighlighting");
#endif

    vattr = (VIDEO_ATTR) b_val(curbp, VAL_HILITEMATCH);
    if (vattr == 0)
	return;

    (void) clear_match_attrs(TRUE, 1);

    if (curwp == 0)
	return;

    origdot = DOT;
    DOT.l = buf_head(curbp);
    DOT.o = 0;
    nextdot = DOT;

    scanboundry(FALSE, DOT, FORWARD);
    do {
	if (b_val(curbp, MDHILITEOVERLAP)) {
	    movenext(&(DOT), FORWARD);
	} else {
	    movenext(&nextdot, FORWARD);
	    DOT = nextdot;
	}
	status = scanner(gregexp, FORWARD, FALSE, (int *) 0);
	if (status != TRUE)
	    break;
	if (vattr != VACOLOR)
	    videoattribute = vattr;
	else {
	    int c;
	    for (c = NSUBEXP - 1; c > 0; c--)
		if (gregexp->startp[c] == gregexp->startp[0]
		    && gregexp->endp[c] == gregexp->endp[0])
		    break;
	    if (c > NCOLORS - 1)
		videoattribute = VCOLORATTR(NCOLORS - 1);
	    else
		videoattribute = VCOLORATTR(c + 1);
	}
	MK.l = DOT.l;
	MK.o = DOT.o + (C_NUM) gregexp->mlen;

	/* provide a location for the next non-overlapping match */
	nextdot = MK;
	if (gregexp->mlen > 0)
	    nextdot.o -= BytesBefore(nextdot.l, nextdot.o);

	/* show highlighting from DOT to MK */
	regionshape = rgn_EXACT;
	videoattribute |= VOWN_MATCHES;
	status = attributeregion();
    } while (status == TRUE);

    DOT = origdot;
    regionshape = oregionshape;
    curbp->b_highlight = HILITE_ON;	/* & ~HILITE_DIRTY */
    hilite_suppressed = FALSE;
#endif /* OPT_HILITEMATCH */
}
Пример #17
0
/*
 * This is invoked as a wrapper for 'kbd_putc()'.  It writes to the Messages
 * scratch buffer, and also to the message line.  If the Messages buffer isn't
 * visible, it is automatically popped up when a new message line is begun.
 * Since it's a scratch buffer, popping it down destroys it.
 */
int
msg_putc(int c)
{
    BUFFER *savebp = curbp;
    WINDOW *savewp = curwp;
    MARK savemk;
    int saverow = ttrow;
    int savecol = ttcol;
    register BUFFER *bp;
    register WINDOW *wp;

    if ((bp = create_msgs()) == 0)
	return TRUE;

    savemk = DOT;
    beginDisplay();
    /*
     * Modify the current-buffer state as unobtrusively as possible (i.e.,
     * don't modify the buffer order, and don't make the buffer visible if
     * it isn't already!).  To use the 'bputc()' logic, though, we've got
     * to have a window, even if it's not real.
     */
    curbp = bp;
    if ((wp = bp2any_wp(bp)) == NULL) {
	static WINDOW dummy;
	wp = &dummy;
	wp->w_bufp = bp;
    }
    curwp = wp;
    DOT.l = lback(buf_head(bp));
    DOT.o = llength(DOT.l);

    /*
     * Write into the [Messages]-buffer
     */
#if OPT_TRACE
    if (c == '\n') {
	static TBUFF *ss;
	int len = (DOT.o > 0) ? DOT.o : 1;
	if (tb_init(&ss, EOS) != 0
	    && tb_bappend(&ss,
			  (DOT.o > 0) ? lvalue(DOT.l) : "?",
			  (size_t) len) != 0
	    && tb_append(&ss, EOS) != 0) {
	    TRACE(("msg:%s\n",
		   visible_buff(tb_values(ss),
				(int) tb_length(ss) - 1, TRUE)));
	}
    }
#endif
    if ((c != '\n') || (DOT.o > 0)) {
	bputc(c);
	b_clr_changed(bp);
    }

    /* Finally, restore the original current-buffer and write the character
     * to the message line.
     */
    curbp = savebp;
    curwp = savewp;
    if (savewp)
	DOT = savemk;
    movecursor(saverow, savecol);
    if (c != '\n') {
	if (sgarbf) {
	    mlsavec(c);
	} else {
	    kbd_putc(c);
	}
    }
    endofDisplay();

    return TRUE;
}
Пример #18
0
static void
skipblanksb(void)
{
    while (lback(DOT.l) != buf_head(curbp) && is_empty_line(DOT))
	DOT.l = lback(DOT.l);
}