diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-11-18 23:37:32 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-11-18 23:37:32 +0000 |
commit | f7421fa03f090fc3948fb1c3000a32097b40a48e (patch) | |
tree | 493553cc492083ddde7a2b1be03d829088d5f14a /usr.bin/mg | |
parent | c266de03a8e6cebc8867a41a73d94f8464193ecf (diff) |
Split kill buffer code into a separate function.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/def.h | 3 | ||||
-rw-r--r-- | usr.bin/mg/line.c | 57 |
2 files changed, 37 insertions, 23 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 06a86b1e924..fc40a519fa8 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.75 2005/11/18 23:15:00 kjell Exp $ */ +/* $OpenBSD: def.h,v 1.76 2005/11/18 23:37:30 kjell Exp $ */ /* This file is in the public domain. */ @@ -356,6 +356,7 @@ int lreplace(RSIZE, char *); void kdelete(void); int kinsert(int, int); int kremove(int); +int kchunk(char *, RSIZE, int); /* window.c X */ struct mgwin *new_window(struct buffer *); diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c index 34b11f0b169..8c84474d967 100644 --- a/usr.bin/mg/line.c +++ b/usr.bin/mg/line.c @@ -1,4 +1,4 @@ -/* $OpenBSD: line.c,v 1.28 2005/11/18 20:56:53 deraadt Exp $ */ +/* $OpenBSD: line.c,v 1.29 2005/11/18 23:37:31 kjell Exp $ */ /* This file is in the public domain. */ @@ -427,13 +427,6 @@ ldelete(RSIZE n, int kflag) undo_add_delete(curwp->w_dotp, curwp->w_doto, n); - /* - * HACK - doesn't matter, and fixes back-over-nl bug for empty - * kill buffers. - */ - if (kused == kstart) - kflag = KFORW; - while (n != 0) { dotp = curwp->w_dotp; doto = curwp->w_doto; @@ -460,20 +453,8 @@ ldelete(RSIZE n, int kflag) lchange(WFEDIT); /* Scrunch text */ cp1 = &dotp->l_text[doto]; - if (kflag == KFORW) { - while (ksize - kused < chunk) - if (kgrow(kflag) == FALSE) - return (FALSE); - bcopy(cp1, &(kbufp[kused]), (int)chunk); - kused += chunk; - } else if (kflag == KBACK) { - while (kstart < chunk) - if (kgrow(kflag) == FALSE) - return (FALSE); - bcopy(cp1, &(kbufp[kstart - chunk]), (int)chunk); - kstart -= chunk; - } else if (kflag != KNONE) - panic("broken ldelete call"); + if (kchunk(cp1, chunk, kflag) == FALSE) + return(FALSE); for (cp2 = cp1 + chunk; cp2 < &dotp->l_text[dotp->l_used]; cp2++) *cp1++ = *cp2; @@ -681,3 +662,35 @@ kremove(int n) return (-1); return (CHARMASK(kbufp[n + kstart])); } + +/* + * Copy a string into the kill buffer. kflag gives direction. + * if KNONE, do nothing. + */ +int +kchunk(char *cp1, RSIZE chunk, int kflag) +{ + /* + * HACK - doesn't matter, and fixes back-over-nl bug for empty + * kill buffers. + */ + if (kused == kstart) + kflag = KFORW; + + if (kflag == KFORW) { + while (ksize - kused < chunk) + if (kgrow(kflag) == FALSE) + return (FALSE); + bcopy(cp1, &(kbufp[kused]), (int)chunk); + kused += chunk; + } else if (kflag == KBACK) { + while (kstart < chunk) + if (kgrow(kflag) == FALSE) + return (FALSE); + bcopy(cp1, &(kbufp[kstart - chunk]), (int)chunk); + kstart -= chunk; + } else if (kflag != KNONE) + panic("broken ldelete call"); + + return (TRUE); +} |