summaryrefslogtreecommitdiff
path: root/usr.bin/vi/ex/ex_shift.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-05-22 11:37:15 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-05-22 11:37:15 +0000
commit0157a77a51c5e35e093ae03581f66dea010edcc8 (patch)
tree5e8bd32aa4d2b5ed37b7cf3ad26e8bdfc7f20a04 /usr.bin/vi/ex/ex_shift.c
parent806021be093ad00ce2022a532c0f4cc99b0065ac (diff)
new vi
Diffstat (limited to 'usr.bin/vi/ex/ex_shift.c')
-rw-r--r--usr.bin/vi/ex/ex_shift.c97
1 files changed, 42 insertions, 55 deletions
diff --git a/usr.bin/vi/ex/ex_shift.c b/usr.bin/vi/ex/ex_shift.c
index 61264c01fff..e81aa9585bf 100644
--- a/usr.bin/vi/ex/ex_shift.c
+++ b/usr.bin/vi/ex/ex_shift.c
@@ -1,85 +1,67 @@
/*-
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1992, 1993, 1994, 1995, 1996
+ * Keith Bostic. All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * See the LICENSE file for redistribution information.
*/
+#include "config.h"
+
#ifndef lint
-static char sccsid[] = "@(#)ex_shift.c 8.16 (Berkeley) 8/17/94";
+static const char sccsid[] = "@(#)ex_shift.c 10.10 (Berkeley) 3/6/96";
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
-#include <sys/time.h>
#include <bitstring.h>
#include <limits.h>
-#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include "vi.h"
-#include "excmd.h"
+#include "../common/common.h"
enum which {LEFT, RIGHT};
-static int shift __P((SCR *, EXF *, EXCMDARG *, enum which));
+static int shift __P((SCR *, EXCMD *, enum which));
+/*
+ * ex_shiftl -- :<[<...]
+ *
+ *
+ * PUBLIC: int ex_shiftl __P((SCR *, EXCMD *));
+ */
int
-ex_shiftl(sp, ep, cmdp)
+ex_shiftl(sp, cmdp)
SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
+ EXCMD *cmdp;
{
- return (shift(sp, ep, cmdp, LEFT));
+ return (shift(sp, cmdp, LEFT));
}
+/*
+ * ex_shiftr -- :>[>...]
+ *
+ * PUBLIC: int ex_shiftr __P((SCR *, EXCMD *));
+ */
int
-ex_shiftr(sp, ep, cmdp)
+ex_shiftr(sp, cmdp)
SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
+ EXCMD *cmdp;
{
- return (shift(sp, ep, cmdp, RIGHT));
+ return (shift(sp, cmdp, RIGHT));
}
+/*
+ * shift --
+ * Ex shift support.
+ */
static int
-shift(sp, ep, cmdp, rl)
+shift(sp, cmdp, rl)
SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
+ EXCMD *cmdp;
enum which rl;
{
recno_t from, to;
@@ -87,11 +69,17 @@ shift(sp, ep, cmdp, rl)
int curset;
char *p, *bp, *tbp;
+ NEEDFILE(sp, cmdp);
+
if (O_VAL(sp, O_SHIFTWIDTH) == 0) {
- msgq(sp, M_INFO, "shiftwidth option set to 0");
+ msgq(sp, M_INFO, "152|shiftwidth option set to 0");
return (0);
}
+ /* Copy the lines being shifted into the unnamed buffer. */
+ if (cut(sp, NULL, &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE))
+ return (1);
+
/*
* The historic version of vi permitted the user to string any number
* of '>' or '<' characters together, resulting in an indent of the
@@ -109,7 +97,7 @@ shift(sp, ep, cmdp, rl)
curset = 0;
for (from = cmdp->addr1.lno, to = cmdp->addr2.lno; from <= to; ++from) {
- if ((p = file_gline(sp, ep, from, &len)) == NULL)
+ if (db_get(sp, from, DBG_FATAL, &p, &len))
goto err;
if (!len) {
if (sp->lno == from)
@@ -161,7 +149,7 @@ shift(sp, ep, cmdp, rl)
memmove(tbp, p + oldidx, len - oldidx);
/* Set the replacement line. */
- if (file_sline(sp, ep, from, bp, (tbp + (len - oldidx)) - bp)) {
+ if (db_set(sp, from, bp, (tbp + (len - oldidx)) - bp)) {
err: FREE_SPACE(sp, bp, blen);
return (1);
}
@@ -193,12 +181,11 @@ err: FREE_SPACE(sp, bp, blen);
if (!curset) {
sp->lno = to;
sp->cno = 0;
- (void)nonblank(sp, ep, to, &sp->cno);
+ (void)nonblank(sp, to, &sp->cno);
}
FREE_SPACE(sp, bp, blen);
- sp->rptlines[rl == RIGHT ? L_RSHIFT : L_LSHIFT] +=
- cmdp->addr2.lno - cmdp->addr1.lno + 1;
+ sp->rptlines[L_SHIFT] += cmdp->addr2.lno - cmdp->addr1.lno + 1;
return (0);
}