diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-11-22 05:02:45 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-11-22 05:02:45 +0000 |
commit | 3f1928d7d7543e128a88583ececb15de9324d666 (patch) | |
tree | 1e757eb2c5d35627f04aeed39951cc70a204d393 /usr.bin/mg/util.c | |
parent | 666f079336b7d94938ef3545faa03c8dae2071a9 (diff) |
Move kill-related commands to their own file.
This will help move to a kill-ring.
Diffstat (limited to 'usr.bin/mg/util.c')
-rw-r--r-- | usr.bin/mg/util.c | 121 |
1 files changed, 1 insertions, 120 deletions
diff --git a/usr.bin/mg/util.c b/usr.bin/mg/util.c index 3441ef82dad..a56343d7956 100644 --- a/usr.bin/mg/util.c +++ b/usr.bin/mg/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.16 2005/11/19 20:16:35 kjell Exp $ */ +/* $OpenBSD: util.c,v 1.17 2005/11/22 05:02:44 kjell Exp $ */ /* This file is in the public domain. */ @@ -337,125 +337,6 @@ backdel(int f, int n) return (s); } -/* - * Kill line. If called without an argument, it kills from dot to the end - * of the line, unless it is at the end of the line, when it kills the - * newline. If called with an argument of 0, it kills from the start of the - * line to dot. If called with a positive argument, it kills from dot - * forward over that number of newlines. If called with a negative argument - * it kills any text before dot on the current line, then it kills back - * abs(arg) lines. - */ -/* ARGSUSED */ -int -killline(int f, int n) -{ - struct line *nextp; - RSIZE chunk; - int i, c; - - /* clear kill buffer if last wasn't a kill */ - if ((lastflag & CFKILL) == 0) - kdelete(); - thisflag |= CFKILL; - if (!(f & FFARG)) { - for (i = curwp->w_doto; i < llength(curwp->w_dotp); ++i) - if ((c = lgetc(curwp->w_dotp, i)) != ' ' && c != '\t') - break; - if (i == llength(curwp->w_dotp)) - chunk = llength(curwp->w_dotp) - curwp->w_doto + 1; - else { - chunk = llength(curwp->w_dotp) - curwp->w_doto; - if (chunk == 0) - chunk = 1; - } - } else if (n > 0) { - chunk = llength(curwp->w_dotp) - curwp->w_doto + 1; - nextp = lforw(curwp->w_dotp); - i = n; - while (--i) { - if (nextp == curbp->b_linep) - break; - chunk += llength(nextp) + 1; - nextp = lforw(nextp); - } - } else { - /* n <= 0 */ - chunk = curwp->w_doto; - curwp->w_doto = 0; - i = n; - while (i++) { - if (lback(curwp->w_dotp) == curbp->b_linep) - break; - curwp->w_dotp = lback(curwp->w_dotp); - curwp->w_flag |= WFMOVE; - chunk += llength(curwp->w_dotp) + 1; - } - } - /* - * KFORW here is a bug. Should be KBACK/KFORW, but we need to - * rewrite the ldelete code (later)? - */ - return (ldelete(chunk, KFORW)); -} - -/* - * Yank text back from the kill buffer. This is really easy. All of the work - * is done by the standard insert routines. All you do is run the loop, and - * check for errors. The blank lines are inserted with a call to "newline" - * instead of a call to "lnewline" so that the magic stuff that happens when - * you type a carriage return also happens when a carriage return is yanked - * back from the kill buffer. An attempt has been made to fix the cosmetic - * bug associated with a yank when dot is on the top line of the window - * (nothing moves, because all of the new text landed off screen). - */ -/* ARGSUSED */ -int -yank(int f, int n) -{ - struct line *lp; - int c, i, nline; - - if (n < 0) - return (FALSE); - - /* newline counting */ - nline = 0; - - undo_add_boundary(); - undo_no_boundary(TRUE); - while (n--) { - /* mark around last yank */ - isetmark(); - i = 0; - while ((c = kremove(i)) >= 0) { - if (c == '\n') { - if (newline(FFRAND, 1) == FALSE) - return (FALSE); - ++nline; - } else { - if (linsert(1, c) == FALSE) - return (FALSE); - } - ++i; - } - } - /* cosmetic adjustment */ - lp = curwp->w_linep; - - /* if offscreen insert */ - if (curwp->w_dotp == lp) { - while (nline-- && lback(lp) != curbp->b_linep) - lp = lback(lp); - /* adjust framing */ - curwp->w_linep = lp; - curwp->w_flag |= WFHARD; - } - undo_no_boundary(FALSE); - undo_add_boundary(); - return (TRUE); -} - #ifdef NOTAB /* ARGSUSED */ int |