aboutsummaryrefslogtreecommitdiffstats
path: root/usr.bin/vi/nvi
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/vi/nvi')
-rw-r--r--usr.bin/vi/nvi/getc.c252
-rw-r--r--usr.bin/vi/nvi/v_again.c61
-rw-r--r--usr.bin/vi/nvi/v_at.c61
-rw-r--r--usr.bin/vi/nvi/v_ch.c273
-rw-r--r--usr.bin/vi/nvi/v_delete.c147
-rw-r--r--usr.bin/vi/nvi/v_ex.c55
-rw-r--r--usr.bin/vi/nvi/v_exit.c79
-rw-r--r--usr.bin/vi/nvi/v_exmode.c58
-rw-r--r--usr.bin/vi/nvi/v_filter.c92
-rw-r--r--usr.bin/vi/nvi/v_increment.c153
-rw-r--r--usr.bin/vi/nvi/v_init.c228
-rw-r--r--usr.bin/vi/nvi/v_join.c75
-rw-r--r--usr.bin/vi/nvi/v_left.c166
-rw-r--r--usr.bin/vi/nvi/v_mark.c87
-rw-r--r--usr.bin/vi/nvi/v_match.c152
-rw-r--r--usr.bin/vi/nvi/v_ntext.c1728
-rw-r--r--usr.bin/vi/nvi/v_paragraph.c273
-rw-r--r--usr.bin/vi/nvi/v_put.c130
-rw-r--r--usr.bin/vi/nvi/v_redraw.c56
-rw-r--r--usr.bin/vi/nvi/v_replace.c176
-rw-r--r--usr.bin/vi/nvi/v_right.c144
-rw-r--r--usr.bin/vi/nvi/v_screen.c79
-rw-r--r--usr.bin/vi/nvi/v_scroll.c354
-rw-r--r--usr.bin/vi/nvi/v_search.c364
-rw-r--r--usr.bin/vi/nvi/v_section.c146
-rw-r--r--usr.bin/vi/nvi/v_sentence.c328
-rw-r--r--usr.bin/vi/nvi/v_shift.c78
-rw-r--r--usr.bin/vi/nvi/v_status.c129
-rw-r--r--usr.bin/vi/nvi/v_stop.c61
-rw-r--r--usr.bin/vi/nvi/v_switch.c86
-rw-r--r--usr.bin/vi/nvi/v_tag.c79
-rw-r--r--usr.bin/vi/nvi/v_text.c827
-rw-r--r--usr.bin/vi/nvi/v_ulcase.c159
-rw-r--r--usr.bin/vi/nvi/v_undo.c136
-rw-r--r--usr.bin/vi/nvi/v_util.c127
-rw-r--r--usr.bin/vi/nvi/v_word.c560
-rw-r--r--usr.bin/vi/nvi/v_xchar.c135
-rw-r--r--usr.bin/vi/nvi/v_yank.c114
-rw-r--r--usr.bin/vi/nvi/v_z.c133
-rw-r--r--usr.bin/vi/nvi/vcmd.c522
-rw-r--r--usr.bin/vi/nvi/vcmd.h274
-rw-r--r--usr.bin/vi/nvi/vi.c780
42 files changed, 0 insertions, 9917 deletions
diff --git a/usr.bin/vi/nvi/getc.c b/usr.bin/vi/nvi/getc.c
deleted file mode 100644
index d4ac2304b914..000000000000
--- a/usr.bin/vi/nvi/getc.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)getc.c 8.6 (Berkeley) 10/26/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * Character stream routines --
- * These routines return the file a character at a time. There are two
- * special cases. First, the end of a line, end of a file, start of a
- * file and empty lines are returned as special cases, and no character
- * is returned. Second, empty lines include lines that have only white
- * space in them, because the vi search functions don't care about white
- * space, and this makes it easier for them to be consistent.
- */
-
-/*
- * cs_init --
- * Initialize character stream routines.
- */
-int
-cs_init(sp, ep, csp)
- SCR *sp;
- EXF *ep;
- VCS *csp;
-{
- recno_t lno;
-
- if ((csp->cs_bp =
- file_gline(sp, ep, csp->cs_lno, &csp->cs_len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- msgq(sp, M_BERR, "Empty file.");
- else
- GETLINE_ERR(sp, csp->cs_lno);
- return (1);
- }
- if (csp->cs_len == 0 || v_isempty(csp->cs_bp, csp->cs_len)) {
- csp->cs_cno = 0;
- csp->cs_flags = CS_EMP;
- } else {
- csp->cs_flags = 0;
- csp->cs_ch = csp->cs_bp[csp->cs_cno];
- }
- return (0);
-}
-
-/*
- * cs_next --
- * Retrieve the next character.
- */
-int
-cs_next(sp, ep, csp)
- SCR *sp;
- EXF *ep;
- VCS *csp;
-{
- recno_t slno;
-
- switch (csp->cs_flags) {
- case CS_EMP: /* EMP; get next line. */
- case CS_EOL: /* EOL; get next line. */
- slno = csp->cs_lno; /* Save current line. */
- if ((csp->cs_bp =
- file_gline(sp, ep, ++csp->cs_lno, &csp->cs_len)) == NULL) {
- csp->cs_lno = slno;
- if (file_lline(sp, ep, &slno))
- return (1);
- if (slno > csp->cs_lno) {
- GETLINE_ERR(sp, csp->cs_lno);
- return (1);
- }
- csp->cs_flags = CS_EOF;
- } else if (csp->cs_len == 0 ||
- v_isempty(csp->cs_bp, csp->cs_len)) {
- csp->cs_cno = 0;
- csp->cs_flags = CS_EMP;
- } else {
- csp->cs_flags = 0;
- csp->cs_ch = csp->cs_bp[csp->cs_cno = 0];
- }
- break;
- case 0:
- if (csp->cs_cno == csp->cs_len - 1)
- csp->cs_flags = CS_EOL;
- else
- csp->cs_ch = csp->cs_bp[++csp->cs_cno];
- break;
- case CS_EOF: /* EOF; only returned once. */
- default:
- abort();
- /* NOTREACHED */
- }
- return (0);
-}
-
-/*
- * cs_fspace --
- * If on a space, eat forward until something other than a
- * whitespace character.
- *
- * XXX
- * Semantics of checking the current character were coded for the fword()
- * function -- once the other word routines are converted, they may have
- * to change.
- */
-int
-cs_fspace(sp, ep, csp)
- SCR *sp;
- EXF *ep;
- VCS *csp;
-{
- if (csp->cs_flags != 0 || !isblank(csp->cs_ch))
- return (0);
- for (;;) {
- if (cs_next(sp, ep, csp))
- return (1);
- if (csp->cs_flags != 0 || !isblank(csp->cs_ch))
- break;
- }
- return (0);
-}
-
-/*
- * cs_fblank --
- * Eat forward to the next non-whitespace character.
- */
-int
-cs_fblank(sp, ep, csp)
- SCR *sp;
- EXF *ep;
- VCS *csp;
-{
- for (;;) {
- if (cs_next(sp, ep, csp))
- return (1);
- if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
- csp->cs_flags == 0 && isblank(csp->cs_ch))
- continue;
- break;
- }
- return (0);
-}
-
-/*
- * cs_prev --
- * Retrieve the previous character.
- */
-int
-cs_prev(sp, ep, csp)
- SCR *sp;
- EXF *ep;
- VCS *csp;
-{
- recno_t slno;
-
- switch (csp->cs_flags) {
- case CS_EMP: /* EMP; get previous line. */
- case CS_EOL: /* EOL; get previous line. */
- if (csp->cs_lno == 1) { /* SOF. */
- csp->cs_flags = CS_SOF;
- break;
- }
- slno = csp->cs_lno; /* Save current line. */
- if ((csp->cs_bp = /* Line should exist. */
- file_gline(sp, ep, --csp->cs_lno, &csp->cs_len)) == NULL) {
- GETLINE_ERR(sp, csp->cs_lno);
- csp->cs_lno = slno;
- return (1);
- }
- if (csp->cs_len == 0 || v_isempty(csp->cs_bp, csp->cs_len)) {
- csp->cs_cno = 0;
- csp->cs_flags = CS_EMP;
- } else {
- csp->cs_flags = 0;
- csp->cs_cno = csp->cs_len - 1;
- csp->cs_ch = csp->cs_bp[csp->cs_cno];
- }
- break;
- case 0:
- if (csp->cs_cno == 0)
- csp->cs_flags = CS_EOL;
- else
- csp->cs_ch = csp->cs_bp[--csp->cs_cno];
- break;
- case CS_SOF: /* SOF; only returned once. */
- default:
- abort();
- /* NOTREACHED */
- }
- return (0);
-}
-
-/*
- * cs_bblank --
- * Eat backward to the next non-whitespace character.
- */
-int
-cs_bblank(sp, ep, csp)
- SCR *sp;
- EXF *ep;
- VCS *csp;
-{
- for (;;) {
- if (cs_prev(sp, ep, csp))
- return (1);
- if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
- csp->cs_flags == 0 && isblank(csp->cs_ch))
- continue;
- break;
- }
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_again.c b/usr.bin/vi/nvi/v_again.c
deleted file mode 100644
index 7e9ea5650d83..000000000000
--- a/usr.bin/vi/nvi/v_again.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_again.c 8.2 (Berkeley) 11/13/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * v_again -- &
- * Repeat the previous substitution.
- */
-int
-v_again(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
-
- SETCMDARG(cmd, C_SUBAGAIN, 2, fm->lno, fm->lno, 1, "");
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_at.c b/usr.bin/vi/nvi/v_at.c
deleted file mode 100644
index 3b21fc3186d5..000000000000
--- a/usr.bin/vi/nvi/v_at.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_at.c 8.3 (Berkeley) 8/25/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-int
-v_at(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
-
- SETCMDARG(cmd, C_AT, 0, OOBLNO, OOBLNO, 0, NULL);
- cmd.buffer = vp->buffer;
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_ch.c b/usr.bin/vi/nvi/v_ch.c
deleted file mode 100644
index 40807d1db6b1..000000000000
--- a/usr.bin/vi/nvi/v_ch.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_ch.c 8.2 (Berkeley) 12/20/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <stdlib.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-#define NOPREV { \
- msgq(sp, M_BERR, "No previous F, f, T or t search."); \
- return (1); \
-}
-
-#define NOTFOUND(ch) { \
- msgq(sp, M_BERR, "%s not found.", charname(sp, ch)); \
- return (1); \
-}
-
-/*
- * v_chrepeat -- [count];
- * Repeat the last F, f, T or t search.
- */
-int
-v_chrepeat(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- vp->character = sp->lastckey;
-
- switch (sp->csearchdir) {
- case CNOTSET:
- NOPREV;
- case FSEARCH:
- return (v_chF(sp, ep, vp, fm, tm, rp));
- case fSEARCH:
- return (v_chf(sp, ep, vp, fm, tm, rp));
- case TSEARCH:
- return (v_chT(sp, ep, vp, fm, tm, rp));
- case tSEARCH:
- return (v_cht(sp, ep, vp, fm, tm, rp));
- default:
- abort();
- }
- /* NOTREACHED */
-}
-
-/*
- * v_chrrepeat -- [count],
- * Repeat the last F, f, T or t search in the reverse direction.
- */
-int
-v_chrrepeat(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int rval;
- enum cdirection savedir;
-
- vp->character = sp->lastckey;
- savedir = sp->csearchdir;
-
- switch (sp->csearchdir) {
- case CNOTSET:
- NOPREV;
- case FSEARCH:
- rval = v_chf(sp, ep, vp, fm, tm, rp);
- break;
- case fSEARCH:
- rval = v_chF(sp, ep, vp, fm, tm, rp);
- break;
- case TSEARCH:
- rval = v_cht(sp, ep, vp, fm, tm, rp);
- break;
- case tSEARCH:
- rval = v_chT(sp, ep, vp, fm, tm, rp);
- break;
- default:
- abort();
- }
- sp->csearchdir = savedir;
- return (rval);
-}
-
-/*
- * v_cht -- [count]tc
- * Search forward in the line for the next occurrence of the character.
- * Place the cursor on it if a motion command, to its left if its not.
- */
-int
-v_cht(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int rval;
-
- rval = v_chf(sp, ep, vp, fm, tm, rp);
- if (!rval)
- --rp->cno; /* XXX: Motion interaction with v_chf. */
- sp->csearchdir = tSEARCH;
- return (rval);
-}
-
-/*
- * v_chf -- [count]fc
- * Search forward in the line for the next occurrence of the character.
- * Place the cursor to its right if a motion command, on it if its not.
- */
-int
-v_chf(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- size_t len;
- recno_t lno;
- u_long cnt;
- int key;
- char *endp, *p, *startp;
-
- /*
- * !!!
- * If it's a dot command, it doesn't reset the key for which
- * we're searching, e.g. in "df1|f2|.|;", the ';' searches
- * for a '2'.
- */
- key = vp->character;
- if (!F_ISSET(vp, VC_ISDOT))
- sp->lastckey = key;
- sp->csearchdir = fSEARCH;
-
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- NOTFOUND(key);
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- if (len == 0)
- NOTFOUND(key);
-
- startp = p;
- endp = p + len;
- p += fm->cno;
- for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- while (++p < endp && *p != key);
- if (p == endp)
- NOTFOUND(key);
- }
- rp->lno = fm->lno;
- rp->cno = p - startp;
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- ++rp->cno;
- return (0);
-}
-
-/*
- * v_chT -- [count]Tc
- * Search backward in the line for the next occurrence of the character.
- * Place the cursor to its right.
- */
-int
-v_chT(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int rval;
-
- rval = v_chF(sp, ep, vp, fm, tm, rp);
- if (!rval)
- ++rp->cno;
- sp->csearchdir = TSEARCH;
- return (0);
-}
-
-/*
- * v_chF -- [count]Fc
- * Search backward in the line for the next occurrence of the character.
- * Place the cursor on it.
- */
-int
-v_chF(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- size_t len;
- u_long cnt;
- int key;
- char *p, *endp;
-
- /*
- * !!!
- * If it's a dot command, it doesn't reset the key for which
- * we're searching, e.g. in "df1|f2|.|;", the ';' searches
- * for a '2'.
- */
- key = vp->character;
- if (!F_ISSET(vp, VC_ISDOT))
- sp->lastckey = key;
- sp->csearchdir = FSEARCH;
-
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- NOTFOUND(key);
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- if (len == 0)
- NOTFOUND(key);
-
- endp = p - 1;
- p += fm->cno;
- for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- while (--p > endp && *p != key);
- if (p == endp)
- NOTFOUND(key);
- }
- rp->lno = fm->lno;
- rp->cno = (p - endp) - 1;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_delete.c b/usr.bin/vi/nvi/v_delete.c
deleted file mode 100644
index 241ddf654f2e..000000000000
--- a/usr.bin/vi/nvi/v_delete.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_delete.c 8.7 (Berkeley) 1/11/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_Delete -- [buffer][count]D
- * Delete line command.
- */
-int
-v_Delete(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- size_t len;
-
- if (file_gline(sp, ep, fm->lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- return (0);
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- if (len == 0)
- return (0);
-
- tm->lno = fm->lno;
- tm->cno = len;
-
- /* Yank the lines. */
- if (cut(sp, ep, NULL,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, CUT_DELETE))
- return (1);
- if (delete(sp, ep, fm, tm, 0))
- return (1);
-
- rp->lno = fm->lno;
- rp->cno = fm->cno ? fm->cno - 1 : 0;
- return (0);
-}
-
-/*
- * v_delete -- [buffer][count]d[count]motion
- * Delete a range of text.
- */
-int
-v_delete(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t nlines;
- size_t len;
- int lmode;
-
- /* Yank the lines. */
- lmode = F_ISSET(vp, VC_LMODE) ? CUT_LINEMODE : 0;
- if (cut(sp, ep, NULL,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- fm, tm, lmode | CUT_DELETE))
- return (1);
- if (delete(sp, ep, fm, tm, lmode))
- return (1);
-
- /* Check for deleting the file. */
- if (file_lline(sp, ep, &nlines))
- return (1);
- if (nlines == 0) {
- rp->lno = 1;
- rp->cno = 0;
- return (0);
- }
-
- /*
- * If deleting lines, leave the cursor at the lowest line deleted,
- * else, leave the cursor where it started. Always correct for EOL.
- *
- * The historic vi would delete the line the cursor was on (even if
- * not in line mode) if the motion from the cursor was past the EOF
- * and the cursor didn't originate on the last line of the file. A
- * strange special case. We never delete the line the cursor is on.
- * We'd have to pass a flag down to the delete() routine which would
- * have to special case it.
- */
- if (lmode) {
- rp->lno = MIN(fm->lno, tm->lno);
- if (rp->lno > nlines)
- rp->lno = nlines;
- rp->cno = 0;
- (void)nonblank(sp, ep, rp->lno, &rp->cno);
- return (0);
- }
-
- rp->lno = fm->lno;
- if (file_gline(sp, ep, rp->lno, &len) == NULL) {
- GETLINE_ERR(sp, rp->lno);
- return (1);
- }
- if (fm->cno >= len)
- rp->cno = len ? len - 1 : 0;
- else
- rp->cno = fm->cno;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_ex.c b/usr.bin/vi/nvi/v_ex.c
deleted file mode 100644
index 631cd342d010..000000000000
--- a/usr.bin/vi/nvi/v_ex.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_ex.c 8.1 (Berkeley) 6/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_ex --
- * Run ex.
- */
-int
-v_ex(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (sp->s_ex_run(sp, ep, rp));
-}
diff --git a/usr.bin/vi/nvi/v_exit.c b/usr.bin/vi/nvi/v_exit.c
deleted file mode 100644
index f308c480d3d7..000000000000
--- a/usr.bin/vi/nvi/v_exit.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_exit.c 8.5 (Berkeley) 12/10/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * v_exit -- ZZ
- * Save the file and exit.
- */
-int
-v_exit(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- if (F_ISSET(ep, F_MODIFIED) &&
- file_write(sp, ep, NULL, NULL, NULL, FS_ALL))
- return (1);
-
- /*
- * !!!
- * Historic practice: quit! or two quit's done in succession
- * (where ZZ counts as a quit) didn't check for other files.
- *
- * Also check for related screens; if they exist, quit, the
- * user will get the message on the last screen.
- */
- if (sp->ccnt != sp->q_ccnt + 1 &&
- ep->refcnt <= 1 && file_unedited(sp) != NULL) {
- sp->q_ccnt = sp->ccnt;
- msgq(sp, M_ERR,
- "More files to edit; use \":n\" to go to the next file");
- return (1);
- }
-
- F_SET(sp, S_EXIT);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_exmode.c b/usr.bin/vi/nvi/v_exmode.c
deleted file mode 100644
index 150ec52ccf9c..000000000000
--- a/usr.bin/vi/nvi/v_exmode.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_exmode.c 8.3 (Berkeley) 11/13/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_exmode --
- * Put the editor in EX mode.
- */
-int
-v_exmode(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- sp->saved_vi_mode = F_ISSET(sp, S_VI_CURSES | S_VI_XAW);
- F_CLR(sp, S_SCREENS);
- F_SET(sp, S_EX);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_filter.c b/usr.bin/vi/nvi/v_filter.c
deleted file mode 100644
index 52ff2ae77b8d..000000000000
--- a/usr.bin/vi/nvi/v_filter.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_filter.c 8.10 (Berkeley) 12/2/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-#include "excmd.h"
-
-/*
- * v_filter -- [count]!motion command(s)
- * Run range through shell commands, replacing text.
- */
-int
-v_filter(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
- TEXT *tp;
-
- /*
- * !!!
- * Historical vi permitted "!!" in an empty file. This is
- * handled as a special case in the ex_bang routine. Don't
- * modify this setup without understanding that one. In
- * particular, note that we're manipulating the ex argument
- * structures behind ex's back.
- */
- SETCMDARG(cmd, C_BANG, 2, fm->lno, tm->lno, 0, NULL);
- EXP(sp)->argsoff = 0; /* XXX */
- if (F_ISSET(vp, VC_ISDOT)) {
- if (argv_exp1(sp, ep, &cmd, "!", 1, 1))
- return (1);
- } else {
- /* Get the command from the user. */
- if (sp->s_get(sp, ep, &sp->tiq,
- '!', TXT_BS | TXT_CR | TXT_ESCAPE | TXT_PROMPT) != INP_OK)
- return (1);
- /*
- * Len is 0 if backspaced over the prompt,
- * 1 if only CR entered.
- */
- tp = sp->tiq.cqh_first;
- if (tp->len <= 1)
- return (0);
-
- if (argv_exp1(sp, ep, &cmd, tp->lb + 1, tp->len - 1, 1))
- return (1);
- }
- cmd.argc = EXP(sp)->argsoff; /* XXX */
- cmd.argv = EXP(sp)->args; /* XXX */
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_increment.c b/usr.bin/vi/nvi/v_increment.c
deleted file mode 100644
index dfae29ea463e..000000000000
--- a/usr.bin/vi/nvi/v_increment.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_increment.c 8.6 (Berkeley) 12/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static char * const fmt[] = {
-#define DEC 0
- "%ld",
-#define SDEC 1
- "%+ld",
-#define HEXC 2
- "%#0.*lX",
-#define HEXL 3
- "%#0.*lx",
-#define OCTAL 4
- "%#0.*lo",
-};
-
-/*
- * v_increment -- [count]#[#+-]
- * Increment/decrement a keyword number.
- */
-int
-v_increment(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- VI_PRIVATE *vip;
- u_long ulval;
- long lval;
- size_t blen, len, nlen;
- int rval;
- char *bp, *ntype, *p, nbuf[100];
-
- vip = VIP(sp);
-
- /* Do repeat operations. */
- if (vp->character == '#')
- vp->character = vip->inc_lastch;
-
- /* Get new value. */
- if (F_ISSET(vp, VC_C1SET))
- vip->inc_lastval = vp->count;
-
- if (vp->character != '+' && vp->character != '-') {
- msgq(sp, M_ERR, "usage: %s.", vp->kp->usage);
- return (1);
- }
- vip->inc_lastch = vp->character;
-
- /* Figure out the resulting type and number. */
- p = vp->keyword;
- len = vp->klen;
- if (len > 1 && p[0] == '0') {
- if (vp->character == '+') {
- ulval = strtoul(vp->keyword, NULL, 0);
- if (ULONG_MAX - ulval < vip->inc_lastval)
- goto overflow;
- ulval += vip->inc_lastval;
- } else {
- ulval = strtoul(vp->keyword, NULL, 0);
- if (ulval < vip->inc_lastval)
- goto underflow;
- ulval -= vip->inc_lastval;
- }
- ntype = fmt[OCTAL];
- if (len > 2)
- if (p[1] == 'X')
- ntype = fmt[HEXC];
- else if (p[1] == 'x')
- ntype = fmt[HEXL];
- nlen = snprintf(nbuf, sizeof(nbuf), ntype, len, ulval);
- } else {
- if (vp->character == '+') {
- lval = strtol(vp->keyword, NULL, 0);
- if (lval > 0 && LONG_MAX - lval < vip->inc_lastval) {
-overflow: msgq(sp, M_ERR, "Resulting number too large.");
- return (1);
- }
- lval += vip->inc_lastval;
- } else {
- lval = strtol(vp->keyword, NULL, 0);
- if (lval < 0 && -(LONG_MIN - lval) < vip->inc_lastval) {
-underflow: msgq(sp, M_ERR, "Resulting number too small.");
- return (1);
- }
- lval -= vip->inc_lastval;
- }
- ntype = lval != 0 &&
- (*vp->keyword == '+' || *vp->keyword == '-') ?
- fmt[SDEC] : fmt[DEC];
- nlen = snprintf(nbuf, sizeof(nbuf), ntype, lval);
- }
-
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- GET_SPACE_RET(sp, bp, blen, len + nlen);
- memmove(bp, p, fm->cno);
- memmove(bp + fm->cno, nbuf, nlen);
- memmove(bp + fm->cno + nlen,
- p + fm->cno + vp->klen, len - fm->cno - vp->klen);
- len = len - vp->klen + nlen;
-
- rval = file_sline(sp, ep, fm->lno, bp, len);
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
diff --git a/usr.bin/vi/nvi/v_init.c b/usr.bin/vi/nvi/v_init.c
deleted file mode 100644
index f0d2facf4ea3..000000000000
--- a/usr.bin/vi/nvi/v_init.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_init.c 8.18 (Berkeley) 1/9/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-#include "excmd.h"
-
-static int v_comment __P((SCR *, EXF *));
-
-/*
- * v_screen_copy --
- * Copy vi screen.
- */
-int
-v_screen_copy(orig, sp)
- SCR *orig, *sp;
-{
- VI_PRIVATE *ovip, *nvip;
-
- /* Create the private vi structure. */
- CALLOC_RET(orig, nvip, VI_PRIVATE *, 1, sizeof(VI_PRIVATE));
- sp->vi_private = nvip;
-
- if (orig == NULL) {
- nvip->inc_lastch = '+';
- nvip->inc_lastval = 1;
- } else {
- ovip = VIP(orig);
-
- /* User can replay the last input, but nothing else. */
- if (ovip->rep_len != 0) {
- MALLOC(orig, nvip->rep, char *, ovip->rep_len);
- if (nvip->rep != NULL) {
- memmove(nvip->rep, ovip->rep, ovip->rep_len);
- nvip->rep_len = ovip->rep_len;
- }
- }
-
- nvip->inc_lastch = ovip->inc_lastch;
- nvip->inc_lastval = ovip->inc_lastval;
-
- if (ovip->paragraph != NULL &&
- (nvip->paragraph = strdup(ovip->paragraph)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- }
- return (0);
-}
-
-/*
- * v_screen_end --
- * End a vi screen.
- */
-int
-v_screen_end(sp)
- SCR *sp;
-{
- VI_PRIVATE *vip;
-
- vip = VIP(sp);
-
- if (vip->rep != NULL)
- FREE(vip->rep, vip->rep_len);
-
- if (vip->paragraph != NULL)
- FREE(vip->paragraph, vip->paragraph_len);
-
- /* Free private memory. */
- FREE(vip, sizeof(VI_PRIVATE));
- sp->vi_private = NULL;
-
- return (0);
-}
-
-/*
- * v_init --
- * Initialize vi.
- */
-int
-v_init(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- size_t len;
-
- /*
- * The default address is line 1, column 0. If the address set
- * bit is on for this file, load the address, ensuring that it
- * exists.
- */
- if (F_ISSET(sp->frp, FR_CURSORSET)) {
- sp->lno = sp->frp->lno;
- sp->cno = sp->frp->cno;
-
- if (file_gline(sp, ep, sp->lno, &len) == NULL) {
- if (sp->lno != 1 || sp->cno != 0) {
- if (file_lline(sp, ep, &sp->lno))
- return (1);
- if (sp->lno == 0)
- sp->lno = 1;
- sp->cno = 0;
- }
- } else if (sp->cno >= len)
- sp->cno = 0;
-
- } else {
- sp->lno = 1;
- sp->cno = 0;
-
- if (O_ISSET(sp, O_COMMENT) && v_comment(sp, ep))
- return (1);
- }
-
- /* Reset strange attraction. */
- sp->rcm = 0;
- sp->rcmflags = 0;
-
- /* Make ex display to a special function. */
- if ((sp->stdfp = fwopen(sp, sp->s_ex_write)) == NULL) {
- msgq(sp, M_SYSERR, "ex output");
- return (1);
- }
-#ifdef MAKE_EX_OUTPUT_LINE_BUFFERED
- (void)setvbuf(sp->stdfp, NULL, _IOLBF, 0);
-#endif
-
- /* Display the status line. */
- return (status(sp, ep, sp->lno, 0));
-}
-
-/*
- * v_end --
- * End vi session.
- */
-int
-v_end(sp)
- SCR *sp;
-{
- /* Close down ex output file descriptor. */
- (void)fclose(sp->stdfp);
-
- return (0);
-}
-
-/*
- * v_optchange --
- * Handle change of options for vi.
- */
-int
-v_optchange(sp, opt)
- SCR *sp;
- int opt;
-{
- switch (opt) {
- case O_PARAGRAPHS:
- case O_SECTIONS:
- return (v_buildparagraph(sp));
- }
- return (0);
-}
-
-/*
- * v_comment --
- * Skip the first comment.
- */
-static int
-v_comment(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- recno_t lno;
- size_t len;
- char *p;
-
- for (lno = 1;
- (p = file_gline(sp, ep, lno, &len)) != NULL && len == 0; ++lno);
- if (p == NULL || len <= 1 || memcmp(p, "/*", 2))
- return (0);
- do {
- for (; len; --len, ++p)
- if (p[0] == '*' && len > 1 && p[1] == '/') {
- sp->lno = lno;
- return (0);
- }
- } while ((p = file_gline(sp, ep, ++lno, &len)) != NULL);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_join.c b/usr.bin/vi/nvi/v_join.c
deleted file mode 100644
index c3f81d6d1a5c..000000000000
--- a/usr.bin/vi/nvi/v_join.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_join.c 8.3 (Berkeley) 8/29/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * v_join -- [count]J
- * Join lines together.
- */
-int
-v_join(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
- int lno;
-
- /*
- * YASC.
- * The general rule is that '#J' joins # lines, counting the current
- * line. However, 'J' and '1J' are the same as '2J', i.e. join the
- * current and next lines. This doesn't map well into the ex command
- * (which takes two line numbers), so we handle it here. Note that
- * we never test for EOF -- historically going past the end of file
- * worked just fine.
- */
- lno = fm->lno + 1;
- if (F_ISSET(vp, VC_C1SET) && vp->count > 2)
- lno = fm->lno + (vp->count - 1);
-
- SETCMDARG(cmd, C_JOIN, 2, fm->lno, lno, 0, NULL);
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_left.c b/usr.bin/vi/nvi/v_left.c
deleted file mode 100644
index cc80b379b06d..000000000000
--- a/usr.bin/vi/nvi/v_left.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_left.c 8.3 (Berkeley) 12/16/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_left -- [count]^H, [count]h
- * Move left by columns.
- */
-int
-v_left(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t cnt;
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- if (fm->cno == 0) {
- msgq(sp, M_BERR, "Already in the first column.");
- return (1);
- }
-
- rp->lno = fm->lno;
- if (fm->cno > cnt)
- rp->cno = fm->cno - cnt;
- else
- rp->cno = 0;
- return (0);
-}
-
-/*
- * v_cfirst -- [count]_
- *
- * Move to the first non-blank column on a line.
- */
-int
-v_cfirst(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t cnt;
-
- /*
- * A count moves down count - 1 rows, so, "3_" is the same as "2j_".
- *
- * !!!
- * Historically, if the _ is a motion, it is always a line motion,
- * and the line motion flag is set.
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if (cnt != 1) {
- --vp->count;
- if (v_down(sp, ep, vp, fm, tm, rp))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- F_SET(vp, VC_LMODE);
- } else
- rp->lno = fm->lno;
- rp->cno = 0;
- if (nonblank(sp, ep, rp->lno, &rp->cno))
- return (1);
- return (0);
-}
-
-/*
- * v_first -- ^
- * Move to the first non-blank column on this line.
- */
-int
-v_first(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * Yielding to none in our quest for compatibility with every
- * historical blemish of vi, no matter how strange it might be,
- * we permit the user to enter a count and then ignore it.
- */
- rp->cno = 0;
- if (nonblank(sp, ep, fm->lno, &rp->cno))
- return (1);
- rp->lno = fm->lno;
- return (0);
-}
-
-/*
- * v_ncol -- [count]|
- * Move to column count or the first column on this line. If the
- * requested column is past EOL, move to EOL. The nasty part is
- * that we have to know character column widths to make this work.
- */
-int
-v_ncol(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- if (F_ISSET(vp, VC_C1SET) && vp->count > 1)
- rp->cno =
- sp->s_chposition(sp, ep, fm->lno, (size_t)--vp->count);
- else
- rp->cno = 0;
- rp->lno = fm->lno;
- return (0);
-}
-
-/*
- * v_zero -- 0
- * Move to the first column on this line.
- */
-int
-v_zero(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- rp->lno = fm->lno;
- rp->cno = 0;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_mark.c b/usr.bin/vi/nvi/v_mark.c
deleted file mode 100644
index 714242d9331e..000000000000
--- a/usr.bin/vi/nvi/v_mark.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_mark.c 8.3 (Berkeley) 10/31/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_mark -- m[a-z]
- * Set a mark.
- */
-int
-v_mark(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- rp->lno = fm->lno;
- rp->cno = fm->cno;
- return (mark_set(sp, ep, vp->character, fm, 1));
-}
-
-/*
- * v_gomark -- '['`a-z], or `['`a-z]
- * Move to a mark.
- *
- * The single quote form moves to the first nonblank character of a line
- * containing a mark. The back quote form moves to a mark, setting both
- * row and column. We use a single routine for both forms, taking care
- * of the nonblank behavior using a flag for the command.
- *
- * Although not commonly known, the "'`" and "'`" forms are historically
- * valid. The behavior is determined by the first character, so "`'" is
- * the same as "``". Remember this fact -- you'll be amazed at how many
- * people don't know it and will be delighted that you are able to tell
- * them.
- */
-int
-v_gomark(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- MARK *mp;
-
- if ((mp = mark_get(sp, ep, vp->character)) == NULL)
- return (1);
- *rp = *mp;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_match.c b/usr.bin/vi/nvi/v_match.c
deleted file mode 100644
index 963cca551fe8..000000000000
--- a/usr.bin/vi/nvi/v_match.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_match.c 8.7 (Berkeley) 12/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_match -- %
- * Search to matching character.
- */
-int
-v_match(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- register int cnt, matchc, startc;
- VCS cs;
- recno_t lno;
- size_t len, off;
- int (*gc)__P((SCR *, EXF *, VCS *));
- char *p;
-
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- goto nomatch;
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- /*
- * !!!
- * Historical practice was to search in the forward direction only.
- */
- for (off = fm->cno;; ++off) {
- if (off >= len) {
-nomatch: msgq(sp, M_BERR, "No match character on this line.");
- return (1);
- }
- switch (startc = p[off]) {
- case '(':
- matchc = ')';
- gc = cs_next;
- break;
- case ')':
- matchc = '(';
- gc = cs_prev;
- break;
- case '[':
- matchc = ']';
- gc = cs_next;
- break;
- case ']':
- matchc = '[';
- gc = cs_prev;
- break;
- case '{':
- matchc = '}';
- gc = cs_next;
- break;
- case '}':
- matchc = '{';
- gc = cs_prev;
- break;
- default:
- continue;
- }
- break;
- }
-
- cs.cs_lno = fm->lno;
- cs.cs_cno = off;
- if (cs_init(sp, ep, &cs))
- return (1);
- for (cnt = 1;;) {
- if (gc(sp, ep, &cs))
- return (1);
- if (cs.cs_flags != 0) {
- if (cs.cs_flags == CS_EOF || cs.cs_flags == CS_SOF)
- break;
- continue;
- }
- if (cs.cs_ch == startc)
- ++cnt;
- else if (cs.cs_ch == matchc && --cnt == 0)
- break;
- }
- if (cnt) {
- msgq(sp, M_BERR, "Matching character not found.");
- return (1);
- }
- rp->lno = cs.cs_lno;
- rp->cno = cs.cs_cno;
-
- /*
- * Movement commands go one space further. Increment the return
- * MARK or from MARK depending on the direction of the search.
- */
- if (F_ISSET(vp, VC_C | VC_D | VC_Y)) {
- if (file_gline(sp, ep, rp->lno, &len) == NULL) {
- GETLINE_ERR(sp, rp->lno);
- return (1);
- }
- if (len)
- if (gc == cs_next)
- ++rp->cno;
- else
- ++fm->cno;
- }
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_ntext.c b/usr.bin/vi/nvi/v_ntext.c
deleted file mode 100644
index 1c17ffc5bdd0..000000000000
--- a/usr.bin/vi/nvi/v_ntext.c
+++ /dev/null
@@ -1,1728 +0,0 @@
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_ntext.c 8.80 (Berkeley) 1/13/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "vi.h"
-#include "seq.h"
-#include "vcmd.h"
-#include "excmd.h"
-
-static int txt_abbrev __P((SCR *, TEXT *, ARG_CHAR_T, int, int *, int *));
-static void txt_ai_resolve __P((SCR *, TEXT *));
-static TEXT *txt_backup __P((SCR *, EXF *, TEXTH *, TEXT *, u_int));
-static void txt_err __P((SCR *, EXF *, TEXTH *));
-static int txt_hex __P((SCR *, TEXT *, int *, ARG_CHAR_T));
-static int txt_indent __P((SCR *, TEXT *));
-static int txt_margin __P((SCR *, TEXT *, int *, ARG_CHAR_T));
-static int txt_outdent __P((SCR *, TEXT *));
-static void txt_showmatch __P((SCR *, EXF *));
-static int txt_resolve __P((SCR *, EXF *, TEXTH *));
-
-/* Cursor character (space is hard to track on the screen). */
-#if defined(DEBUG) && 0
-#undef CURSOR_CH
-#define CURSOR_CH '+'
-#endif
-
-/* Local version of BINC. */
-#define TBINC(sp, lp, llen, nlen) { \
- if ((nlen) > llen && binc(sp, &(lp), &(llen), nlen)) \
- goto err; \
-}
-
-/*
- * newtext --
- * Read in text from the user.
- *
- * !!!
- * Historic vi always used:
- *
- * ^D: autoindent deletion
- * ^H: last character deletion
- * ^W: last word deletion
- * ^V: quote the next character
- *
- * regardless of the user's choices for these characters. The user's erase
- * and kill characters worked in addition to these characters. Ex was not
- * completely consistent with this, as it did map the scroll command to the
- * user's EOF character.
- *
- * This implementation does not use fixed characters, but uses whatever the
- * user specified as described by the termios structure. I'm getting away
- * with something here, but I think I'm unlikely to get caught.
- *
- * !!!
- * Historic vi did a special screen optimization for tab characters. For
- * the keystrokes "iabcd<esc>0C<tab>", the tab would overwrite the rest of
- * the string when it was displayed. Because this implementation redisplays
- * the entire line on each keystroke, the "bcd" gets pushed to the right as
- * we ignore that the user has "promised" to change the rest of the characters.
- * Users have noticed, but this isn't worth fixing, and, the way that the
- * historic vi did it results in an even worse bug. Given the keystrokes
- * "iabcd<esc>0R<tab><esc>", the "bcd" disappears, and magically reappears
- * on the second <esc> key.
- */
-int
-v_ntext(sp, ep, tiqh, tm, lp, len, rp, prompt, ai_line, flags)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
- MARK *tm; /* To MARK. */
- const char *lp; /* Input line. */
- const size_t len; /* Input line length. */
- MARK *rp; /* Return MARK. */
- int prompt; /* Prompt to display. */
- recno_t ai_line; /* Line number to use for autoindent count. */
- u_int flags; /* TXT_ flags. */
-{
- /* State of abbreviation checks. */
- enum { A_NOTSET, A_SPACE, A_NOTSPACE } abb;
- /* State of the "[^0]^D" sequences. */
- enum { C_NOTSET, C_CARATSET, C_NOCHANGE, C_ZEROSET } carat_st;
- /* State of the hex input character. */
- enum { H_NOTSET, H_NEXTCHAR, H_INHEX } hex;
- /* State of quotation. */
- enum { Q_NOTSET, Q_NEXTCHAR, Q_THISCHAR } quoted;
- CH ikey; /* Input character structure. */
- CHAR_T ch; /* Input character. */
- GS *gp; /* Global pointer. */
- TEXT *tp, *ntp, ait; /* Input and autoindent text structures. */
- size_t rcol; /* 0-N: insert offset in the replay buffer. */
- size_t col; /* Current column. */
- u_long margin; /* Wrapmargin value. */
- u_int iflags; /* Input flags. */
- int ab_cnt, ab_turnoff; /* Abbreviation count, if turned off. */
- int eval; /* Routine return value. */
- int replay; /* If replaying a set of input. */
- int showmatch; /* Showmatch set on this character. */
- int testnr; /* Test first character for nul replay. */
- int max, tmp;
- char *p;
-
- /*
- * Set the input flag, so tabs get displayed correctly
- * and everyone knows that the text buffer is in use.
- */
- F_SET(sp, S_INPUT);
-
- /* Local initialization. */
- eval = 0;
- gp = sp->gp;
-
- /*
- * Get one TEXT structure with some initial buffer space, reusing
- * the last one if it's big enough. (All TEXT bookkeeping fields
- * default to 0 -- text_init() handles this.) If changing a line,
- * copy it into the TEXT buffer.
- */
- if (tiqh->cqh_first != (void *)tiqh) {
- tp = tiqh->cqh_first;
- if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < len + 32) {
- text_lfree(tiqh);
- goto newtp;
- }
- tp->ai = tp->insert = tp->offset = tp->owrite = 0;
- if (lp != NULL) {
- tp->len = len;
- memmove(tp->lb, lp, len);
- } else
- tp->len = 0;
- } else {
-newtp: if ((tp = text_init(sp, lp, len, len + 32)) == NULL)
- return (1);
- CIRCLEQ_INSERT_HEAD(tiqh, tp, q);
- }
-
- /* Set the starting line number. */
- tp->lno = sp->lno;
-
- /*
- * Set the insert and overwrite counts. If overwriting characters,
- * do insertion afterward. If not overwriting characters, assume
- * doing insertion. If change is to a mark, emphasize it with an
- * END_CH.
- */
- if (len) {
- if (LF_ISSET(TXT_OVERWRITE)) {
- tp->owrite = tm->cno - sp->cno;
- tp->insert = len - tm->cno;
- } else
- tp->insert = len - sp->cno;
-
- if (LF_ISSET(TXT_EMARK))
- tp->lb[tm->cno - 1] = END_CH;
- }
-
- /*
- * Many of the special cases in this routine are to handle autoindent
- * support. Somebody decided that it would be a good idea if "^^D"
- * and "0^D" deleted all of the autoindented characters. In an editor
- * that takes single character input from the user, this wasn't a very
- * good idea. Note also that "^^D" resets the next lines' autoindent,
- * but "0^D" doesn't.
- *
- * We assume that autoindent only happens on empty lines, so insert
- * and overwrite will be zero. If doing autoindent, figure out how
- * much indentation we need and fill it in. Update input column and
- * screen cursor as necessary.
- */
- if (LF_ISSET(TXT_AUTOINDENT) && ai_line != OOBLNO) {
- if (txt_auto(sp, ep, ai_line, NULL, 0, tp))
- return (1);
- sp->cno = tp->ai;
- } else {
- /*
- * The cc and S commands have a special feature -- leading
- * <blank> characters are handled as autoindent characters.
- * Beauty!
- */
- if (LF_ISSET(TXT_AICHARS)) {
- tp->offset = 0;
- tp->ai = sp->cno;
- } else
- tp->offset = sp->cno;
- }
-
- /* If getting a command buffer from the user, there may be a prompt. */
- if (LF_ISSET(TXT_PROMPT)) {
- tp->lb[sp->cno++] = prompt;
- ++tp->len;
- ++tp->offset;
- }
-
- /*
- * If appending after the end-of-line, add a space into the buffer
- * and move the cursor right. This space is inserted, i.e. pushed
- * along, and then deleted when the line is resolved. Assumes that
- * the cursor is already positioned at the end of the line. This
- * avoids the nastiness of having the cursor reside on a magical
- * column, i.e. a column that doesn't really exist. The only down
- * side is that we may wrap lines or scroll the screen before it's
- * strictly necessary. Not a big deal.
- */
- if (LF_ISSET(TXT_APPENDEOL)) {
- tp->lb[sp->cno] = CURSOR_CH;
- ++tp->len;
- ++tp->insert;
- }
-
- /*
- * Historic practice is that the wrapmargin value was a distance
- * from the RIGHT-HAND column, not the left. It's more useful to
- * us as a distance from the left-hand column.
- *
- * !!!
- * Replay commands are not affected by wrapmargin values. What
- * I found surprising was that people actually depend on it, as
- * in this gem of a macro which centers lines:
- *
- * map #c $mq81a ^V^[81^V|D`qld0:s/ / /g^V^M$p
- *
- * XXX
- * Setting margin causes a significant performance hit. Normally
- * we don't update the screen if there are keys waiting, but we
- * have to if margin is set, otherwise the screen routines don't
- * know where the cursor is.
- */
- if (LF_ISSET(TXT_REPLAY) || !LF_ISSET(TXT_WRAPMARGIN))
- margin = 0;
- else if ((margin = O_VAL(sp, O_WRAPMARGIN)) != 0)
- margin = sp->cols - margin;
-
- /* Initialize abbreviations checks. */
- if (F_ISSET(gp, G_ABBREV) && LF_ISSET(TXT_MAPINPUT)) {
- abb = A_NOTSPACE;
- ab_cnt = ab_turnoff = 0;
- } else
- abb = A_NOTSET;
-
- /*
- * Set up the dot command. Dot commands are done by saving the
- * actual characters and replaying the input. We have to push
- * the characters onto the key stack and then handle them normally,
- * otherwise things like wrapmargin will fail.
- *
- * XXX
- * It would be nice if we could swallow backspaces and such, but
- * it's not all that easy to do. Another possibility would be to
- * recognize full line insertions, which could be performed quickly,
- * without replay.
- */
-nullreplay:
- rcol = 0;
- if (replay = LF_ISSET(TXT_REPLAY)) {
- /*
- * !!!
- * Historically, it wasn't an error to replay non-existent
- * input. This test is necessary, we get here by the user
- * doing an input command followed by a nul.
- *
- * !!!
- * Historically, vi did not remap or reabbreviate replayed
- * input. It did, however, beep at you if you changed an
- * abbreviation and then replayed the input. We're not that
- * compatible.
- */
- if (VIP(sp)->rep == NULL)
- return (0);
- if (term_push(sp, VIP(sp)->rep, VIP(sp)->rep_cnt, 0, CH_NOMAP))
- return (1);
- testnr = 0;
- abb = A_NOTSET;
- LF_CLR(TXT_RECORD);
- } else
- testnr = 1;
-
- iflags = LF_ISSET(TXT_MAPCOMMAND | TXT_MAPINPUT);
- for (gp, showmatch = 0,
- carat_st = C_NOTSET, hex = H_NOTSET, quoted = Q_NOTSET;;) {
- /*
- * Reset the line and update the screen. (The txt_showmatch()
- * code refreshes the screen for us.) Don't refresh unless
- * we're about to wait on a character or we need to know where
- * the cursor really is.
- */
- if (showmatch || margin || !KEYS_WAITING(sp)) {
- if (sp->s_change(sp, ep, tp->lno, LINE_RESET))
- goto err;
- if (showmatch) {
- showmatch = 0;
- txt_showmatch(sp, ep);
- } else if (sp->s_refresh(sp, ep))
- goto err;
- }
-
- /* Get the next character. */
-next_ch: if (term_key(sp, &ikey, iflags) != INP_OK)
- goto err;
- ch = ikey.ch;
-
- /* Abbreviation check. See comment in txt_abbrev(). */
-#define MAX_ABBREVIATION_EXPANSION 256
- if (ikey.flags & CH_ABBREVIATED) {
- if (++ab_cnt > MAX_ABBREVIATION_EXPANSION) {
- term_ab_flush(sp,
- "Abbreviation exceeded maximum number of characters");
- ab_cnt = 0;
- continue;
- }
- } else
- ab_cnt = 0;
-
- /*
- * !!!
- * Historic feature. If the first character of the input is
- * a nul, replay the previous input. This isn't documented
- * anywhere, and is a great test of vi clones.
- */
- if (ch == '\0' && testnr) {
- LF_SET(TXT_REPLAY);
- goto nullreplay;
- }
- testnr = 0;
-
- /*
- * Check to see if the character fits into the input (and
- * replay, if necessary) buffers. It isn't necessary to
- * have tp->len bytes, since it doesn't consider overwrite
- * characters, but not worth fixing.
- */
- if (LF_ISSET(TXT_RECORD)) {
- TBINC(sp, VIP(sp)->rep, VIP(sp)->rep_len, rcol + 1);
- VIP(sp)->rep[rcol++] = ch;
- }
- TBINC(sp, tp->lb, tp->lb_len, tp->len + 1);
-
- /*
- * If the character was quoted, replace the last character
- * (the literal mark) with the new character. If quoted
- * by someone else, simply insert the character.
- *
- * !!!
- * Extension -- if the quoted character is HEX_CH, enter hex
- * mode. If the user enters "<HEX_CH>[isxdigit()]*" we will
- * try to use the value as a character. Anything else resets
- * hex mode.
- */
- if (ikey.flags & CH_QUOTED)
- goto ins_ch;
- if (quoted == Q_THISCHAR) {
- --sp->cno;
- ++tp->owrite;
- quoted = Q_NOTSET;
-
- if (ch == HEX_CH)
- hex = H_NEXTCHAR;
- goto ins_ch;
- }
-
- switch (ikey.value) {
- case K_CR:
- case K_NL: /* New line. */
-#define LINE_RESOLVE { \
- /* \
- * Handle abbreviations. If there was one, \
- * discard the replay characters. \
- */ \
- if (abb == A_NOTSPACE && !replay) { \
- if (txt_abbrev(sp, tp, ch, \
- LF_ISSET(TXT_INFOLINE), &tmp, \
- &ab_turnoff)) \
- goto err; \
- if (tmp) { \
- if (LF_ISSET(TXT_RECORD)) \
- rcol -= tmp; \
- goto next_ch; \
- } \
- } \
- if (abb != A_NOTSET) \
- abb = A_SPACE; \
- /* Handle hex numbers. */ \
- if (hex == H_INHEX) { \
- if (txt_hex(sp, tp, &tmp, ch)) \
- goto err; \
- if (tmp) { \
- hex = H_NOTSET; \
- goto next_ch; \
- } \
- } \
- /* \
- * The 'R' command returns any overwriteable \
- * characters in the first line to the original \
- * characters.
- */ \
- if (LF_ISSET(TXT_REPLACE) && tp->owrite && \
- tp == tiqh->cqh_first) { \
- memmove(tp->lb + sp->cno, \
- lp + sp->cno, tp->owrite); \
- tp->insert += tp->owrite; \
- tp->owrite = 0; \
- } \
- /* Delete any appended cursor. */ \
- if (LF_ISSET(TXT_APPENDEOL)) { \
- --tp->len; \
- --tp->insert; \
- } \
-}
- LINE_RESOLVE;
-
- /* CR returns from the vi command line. */
- if (LF_ISSET(TXT_CR)) {
- /*
- * If a script window and not the colon
- * line, push a <cr> so it gets executed.
- */
- if (F_ISSET(sp, S_SCRIPT) &&
- !LF_ISSET(TXT_INFOLINE))
- (void)term_push(sp,
- "\r", 1, 0, CH_NOMAP);
- goto k_escape;
- }
-
- /*
- * Historic practice was to delete any <blank>
- * characters following the inserted newline.
- * This affects the 'R', 'c', and 's' commands.
- */
- for (p = tp->lb + sp->cno + tp->owrite;
- tp->insert && isblank(*p);
- ++p, ++tp->owrite, --tp->insert);
-
- /*
- * Move any remaining insert characters into
- * a new TEXT structure.
- */
- if ((ntp = text_init(sp,
- tp->lb + sp->cno + tp->owrite,
- tp->insert, tp->insert + 32)) == NULL)
- goto err;
-
- /* Set bookkeeping for the new line. */
- ntp->lno = tp->lno + 1;
- ntp->insert = tp->insert;
-
- /*
- * Note if the user inserted any characters on this
- * line. Done before calling txt_ai_resolve() because
- * it changes the value of sp->cno without making the
- * corresponding changes to tp->ai.
- */
- tmp = sp->cno <= tp->ai;
-
- /*
- * Resolve autoindented characters for the old line.
- * Reset the autoindent line value. 0^D keeps the ai
- * line from changing, ^D changes the level, even if
- * there are no characters in the old line. Note,
- * if using the current tp structure, use the cursor
- * as the length, the user may have erased autoindent
- * characters.
- */
- if (LF_ISSET(TXT_AUTOINDENT)) {
- txt_ai_resolve(sp, tp);
-
- if (carat_st == C_NOCHANGE) {
- if (txt_auto(sp, ep,
- OOBLNO, &ait, ait.ai, ntp))
- goto err;
- FREE_SPACE(sp, ait.lb, ait.lb_len);
- } else
- if (txt_auto(sp, ep,
- OOBLNO, tp, sp->cno, ntp))
- goto err;
- carat_st = C_NOTSET;
- }
-
- /*
- * If the user hasn't entered any characters, delete
- * any autoindent characters.
- *
- * !!!
- * Historic vi didn't get the insert test right, if
- * there were characters after the cursor, entering
- * a <cr> left the autoindent characters on the line.
- */
- if (tmp)
- sp->cno = 0;
-
- /* Reset bookkeeping for the old line. */
- tp->len = sp->cno;
- tp->ai = tp->insert = tp->owrite = 0;
-
- /* New cursor position. */
- sp->cno = ntp->ai;
-
- /* New lines are TXT_APPENDEOL if nothing to insert. */
- if (ntp->insert == 0) {
- TBINC(sp, tp->lb, tp->lb_len, tp->len + 1);
- LF_SET(TXT_APPENDEOL);
- ntp->lb[sp->cno] = CURSOR_CH;
- ++ntp->insert;
- ++ntp->len;
- }
-
- /* Update the old line. */
- if (sp->s_change(sp, ep, tp->lno, LINE_RESET))
- goto err;
-
- /*
- * Swap old and new TEXT's, and insert the new TEXT
- * into the queue. (DON'T insert until the old line
- * has been updated, or the inserted line count in
- * line.c:file_gline() will be wrong.)
- */
- tp = ntp;
- CIRCLEQ_INSERT_TAIL(tiqh, tp, q);
-
- /* Reset the cursor. */
- sp->lno = tp->lno;
-
- /* Update the new line. */
- if (sp->s_change(sp, ep, tp->lno, LINE_INSERT))
- goto err;
-
- /* Set the renumber bit. */
- F_SET(sp, S_RENUMBER);
-
- /* Refresh if nothing waiting. */
- if ((margin || !KEYS_WAITING(sp)) &&
- sp->s_refresh(sp, ep))
- goto err;
- goto next_ch;
- case K_ESCAPE: /* Escape. */
- if (!LF_ISSET(TXT_ESCAPE))
- goto ins_ch;
-
- LINE_RESOLVE;
-
- /*
- * If there aren't any trailing characters in the line
- * and the user hasn't entered any characters, delete
- * the autoindent characters.
- */
- if (!tp->insert && sp->cno <= tp->ai) {
- tp->len = tp->owrite = 0;
- sp->cno = 0;
- } else if (LF_ISSET(TXT_AUTOINDENT))
- txt_ai_resolve(sp, tp);
-
- /* If there are insert characters, copy them down. */
-k_escape: if (tp->insert && tp->owrite)
- memmove(tp->lb + sp->cno,
- tp->lb + sp->cno + tp->owrite, tp->insert);
- tp->len -= tp->owrite;
-
- /*
- * Delete any lines that were inserted into the text
- * structure and then erased.
- */
- while (tp->q.cqe_next != (void *)tiqh) {
- ntp = tp->q.cqe_next;
- CIRCLEQ_REMOVE(tiqh, ntp, q);
- text_free(ntp);
- }
-
- /*
- * If not resolving the lines into the file, end
- * it with a nul.
- *
- * XXX
- * This is wrong, should pass back a length.
- */
- if (LF_ISSET(TXT_RESOLVE)) {
- if (txt_resolve(sp, ep, tiqh))
- goto err;
- /*
- * Clear input flag -- input buffer no longer
- * valid.
- */
- F_CLR(sp, S_INPUT);
- } else {
- TBINC(sp, tp->lb, tp->lb_len, tp->len + 1);
- tp->lb[tp->len] = '\0';
- }
-
- /*
- * Set the return cursor position to rest on the last
- * inserted character.
- */
- if (rp != NULL) {
- rp->lno = tp->lno;
- rp->cno = sp->cno ? sp->cno - 1 : 0;
- if (sp->s_change(sp, ep, rp->lno, LINE_RESET))
- goto err;
- }
- goto ret;
- case K_CARAT: /* Delete autoindent chars. */
- if (LF_ISSET(TXT_AUTOINDENT) && sp->cno <= tp->ai)
- carat_st = C_CARATSET;
- goto ins_ch;
- case K_ZERO: /* Delete autoindent chars. */
- if (LF_ISSET(TXT_AUTOINDENT) && sp->cno <= tp->ai)
- carat_st = C_ZEROSET;
- goto ins_ch;
- case K_VEOF: /* Delete autoindent char. */
- /*
- * If in the first column or no characters to erase,
- * ignore the ^D (this matches historic practice). If
- * not doing autoindent or already inserted non-ai
- * characters, it's a literal. The latter test is done
- * in the switch, as the CARAT forms are N + 1, not N.
- */
- if (!LF_ISSET(TXT_AUTOINDENT))
- goto ins_ch;
- if (sp->cno == 0 || tp->ai == 0)
- break;
- switch (carat_st) {
- case C_CARATSET: /* ^^D */
- if (sp->cno > tp->ai + tp->offset + 1)
- goto ins_ch;
-
- /* Save the ai string for later. */
- ait.lb = NULL;
- ait.lb_len = 0;
- TBINC(sp, ait.lb, ait.lb_len, tp->ai);
- memmove(ait.lb, tp->lb, tp->ai);
- ait.ai = ait.len = tp->ai;
-
- carat_st = C_NOCHANGE;
- goto leftmargin;
- case C_ZEROSET: /* 0^D */
- if (sp->cno > tp->ai + tp->offset + 1)
- goto ins_ch;
- carat_st = C_NOTSET;
-leftmargin: tp->lb[sp->cno - 1] = ' ';
- tp->owrite += sp->cno - tp->offset;
- tp->ai = 0;
- sp->cno = tp->offset;
- break;
- case C_NOTSET: /* ^D */
- if (sp->cno > tp->ai + tp->offset)
- goto ins_ch;
- (void)txt_outdent(sp, tp);
- break;
- default:
- abort();
- }
- break;
- case K_VERASE: /* Erase the last character. */
- /*
- * If can erase over the prompt, return. Len is 0
- * if backspaced over the prompt, 1 if only CR entered.
- */
- if (LF_ISSET(TXT_BS) && sp->cno <= tp->offset) {
- tp->len = 0;
- goto ret;
- }
-
- /*
- * If at the beginning of the line, try and drop back
- * to a previously inserted line.
- */
- if (sp->cno == 0) {
- if ((ntp = txt_backup(sp,
- ep, tiqh, tp, flags)) == NULL)
- goto err;
- tp = ntp;
- break;
- }
-
- /* If nothing to erase, bell the user. */
- if (sp->cno <= tp->offset) {
- msgq(sp, M_BERR,
- "No more characters to erase.");
- break;
- }
-
- /* Drop back one character. */
- --sp->cno;
-
- /*
- * Increment overwrite, decrement ai if deleted.
- *
- * !!!
- * Historic vi did not permit users to use erase
- * characters to delete autoindent characters.
- */
- ++tp->owrite;
- if (sp->cno < tp->ai)
- --tp->ai;
- break;
- case K_VINTR:
- /*
- * !!!
- * Historically, <interrupt> exited the user from
- * editing the infoline, and returned to the main
- * screen. It also beeped the terminal, but that
- * seems excessive.
- */
- if (LF_ISSET(TXT_INFOLINE)) {
- tp->lb[tp->len = 0] = '\0';
- goto ret;
- }
- goto ins_ch;
- case K_VWERASE: /* Skip back one word. */
- /*
- * If at the beginning of the line, try and drop back
- * to a previously inserted line.
- */
- if (sp->cno == 0) {
- if ((ntp = txt_backup(sp,
- ep, tiqh, tp, flags)) == NULL)
- goto err;
- tp = ntp;
- }
-
- /*
- * If at offset, nothing to erase so bell the user.
- */
- if (sp->cno <= tp->offset) {
- msgq(sp, M_BERR,
- "No more characters to erase.");
- break;
- }
-
- /*
- * First werase goes back to any autoindent
- * and second werase goes back to the offset.
- *
- * !!!
- * Historic vi did not permit users to use erase
- * characters to delete autoindent characters.
- */
- if (tp->ai && sp->cno > tp->ai)
- max = tp->ai;
- else {
- tp->ai = 0;
- max = tp->offset;
- }
-
- /* Skip over trailing space characters. */
- while (sp->cno > max && isblank(tp->lb[sp->cno - 1])) {
- --sp->cno;
- ++tp->owrite;
- }
- if (sp->cno == max)
- break;
- /*
- * There are three types of word erase found on UNIX
- * systems. They can be identified by how the string
- * /a/b/c is treated -- as 1, 3, or 6 words. Historic
- * vi had two classes of characters, and strings were
- * delimited by them and <blank>'s, so, 6 words. The
- * historic tty interface used <blank>'s to delimit
- * strings, so, 1 word. The algorithm offered in the
- * 4.4BSD tty interface (as stty altwerase) treats it
- * as 3 words -- there are two classes of characters,
- * and strings are delimited by them and <blank>'s.
- * The difference is that the type of the first erased
- * character erased is ignored, which is exactly right
- * when erasing pathname components. Here, the options
- * TXT_ALTWERASE and TXT_TTYWERASE specify the 4.4BSD
- * tty interface and the historic tty driver behavior,
- * respectively, and the default is the same as the
- * historic vi behavior.
- */
- if (LF_ISSET(TXT_TTYWERASE))
- while (sp->cno > max) {
- --sp->cno;
- ++tp->owrite;
- if (isblank(tp->lb[sp->cno - 1]))
- break;
- }
- else {
- if (LF_ISSET(TXT_ALTWERASE)) {
- --sp->cno;
- ++tp->owrite;
- if (isblank(tp->lb[sp->cno - 1]))
- break;
- }
- if (sp->cno > max)
- tmp = inword(tp->lb[sp->cno - 1]);
- while (sp->cno > max) {
- --sp->cno;
- ++tp->owrite;
- if (tmp != inword(tp->lb[sp->cno - 1])
- || isblank(tp->lb[sp->cno - 1]))
- break;
- }
- }
- break;
- case K_VKILL: /* Restart this line. */
- /*
- * If at the beginning of the line, try and drop back
- * to a previously inserted line.
- */
- if (sp->cno == 0) {
- if ((ntp = txt_backup(sp,
- ep, tiqh, tp, flags)) == NULL)
- goto err;
- tp = ntp;
- }
-
- /* If at offset, nothing to erase so bell the user. */
- if (sp->cno <= tp->offset) {
- msgq(sp, M_BERR,
- "No more characters to erase.");
- break;
- }
-
- /*
- * First kill goes back to any autoindent
- * and second kill goes back to the offset.
- *
- * !!!
- * Historic vi did not permit users to use erase
- * characters to delete autoindent characters.
- */
- if (tp->ai && sp->cno > tp->ai)
- max = tp->ai;
- else {
- tp->ai = 0;
- max = tp->offset;
- }
- tp->owrite += sp->cno - max;
- sp->cno = max;
- break;
- case K_CNTRLT: /* Add autoindent char. */
- if (!LF_ISSET(TXT_CNTRLT))
- goto ins_ch;
- if (txt_indent(sp, tp))
- goto err;
- goto ebuf_chk;
- case K_CNTRLZ:
- (void)sp->s_suspend(sp);
- break;
-#ifdef HISTORIC_PRACTICE_IS_TO_INSERT_NOT_REPAINT
- case K_FORMFEED:
- F_SET(sp, S_REFRESH);
- break;
-#endif
- case K_RIGHTBRACE:
- case K_RIGHTPAREN:
- showmatch = LF_ISSET(TXT_SHOWMATCH);
- goto ins_ch;
- case K_VLNEXT: /* Quote the next character. */
- /* If in hex mode, see if we've entered a hex value. */
- if (hex == H_INHEX) {
- if (txt_hex(sp, tp, &tmp, ch))
- goto err;
- if (tmp) {
- hex = H_NOTSET;
- goto next_ch;
- }
- }
- ch = '^';
- quoted = Q_NEXTCHAR;
- /* FALLTHROUGH */
- default: /* Insert the character. */
-ins_ch: /*
- * If entering a space character after a word, check
- * for abbreviations. If there was one, discard the
- * replay characters.
- */
- if (isblank(ch) && abb == A_NOTSPACE && !replay) {
- if (txt_abbrev(sp, tp, ch,
- LF_ISSET(TXT_INFOLINE), &tmp, &ab_turnoff))
- goto err;
- if (tmp) {
- if (LF_ISSET(TXT_RECORD))
- rcol -= tmp;
- goto next_ch;
- }
- }
- /* If in hex mode, see if we've entered a hex value. */
- if (hex == H_INHEX && !isxdigit(ch)) {
- if (txt_hex(sp, tp, &tmp, ch))
- goto err;
- if (tmp) {
- hex = H_NOTSET;
- goto next_ch;
- }
- }
- /* Check to see if we've crossed the margin. */
- if (margin) {
- if (sp->s_column(sp, ep, &col))
- goto err;
- if (col >= margin) {
- if (txt_margin(sp, tp, &tmp, ch))
- goto err;
- if (tmp)
- goto next_ch;
- }
- }
- if (abb != A_NOTSET)
- abb = isblank(ch) ? A_SPACE : A_NOTSPACE;
-
- if (tp->owrite) /* Overwrite a character. */
- --tp->owrite;
- else if (tp->insert) { /* Insert a character. */
- ++tp->len;
- if (tp->insert == 1)
- tp->lb[sp->cno + 1] = tp->lb[sp->cno];
- else
- memmove(tp->lb + sp->cno + 1,
- tp->lb + sp->cno, tp->insert);
- }
-
- tp->lb[sp->cno++] = ch;
-
- /*
- * If we've reached the end of the buffer, then we
- * need to switch into insert mode. This happens
- * when there's a change to a mark and the user puts
- * in more characters than the length of the motion.
- */
-ebuf_chk: if (sp->cno >= tp->len) {
- TBINC(sp, tp->lb, tp->lb_len, tp->len + 1);
- LF_SET(TXT_APPENDEOL);
- tp->lb[sp->cno] = CURSOR_CH;
- ++tp->insert;
- ++tp->len;
- }
-
- if (hex == H_NEXTCHAR)
- hex = H_INHEX;
- if (quoted == Q_NEXTCHAR)
- quoted = Q_THISCHAR;
- break;
- }
-#if defined(DEBUG) && 1
- if (sp->cno + tp->insert + tp->owrite != tp->len)
- msgq(sp, M_ERR,
- "len %u != cno: %u ai: %u insert %u overwrite %u",
- tp->len, sp->cno, tp->ai, tp->insert, tp->owrite);
- tp->len = sp->cno + tp->insert + tp->owrite;
-#endif
- }
-
- /* Clear input flag. */
-ret: F_CLR(sp, S_INPUT);
-
- if (LF_ISSET(TXT_RECORD))
- VIP(sp)->rep_cnt = rcol;
- return (eval);
-
- /* Error jump. */
-err: eval = 1;
- txt_err(sp, ep, tiqh);
- goto ret;
-}
-
-/*
- * txt_abbrev --
- * Handle abbreviations.
- */
-static int
-txt_abbrev(sp, tp, pushc, isinfoline, didsubp, turnoffp)
- SCR *sp;
- TEXT *tp;
- ARG_CHAR_T pushc;
- int isinfoline, *didsubp, *turnoffp;
-{
- CHAR_T ch;
- SEQ *qp;
- size_t len, off;
- char *p;
-
- /* Find the beginning of this "word". */
- for (off = sp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
- if (isblank(*p)) {
- ++p;
- break;
- }
- ++len;
- if (off == tp->ai || off == tp->offset)
- break;
- }
-
- /*
- * !!!
- * Historic vi exploded abbreviations on the command line. This has
- * obvious problems in that unabbreviating the string can be extremely
- * tricky, particularly if the string has, say, an embedded escape
- * character. Personally, I think it's a stunningly bad idea. Other
- * examples of problems this caused in historic vi are:
- * :ab foo bar
- * :ab foo baz
- * results in "bar" being abbreviated to "baz", which wasn't what the
- * user had in mind at all. Also, the commands:
- * :ab foo bar
- * :unab foo<space>
- * resulted in an error message that "bar" wasn't mapped. Finally,
- * since the string was already exploded by the time the unabbreviate
- * command got it, all it knew was that an abbreviation had occurred.
- * Cleverly, it checked the replacement string for its unabbreviation
- * match, which meant that the commands:
- * :ab foo1 bar
- * :ab foo2 bar
- * :unab foo2
- * unabbreviates "foo1", and the commands:
- * :ab foo bar
- * :ab bar baz
- * unabbreviates "foo"!
- *
- * Anyway, people neglected to first ask my opinion before they wrote
- * macros that depend on this stuff, so, we make this work as follows.
- * When checking for an abbreviation on the command line, if we get a
- * string which is <blank> terminated and which starts at the beginning
- * of the line, we check to see it is the abbreviate or unabbreviate
- * commands. If it is, turn abbreviations off and return as if no
- * abbreviation was found. Not also, minor trickiness, so that if the
- * user erases the line and starts another command, we go ahead an turn
- * abbreviations back on.
- *
- * This makes the layering look like a Nachos Supreme.
- */
- *didsubp = 0;
- if (isinfoline)
- if (off == tp->ai || off == tp->offset)
- if (ex_is_abbrev(p, len)) {
- *turnoffp = 1;
- return (0);
- } else
- *turnoffp = 0;
- else
- if (*turnoffp)
- return (0);
-
- /* Check for any abbreviations. */
- if ((qp = seq_find(sp, NULL, p, len, SEQ_ABBREV, NULL)) == NULL)
- return (0);
-
- /*
- * Push the abbreviation onto the tty stack. Historically, characters
- * resulting from an abbreviation expansion were themselves subject to
- * map expansions, O_SHOWMATCH matching etc. This means the expanded
- * characters will be re-tested for abbreviations. It's difficult to
- * know what historic practice in this case was, since abbreviations
- * were applied to :colon command lines, so entering abbreviations that
- * looped was tricky, although possible. In addition, obvious loops
- * didn't work as expected. (The command ':ab a b|ab b c|ab c a' will
- * silently only implement and/or display the last abbreviation.)
- *
- * This implementation doesn't recover well from such abbreviations.
- * The main input loop counts abbreviated characters, and, when it
- * reaches a limit, discards any abbreviated characters on the queue.
- * It's difficult to back up to the original position, as the replay
- * queue would have to be adjusted, and the line state when an initial
- * abbreviated character was received would have to be saved.
- */
- ch = pushc;
- if (term_push(sp, &ch, 1, 0, CH_ABBREVIATED))
- return (1);
- if (term_push(sp, qp->output, qp->olen, 0, CH_ABBREVIATED))
- return (1);
-
- /*
- * Move the cursor to the start of the abbreviation,
- * adjust the length.
- */
- sp->cno -= len;
- tp->len -= len;
-
- /* Copy any insert characters back. */
- if (tp->insert)
- memmove(tp->lb + sp->cno + tp->owrite,
- tp->lb + sp->cno + tp->owrite + len, tp->insert);
-
- /*
- * We return the length of the abbreviated characters. This is so
- * the calling routine can replace the replay characters with the
- * abbreviation. This means that subsequent '.' commands will produce
- * the same text, regardless of intervening :[un]abbreviate commands.
- * This is historic practice.
- */
- *didsubp = len;
- return (0);
-}
-
-/* Offset to next column of stop size. */
-#define STOP_OFF(c, stop) (stop - (c) % stop)
-
-/*
- * txt_ai_resolve --
- * When a line is resolved by <esc> or <cr>, review autoindent
- * characters.
- */
-static void
-txt_ai_resolve(sp, tp)
- SCR *sp;
- TEXT *tp;
-{
- u_long ts;
- int del;
- size_t cno, len, new, old, scno, spaces, tab_after_sp, tabs;
- char *p;
-
- /*
- * If the line is empty, has an offset, or no autoindent
- * characters, we're done.
- */
- if (!tp->len || tp->offset || !tp->ai)
- return;
-
- /*
- * The autoindent characters plus any leading <blank> characters
- * in the line are resolved into the minimum number of characters.
- * Historic practice.
- */
- ts = O_VAL(sp, O_TABSTOP);
-
- /* Figure out the last <blank> screen column. */
- for (p = tp->lb, scno = 0, len = tp->len,
- spaces = tab_after_sp = 0; len-- && isblank(*p); ++p)
- if (*p == '\t') {
- if (spaces)
- tab_after_sp = 1;
- scno += STOP_OFF(scno, ts);
- } else {
- ++spaces;
- ++scno;
- }
-
- /*
- * If there are no spaces, or no tabs after spaces and less than
- * ts spaces, it's already minimal.
- */
- if (!spaces || !tab_after_sp && spaces < ts)
- return;
-
- /* Count up spaces/tabs needed to get to the target. */
- for (cno = 0, tabs = 0; cno + STOP_OFF(cno, ts) <= scno; ++tabs)
- cno += STOP_OFF(cno, ts);
- spaces = scno - cno;
-
- /*
- * Figure out how many characters we're dropping -- if we're not
- * dropping any, it's already minimal, we're done.
- */
- old = p - tp->lb;
- new = spaces + tabs;
- if (old == new)
- return;
-
- /* Shift the rest of the characters down, adjust the counts. */
- del = old - new;
- memmove(p - del, p, tp->len - old);
- sp->cno -= del;
- tp->len -= del;
-
- /* Fill in space/tab characters. */
- for (p = tp->lb; tabs--;)
- *p++ = '\t';
- while (spaces--)
- *p++ = ' ';
-}
-
-/*
- * txt_auto --
- * Handle autoindent. If aitp isn't NULL, use it, otherwise,
- * retrieve the line.
- */
-int
-txt_auto(sp, ep, lno, aitp, len, tp)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- size_t len;
- TEXT *aitp, *tp;
-{
- size_t nlen;
- char *p, *t;
-
- if (aitp == NULL) {
- if ((p = t = file_gline(sp, ep, lno, &len)) == NULL)
- return (0);
- } else
- p = t = aitp->lb;
- for (nlen = 0; len; ++p) {
- if (!isblank(*p))
- break;
- /* If last character is a space, it counts. */
- if (--len == 0) {
- ++p;
- break;
- }
- }
-
- /* No indentation. */
- if (p == t)
- return (0);
-
- /* Set count. */
- nlen = p - t;
-
- /* Make sure the buffer's big enough. */
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + nlen);
-
- /* Copy the indentation into the new buffer. */
- memmove(tp->lb + nlen, tp->lb, tp->len);
- memmove(tp->lb, t, nlen);
- tp->len += nlen;
-
- /* Return the additional length. */
- tp->ai = nlen;
- return (0);
-}
-
-/*
- * txt_backup --
- * Back up to the previously edited line.
- */
-static TEXT *
-txt_backup(sp, ep, tiqh, tp, flags)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
- TEXT *tp;
- u_int flags;
-{
- TEXT *ntp;
- recno_t lno;
- size_t total;
-
- /* Get a handle on the previous TEXT structure. */
- if ((ntp = tp->q.cqe_prev) == (void *)tiqh) {
- msgq(sp, M_BERR, "Already at the beginning of the insert");
- return (tp);
- }
-
- /* Make sure that we have enough space. */
- total = ntp->len + tp->insert;
- if (LF_ISSET(TXT_APPENDEOL))
- ++total;
- if (total > ntp->lb_len &&
- binc(sp, &ntp->lb, &ntp->lb_len, total))
- return (NULL);
-
- /*
- * Append a cursor or copy inserted bytes to the end of the old line.
- * Test for appending a cursor first, because the TEXT insert field
- * will be 1 if we're appending a cursor. I don't think there's a
- * third case, so abort() if there is.
- */
- if (LF_ISSET(TXT_APPENDEOL)) {
- ntp->lb[ntp->len] = CURSOR_CH;
- ntp->insert = 1;
- } else if (tp->insert) {
- memmove(ntp->lb + ntp->len, tp->lb + tp->owrite, tp->insert);
- ntp->insert = tp->insert;
- } else
- abort();
-
- /* Set bookkeeping information. */
- sp->lno = ntp->lno;
- sp->cno = ntp->len;
- ntp->len += ntp->insert;
-
- /* Release the current TEXT. */
- lno = tp->lno;
- CIRCLEQ_REMOVE(tiqh, tp, q);
- text_free(tp);
-
- /* Update the old line on the screen. */
- if (sp->s_change(sp, ep, lno, LINE_DELETE))
- return (NULL);
-
- /* Return the old line. */
- return (ntp);
-}
-
-/*
- * txt_err --
- * Handle an error during input processing.
- */
-static void
-txt_err(sp, ep, tiqh)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
-{
- recno_t lno;
- size_t len;
-
- /*
- * The problem with input processing is that the cursor is at an
- * indeterminate position since some input may have been lost due
- * to a malloc error. So, try to go back to the place from which
- * the cursor started, knowing that it may no longer be available.
- *
- * We depend on at least one line number being set in the text
- * chain.
- */
- for (lno = tiqh->cqh_first->lno;
- file_gline(sp, ep, lno, &len) == NULL && lno > 0; --lno);
-
- sp->lno = lno == 0 ? 1 : lno;
- sp->cno = 0;
-
- /* Redraw the screen, just in case. */
- F_SET(sp, S_REDRAW);
-}
-
-/*
- * txt_hex --
- * Let the user insert any character value they want.
- *
- * !!!
- * This is an extension. The pattern "^Vx[0-9a-fA-F]*" is a way
- * for the user to specify a character value which their keyboard
- * may not be able to enter.
- */
-static int
-txt_hex(sp, tp, was_hex, pushc)
- SCR *sp;
- TEXT *tp;
- int *was_hex;
- ARG_CHAR_T pushc;
-{
- CHAR_T ch, savec;
- size_t len, off;
- u_long value;
- char *p, *wp;
-
- /*
- * Null-terminate the string. Since nul isn't a legal hex value,
- * this should be okay, and lets us use a local routine, which
- * presumably understands the character set, to convert the value.
- */
- savec = tp->lb[sp->cno];
- tp->lb[sp->cno] = 0;
-
- /* Find the previous HEX_CH. */
- for (off = sp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
- if (*p == HEX_CH) {
- wp = p + 1;
- break;
- }
- ++len;
- /* If not on this line, there's nothing to do. */
- if (off == tp->ai || off == tp->offset)
- goto nothex;
- }
-
- /* If no length, then it wasn't a hex value. */
- if (len == 0)
- goto nothex;
-
- /* Get the value. */
- value = strtol(wp, NULL, 16);
- if (value == LONG_MIN || value == LONG_MAX || value > MAX_CHAR_T) {
-nothex: tp->lb[sp->cno] = savec;
- *was_hex = 0;
- return (0);
- }
-
- ch = pushc;
- if (term_push(sp, &ch, 1, 0, CH_NOMAP | CH_QUOTED))
- return (1);
- ch = value;
- if (term_push(sp, &ch, 1, 0, CH_NOMAP | CH_QUOTED))
- return (1);
-
- tp->lb[sp->cno] = savec;
-
- /* Move the cursor to the start of the hex value, adjust the length. */
- sp->cno -= len + 1;
- tp->len -= len + 1;
-
- /* Copy any insert characters back. */
- if (tp->insert)
- memmove(tp->lb + sp->cno + tp->owrite,
- tp->lb + sp->cno + tp->owrite + len + 1, tp->insert);
-
- *was_hex = 1;
- return (0);
-}
-
-/*
- * Txt_indent and txt_outdent are truly strange. ^T and ^D do movements
- * to the next or previous shiftwidth value, i.e. for a 1-based numbering,
- * with shiftwidth=3, ^T moves a cursor on the 7th, 8th or 9th column to
- * the 10th column, and ^D moves it back.
- *
- * !!!
- * The ^T and ^D characters in historical vi only had special meaning when
- * they were the first characters typed after entering text input mode.
- * Since normal erase characters couldn't erase autoindent (in this case
- * ^T) characters, this meant that inserting text into previously existing
- * text was quite strange, ^T only worked if it was the first keystroke,
- * and then it could only be erased by using ^D. This implementation treats
- * ^T specially anywhere it occurs in the input, and permits the standard
- * erase characters to erase characters inserted using it.
- *
- * XXX
- * Technically, txt_indent, txt_outdent should part of the screen interface,
- * as they require knowledge of the size of a space character on the screen.
- * (Not the size of tabs, because tabs are logically composed of spaces.)
- * They're left in the text code because they're complicated, not to mention
- * the gruesome awareness that if spaces aren't a single column on the screen
- * for any language, we're into some serious, ah, for lack of a better word,
- * "issues".
- */
-
-/*
- * txt_indent --
- * Handle ^T indents.
- */
-static int
-txt_indent(sp, tp)
- SCR *sp;
- TEXT *tp;
-{
- u_long sw, ts;
- size_t cno, off, scno, spaces, tabs;
-
- ts = O_VAL(sp, O_TABSTOP);
- sw = O_VAL(sp, O_SHIFTWIDTH);
-
- /* Get the current screen column. */
- for (off = scno = 0; off < sp->cno; ++off)
- if (tp->lb[off] == '\t')
- scno += STOP_OFF(scno, ts);
- else
- ++scno;
-
- /* Count up spaces/tabs needed to get to the target. */
- for (cno = scno, scno += STOP_OFF(scno, sw), tabs = 0;
- cno + STOP_OFF(cno, ts) <= scno; ++tabs)
- cno += STOP_OFF(cno, ts);
- spaces = scno - cno;
-
- /* Put space/tab characters in place of any overwrite characters. */
- for (; tp->owrite && tabs; --tp->owrite, --tabs, ++tp->ai)
- tp->lb[sp->cno++] = '\t';
- for (; tp->owrite && spaces; --tp->owrite, --spaces, ++tp->ai)
- tp->lb[sp->cno++] = ' ';
-
- if (!tabs && !spaces)
- return (0);
-
- /* Make sure there's enough room. */
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + spaces + tabs);
-
- /* Move the insert characters out of the way. */
- if (tp->insert)
- memmove(tp->lb + sp->cno + spaces + tabs,
- tp->lb + sp->cno, tp->insert);
-
- /* Add new space/tab characters. */
- for (; tabs--; ++tp->len, ++tp->ai)
- tp->lb[sp->cno++] = '\t';
- for (; spaces--; ++tp->len, ++tp->ai)
- tp->lb[sp->cno++] = ' ';
- return (0);
-}
-
-/*
- * txt_outdent --
- * Handle ^D outdents.
- *
- */
-static int
-txt_outdent(sp, tp)
- SCR *sp;
- TEXT *tp;
-{
- u_long sw, ts;
- size_t cno, off, scno, spaces;
-
- ts = O_VAL(sp, O_TABSTOP);
- sw = O_VAL(sp, O_SHIFTWIDTH);
-
- /* Get the current screen column. */
- for (off = scno = 0; off < sp->cno; ++off)
- if (tp->lb[off] == '\t')
- scno += STOP_OFF(scno, ts);
- else
- ++scno;
-
- /* Get the previous shiftwidth column. */
- for (cno = scno; --scno % sw != 0;);
-
- /* Decrement characters until less than or equal to that slot. */
- for (; cno > scno; --sp->cno, --tp->ai, ++tp->owrite)
- if (tp->lb[--off] == '\t')
- cno -= STOP_OFF(cno, ts);
- else
- --cno;
-
- /* Spaces needed to get to the target. */
- spaces = scno - cno;
-
- /* Maybe just a delete. */
- if (spaces == 0)
- return (0);
-
- /* Make sure there's enough room. */
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + spaces);
-
- /* Use up any overwrite characters. */
- for (; tp->owrite && spaces; --spaces, ++tp->ai, --tp->owrite)
- tp->lb[sp->cno++] = ' ';
-
- /* Maybe that was enough. */
- if (spaces == 0)
- return (0);
-
- /* Move the insert characters out of the way. */
- if (tp->insert)
- memmove(tp->lb + sp->cno + spaces,
- tp->lb + sp->cno, tp->insert);
-
- /* Add new space characters. */
- for (; spaces--; ++tp->len, ++tp->ai)
- tp->lb[sp->cno++] = ' ';
- return (0);
-}
-
-/*
- * txt_resolve --
- * Resolve the input text chain into the file.
- */
-static int
-txt_resolve(sp, ep, tiqh)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
-{
- TEXT *tp;
- recno_t lno;
-
- /* The first line replaces a current line. */
- tp = tiqh->cqh_first;
- if (file_sline(sp, ep, tp->lno, tp->lb, tp->len))
- return (1);
-
- /* All subsequent lines are appended into the file. */
- for (lno = tp->lno; (tp = tp->q.cqe_next) != (void *)&sp->tiq; ++lno)
- if (file_aline(sp, ep, 0, lno, tp->lb, tp->len))
- return (1);
- return (0);
-}
-
-/*
- * txt_showmatch --
- * Show a character match.
- *
- * !!!
- * Historic vi tried to display matches even in the :colon command line.
- * I think not.
- */
-static void
-txt_showmatch(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- struct timeval second;
- VCS cs;
- MARK m;
- fd_set zero;
- int cnt, endc, startc;
-
- /*
- * Do a refresh first, in case the v_ntext() code hasn't done
- * one in awhile, so the user can see what we're complaining
- * about.
- */
- if (sp->s_refresh(sp, ep))
- return;
- /*
- * We don't display the match if it's not on the screen. Find
- * out what the first character on the screen is.
- */
- if (sp->s_position(sp, ep, &m, 0, P_TOP))
- return;
-
- /* Initialize the getc() interface. */
- cs.cs_lno = sp->lno;
- cs.cs_cno = sp->cno - 1;
- if (cs_init(sp, ep, &cs))
- return;
- startc = (endc = cs.cs_ch) == ')' ? '(' : '{';
-
- /* Search for the match. */
- for (cnt = 1;;) {
- if (cs_prev(sp, ep, &cs))
- return;
- if (cs.cs_lno < m.lno ||
- cs.cs_lno == m.lno && cs.cs_cno < m.cno)
- return;
- if (cs.cs_flags != 0) {
- if (cs.cs_flags == CS_EOF || cs.cs_flags == CS_SOF) {
- (void)sp->s_bell(sp);
- return;
- }
- continue;
- }
- if (cs.cs_ch == endc)
- ++cnt;
- else if (cs.cs_ch == startc && --cnt == 0)
- break;
- }
-
- /* Move to the match. */
- m.lno = sp->lno;
- m.cno = sp->cno;
- sp->lno = cs.cs_lno;
- sp->cno = cs.cs_cno;
- (void)sp->s_refresh(sp, ep);
-
- /*
- * Sleep(3) is eight system calls. Do it fast -- besides,
- * I don't want to wait an entire second.
- */
- FD_ZERO(&zero);
- second.tv_sec = O_VAL(sp, O_MATCHTIME) / 10;
- second.tv_usec = (O_VAL(sp, O_MATCHTIME) % 10) * 100000L;
- (void)select(0, &zero, &zero, &zero, &second);
-
- /* Return to the current location. */
- sp->lno = m.lno;
- sp->cno = m.cno;
- (void)sp->s_refresh(sp, ep);
-}
-
-/*
- * txt_margin --
- * Handle margin wrap.
- *
- * !!!
- * Historic vi belled the user each time a character was entered after
- * crossing the margin until a space was entered which could be used to
- * break the line. I don't, it tends to wake the cats.
- */
-static int
-txt_margin(sp, tp, didbreak, pushc)
- SCR *sp;
- TEXT *tp;
- int *didbreak;
- ARG_CHAR_T pushc;
-{
- CHAR_T ch;
- size_t len, off, tlen;
- char *p, *wp;
-
- /* Find the closest previous blank. */
- for (off = sp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
- if (isblank(*p)) {
- wp = p + 1;
- break;
- }
- ++len;
- /* If it's the beginning of the line, there's nothing to do. */
- if (off == tp->ai || off == tp->offset) {
- *didbreak = 0;
- return (0);
- }
- }
-
- /*
- * Historic practice is to delete any trailing whitespace
- * from the previous line.
- */
- for (tlen = len;; --p, --off) {
- if (!isblank(*p))
- break;
- ++tlen;
- if (off == tp->ai || off == tp->offset)
- break;
- }
-
- ch = pushc;
- if (term_push(sp, &ch, 1, 0, CH_NOMAP))
- return (1);
- if (len && term_push(sp, wp, len, 0, CH_NOMAP | CH_QUOTED))
- return (1);
- ch = '\n';
- if (term_push(sp, &ch, 1, 0, CH_NOMAP))
- return (1);
-
- sp->cno -= tlen;
- tp->owrite += tlen;
- *didbreak = 1;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_paragraph.c b/usr.bin/vi/nvi/v_paragraph.c
deleted file mode 100644
index 00591cbe899e..000000000000
--- a/usr.bin/vi/nvi/v_paragraph.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_paragraph.c 8.4 (Berkeley) 12/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * Paragraphs are empty lines after text or values from the paragraph or
- * section options.
- */
-
-/*
- * v_paragraphf -- [count]}
- * Move forward count paragraphs.
- */
-int
-v_paragraphf(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- enum { P_INTEXT, P_INBLANK } pstate;
- size_t lastlen, len;
- recno_t cnt, lastlno, lno;
- char *p, *lp;
-
- /* Figure out what state we're currently in. */
- lno = fm->lno;
- if ((p = file_gline(sp, ep, lno, &len)) == NULL)
- goto eof;
-
- /*
- * If we start in text, we want to switch states 2 * N - 1
- * times, in non-text, 2 * N times.
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- cnt *= 2;
- if (len == 0 || v_isempty(p, len))
- pstate = P_INBLANK;
- else {
- --cnt;
- pstate = P_INTEXT;
- }
-
- for (;;) {
- lastlno = lno;
- lastlen = len;
- if ((p = file_gline(sp, ep, ++lno, &len)) == NULL)
- goto eof;
- switch (pstate) {
- case P_INTEXT:
- if (p[0] == '.' && len >= 2)
- for (lp = VIP(sp)->paragraph; *lp; lp += 2)
- if (lp[0] == p[1] &&
- (lp[1] == ' ' || lp[1] == p[2]) &&
- !--cnt)
- goto found;
- if (len == 0 || v_isempty(p, len)) {
- if (!--cnt)
- goto found;
- pstate = P_INBLANK;
- }
- break;
- case P_INBLANK:
- if (len == 0 || v_isempty(p, len))
- break;
- if (--cnt) {
- pstate = P_INTEXT;
- break;
- }
- /*
- * Historically, a motion command was up to the end
- * of the previous line, whereas the movement command
- * was to the start of the new "paragraph".
- */
-found: if (F_ISSET(vp, VC_C | VC_D | VC_Y)) {
- rp->lno = lastlno;
- rp->cno = lastlen ? lastlen + 1 : 0;
- } else {
- rp->lno = lno;
- rp->cno = 0;
- }
- return (0);
- default:
- abort();
- }
- }
-
- /*
- * EOF is a movement sink, however, the } command historically
- * moved to the end of the last line if repeatedly invoked.
- */
-eof: if (fm->lno != lno - 1) {
- rp->lno = lno - 1;
- rp->cno = len ? len - 1 : 0;
- return (0);
- }
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL)
- GETLINE_ERR(sp, fm->lno);
- if (fm->cno != (len ? len - 1 : 0)) {
- rp->lno = lno - 1;
- rp->cno = len ? len - 1 : 0;
- return (0);
- }
- v_eof(sp, ep, NULL);
- return (1);
-}
-
-/*
- * v_paragraphb -- [count]{
- * Move forward count paragraph.
- */
-int
-v_paragraphb(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- enum { P_INTEXT, P_INBLANK } pstate;
- size_t len;
- recno_t cnt, lno;
- char *p, *lp;
-
- /*
- * The { command historically moved to the beginning of the first
- * line if invoked on the first line.
- *
- * Check for SOF.
- */
- if (fm->lno <= 1) {
- if (fm->cno == 0) {
- v_sof(sp, NULL);
- return (1);
- }
- rp->lno = 1;
- rp->cno = 0;
- return (0);
- }
-
- /* Figure out what state we're currently in. */
- lno = fm->lno;
- if ((p = file_gline(sp, ep, lno, &len)) == NULL)
- goto sof;
-
- /*
- * If we start in text, we want to switch states 2 * N - 1
- * times, in non-text, 2 * N times.
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- cnt *= 2;
- if (len == 0 || v_isempty(p, len))
- pstate = P_INBLANK;
- else {
- --cnt;
- pstate = P_INTEXT;
- }
-
- for (;;) {
- if ((p = file_gline(sp, ep, --lno, &len)) == NULL)
- goto sof;
- switch (pstate) {
- case P_INTEXT:
- if (p[0] == '.' && len >= 2)
- for (lp = VIP(sp)->paragraph; *lp; lp += 2)
- if (lp[0] == p[1] &&
- (lp[1] == ' ' || lp[1] == p[2]) &&
- !--cnt)
- goto found;
- if (len == 0 || v_isempty(p, len)) {
- if (!--cnt)
- goto found;
- pstate = P_INBLANK;
- }
- break;
- case P_INBLANK:
- if (len != 0 && !v_isempty(p, len)) {
- if (!--cnt) {
-found: rp->lno = lno;
- rp->cno = 0;
- return (0);
- }
- pstate = P_INTEXT;
- }
- break;
- default:
- abort();
- }
- }
-
- /* SOF is a movement sink. */
-sof: rp->lno = 1;
- rp->cno = 0;
- return (0);
-}
-
-/*
- * v_buildparagraph --
- * Build the paragraph command search pattern.
- */
-int
-v_buildparagraph(sp)
- SCR *sp;
-{
- VI_PRIVATE *vip;
- size_t p_len, s_len;
- char *p, *p_p, *s_p;
-
- /*
- * The vi paragraph command searches for either a paragraph or
- * section option macro.
- */
- p_len = (p_p = O_STR(sp, O_PARAGRAPHS)) == NULL ? 0 : strlen(p_p);
- s_len = (s_p = O_STR(sp, O_SECTIONS)) == NULL ? 0 : strlen(s_p);
-
- if (p_len == 0 && s_len == 0)
- return (0);
-
- MALLOC_RET(sp, p, char *, p_len + s_len + 1);
-
- vip = VIP(sp);
- if (vip->paragraph != NULL)
- FREE(vip->paragraph, vip->paragraph_len);
-
- if (p_p != NULL)
- memmove(p, p_p, p_len + 1);
- if (s_p != NULL)
- memmove(p + p_len, s_p, s_len + 1);
- vip->paragraph = p;
- vip->paragraph_len = p_len + s_len + 1;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_put.c b/usr.bin/vi/nvi/v_put.c
deleted file mode 100644
index 60227ea4ccfd..000000000000
--- a/usr.bin/vi/nvi/v_put.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_put.c 8.6 (Berkeley) 1/9/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static void inc_buf __P((SCR *, VICMDARG *));
-
-/*
- * v_Put -- [buffer]P
- * Insert the contents of the buffer before the cursor.
- */
-int
-v_Put(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- if (F_ISSET(vp, VC_ISDOT))
- inc_buf(sp, vp);
- return (put(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, rp, 0));
-}
-
-/*
- * v_put -- [buffer]p
- * Insert the contents of the buffer after the cursor.
- */
-int
-v_put(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- if (F_ISSET(vp, VC_ISDOT))
- inc_buf(sp, vp);
-
- return (put(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, rp, 1));
-}
-
-/*
- * Historical whackadoo. The dot command `puts' the numbered buffer
- * after the last one put. For example, `"4p.' would put buffer #4
- * and buffer #5. If the user continued to enter '.', the #9 buffer
- * would be repeatedly output. This was not documented, and is a bit
- * tricky to reconstruct. Historical versions of vi also dropped the
- * contents of the default buffer after each put, so after `"4p' the
- * default buffer would be empty. This makes no sense to me, so we
- * don't bother. Don't assume sequential order of numeric characters.
- *
- * And, if that weren't exciting enough, failed commands don't normally
- * set the dot command. Well, boys and girls, an exception is that
- * the buffer increment gets done regardless of the success of the put.
- */
-static void
-inc_buf(sp, vp)
- SCR *sp;
- VICMDARG *vp;
-{
- CHAR_T v;
-
- switch (vp->buffer) {
- case '1':
- v = '2';
- break;
- case '2':
- v = '3';
- break;
- case '3':
- v = '4';
- break;
- case '4':
- v = '5';
- break;
- case '5':
- v = '6';
- break;
- case '6':
- v = '7';
- break;
- case '7':
- v = '8';
- break;
- case '8':
- v = '9';
- break;
- default:
- return;
- }
- VIP(sp)->sdot.buffer = vp->buffer = v;
-}
diff --git a/usr.bin/vi/nvi/v_redraw.c b/usr.bin/vi/nvi/v_redraw.c
deleted file mode 100644
index fca5ba33b713..000000000000
--- a/usr.bin/vi/nvi/v_redraw.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_redraw.c 8.2 (Berkeley) 8/25/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_redraw --
- * Redraw the screen.
- */
-int
-v_redraw(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- F_SET(sp, S_REFRESH);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_replace.c b/usr.bin/vi/nvi/v_replace.c
deleted file mode 100644
index f9378e7ac4ed..000000000000
--- a/usr.bin/vi/nvi/v_replace.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_replace.c 8.12 (Berkeley) 12/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_replace -- [count]rc
- * The r command in historic vi was almost beautiful in its badness.
- * For example, "r<erase>" and "r<word erase>" beeped the terminal
- * and deleted a single character. "Nr<carriage return>", where N
- * was greater than 1, inserted a single carriage return. This may
- * not be right, but at least it's not insane.
- */
-int
-v_replace(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- CH ikey;
- TEXT *tp;
- recno_t lno;
- size_t blen, len;
- u_long cnt;
- int rval;
- char *bp, *p;
-
- /*
- * If the line doesn't exist, or it's empty, replacement isn't
- * allowed. It's not hard to implement, but:
- *
- * 1: It's historic practice.
- * 2: For consistency, this change would require that the more
- * general case, "Nr", when the user is < N characters from
- * the end of the line, also work.
- * 3: Replacing a newline has somewhat odd semantics.
- */
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- goto nochar;
- }
- if (len == 0) {
-nochar: msgq(sp, M_BERR, "No characters to replace");
- return (1);
- }
-
- /*
- * Figure out how many characters to be replace; for no particular
- * reason other than that the semantics of replacing the newline
- * are confusing, only permit the replacement of the characters in
- * the current line. I suppose we could simply append the replacement
- * characters to the line, but I see no compelling reason to do so.
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- rp->cno = fm->cno + cnt - 1;
- if (rp->cno > len - 1) {
- v_eol(sp, ep, fm);
- return (1);
- }
-
- /* Get the character, literal escapes, escape terminates. */
- if (F_ISSET(vp, VC_ISDOT)) {
- ikey.ch = VIP(sp)->rlast;
- ikey.value = term_key_val(sp, ikey.ch);
- } else {
- if (term_key(sp, &ikey, 0) != INP_OK)
- return (1);
- switch (ikey.value) {
- case K_ESCAPE:
- *rp = *fm;
- return (0);
- case K_VLNEXT:
- if (term_key(sp, &ikey, 0) != INP_OK)
- return (1);
- break;
- }
- VIP(sp)->rlast = ikey.ch;
- }
-
- /* Copy the line. */
- GET_SPACE_RET(sp, bp, blen, len);
- memmove(bp, p, len);
- p = bp;
-
- if (ikey.value == K_CR || ikey.value == K_NL) {
- /* Set return line. */
- rp->lno = fm->lno + cnt;
-
- /* The first part of the current line. */
- if (file_sline(sp, ep, fm->lno, p, fm->cno))
- goto err_ret;
-
- /*
- * The rest of the current line. And, of course, now it gets
- * tricky. Any white space after the replaced character is
- * stripped, and autoindent is applied. Put the cursor on the
- * last indent character as did historic vi.
- */
- for (p += fm->cno + cnt, len -= fm->cno + cnt;
- len && isblank(*p); --len, ++p);
-
- if ((tp = text_init(sp, p, len, len)) == NULL)
- goto err_ret;
- if (txt_auto(sp, ep, fm->lno, NULL, 0, tp))
- goto err_ret;
- rp->cno = tp->ai ? tp->ai - 1 : 0;
- if (file_aline(sp, ep, 1, fm->lno, tp->lb, tp->len))
- goto err_ret;
- text_free(tp);
-
- rval = 0;
-
- /* All of the middle lines. */
- while (--cnt)
- if (file_aline(sp, ep, 1, fm->lno, "", 0)) {
-err_ret: rval = 1;
- break;
- }
- } else {
- memset(bp + fm->cno, ikey.ch, cnt);
- rval = file_sline(sp, ep, fm->lno, bp, len);
-
- rp->lno = fm->lno;
- rp->cno = fm->cno + cnt - 1;
- }
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
diff --git a/usr.bin/vi/nvi/v_right.c b/usr.bin/vi/nvi/v_right.c
deleted file mode 100644
index 54b7be92d005..000000000000
--- a/usr.bin/vi/nvi/v_right.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_right.c 8.3 (Berkeley) 12/16/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_right -- [count]' ', [count]l
- * Move right by columns.
- *
- * Special case: the 'c' and 'd' commands can move past the end of line.
- */
-int
-v_right(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
-
- if (file_gline(sp, ep, fm->lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_eol(sp, ep, NULL);
- else
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- rp->lno = fm->lno;
- if (len == 0 || fm->cno == len - 1) {
- if (F_ISSET(vp, VC_C | VC_D | VC_Y)) {
- rp->cno = len;
- return (0);
- }
- v_eol(sp, ep, NULL);
- return (1);
- }
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- rp->cno = fm->cno + cnt;
- if (rp->cno > len - 1)
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- rp->cno = len;
- else
- rp->cno = len - 1;
- return (0);
-}
-
-/*
- * v_dollar -- [count]$
- * Move to the last column.
- */
-int
-v_dollar(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- size_t len;
- u_long cnt;
-
- /*
- * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
- *
- * !!!
- * Historically, if the $ is a motion, and deleting from at or before
- * the first non-blank of the line, it's a line motion, and the line
- * motion flag is set.
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if (cnt != 1) {
- --vp->count;
- if (v_down(sp, ep, vp, fm, tm, rp))
- return (1);
- rp->cno = 0;
- if (nonblank(sp, ep, rp->lno, &rp->cno))
- return (1);
- if (fm->cno <= rp->cno && F_ISSET(vp, VC_C | VC_D | VC_Y))
- F_SET(vp, VC_LMODE);
- } else
- rp->lno = fm->lno;
-
- if (file_gline(sp, ep, rp->lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_eol(sp, ep, NULL);
- else
- GETLINE_ERR(sp, rp->lno);
- return (1);
- }
-
- if (len == 0) {
- v_eol(sp, ep, NULL);
- return (1);
- }
-
- /* If it's a motion component, move one past the end of the line. */
- rp->cno = F_ISSET(vp, VC_C | VC_D | VC_Y) ? len : len - 1;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_screen.c b/usr.bin/vi/nvi/v_screen.c
deleted file mode 100644
index 986bfa4f29a2..000000000000
--- a/usr.bin/vi/nvi/v_screen.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_screen.c 8.8 (Berkeley) 11/28/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_screen --
- * Switch screens.
- */
-int
-v_screen(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * Try for the next lower screen, or, go back to the first
- * screen on the stack.
- */
- if (sp->q.cqe_next != (void *)&sp->gp->dq)
- sp->nextdisp = sp->q.cqe_next;
- else if (sp->gp->dq.cqh_first == sp) {
- msgq(sp, M_ERR, "No other screen to switch to.");
- return (1);
- } else
- sp->nextdisp = sp->gp->dq.cqh_first;
-
- /*
- * Display the old screen's status line so the user can
- * find the screen they want.
- */
- (void)status(sp, ep, fm->lno, 0);
-
- /* Save the old screen's cursor information. */
- sp->frp->lno = sp->lno;
- sp->frp->cno = sp->cno;
- F_SET(sp->frp, FR_CURSORSET);
-
- F_SET(sp, S_SSWITCH);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_scroll.c b/usr.bin/vi/nvi/v_scroll.c
deleted file mode 100644
index f69ea0fb4e87..000000000000
--- a/usr.bin/vi/nvi/v_scroll.c
+++ /dev/null
@@ -1,354 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_scroll.c 8.8 (Berkeley) 12/16/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * The historic vi had a problem in that all movements were by physical
- * lines, not by logical, or screen lines. Arguments can be made that this
- * is the right thing to do. For example, single line movements, such as
- * 'j' or 'k', should probably work on physical lines. Commands like "dj",
- * or "j.", where '.' is a change command, make more sense for physical lines
- * than they do for logical lines.
- *
- * These arguments, however, don't apply to scrolling commands like ^D and
- * ^F -- if the window is fairly small, using physical lines can result in
- * a half-page scroll repainting the entire screen, which is not what the
- * user wanted. Second, if the line is larger than the screen, using physical
- * lines can make it impossible to display parts of the line -- there aren't
- * any commands that don't display the beginning of the line in historic vi,
- * and if both the beginning and end of the line can't be on the screen at
- * the same time, you lose. This is even worse in the case of the H, L, and
- * M commands -- for large lines, they may all refer to the same line and
- * will result in no movement at all.
- *
- * This implementation does the scrolling (^B, ^D, ^F, ^U, ^Y, ^E), and the
- * cursor positioning commands (H, L, M) commands using logical lines, not
- * physical.
- *
- * Another issue is that page and half-page scrolling commands historically
- * moved to the first non-blank character in the new line. If the line is
- * approximately the same size as the screen, this loses because the cursor
- * before and after a ^D, may refer to the same location on the screen. In
- * this implementation, scrolling commands set the cursor to the first non-
- * blank character if the line changes because of the scroll. Otherwise,
- * the cursor is left alone.
- */
-
-/*
- * v_lgoto -- [count]G
- * Go to first non-blank character of the line count, the last line
- * of the file by default.
- */
-int
-v_lgoto(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t last;
-
- if (file_lline(sp, ep, &last))
- return (1);
- if (F_ISSET(vp, VC_C1SET)) {
- if (last < vp->count) {
- v_eof(sp, ep, fm);
- return (1);
- }
- rp->lno = vp->count;
- } else
- rp->lno = last ? last : 1;
- return (0);
-}
-
-/*
- * v_home -- [count]H
- * Move to the first non-blank character of the logical line
- * count from the top of the screen, 1 by default.
- */
-int
-v_home(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (sp->s_position(sp, ep, rp,
- F_ISSET(vp, VC_C1SET) ? vp->count : 0, P_TOP));
-}
-
-/*
- * v_middle -- M
- * Move to the first non-blank character of the logical line
- * in the middle of the screen.
- */
-int
-v_middle(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * Yielding to none in our quest for compatibility with every
- * historical blemish of vi, no matter how strange it might be,
- * we permit the user to enter a count and then ignore it.
- */
- return (sp->s_position(sp, ep, rp, 0, P_MIDDLE));
-}
-
-/*
- * v_bottom -- [count]L
- * Move to the first non-blank character of the logical line
- * count from the bottom of the screen, 1 by default.
- */
-int
-v_bottom(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (sp->s_position(sp, ep,
- rp, F_ISSET(vp, VC_C1SET) ? vp->count : 0, P_BOTTOM));
-}
-
-/*
- * v_up -- [count]^P, [count]k, [count]-
- * Move up by lines.
- */
-int
-v_up(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
-
- lno = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- if (fm->lno <= lno) {
- v_sof(sp, fm);
- return (1);
- }
- rp->lno = fm->lno - lno;
- return (0);
-}
-
-/*
- * v_cr -- [count]^M
- * In a script window, send the line to the shell.
- * In a regular window, move down by lines.
- */
-int
-v_cr(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * If it's a script window, exec the line,
- * otherwise it's the same as v_down().
- */
- return (F_ISSET(sp, S_SCRIPT) ?
- sscr_exec(sp, ep, fm->lno) : v_down(sp, ep, vp, fm, tm, rp));
-}
-
-/*
- * v_down -- [count]^J, [count]^N, [count]j, [count]^M, [count]+
- * Move down by lines.
- */
-int
-v_down(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
-
- lno = fm->lno + (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
-
- if (file_gline(sp, ep, lno, NULL) == NULL) {
- v_eof(sp, ep, fm);
- return (1);
- }
- rp->lno = lno;
- return (0);
-}
-
-/*
- * v_hpageup -- [count]^U
- * Page up half screens.
- */
-int
-v_hpageup(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * Half screens always succeed unless already at SOF. Half screens
- * set the scroll value, even if the command ultimately failed, in
- * historic vi. It's probably a don't care.
- */
- if (F_ISSET(vp, VC_C1SET))
- O_VAL(sp, O_SCROLL) = vp->count;
- else
- vp->count = O_VAL(sp, O_SCROLL);
-
- return (sp->s_down(sp, ep, rp, (recno_t)O_VAL(sp, O_SCROLL), 1));
-}
-
-/*
- * v_hpagedown -- [count]^D
- * Page down half screens.
- */
-int
-v_hpagedown(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * Half screens always succeed unless already at EOF. Half screens
- * set the scroll value, even if the command ultimately failed, in
- * historic vi. It's probably a don't care.
- */
- if (F_ISSET(vp, VC_C1SET))
- O_VAL(sp, O_SCROLL) = vp->count;
- else
- vp->count = O_VAL(sp, O_SCROLL);
-
- return (sp->s_up(sp, ep, rp, (recno_t)O_VAL(sp, O_SCROLL), 1));
-}
-
-/*
- * v_pageup -- [count]^B
- * Page up full screens.
- *
- * !!!
- * Historic vi did not move to the SOF if the screen couldn't move, i.e.
- * if SOF was already displayed on the screen. This implementation does
- * move to SOF in that case, making ^B more like the the historic ^U.
- */
-int
-v_pageup(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t count;
-
- /* Calculation from POSIX 1003.2/D8. */
- count = (F_ISSET(vp, VC_C1SET) ? vp->count : 1) * (sp->t_rows - 1);
-
- return (sp->s_down(sp, ep, rp, count, 1));
-}
-
-/*
- * v_pagedown -- [count]^F
- * Page down full screens.
- * !!!
- * Historic vi did not move to the EOF if the screen couldn't move, i.e.
- * if EOF was already displayed on the screen. This implementation does
- * move to EOF in that case, making ^F more like the the historic ^D.
- */
-int
-v_pagedown(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t count;
-
- /* Calculation from POSIX 1003.2/D8. */
- count = (F_ISSET(vp, VC_C1SET) ? vp->count : 1) * (sp->t_rows - 1);
-
- return (sp->s_up(sp, ep, rp, count, 1));
-}
-
-/*
- * v_lineup -- [count]^Y
- * Page up by lines.
- */
-int
-v_lineup(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * The cursor moves down, staying with its original line, unless it
- * reaches the bottom of the screen.
- */
- return (sp->s_down(sp, ep,
- rp, F_ISSET(vp, VC_C1SET) ? vp->count : 1, 0));
-}
-
-/*
- * v_linedown -- [count]^E
- * Page down by lines.
- */
-int
-v_linedown(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * The cursor moves up, staying with its original line, unless it
- * reaches the top of the screen.
- */
- return (sp->s_up(sp, ep,
- rp, F_ISSET(vp, VC_C1SET) ? vp->count : 1, 0));
-}
diff --git a/usr.bin/vi/nvi/v_search.c b/usr.bin/vi/nvi/v_search.c
deleted file mode 100644
index 25dcaf5e2e10..000000000000
--- a/usr.bin/vi/nvi/v_search.c
+++ /dev/null
@@ -1,364 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_search.c 8.16 (Berkeley) 12/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static int bcorrect __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, u_int));
-static int fcorrect __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, u_int));
-static int getptrn __P((SCR *, EXF *, int, char **));
-
-/*
- * v_searchn -- n
- * Repeat last search.
- */
-int
-v_searchn(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int flags;
-
- flags = SEARCH_MSG;
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- flags |= SEARCH_EOL;
- switch (sp->searchdir) {
- case BACKWARD:
- if (b_search(sp, ep, fm, rp, NULL, NULL, &flags))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y | VC_SH) &&
- bcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- break;
- case FORWARD:
- if (f_search(sp, ep, fm, rp, NULL, NULL, &flags))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y| VC_SH) &&
- fcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- break;
- case NOTSET:
- msgq(sp, M_ERR, "No previous search pattern.");
- return (1);
- default:
- abort();
- }
- return (0);
-}
-
-/*
- * v_searchN -- N
- * Reverse last search.
- */
-int
-v_searchN(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int flags;
-
- flags = SEARCH_MSG;
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- flags |= SEARCH_EOL;
- switch (sp->searchdir) {
- case BACKWARD:
- if (f_search(sp, ep, fm, rp, NULL, NULL, &flags))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y | VC_SH) &&
- fcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- break;
- case FORWARD:
- if (b_search(sp, ep, fm, rp, NULL, NULL, &flags))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y | VC_SH) &&
- bcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- break;
- case NOTSET:
- msgq(sp, M_ERR, "No previous search pattern.");
- return (1);
- default:
- abort();
- }
- return (0);
-}
-
-/*
- * v_searchw -- [count]^A
- * Search for the word under the cursor.
- */
-int
-v_searchw(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- size_t blen, len;
- u_int flags;
- int rval;
- char *bp;
-
- len = vp->kbuflen + sizeof(RE_WSTART) + sizeof(RE_WSTOP);
- GET_SPACE_RET(sp, bp, blen, len);
- (void)snprintf(bp, blen, "%s%s%s", RE_WSTART, vp->keyword, RE_WSTOP);
-
- flags = SEARCH_MSG;
- rval = f_search(sp, ep, fm, rp, bp, NULL, &flags);
-
- FREE_SPACE(sp, bp, blen);
- if (rval)
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y | VC_SH) &&
- fcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- return (0);
-}
-
-/*
- * v_searchb -- [count]?RE[? offset]
- * Search backward.
- */
-int
-v_searchb(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int flags;
- char *ptrn;
-
- if (F_ISSET(vp, VC_ISDOT))
- ptrn = NULL;
- else {
- if (getptrn(sp, ep, '?', &ptrn))
- return (1);
- if (ptrn == NULL)
- return (0);
- }
-
- flags = SEARCH_MSG | SEARCH_PARSE | SEARCH_SET | SEARCH_TERM;
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- flags |= SEARCH_EOL;
- if (b_search(sp, ep, fm, rp, ptrn, NULL, &flags))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y | VC_SH) &&
- bcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- return (0);
-}
-
-/*
- * v_searchf -- [count]/RE[/ offset]
- * Search forward.
- */
-int
-v_searchf(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- int flags;
- char *ptrn;
-
- if (F_ISSET(vp, VC_ISDOT))
- ptrn = NULL;
- else {
- if (getptrn(sp, ep, '/', &ptrn))
- return (1);
- if (ptrn == NULL)
- return (0);
- }
-
- flags = SEARCH_MSG | SEARCH_PARSE | SEARCH_SET | SEARCH_TERM;
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- flags |= SEARCH_EOL;
- if (f_search(sp, ep, fm, rp, ptrn, NULL, &flags))
- return (1);
- if (F_ISSET(vp, VC_C | VC_D | VC_Y | VC_SH) &&
- fcorrect(sp, ep, vp, fm, rp, flags))
- return (1);
- return (0);
-}
-
-/*
- * getptrn --
- * Get the search pattern.
- */
-static int
-getptrn(sp, ep, prompt, storep)
- SCR *sp;
- EXF *ep;
- int prompt;
- char **storep;
-{
- TEXT *tp;
-
- if (sp->s_get(sp, ep, &sp->tiq, prompt,
- TXT_BS | TXT_CR | TXT_ESCAPE | TXT_PROMPT) != INP_OK)
- return (1);
-
- /* Len is 0 if backspaced over the prompt, 1 if only CR entered. */
- tp = sp->tiq.cqh_first;
- if (tp->len == 0)
- *storep = NULL;
- else
- *storep = tp->lb;
- return (0);
-}
-
-/*
- * !!!
- * Historically, commands didn't affect the line searched to if the motion
- * command was a search and the pattern match was the start or end of the
- * line. There were some special cases, however, concerning search to the
- * start of end of a line.
- *
- * Vi was not, however, consistent, and it was fairly easy to confuse it.
- * For example, given the two lines:
- *
- * abcdefghi
- * ABCDEFGHI
- *
- * placing the cursor on the 'A' and doing y?$ would so confuse it that 'h'
- * 'k' and put would no longer work correctly. In any case, we try to do
- * the right thing, but it's not likely exactly match historic practice.
- */
-
-/*
- * bcorrect --
- * Handle command with a backward search as the motion.
- */
-static int
-bcorrect(sp, ep, vp, fm, rp, flags)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *rp;
- u_int flags;
-{
- size_t len;
- char *p;
-
- /*
- * !!!
- * Correct backward searches which start at column 0 to be one
- * past the last column of the previous line.
- *
- * Backward searches become line mode operations if they start
- * at column 0 and end at column 0 of another line.
- */
- if (fm->lno > rp->lno && fm->cno == 0) {
- if ((p = file_gline(sp, ep, --fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, rp->lno);
- return (1);
- }
- if (rp->cno == 0)
- F_SET(vp, VC_LMODE);
- fm->cno = len;
- }
-
- /*
- * !!!
- * Commands would become line mode operations if there was a delta
- * specified to the search pattern.
- */
- if (LF_ISSET(SEARCH_DELTA)) {
- F_SET(vp, VC_LMODE);
- return (0);
- }
- return (0);
-}
-
-/*
- * fcorrect --
- * Handle command with a forward search as the motion.
- */
-static int
-fcorrect(sp, ep, vp, fm, rp, flags)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *rp;
- u_int flags;
-{
- size_t len;
- char *p;
-
- /*
- * !!!
- * Correct forward searches which end at column 0 to be one
- * past the last column of the previous line.
- *
- * Forward searches become line mode operations if they start
- * at column 0 and end at column 0 of another line.
- */
- if (fm->lno < rp->lno && rp->cno == 0) {
- if ((p = file_gline(sp, ep, --rp->lno, &len)) == NULL) {
- GETLINE_ERR(sp, rp->lno);
- return (1);
- }
- if (fm->cno == 0)
- F_SET(vp, VC_LMODE);
- rp->cno = len;
- }
-
- /*
- * !!!
- * Commands would become line mode operations if there was a delta
- * specified to the search pattern.
- */
- if (LF_ISSET(SEARCH_DELTA)) {
- F_SET(vp, VC_LMODE);
- return (0);
- }
-
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_section.c b/usr.bin/vi/nvi/v_section.c
deleted file mode 100644
index 8d97e2f10b4e..000000000000
--- a/usr.bin/vi/nvi/v_section.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_section.c 8.4 (Berkeley) 1/22/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * In historic vi, the section commands ignored empty lines, unlike the
- * paragraph commands, which was probably okay. However, they also moved
- * to the start of the last line when there where no more sections instead
- * of the end of the last line like the paragraph commands. I've changed
- * the latter behaviore to match the paragraphs command.
- *
- * In historic vi, a "function" was defined as the first character of the
- * line being an open brace, which could be followed by anything. This
- * implementation follows that historic practice.
- */
-
-/* Macro to do a check on each line. */
-#define CHECK { \
- if (len == 0) \
- continue; \
- if (p[0] == '{') { \
- if (!--cnt) { \
- rp->cno = 0; \
- rp->lno = lno; \
- return (0); \
- } \
- continue; \
- } \
- if (p[0] != '.' || len < 3) \
- continue; \
- for (lp = list; *lp; lp += 2) \
- if (lp[0] == p[1] && \
- (lp[1] == ' ' || lp[1] == p[2]) && !--cnt) { \
- rp->cno = 0; \
- rp->lno = lno; \
- return (0); \
- } \
-}
-
-/*
- * v_sectionf -- [count]]]
- * Move forward count sections/functions.
- */
-int
-v_sectionf(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- size_t len;
- recno_t cnt, lno;
- char *p, *list, *lp;
-
- /* Get macro list. */
- if ((list = O_STR(sp, O_SECTIONS)) == NULL)
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- for (lno = fm->lno; (p = file_gline(sp, ep, ++lno, &len)) != NULL;)
- CHECK;
-
- /* EOF is a movement sink. */
- if (fm->lno != lno - 1) {
- rp->lno = lno - 1;
- rp->cno = len ? len - 1 : 0;
- return (0);
- }
- v_eof(sp, ep, NULL);
- return (1);
-}
-
-/*
- * v_sectionb -- [count][[
- * Move backward count sections/functions.
- */
-int
-v_sectionb(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- size_t len;
- recno_t cnt, lno;
- char *p, *list, *lp;
-
- /* Check for SOF. */
- if (fm->lno <= 1) {
- v_sof(sp, NULL);
- return (1);
- }
-
- /* Get macro list. */
- if ((list = O_STR(sp, O_SECTIONS)) == NULL)
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- for (lno = fm->lno; (p = file_gline(sp, ep, --lno, &len)) != NULL;)
- CHECK;
-
- /* SOF is a movement sink. */
- rp->lno = 1;
- rp->cno = 0;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_sentence.c b/usr.bin/vi/nvi/v_sentence.c
deleted file mode 100644
index 684952124f14..000000000000
--- a/usr.bin/vi/nvi/v_sentence.c
+++ /dev/null
@@ -1,328 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_sentence.c 8.7 (Berkeley) 8/26/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * In historic vi, a sentence was delimited by a '.', '?' or '!' character
- * followed by TWO spaces or a newline. One or more empty lines was also
- * treated as a separate sentence. The Berkeley documentation for historical
- * vi states that any number of ')', ']', '"' and '\'' characters can be
- * between the delimiter character and the spaces or end of line, however,
- * the historical implementation did not handle additional '"' characters.
- * We follow the documentation here, not the implementation.
- *
- * Once again, historical vi didn't do sentence movements associated with
- * counts consistently, mostly in the presence of lines containing only
- * white-space characters.
- *
- * This implementation also permits a single tab to delimit sentences, and
- * treats lines containing only white-space characters as empty lines.
- * And, tabs are eaten (along with spaces) when skipping to the start of the
- * text follow a "sentence".
- */
-
-/*
- * v_sentencef -- [count])
- * Move forward count sentences.
- */
-int
-v_sentencef(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- enum { BLANK, NONE, PERIOD } state;
- VCS cs;
- u_long cnt;
-
- cs.cs_lno = fm->lno;
- cs.cs_cno = fm->cno;
- if (cs_init(sp, ep, &cs))
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * If in white-space, the next start of sentence counts as one.
- * This may not handle " . " correctly, but it's real unclear
- * what correctly means in that case.
- */
- if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
- if (cs_fblank(sp, ep, &cs))
- return (1);
- if (--cnt == 0) {
- if (fm->lno != cs.cs_lno || fm->cno != cs.cs_cno)
- goto okret;
- return (1);
- }
- }
- for (state = NONE;;) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- break;
- if (cs.cs_flags == CS_EOL) {
- if ((state == PERIOD || state == BLANK) && --cnt == 0) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == 0 &&
- isblank(cs.cs_ch) && cs_fblank(sp, ep, &cs))
- return (1);
- goto okret;
- }
- state = NONE;
- continue;
- }
- if (cs.cs_flags == CS_EMP) { /* An EMP is two sentences. */
- if (--cnt == 0)
- goto okret;
- if (cs_fblank(sp, ep, &cs))
- return (1);
- if (--cnt == 0)
- goto okret;
- state = NONE;
- continue;
- }
- switch (cs.cs_ch) {
- case '.':
- case '?':
- case '!':
- state = PERIOD;
- break;
- case ')':
- case ']':
- case '"':
- case '\'':
- if (state != PERIOD)
- state = NONE;
- break;
- case '\t':
- if (state == PERIOD)
- state = BLANK;
- /* FALLTHROUGH */
- case ' ':
- if (state == PERIOD) {
- state = BLANK;
- break;
- }
- if (state == BLANK && --cnt == 0) {
- if (cs_fblank(sp, ep, &cs))
- return (1);
- goto okret;
- }
- /* FALLTHROUGH */
- default:
- state = NONE;
- break;
- }
- }
-
- /* EOF is a movement sink. */
- if (fm->lno != cs.cs_lno || fm->cno != cs.cs_cno)
- goto okret;
- v_eof(sp, ep, NULL);
- return (1);
-
-okret: rp->lno = cs.cs_lno;
- rp->cno = cs.cs_cno;
-
- /*
- * Historic, uh, features, yeah, that's right, call 'em features.
- * If the sentence movement is cutting an entire line, the buffer
- * is in line mode. Reach up into the caller's VICMDARG structure,
- * and whack the flags.
- */
- if (F_ISSET(vp, VC_C | VC_D | VC_Y) &&
- fm->cno == 0 && (rp->cno == 0 || cs.cs_flags != 0)) {
- if (rp->cno == 0)
- --rp->lno;
- F_SET(vp, VC_LMODE);
- }
- return (0);
-}
-
-/*
- * v_sentenceb -- [count](
- * Move backward count sentences.
- */
-int
-v_sentenceb(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- VCS cs;
- recno_t slno;
- size_t len, scno;
- u_long cnt;
- int last1, last2;
-
- if (fm->lno == 1 && fm->cno == 0) {
- v_sof(sp, NULL);
- return (1);
- }
-
- cs.cs_lno = fm->lno;
- cs.cs_cno = fm->cno;
- if (cs_init(sp, ep, &cs))
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * If on an empty line, skip to the next previous
- * non-white-space character.
- */
- if (cs.cs_flags == CS_EMP) {
- if (cs_bblank(sp, ep, &cs))
- return (1);
- for (;;) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags != CS_EOL)
- break;
- }
- }
-
- for (last1 = last2 = 0;;) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_SOF) /* SOF is a movement sink. */
- break;
- if (cs.cs_flags == CS_EOL) {
- last2 = last1;
- last1 = 1;
- continue;
- }
- if (cs.cs_flags == CS_EMP) {
- if (--cnt == 0)
- goto ret;
- if (cs_bblank(sp, ep, &cs))
- return (1);
- last1 = last2 = 0;
- continue;
- }
- switch (cs.cs_ch) {
- case '.':
- case '?':
- case '!':
- if (!last1 || --cnt != 0) {
- last2 = last1 = 0;
- continue;
- }
-
-ret: slno = cs.cs_lno;
- scno = cs.cs_cno;
-
- /*
- * Move to the start of the sentence, skipping blanks
- * and special characters.
- */
- do {
- if (cs_next(sp, ep, &cs))
- return (1);
- } while (!cs.cs_flags &&
- (cs.cs_ch == ')' || cs.cs_ch == ']' ||
- cs.cs_ch == '"' || cs.cs_ch == '\''));
- if ((cs.cs_flags || isblank(cs.cs_ch)) &&
- cs_fblank(sp, ep, &cs))
- return (1);
-
- /*
- * If it was ". xyz", with the cursor on the 'x', or
- * "end. ", with the cursor in the spaces, or the
- * beginning of a sentence preceded by an empty line,
- * we can end up where we started. Fix it.
- */
- if (fm->lno != cs.cs_lno || fm->cno != cs.cs_cno)
- goto okret;
-
- /*
- * Well, if an empty line preceded possible blanks
- * and the sentence, it could be a real sentence.
- */
- for (;;) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOL)
- continue;
- if (cs.cs_flags == 0 && isblank(cs.cs_ch))
- continue;
- break;
- }
- if (cs.cs_flags == CS_EMP)
- goto okret;
-
- /* But it wasn't; try again. */
- ++cnt;
- cs.cs_lno = slno;
- cs.cs_cno = scno;
- last2 = last1 = 0;
- break;
- case '\t':
- last1 = last2 = 1;
- break;
- default:
- last2 = last1;
- last1 =
- cs.cs_flags == CS_EOL || isblank(cs.cs_ch) ||
- cs.cs_ch == ')' || cs.cs_ch == ']' ||
- cs.cs_ch == '"' || cs.cs_ch == '\'' ? 1 : 0;
- }
- }
-
-okret: rp->lno = cs.cs_lno;
- rp->cno = cs.cs_cno;
-
- /*
- * See comment in v_sentencef(). Ignore errors, they should
- * never occur, and they'll get caught later.
- */
- if (F_ISSET(vp, VC_C | VC_D | VC_Y) && rp->cno == 0 &&
- file_gline(sp, ep, fm->lno, &len) != NULL && (len == 0 ||
- fm->cno == len - 1))
- F_SET(vp, VC_LMODE);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_shift.c b/usr.bin/vi/nvi/v_shift.c
deleted file mode 100644
index 2e984147a1c1..000000000000
--- a/usr.bin/vi/nvi/v_shift.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_shift.c 8.3 (Berkeley) 11/13/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * v_shiftl -- [count]<motion
- * Shift lines left.
- */
-int
-v_shiftl(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
-
- SETCMDARG(cmd, C_SHIFTL, 2, fm->lno, tm->lno, 0, "<");
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
-
-/*
- * v_shiftr -- [count]>motion
- * Shift lines right.
- */
-int
-v_shiftr(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
-
- SETCMDARG(cmd, C_SHIFTR, 2, fm->lno, tm->lno, 0, ">");
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_status.c b/usr.bin/vi/nvi/v_status.c
deleted file mode 100644
index 9109c0196a80..000000000000
--- a/usr.bin/vi/nvi/v_status.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_status.c 8.10 (Berkeley) 11/20/93";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <unistd.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_status -- ^G
- * Show the file status.
- */
-int
-v_status(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
-
- /*
- * ^G in historic vi reset the cursor column to the first
- * non-blank character in the line. This doesn't seem of
- * any usefulness whatsoever, so I don't bother.
- */
- return (status(sp, ep, fm->lno, 1));
-}
-
-int
-status(sp, ep, lno, showlast)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- int showlast;
-{
- recno_t last;
- char *mo, *nc, *nf, *ro, *pid;
-#ifdef DEBUG
- char pbuf[50];
-
- (void)snprintf(pbuf, sizeof(pbuf), " (pid %u)", getpid());
- pid = pbuf;
-#else
- pid = "";
-#endif
- /*
- * See nvi/exf.c:file_init() for a description of how and
- * when the read-only bit is set. Possible displays are:
- *
- * new file
- * new file, readonly
- * [un]modified
- * [un]modified, readonly
- * name changed, [un]modified
- * name changed, [un]modified, readonly
- *
- * !!!
- * The historic display for "name changed" was "[Not edited]".
- */
- if (F_ISSET(sp->frp, FR_NEWFILE)) {
- F_CLR(sp->frp, FR_NEWFILE);
- nf = "new file";
- mo = nc = "";
- } else {
- nf = "";
- if (sp->frp->cname != NULL) {
- nc = "name changed";
- mo = F_ISSET(ep, F_MODIFIED) ?
- ", modified" : ", unmodified";
- } else {
- nc = "";
- mo = F_ISSET(ep, F_MODIFIED) ?
- "modified" : "unmodified";
- }
- }
- ro = F_ISSET(sp->frp, FR_RDONLY) ? ", readonly" : "";
- if (showlast) {
- if (file_lline(sp, ep, &last))
- return (1);
- if (last >= 1)
- msgq(sp, M_INFO,
- "%s: %s%s%s%s: line %lu of %lu [%ld%%]%s",
- FILENAME(sp->frp), nf, nc, mo, ro, lno,
- last, (lno * 100) / last, pid);
- else
- msgq(sp, M_INFO, "%s: %s%s%s%s: empty file%s",
- FILENAME(sp->frp), nf, nc, mo, ro, pid);
- } else
- msgq(sp, M_INFO, "%s: %s%s%s%s: line %lu%s",
- FILENAME(sp->frp), nf, nc, mo, ro, lno, pid);
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_stop.c b/usr.bin/vi/nvi/v_stop.c
deleted file mode 100644
index 2f64bfedf195..000000000000
--- a/usr.bin/vi/nvi/v_stop.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_stop.c 8.5 (Berkeley) 10/28/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-int
-v_stop(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /* If autowrite is set, write out the file. */
- if (F_ISSET(ep, F_MODIFIED) && O_ISSET(sp, O_AUTOWRITE)) {
- if (file_write(sp, ep, NULL, NULL, NULL, FS_ALL))
- return (1);
- if (sp->s_refresh(sp, ep))
- return (1);
- }
- return (sp->s_suspend(sp));
-}
diff --git a/usr.bin/vi/nvi/v_switch.c b/usr.bin/vi/nvi/v_switch.c
deleted file mode 100644
index d0d000facb2b..000000000000
--- a/usr.bin/vi/nvi/v_switch.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_switch.c 8.5 (Berkeley) 11/23/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-#include "excmd.h"
-
-/*
- * v_switch -- ^^
- * Switch to the previous file.
- */
-int
-v_switch(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
- char *name;
-
- /*
- * Try the alternate file name, then the previous file
- * name. Use the real name, not the user's current name.
- */
- if (sp->alt_name != NULL)
- name = sp->alt_name;
- else if (sp->p_frp != NULL)
- name = sp->p_frp->name;
- else {
- msgq(sp, M_ERR, "No previous file to edit.");
- return (1);
- }
-
- /* If autowrite is set, write out the file. */
- if (F_ISSET(ep, F_MODIFIED))
- if (O_ISSET(sp, O_AUTOWRITE)) {
- if (file_write(sp, ep, NULL, NULL, NULL, FS_ALL))
- return (1);
- } else {
- msgq(sp, M_ERR,
- "Modified since last write; write or use :edit! to override.");
- return (1);
- }
-
- SETCMDARG(cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0, name);
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_tag.c b/usr.bin/vi/nvi/v_tag.c
deleted file mode 100644
index 530e35279420..000000000000
--- a/usr.bin/vi/nvi/v_tag.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_tag.c 8.2 (Berkeley) 12/3/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * v_tagpush -- ^[
- * Do a tag search on a the cursor keyword.
- */
-int
-v_tagpush(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
-
- SETCMDARG(cmd, C_TAG, 0, OOBLNO, 0, 0, vp->keyword);
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
-
-/*
- * v_tagpop -- ^T
- * Pop the tags stack.
- */
-/* ARGSUSED */
-int
-v_tagpop(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- EXCMDARG cmd;
-
- SETCMDARG(cmd, C_TAGPOP, 0, OOBLNO, 0, 0, NULL);
- return (sp->s_ex_cmd(sp, ep, &cmd, rp));
-}
diff --git a/usr.bin/vi/nvi/v_text.c b/usr.bin/vi/nvi/v_text.c
deleted file mode 100644
index 083b5b248e22..000000000000
--- a/usr.bin/vi/nvi/v_text.c
+++ /dev/null
@@ -1,827 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_text.c 8.23 (Berkeley) 1/9/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * !!!
- * Repeated input in the historic vi is mostly wrong and this isn't very
- * backward compatible. For example, if the user entered "3Aab\ncd" in
- * the historic vi, the "ab" was repeated 3 times, and the "\ncd" was then
- * appended to the result. There was also a hack which I don't remember
- * right now, where "3o" would open 3 lines and then let the user fill them
- * in, to make screen movements on 300 baud modems more tolerable. I don't
- * think it's going to be missed.
- */
-
-#define SET_TXT_STD(sp, f) { \
- LF_INIT((f) | TXT_BEAUTIFY | TXT_CNTRLT | TXT_ESCAPE | \
- TXT_MAPINPUT | TXT_RECORD | TXT_RESOLVE); \
- if (O_ISSET(sp, O_ALTWERASE)) \
- LF_SET(TXT_ALTWERASE); \
- if (O_ISSET(sp, O_AUTOINDENT)) \
- LF_SET(TXT_AUTOINDENT); \
- if (O_ISSET(sp, O_SHOWMATCH)) \
- LF_SET(TXT_SHOWMATCH); \
- if (O_ISSET(sp, O_WRAPMARGIN)) \
- LF_SET(TXT_WRAPMARGIN); \
- if (F_ISSET(sp, S_SCRIPT)) \
- LF_SET(TXT_CR); \
- if (O_ISSET(sp, O_TTYWERASE)) \
- LF_SET(TXT_TTYWERASE); \
-}
-
-/*
- * !!!
- * There's a problem with the way that we do logging for change commands with
- * implied motions (e.g. A, I, O, cc, etc.). Since the main vi loop logs the
- * starting cursor position before the change command "moves" the cursor, the
- * cursor position to which we return on undo will be where the user entered
- * the change command, not the start of the change. Several of the following
- * routines re-log the cursor to make this work correctly. Historic vi tried
- * to do the same thing, and mostly got it right. (The only spectacular way
- * it fails is if the user entered 'o' from anywhere but the last character of
- * the line, the undo returned the cursor to the start of the line. If the
- * user was on the last character of the line, the cursor returned to that
- * position.)
- */
-
-static int v_CS __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, MARK *, u_int));
-
-/*
- * v_iA -- [count]A
- * Append text to the end of the line.
- */
-int
-v_iA(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- int first;
- char *p;
-
- SET_TXT_STD(sp, TXT_APPENDEOL);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- for (first = 1, lno = fm->lno,
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- /* Move the cursor to the end of the line + 1. */
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- lno = 1;
- len = 0;
- } else {
- /* Correct logging for implied cursor motion. */
- sp->cno = len == 0 ? 0 : len - 1;
- if (first == 1) {
- log_cursor(sp, ep);
- first = 0;
- }
- /* Start the change after the line. */
- sp->cno = len;
- }
-
- if (v_ntext(sp, ep,
- &sp->tiq, NULL, p, len, rp, 0, OOBLNO, flags))
- return (1);
-
- SET_TXT_STD(sp, TXT_APPENDEOL | TXT_REPLAY);
- sp->lno = lno = rp->lno;
- sp->cno = rp->cno;
- }
- return (0);
-}
-
-/*
- * v_ia -- [count]a
- * Append text to the cursor position.
- */
-int
-v_ia(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- u_long cnt;
- u_int flags;
- size_t len;
- char *p;
-
- SET_TXT_STD(sp, 0);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- for (lno = fm->lno,
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- /*
- * Move the cursor one column to the right and
- * repaint the screen.
- */
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- lno = 1;
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else if (len) {
- if (len == sp->cno + 1) {
- sp->cno = len;
- LF_SET(TXT_APPENDEOL);
- } else
- ++sp->cno;
- } else
- LF_SET(TXT_APPENDEOL);
-
- if (v_ntext(sp, ep,
- &sp->tiq, NULL, p, len, rp, 0, OOBLNO, flags))
- return (1);
-
- SET_TXT_STD(sp, TXT_REPLAY);
- sp->lno = lno = rp->lno;
- sp->cno = rp->cno;
- }
- return (0);
-}
-
-/*
- * v_iI -- [count]I
- * Insert text at the first non-blank character in the line.
- */
-int
-v_iI(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- int first;
- char *p;
-
- SET_TXT_STD(sp, 0);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- for (first = 1, lno = fm->lno,
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- /*
- * Move the cursor to the start of the line and repaint
- * the screen.
- */
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- lno = 1;
- len = 0;
- } else {
- sp->cno = 0;
- if (nonblank(sp, ep, lno, &sp->cno))
- return (1);
- /* Correct logging for implied cursor motion. */
- if (first == 1) {
- log_cursor(sp, ep);
- first = 0;
- }
- }
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
-
- if (v_ntext(sp, ep,
- &sp->tiq, NULL, p, len, rp, 0, OOBLNO, flags))
- return (1);
-
- SET_TXT_STD(sp, TXT_REPLAY);
- sp->lno = lno = rp->lno;
- sp->cno = rp->cno;
- }
- return (0);
-}
-
-/*
- * v_ii -- [count]i
- * Insert text at the cursor position.
- */
-int
-v_ii(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- char *p;
-
- SET_TXT_STD(sp, 0);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- for (lno = fm->lno,
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- lno = 1;
- len = 0;
- }
- /* If len == sp->cno, it's a replay caused by a count. */
- if (len == 0 || len == sp->cno)
- LF_SET(TXT_APPENDEOL);
-
- if (v_ntext(sp, ep,
- &sp->tiq, NULL, p, len, rp, 0, OOBLNO, flags))
- return (1);
-
- /*
- * On replay, if the line isn't empty, advance the insert
- * by one (make it an append).
- */
- SET_TXT_STD(sp, TXT_REPLAY);
- sp->lno = lno = rp->lno;
- if ((sp->cno = rp->cno) != 0)
- ++sp->cno;
- }
- return (0);
-}
-
-/*
- * v_iO -- [count]O
- * Insert text above this line.
- */
-int
-v_iO(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t ai_line, lno;
- size_t len;
- u_long cnt;
- u_int flags;
- int first;
- char *p;
-
- SET_TXT_STD(sp, TXT_APPENDEOL);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- for (first = 1, cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- if (sp->lno == 1) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0)
- goto insert;
- p = NULL;
- len = 0;
- ai_line = OOBLNO;
- } else {
-insert: p = "";
- sp->cno = 0;
- /* Correct logging for implied cursor motion. */
- if (first == 1) {
- log_cursor(sp, ep);
- first = 0;
- }
- if (file_iline(sp, ep, sp->lno, p, 0))
- return (1);
- if ((p = file_gline(sp, ep, sp->lno, &len)) == NULL) {
- GETLINE_ERR(sp, sp->lno);
- return (1);
- }
- ai_line = sp->lno + 1;
- }
-
- if (v_ntext(sp, ep,
- &sp->tiq, NULL, p, len, rp, 0, ai_line, flags))
- return (1);
-
- SET_TXT_STD(sp, TXT_APPENDEOL | TXT_REPLAY);
- sp->lno = lno = rp->lno;
- sp->cno = rp->cno;
- }
- return (0);
-}
-
-/*
- * v_io -- [count]o
- * Insert text after this line.
- */
-int
-v_io(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t ai_line, lno;
- size_t len;
- u_long cnt;
- u_int flags;
- int first;
- char *p;
-
- SET_TXT_STD(sp, TXT_APPENDEOL);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- for (first = 1,
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- if (sp->lno == 1) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0)
- goto insert;
- p = NULL;
- len = 0;
- ai_line = OOBLNO;
- } else {
-insert: p = "";
- sp->cno = 0;
- /* Correct logging for implied cursor motion. */
- if (first == 1) {
- log_cursor(sp, ep);
- first = 0;
- }
- len = 0;
- if (file_aline(sp, ep, 1, sp->lno, p, len))
- return (1);
- if ((p = file_gline(sp, ep, ++sp->lno, &len)) == NULL) {
- GETLINE_ERR(sp, sp->lno);
- return (1);
- }
- ai_line = sp->lno - 1;
- }
-
- if (v_ntext(sp, ep,
- &sp->tiq, NULL, p, len, rp, 0, ai_line, flags))
- return (1);
-
- SET_TXT_STD(sp, TXT_APPENDEOL | TXT_REPLAY);
- sp->lno = lno = rp->lno;
- sp->cno = rp->cno;
- }
- return (0);
-}
-
-/*
- * v_Change -- [buffer][count]C
- * Change line command.
- */
-int
-v_Change(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (v_CS(sp, ep, vp, fm, tm, rp, 0));
-}
-
-/*
- * v_Subst -- [buffer][count]S
- * Line substitute command.
- */
-int
-v_Subst(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- u_int flags;
-
- /*
- * The S command is the same as a 'C' command from the beginning
- * of the line. This is hard to do in the parser, so do it here.
- *
- * If autoindent is on, the change is from the first *non-blank*
- * character of the line, not the first character. And, to make
- * it just a bit more exciting, the initial space is handled as
- * auto-indent characters.
- */
- LF_INIT(0);
- if (O_ISSET(sp, O_AUTOINDENT)) {
- fm->cno = 0;
- if (nonblank(sp, ep, fm->lno, &fm->cno))
- return (1);
- LF_SET(TXT_AICHARS);
- } else
- fm->cno = 0;
- sp->cno = fm->cno;
- return (v_CS(sp, ep, vp, fm, tm, rp, flags));
-}
-
-/*
- * v_CS --
- * C and S commands.
- */
-static int
-v_CS(sp, ep, vp, fm, tm, rp, iflags)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
- u_int iflags;
-{
- recno_t lno;
- size_t len;
- char *p;
- u_int flags;
-
- SET_TXT_STD(sp, iflags);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
-
- /*
- * There are two cases -- if a count is supplied, we do a line
- * mode change where we delete the lines and then insert text
- * into a new line. Otherwise, we replace the current line.
- */
- tm->lno = fm->lno + (F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0);
- if (fm->lno != tm->lno) {
- /* Make sure that the to line is real. */
- if (file_gline(sp, ep, tm->lno, NULL) == NULL) {
- v_eof(sp, ep, fm);
- return (1);
- }
-
- /* Cut the lines. */
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- fm, tm, CUT_LINEMODE))
- return (1);
-
- /* Insert a line while we still can... */
- if (file_iline(sp, ep, fm->lno, "", 0))
- return (1);
- ++fm->lno;
- ++tm->lno;
-
- /* Delete the lines. */
- if (delete(sp, ep, fm, tm, 1))
- return (1);
-
- /* Get the inserted line. */
- if ((p = file_gline(sp, ep, --fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- tm = NULL;
- sp->lno = fm->lno;
- sp->cno = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- /* The line may be empty, but that's okay. */
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, tm->lno);
- return (1);
- }
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- fm, tm, CUT_LINEMODE))
- return (1);
- tm->cno = len;
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_EMARK | TXT_OVERWRITE);
- }
- }
- /* Correct logging for implied cursor motion. */
- log_cursor(sp, ep);
- return (v_ntext(sp, ep,
- &sp->tiq, tm, p, len, rp, 0, OOBLNO, flags));
-}
-
-/*
- * v_change -- [buffer][count]c[count]motion
- * Change command.
- */
-int
-v_change(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- size_t blen, len;
- u_int flags;
- int lmode, rval;
- char *bp, *p;
-
- SET_TXT_STD(sp, 0);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
-
- /*
- * Move the cursor to the start of the change. Note, if autoindent
- * is turned on, the cc command in line mode changes from the first
- * *non-blank* character of the line, not the first character. And,
- * to make it just a bit more exciting, the initial space is handled
- * as auto-indent characters.
- */
- lmode = F_ISSET(vp, VC_LMODE) ? CUT_LINEMODE : 0;
- if (lmode) {
- fm->cno = 0;
- if (O_ISSET(sp, O_AUTOINDENT)) {
- if (nonblank(sp, ep, fm->lno, &fm->cno))
- return (1);
- LF_SET(TXT_AICHARS);
- }
- }
- sp->lno = fm->lno;
- sp->cno = fm->cno;
-
- /* Correct logging for implied cursor motion. */
- log_cursor(sp, ep);
-
- /*
- * If changing within a single line, the line either currently has
- * text or it doesn't. If it doesn't, just insert text. Otherwise,
- * copy it and overwrite it.
- */
- if (fm->lno == tm->lno) {
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (p == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- }
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- fm, tm, lmode))
- return (1);
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_EMARK | TXT_OVERWRITE);
- }
- return (v_ntext(sp, ep,
- &sp->tiq, tm, p, len, rp, 0, OOBLNO, flags));
- }
-
- /*
- * It's trickier if changing over multiple lines. If we're in
- * line mode we delete all of the lines and insert a replacement
- * line which the user edits. If there was leading whitespace
- * in the first line being changed, we copy it and use it as the
- * replacement. If we're not in line mode, we just delete the
- * text and start inserting.
- *
- * Copy the text.
- */
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, lmode))
- return (1);
-
- /* If replacing entire lines and there's leading text. */
- if (lmode && fm->cno) {
- /* Get a copy of the first line changed. */
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- /* Copy the leading text elsewhere. */
- GET_SPACE_RET(sp, bp, blen, fm->cno);
- memmove(bp, p, fm->cno);
- } else
- bp = NULL;
-
- /* Delete the text. */
- if (delete(sp, ep, fm, tm, lmode))
- return (1);
-
- /* If replacing entire lines, insert a replacement line. */
- if (lmode) {
- if (file_iline(sp, ep, fm->lno, bp, fm->cno))
- return (1);
- sp->lno = fm->lno;
- len = sp->cno = fm->cno;
- }
-
- /* Get the line we're editing. */
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- len = 0;
- }
-
- /* Check to see if we're appending to the line. */
- if (fm->cno >= len)
- LF_SET(TXT_APPENDEOL);
-
- /* No to mark. */
- tm = NULL;
-
- rval = v_ntext(sp, ep, &sp->tiq, tm, p, len, rp, 0, OOBLNO, flags);
-
- if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
-
-/*
- * v_Replace -- [count]R
- * Overwrite multiple characters.
- */
-int
-v_Replace(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- char *p;
-
- SET_TXT_STD(sp, 0);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if ((p = file_gline(sp, ep, rp->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, rp->lno);
- return (1);
- }
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_OVERWRITE | TXT_REPLACE);
- }
- tm->lno = rp->lno;
- tm->cno = len ? len : 0;
- if (v_ntext(sp, ep, &sp->tiq, tm, p, len, rp, 0, OOBLNO, flags))
- return (1);
-
- /*
- * Special case. The historic vi handled [count]R badly, in that R
- * would replace some number of characters, and then the count would
- * append count-1 copies of the replacing chars to the replaced space.
- * This seems wrong, so this version counts R commands. There is some
- * trickiness in moving back to where the user stopped replacing after
- * each R command. Basically, if the user ended with a newline, we
- * want to use rp->cno (which will be 0). Otherwise, use the column
- * after the returned cursor, unless it would be past the end of the
- * line, in which case we append to the line.
- */
- while (--cnt) {
- if ((p = file_gline(sp, ep, rp->lno, &len)) == NULL)
- GETLINE_ERR(sp, rp->lno);
- SET_TXT_STD(sp, TXT_REPLAY);
-
- sp->lno = rp->lno;
-
- if (len == 0 || rp->cno == len - 1) {
- sp->cno = len;
- LF_SET(TXT_APPENDEOL);
- } else {
- sp->cno = rp->cno;
- if (rp->cno != 0)
- ++sp->cno;
- LF_SET(TXT_OVERWRITE | TXT_REPLACE);
- }
-
- if (v_ntext(sp, ep,
- &sp->tiq, tm, p, len, rp, 0, OOBLNO, flags))
- return (1);
- }
- return (0);
-}
-
-/*
- * v_subst -- [buffer][count]s
- * Substitute characters.
- */
-int
-v_subst(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- size_t len;
- u_int flags;
- char *p;
-
- SET_TXT_STD(sp, 0);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_EMARK | TXT_OVERWRITE);
- }
-
- tm->lno = fm->lno;
- tm->cno = fm->cno + (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
- if (tm->cno > len)
- tm->cno = len;
-
- if (p != NULL && cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
- return (1);
-
- return (v_ntext(sp, ep,
- &sp->tiq, tm, p, len, rp, 0, OOBLNO, flags));
-}
diff --git a/usr.bin/vi/nvi/v_ulcase.c b/usr.bin/vi/nvi/v_ulcase.c
deleted file mode 100644
index 12fd1c6626b9..000000000000
--- a/usr.bin/vi/nvi/v_ulcase.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_ulcase.c 8.3 (Berkeley) 12/9/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_ulcase -- [count]~
- * Toggle upper & lower case letters.
- *
- * !!!
- * In historic vi, the count was ignored. It would have been better
- * if there had been an associated motion, but it's too late to change
- * it now.
- */
-int
-v_ulcase(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t lno;
- size_t blen, lcnt, len;
- u_long cnt;
- int ch, change, rval;
- char *bp, *p;
-
- /* Figure out what memory to use. */
- GET_SPACE_RET(sp, bp, blen, 256);
-
- /*
- * !!!
- * Historic vi didn't permit ~ to cross newline boundaries.
- * I can think of no reason why it shouldn't, which at least
- * lets you auto-repeat through a paragraph.
- */
- rval = 0;
- for (change = -1, cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt;) {
- /* Get the line; EOF is an infinite sink. */
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno >= fm->lno) {
- GETLINE_ERR(sp, fm->lno);
- rval = 1;
- break;
- }
- if (change == -1) {
- v_eof(sp, ep, NULL);
- return (1);
- }
- break;
- }
-
- /* Set current line number. */
- lno = fm->lno;
-
- /* Empty lines just decrement the count. */
- if (len == 0) {
- --cnt;
- ++fm->lno;
- fm->cno = 0;
- change = 0;
- continue;
- }
-
- /* Get a copy of the line. */
- ADD_SPACE_RET(sp, bp, blen, len);
- memmove(bp, p, len);
-
- /* Set starting pointer. */
- if (change == -1)
- p = bp + fm->cno;
- else
- p = bp;
-
- /*
- * Figure out how many characters get changed in this
- * line. Set the final cursor column.
- */
- if (fm->cno + cnt >= len) {
- lcnt = len - fm->cno;
- ++fm->lno;
- fm->cno = 0;
- } else
- fm->cno += lcnt = cnt;
- cnt -= lcnt;
-
- /* Change the line. */
- for (change = 0; lcnt--; ++p) {
- ch = *(u_char *)p;
- if (islower(ch)) {
- *p = toupper(ch);
- change = 1;
- } else if (isupper(ch)) {
- *p = tolower(ch);
- change = 1;
- }
- }
-
- /* Update the line if necessary. */
- if (change && file_sline(sp, ep, lno, bp, len)) {
- rval = 1;
- break;
- }
- }
-
- /* If changed lines, could be on an illegal line. */
- if (fm->lno != lno && file_gline(sp, ep, fm->lno, &len) == NULL) {
- --fm->lno;
- fm->cno = len ? len - 1 : 0;
- }
- *rp = *fm;
-
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
diff --git a/usr.bin/vi/nvi/v_undo.c b/usr.bin/vi/nvi/v_undo.c
deleted file mode 100644
index 87c749b38179..000000000000
--- a/usr.bin/vi/nvi/v_undo.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_undo.c 8.6 (Berkeley) 1/8/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_Undo -- U
- * Undo changes to this line.
- */
-int
-v_Undo(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /*
- * Historically, U reset the cursor to the first column in the line
- * (not the first non-blank). This seems a bit non-intuitive, but,
- * considering that we may have undone multiple changes, anything
- * else (including the cursor position stored in the logging records)
- * is going to appear random.
- */
- rp->lno = fm->lno;
- rp->cno = 0;
-
- /*
- * !!!
- * Set up the flags so that an immediately subsequent 'u' will roll
- * forward, instead of backward. In historic vi, a 'u' following a
- * 'U' redid all of the changes to the line. Given that the user has
- * explicitly discarded those changes by entering 'U', it seems likely
- * that the user wants something between the original and end forms of
- * the line, so starting to replay the changes seems the best way to
- * get to there.
- */
- F_SET(ep, F_UNDO);
- ep->lundo = BACKWARD;
-
- return (log_setline(sp, ep));
-}
-
-/*
- * v_undo -- u
- * Undo the last change.
- */
-int
-v_undo(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- /* Set the command count. */
- VIP(sp)->u_ccnt = sp->ccnt;
-
- /*
- * !!!
- * In historic vi, 'u' toggled between "undo" and "redo", i.e. 'u'
- * undid the last undo. However, if there has been a change since
- * the last undo/redo, we always do an undo. To make this work when
- * the user can undo multiple operations, we leave the old semantic
- * unchanged, but make '.' after a 'u' do another undo/redo operation.
- * This has two problems.
- *
- * The first is that 'u' didn't set '.' in historic vi. So, if a
- * user made a change, realized it was in the wrong place, does a
- * 'u' to undo it, moves to the right place and then does '.', the
- * change was reapplied. To make this work, we only apply the '.'
- * to the undo command if it's the command immediately following an
- * undo command. See vi/vi.c:getcmd() for the details.
- *
- * The second is that the traditional way to view the numbered cut
- * buffers in vi was to enter the commands "1pu.u.u.u. which will
- * no longer work because the '.' immediately follows the 'u' command.
- * Since we provide a much better method of viewing buffers, and
- * nobody can think of a better way of adding in multiple undo, this
- * remains broken.
- */
- if (!F_ISSET(ep, F_UNDO)) {
- F_SET(ep, F_UNDO);
- ep->lundo = BACKWARD;
- } else if (!F_ISSET(vp, VC_ISDOT))
- ep->lundo = ep->lundo == BACKWARD ? FORWARD : BACKWARD;
-
- switch (ep->lundo) {
- case BACKWARD:
- return (log_backward(sp, ep, rp));
- case FORWARD:
- return (log_forward(sp, ep, rp));
- default:
- abort();
- }
- /* NOTREACHED */
-}
diff --git a/usr.bin/vi/nvi/v_util.c b/usr.bin/vi/nvi/v_util.c
deleted file mode 100644
index 83c4fb4ebbf6..000000000000
--- a/usr.bin/vi/nvi/v_util.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_util.c 8.5 (Berkeley) 11/15/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_eof --
- * Vi end-of-file error.
- */
-void
-v_eof(sp, ep, mp)
- SCR *sp;
- EXF *ep;
- MARK *mp;
-{
- u_long lno;
-
- if (mp == NULL)
- msgq(sp, M_BERR, "Already at end-of-file.");
- else {
- if (file_lline(sp, ep, &lno))
- return;
- if (mp->lno >= lno)
- msgq(sp, M_BERR, "Already at end-of-file.");
- else
- msgq(sp, M_BERR,
- "Movement past the end-of-file.");
- }
-}
-
-/*
- * v_eol --
- * Vi end-of-line error.
- */
-void
-v_eol(sp, ep, mp)
- SCR *sp;
- EXF *ep;
- MARK *mp;
-{
- size_t len;
-
- if (mp == NULL)
- msgq(sp, M_BERR, "Already at end-of-line.");
- else {
- if (file_gline(sp, ep, mp->lno, &len) == NULL) {
- GETLINE_ERR(sp, mp->lno);
- return;
- }
- if (mp->cno == len - 1)
- msgq(sp, M_BERR, "Already at end-of-line.");
- else
- msgq(sp, M_BERR, "Movement past the end-of-line.");
- }
-}
-
-/*
- * v_sof --
- * Vi start-of-file error.
- */
-void
-v_sof(sp, mp)
- SCR *sp;
- MARK *mp;
-{
- if (mp == NULL || mp->lno == 1)
- msgq(sp, M_BERR, "Already at the beginning of the file.");
- else
- msgq(sp, M_BERR, "Movement past the beginning of the file.");
-}
-
-/*
- * v_isempty --
- * Return if the line contains nothing but white-space characters.
- */
-int
-v_isempty(p, len)
- char *p;
- size_t len;
-{
- for (; len--; ++p)
- if (!isblank(*p))
- return (0);
- return (1);
-}
diff --git a/usr.bin/vi/nvi/v_word.c b/usr.bin/vi/nvi/v_word.c
deleted file mode 100644
index 8d917d68e088..000000000000
--- a/usr.bin/vi/nvi/v_word.c
+++ /dev/null
@@ -1,560 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_word.c 8.10 (Berkeley) 10/26/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * There are two types of "words". Bigwords are easy -- groups of anything
- * delimited by whitespace. Normal words are trickier. They are either a
- * group of characters, numbers and underscores, or a group of anything but,
- * delimited by whitespace. When for a word, if you're in whitespace, it's
- * easy, just remove the whitespace and go to the beginning or end of the
- * word. Otherwise, figure out if the next character is in a different group.
- * If it is, go to the beginning or end of that group, otherwise, go to the
- * beginning or end of the current group. The historic version of vi didn't
- * get this right, so, for example, there were cases where "4e" was not the
- * same as "eeee". To get it right you have to resolve the cursor after each
- * search so that the look-ahead to figure out what type of "word" the cursor
- * is in will be correct.
- *
- * Empty lines, and lines that consist of only white-space characters count
- * as a single word, and the beginning and end of the file counts as an
- * infinite number of words.
- *
- * Movements associated with commands are different than movement commands.
- * For example, in "abc def", with the cursor on the 'a', "cw" is from
- * 'a' to 'c', while "w" is from 'a' to 'd'. In general, trailing white
- * space is discarded from the change movement. Another example is that,
- * in the same string, a "cw" on any white space character replaces that
- * single character, and nothing else. Ain't nothin' in here that's easy.
- *
- * One historic note -- in the original vi, the 'w', 'W' and 'B' commands
- * would treat groups of empty lines as individual words, i.e. the command
- * would move the cursor to each new empty line. The 'e' and 'E' commands
- * would treat groups of empty lines as a single word, i.e. the first use
- * would move past the group of lines. The 'b' command would just beep at
- * you. If the lines contained only white-space characters, the 'w' and 'W'
- * commands will just beep at you, and the 'B', 'b', 'E' and 'e' commands
- * will treat the group as a single word, and the 'B' and 'b' commands will
- * treat the lines as individual words. This implementation treats both
- * cases as a single white-space word.
- */
-
-#define FW(test) for (; len && (test); --len, ++p)
-#define BW(test) for (; len && (test); --len, --p)
-
-enum which {BIGWORD, LITTLEWORD};
-
-static int bword __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, int));
-static int eword __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, int));
-static int fword __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, enum which));
-
-/*
- * v_wordw -- [count]w
- * Move forward a word at a time.
- */
-int
-v_wordw(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (fword(sp, ep, vp, fm, rp, LITTLEWORD));
-}
-
-/*
- * v_wordW -- [count]W
- * Move forward a bigword at a time.
- */
-int
-v_wordW(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (fword(sp, ep, vp, fm, rp, BIGWORD));
-}
-
-/*
- * fword --
- * Move forward by words.
- */
-static int
-fword(sp, ep, vp, fm, rp, type)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *rp;
- enum which type;
-{
- enum { INWORD, NOTWORD } state;
- VCS cs;
- u_long cnt;
-
- cs.cs_lno = fm->lno;
- cs.cs_cno = fm->cno;
- if (cs_init(sp, ep, &cs))
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * If in white-space:
- * If the count is 1, and it's a change command, we're done.
- * Else, move to the first non-white-space character, which
- * counts as a single word move. If it's a motion command,
- * don't move off the end of the line.
- */
- if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
- if (cs.cs_flags != CS_EMP && cnt == 1) {
- if (F_ISSET(vp, VC_C)) {
- ++cs.cs_cno;
- goto ret3;
- }
- if (F_ISSET(vp, VC_D | VC_Y)) {
- if (cs_fspace(sp, ep, &cs))
- return (1);
- goto ret1;
- }
- }
- if (cs_fblank(sp, ep, &cs))
- return (1);
- --cnt;
- }
-
- /*
- * Cyclically move to the next word -- this involves skipping
- * over word characters and then any trailing non-word characters.
- * Note, for the 'w' command, the definition of a word keeps
- * switching.
- */
- if (type == BIGWORD)
- while (cnt--) {
- for (;;) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- goto ret2;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- break;
- }
- /*
- * If a motion command and we're at the end of the
- * last word, we're done. Delete and yank eat any
- * trailing blanks, but we don't move off the end
- * of the line regardless.
- */
- if (cnt == 0 && F_ISSET(vp, VC_C | VC_D | VC_Y)) {
- if (F_ISSET(vp, VC_D | VC_Y) &&
- cs_fspace(sp, ep, &cs))
- return (1);
- break;
- }
-
- /* Eat whitespace characters. */
- if (cs_fblank(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- goto ret2;
- }
- else
- while (cnt--) {
- state = cs.cs_flags == 0 &&
- inword(cs.cs_ch) ? INWORD : NOTWORD;
- for (;;) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- goto ret2;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- break;
- if (state == INWORD) {
- if (!inword(cs.cs_ch))
- break;
- } else
- if (inword(cs.cs_ch))
- break;
- }
- /* See comment above. */
- if (cnt == 0 && F_ISSET(vp, VC_C | VC_D | VC_Y)) {
- if (F_ISSET(vp, VC_D | VC_Y) &&
- cs_fspace(sp, ep, &cs))
- return (1);
- break;
- }
-
- /* Eat whitespace characters. */
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- if (cs_fblank(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- goto ret2;
- }
-
- /*
- * If a motion command, and eating the trailing non-word would
- * move us off this line, don't do it. Move the return cursor
- * to one past the EOL instead.
- */
-ret1: if (F_ISSET(vp, VC_C | VC_D | VC_Y) && cs.cs_flags == CS_EOL)
- ++cs.cs_cno;
-
- /* If we didn't move, we must be at EOF. */
-ret2: if (cs.cs_lno == fm->lno && cs.cs_cno == fm->cno) {
- v_eof(sp, ep, fm);
- return (1);
- }
- /*
- * If at EOF, and it's a motion command, move the return cursor
- * one past the EOF.
- */
- if (F_ISSET(vp, VC_C | VC_D | VC_Y) && cs.cs_flags == CS_EOF)
- ++cs.cs_cno;
-ret3: rp->lno = cs.cs_lno;
- rp->cno = cs.cs_cno;
- return (0);
-}
-
-/*
- * v_wordb -- [count]b
- * Move backward a word at a time.
- */
-int
-v_wordb(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (bword(sp, ep, vp, fm, rp, 0));
-}
-
-/*
- * v_WordB -- [count]B
- * Move backward a bigword at a time.
- */
-int
-v_wordB(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (bword(sp, ep, vp, fm, rp, 1));
-}
-
-/*
- * bword --
- * Move backward by words.
- */
-static int
-bword(sp, ep, vp, fm, rp, spaceonly)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *rp;
- int spaceonly;
-{
- register char *p;
- recno_t lno;
- size_t len;
- u_long cno, cnt;
- char *startp;
-
- lno = fm->lno;
- cno = fm->cno;
-
- /* Check for start of file. */
- if (lno == 1 && cno == 0) {
- v_sof(sp, NULL);
- return (1);
- }
-
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_sof(sp, NULL);
- else
- GETLINE_ERR(sp, lno);
- return (1);
- }
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * Reset the length to the number of characters in the line; the
- * first character is the current cursor position.
- */
- len = cno ? cno + 1 : 0;
- if (len == 0)
- goto line;
- for (startp = p, p += cno; cnt--;) {
- if (spaceonly) {
- if (!isblank(*p)) {
- if (len < 2)
- goto line;
- --p;
- --len;
- }
- BW(isblank(*p));
- if (len)
- BW(!isblank(*p));
- else
- goto line;
- } else {
- if (!isblank(*p)) {
- if (len < 2)
- goto line;
- --p;
- --len;
- }
- BW(isblank(*p));
- if (len)
- if (inword(*p))
- BW(inword(*p));
- else
- BW(!isblank(*p) && !inword(*p));
- else
- goto line;
- }
-
- if (cnt && len == 0) {
- /* If we hit SOF, stay there (historic practice). */
-line: if (lno == 1) {
- rp->lno = 1;
- rp->cno = 0;
- return (0);
- }
-
- /*
- * Get the line. If the line is empty, decrement
- * count and get another one.
- */
- if ((p = file_gline(sp, ep, --lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- if (len == 0) {
- if (cnt == 0 || --cnt == 0) {
- rp->lno = lno;
- rp->cno = 0;
- return (0);
- }
- goto line;
- }
-
- /*
- * Set the cursor to the end of the line. If the word
- * at the end of this line has only a single character,
- * we've already skipped over it.
- */
- startp = p;
- if (len) {
- p += len - 1;
- if (cnt && len > 1 && !isblank(p[0]))
- if (inword(p[0])) {
- if (!inword(p[-1]))
- --cnt;
- } else if (!isblank(p[-1]) &&
- !inword(p[-1]))
- --cnt;
- }
- } else {
- ++p;
- ++len;
- }
- }
- rp->lno = lno;
- rp->cno = p - startp;
- return (0);
-}
-
-/*
- * v_worde -- [count]e
- * Move forward to the end of the word.
- */
-int
-v_worde(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (eword(sp, ep, vp, fm, rp, 0));
-}
-
-/*
- * v_wordE -- [count]E
- * Move forward to the end of the bigword.
- */
-int
-v_wordE(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- return (eword(sp, ep, vp, fm, rp, 1));
-}
-
-/*
- * eword --
- * Move forward to the end of the word.
- */
-static int
-eword(sp, ep, vp, fm, rp, spaceonly)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *rp;
- int spaceonly;
-{
- register char *p;
- recno_t lno;
- size_t len, llen;
- u_long cno, cnt;
- int empty;
- char *startp;
-
- lno = fm->lno;
- cno = fm->cno;
-
- if ((p = file_gline(sp, ep, lno, &llen)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_eof(sp, ep, NULL);
- else
- GETLINE_ERR(sp, lno);
- return (1);
- }
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * Reset the length; the first character is the current cursor
- * position. If no more characters in this line, may already
- * be at EOF.
- */
- len = llen - cno;
- if (empty = llen == 0 || llen == cno + 1)
- goto line;
-
- for (startp = p += cno; cnt--; empty = 0) {
- if (spaceonly) {
- if (!isblank(*p)) {
- if (len < 2)
- goto line;
- ++p;
- --len;
- }
- FW(isblank(*p));
- if (len)
- FW(!isblank(*p));
- else
- ++cnt;
- } else {
- if (!isblank(*p)) {
- if (len < 2)
- goto line;
- ++p;
- --len;
- }
- FW(isblank(*p));
- if (len)
- if (inword(*p))
- FW(inword(*p));
- else
- FW(!isblank(*p) && !inword(*p));
- else
- ++cnt;
- }
-
- if (cnt && len == 0) {
- /* If we hit EOF, stay there (historic practice). */
-line: if ((p = file_gline(sp, ep, ++lno, &llen)) == NULL) {
- /*
- * If already at eof, complain, unless it's
- * a change command or a delete command and
- * there's something to delete.
- */
- if (empty) {
- if (F_ISSET(vp, VC_C) ||
- F_ISSET(vp, VC_D) && llen != 0) {
- rp->lno = lno - 1;
- rp->cno = llen ? llen : 1;
- return (0);
- }
- v_eof(sp, ep, NULL);
- return (1);
- }
- if ((p =
- file_gline(sp, ep, --lno, &llen)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- rp->lno = lno;
- rp->cno = llen ? llen - 1 : 0;
- /* The 'c', 'd' and 'y' need one more space. */
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- ++rp->cno;
- return (0);
- }
- len = llen;
- cno = 0;
- startp = p;
- } else {
- --p;
- ++len;
- }
- }
- rp->lno = lno;
- rp->cno = cno + (p - startp);
-
- /* The 'c', 'd' and 'y' need one more space. */
- if (F_ISSET(vp, VC_C | VC_D | VC_Y))
- ++rp->cno;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_xchar.c b/usr.bin/vi/nvi/v_xchar.c
deleted file mode 100644
index 019862240f26..000000000000
--- a/usr.bin/vi/nvi/v_xchar.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_xchar.c 8.4 (Berkeley) 1/9/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-#define NODEL(sp) { \
- msgq(sp, M_BERR, "No characters to delete."); \
- return (1); \
-}
-
-/*
- * v_xchar --
- * Deletes the character(s) on which the cursor sits.
- */
-int
-v_xchar(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- MARK m;
- recno_t lno;
- u_long cnt;
- size_t len;
-
- if (file_gline(sp, ep, fm->lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- NODEL(sp);
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
-
- if (len == 0)
- NODEL(sp);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * Deleting from the cursor toward the end of line, w/o moving the
- * cursor. Note, "2x" at EOL isn't the same as "xx" because the
- * left movement of the cursor as part of the 'x' command isn't
- * taken into account. Historically correct.
- */
- tm->lno = fm->lno;
- if (cnt < len - fm->cno) {
- tm->cno = fm->cno + cnt;
- m = *fm;
- } else {
- tm->cno = len;
- m.lno = fm->lno;
- m.cno = fm->cno ? fm->cno - 1 : 0;
- }
-
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
- return (1);
- if (delete(sp, ep, fm, tm, 0))
- return (1);
-
- *rp = m;
- return (0);
-}
-
-/*
- * v_Xchar --
- * Deletes the character(s) immediately before the current cursor
- * position.
- */
-int
-v_Xchar(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- u_long cnt;
-
- if (fm->cno == 0) {
- msgq(sp, M_BERR, "Already at the left-hand margin.");
- return (1);
- }
-
- *tm = *fm;
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- fm->cno = cnt >= tm->cno ? 0 : tm->cno - cnt;
-
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
- return (1);
- if (delete(sp, ep, fm, tm, 0))
- return (1);
-
- *rp = *fm;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_yank.c b/usr.bin/vi/nvi/v_yank.c
deleted file mode 100644
index 7b2718e647a4..000000000000
--- a/usr.bin/vi/nvi/v_yank.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_yank.c 8.11 (Berkeley) 1/9/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_Yank -- [buffer][count]Y
- * Yank lines of text into a cut buffer.
- */
-int
-v_Yank(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- if (file_gline(sp, ep, tm->lno, NULL) == NULL) {
- v_eof(sp, ep, fm);
- return (1);
- }
- if (cut(sp, ep, NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- fm, tm, CUT_LINEMODE))
- return (1);
-
- sp->rptlines[L_YANKED] += (tm->lno - fm->lno) + 1;
- return (0);
-}
-
-/*
- * v_yank -- [buffer][count]y[count][motion]
- * Yank text (or lines of text) into a cut buffer.
- */
-int
-v_yank(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- if (F_ISSET(vp, VC_LMODE)) {
- if (file_gline(sp, ep, tm->lno, NULL) == NULL) {
- v_eof(sp, ep, fm);
- return (1);
- }
- if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- fm, tm, CUT_LINEMODE))
- return (1);
- } else if (cut(sp, ep,
- NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
- return (1);
-
- /*
- * !!!
- * Historic vi moved the cursor to the from MARK if it was before the
- * current cursor. This makes no sense. For example, "yj" moves the
- * cursor but "yk" does not. Unfortunately, it's too late to change
- * this now. Matching the historic semantics isn't easy. The line
- * number was always changed and column movement was usually relative.
- * However, "y'a" moved the cursor to the first non-blank of the line
- * marked by a, while "y`a" moved the cursor to the line and column
- * marked by a.
- */
- if (F_ISSET(vp, VC_REVMOVE)) {
- rp->lno = fm->lno;
- if (vp->mkp == &vikeys['\'']) {
- rp->cno = 0;
- (void)nonblank(sp, ep, rp->lno, &rp->cno);
- } else if (vp->mkp == &vikeys['`'])
- rp->cno = fm->cno;
- else
- rp->cno = sp->s_relative(sp, ep, rp->lno);
- }
-
- sp->rptlines[L_YANKED] += (tm->lno - fm->lno) + 1;
- return (0);
-}
diff --git a/usr.bin/vi/nvi/v_z.c b/usr.bin/vi/nvi/v_z.c
deleted file mode 100644
index 31937ffc951c..000000000000
--- a/usr.bin/vi/nvi/v_z.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)v_z.c 8.8 (Berkeley) 12/2/93";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_z -- [count]z[count][-.+^<CR>]
- * Move the screen.
- */
-int
-v_z(sp, ep, vp, fm, tm, rp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- MARK *fm, *tm, *rp;
-{
- recno_t last, lno;
- u_int value;
-
- /*
- * The first count is the line to use. If the value doesn't
- * exist, use the last line.
- */
- if (F_ISSET(vp, VC_C1SET)) {
- lno = vp->count;
- if (file_lline(sp, ep, &last))
- return (1);
- if (lno > last)
- lno = last;
- } else
- lno = fm->lno;
-
- /* Set return cursor values. */
- rp->lno = lno;
- rp->cno = fm->cno;
-
- /*
- * The second count is the displayed window size, i.e. the 'z'
- * command is another way to get artificially small windows.
- *
- * !!!
- * A window size of 0 was historically allowed, and simply ignored.
- * Also, this could be much more simply done by modifying the value
- * of the O_WINDOW option, but that's not how it worked historically.
- */
- if (F_ISSET(vp, VC_C2SET) &&
- vp->count2 != 0 && sp->s_rrel(sp, vp->count2))
- return (1);
-
- switch (vp->character) {
- case '-': /* Put the line at the bottom. */
- if (sp->s_fill(sp, ep, lno, P_BOTTOM))
- return (1);
- break;
- case '.': /* Put the line in the middle. */
- if (sp->s_fill(sp, ep, lno, P_MIDDLE))
- return (1);
- break;
- default: /* Put the line at the top for <cr>. */
- value = term_key_val(sp, vp->character);
- if (value != K_CR && value != K_NL) {
- msgq(sp, M_ERR, "usage: %s.", vp->kp->usage);
- return (1);
- }
- /* FALLTHROUGH */
- case '+': /* Put the line at the top. */
- if (sp->s_fill(sp, ep, lno, P_TOP))
- return (1);
- break;
- case '^': /* Print the screen before the z- screen. */
- /*
- * !!!
- * Historic practice isn't real clear on this one. It seems
- * that the command "70z^" is the same as ":70<cr>z-z^" with
- * an off-by-one difference. So, until I find documentation
- * to the contrary, the z^ command in this implementation
- * displays the screen immediately before the current one.
- * Fill the screen with the selected line at the bottom, then,
- * scroll the screen down a page, and move to the middle line
- * of the screen. Historic vi moved the cursor to some random
- * place in the screen, as far as I can tell.
- */
- if (sp->s_fill(sp, ep, lno, P_BOTTOM))
- return (1);
- if (sp->s_down(sp, ep, rp, sp->t_maxrows - 1, 1))
- return (1);
- if (sp->s_position(sp, ep, rp, 0, P_MIDDLE))
- return (1);
- break;
- }
-
- /* If the map changes, have to redraw the entire screen. */
- F_SET(sp, S_REDRAW);
-
- return (0);
-}
diff --git a/usr.bin/vi/nvi/vcmd.c b/usr.bin/vi/nvi/vcmd.c
deleted file mode 100644
index d7f1caf81d0c..000000000000
--- a/usr.bin/vi/nvi/vcmd.c
+++ /dev/null
@@ -1,522 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)vcmd.c 8.22 (Berkeley) 1/8/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * This array maps keystrokes to vi command functions. It is known
- * in ex/ex_usage.c that it takes four columns to name a vi character.
- */
-VIKEYS const vikeys [MAXVIKEY + 1] = {
-/* 000 NUL -- The code in vi.c expects key 0 to be undefined. */
- {NULL},
-/* 001 ^A */
- {v_searchw, V_ABS|V_CNT|V_MOVE|V_KEYW|V_RCM_SET,
- "[count]^A",
- "^A search forward for cursor word"},
-/* 002 ^B */
- {v_pageup, V_ABS|V_CNT|V_RCM_SETLFNB,
- "[count]^B",
- "^B page up by screens"},
-/* 003 ^C */
- {NULL, 0,
- "^C",
- "^C interrupt a search or global command"},
-/* 004 ^D */
- {v_hpagedown, V_ABS|V_CNT|V_RCM_SETLFNB,
- "[count]^D",
- "^D page down by half screens (setting count)"},
-/* 005 ^E */
- {v_linedown, V_CNT,
- "[count]^E",
- "^E page down by lines"},
-/* 006 ^F */
- {v_pagedown, V_ABS|V_CNT|V_RCM_SETLFNB,
- "[count]^F",
- "^F page down by screens"},
-/* 007 ^G */
- {v_status, 0,
- "^G",
- "^G file status"},
-/* 010 ^H */
- {v_left, V_CNT|V_MOVE|V_RCM_SET,
- "[count]^H",
- "^H move left by columns"},
-/* 011 ^I */
- {NULL},
-/* 012 ^J */
- {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM,
- "[count]^J",
- "^J move down by lines"},
-/* 013 ^K */
- {NULL},
-/* 014 ^L */
- {v_redraw, 0,
- "^L",
- "^L redraw screen"},
-/* 015 ^M */
- {v_cr, V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
- "[count]^M",
- "^M move down by lines (to first non-blank)"},
-/* 016 ^N */
- {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM,
- "[count]^N",
- "^N move down by lines"},
-/* 017 ^O */
- {NULL},
-/* 020 ^P */
- {v_up, V_CNT|V_LMODE|V_MOVE|V_RCM,
- "[count]^P",
- "^P move up by lines"},
-/* 021 ^Q -- not available, used for hardware flow control. */
- {NULL},
-/* 022 ^R */
- {v_redraw, 0,
- "^R",
- "^R redraw screen"},
-/* 023 ^S -- not available, used for hardware flow control. */
- {NULL},
-/* 024 ^T */
- {v_tagpop, V_RCM_SET,
- "^T",
- "^T tag pop"},
-/* 025 ^U */
- {v_hpageup, V_ABS|V_CNT|V_RCM_SETLFNB,
- "[count]^U",
- "^U half page up (set count)"},
-/* 026 ^V */
- {NULL, 0,
- "^V",
- "^V input a literal character"},
-/* 027 ^W */
- {v_screen, 0,
- "^W",
- "^W move to next screen"},
-/* 030 ^X */
- {NULL},
-/* 031 ^Y */
- {v_lineup, V_CNT,
- "[count]^Y",
- "^Y page up by lines"},
-/* 032 ^Z */
- {v_stop, 0,
- "^Z",
- "^Z suspend editor"},
-/* 033 ^[ */
- {NULL, 0,
- "^[ <escape>",
- "^[ <escape> leave input mode, return to command mode"},
-/* 034 ^\ */
- {NULL},
-/* 035 ^] */
- {v_tagpush, V_KEYW|V_RCM_SET,
- "^]",
- "^] tag push cursor word"},
-/* 036 ^^ */
- {v_switch, 0,
- "^^",
- "^^ switch to previous file"},
-/* 037 ^_ */
- {NULL},
-/* 040 ' ' */
- {v_right, V_CNT|V_MOVE|V_RCM_SET,
- "[count]' '",
- " <space> move right by columns"},
-/* 041 ! */
- {v_filter, V_CNT|V_DOT|V_MOTION|V_RCM_SET,
- "[count]![count]motion command(s)",
- " ! filter through command(s) to motion"},
-/* 042 " */
- {NULL},
-/* 043 # */
- {v_increment, V_CHAR|V_CNT|V_DOT|V_KEYNUM|V_RCM_SET,
- "[count]#[#+-]",
- " # number increment/decrement"},
-/* 044 $ */
- {v_dollar, V_CNT|V_MOVE|V_RCM_SETLAST,
- " [count]$",
- " $ move to last column"},
-/* 045 % */
- {v_match, V_ABS|V_MOVE|V_RCM_SET,
- "%",
- " % move to match"},
-/* 046 & */
- {v_again, 0,
- "&",
- " & repeat substitution"},
-/* 047 ' */
- {v_gomark, V_ABS|V_CHAR|V_LMODE|V_MOVE|V_RCM_SETFNB,
- "'['a-z]",
- " ' move to mark (to first non-blank)"},
-/* 050 ( */
- {v_sentenceb, V_CNT|V_MOVE|V_RCM_SET,
- "[count](",
- " ( move back sentence"},
-/* 051 ) */
- {v_sentencef, V_ABS|V_CNT|V_MOVE|V_RCM_SET,
- "[count])",
- " ) move forward sentence"},
-/* 052 * */
- {NULL},
-/* 053 + */
- {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
- "[count]+",
- " + move down by lines (to first non-blank)"},
-/* 054 , */
- {v_chrrepeat, V_CNT|V_MOVE|V_RCM_SET,
- "[count],",
- " , reverse last F, f, T or t search"},
-/* 055 - */
- {v_up, V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
- "[count]-",
- " - move up by lines (to first non-blank)"},
-/* 056 . */
- {NULL, 0,
- ".",
- " . repeat the last command"},
-/* 057 / */
- {v_searchf, V_ABS|V_MOVE|V_RCM_SET,
- "/RE[/ offset]",
- " / search forward"},
-/* 060 0 */
- {v_zero, V_MOVE|V_RCM_SET,
- "0",
- " 0 move to first character"},
-/* 061 1 */
- {NULL},
-/* 062 2 */
- {NULL},
-/* 063 3 */
- {NULL},
-/* 064 4 */
- {NULL},
-/* 065 5 */
- {NULL},
-/* 066 6 */
- {NULL},
-/* 067 7 */
- {NULL},
-/* 070 8 */
- {NULL},
-/* 071 9 */
- {NULL},
-/* 072 : */
- {v_ex, 0,
- ":command [| command] ...",
- " : ex command"},
-/* 073 ; */
- {v_chrepeat, V_CNT|V_MOVE|V_RCM_SET,
- "[count];",
- " ; repeat last F, f, T or t search"},
-/* 074 < */
- {v_shiftl, V_CNT|V_DOT|V_MOTION|V_RCM_SET|VC_SH,
- "[count]<[count]motion",
- " < shift lines left to motion"},
-/* 075 = */
- {NULL},
-/* 076 > */
- {v_shiftr, V_CNT|V_DOT|V_MOTION|V_RCM_SET|VC_SH,
- "[count]>[count]motion",
- " > shift lines right to motion"},
-/* 077 ? */
- {v_searchb, V_ABS|V_MOVE|V_RCM_SET,
- "?RE[? offset]",
- " ? search backward"},
-/* 100 @ */
- {v_at, V_RBUF|V_RCM_SET,
- "@buffer",
- " @ execute buffer"},
-/* 101 A */
- {v_iA, V_CNT|V_DOT|V_RCM_SET,
- "[count]A",
- " A append to the line"},
-/* 102 B */
- {v_wordB, V_CNT|V_MOVE|V_RCM_SET,
- "[count]B",
- " B move back bigword"},
-/* 103 C */
- {v_Change, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer][count]C",
- " C change to end-of-line"},
-/* 104 D */
- {v_Delete, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer][count]D",
- " D delete to end-of-line"},
-/* 105 E */
- {v_wordE, V_CNT|V_MOVE|V_RCM_SET,
- "[count]E",
- " E move to end of bigword"},
-/* 106 F */
- {v_chF, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
- "[count]F character",
- " F character in line backward search"},
-/* 107 G */
- {v_lgoto, V_ABS|V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
- "[count]G",
- " G move to line"},
-/* 110 H */
- {v_home, V_CNT|V_LMODE|V_MOVE|V_RCM_SETNNB,
- "[count]H",
- " H move to count lines from screen top"},
-/* 111 I */
- {v_iI, V_CNT|V_DOT|V_RCM_SET,
- "[count]I",
- " I insert at line beginning"},
-/* 112 J */
- {v_join, V_CNT|V_DOT|V_RCM_SET,
- "[count]J",
- " J join lines"},
-/* 113 K */
- {NULL},
-/* 114 L */
- {v_bottom, V_CNT|V_LMODE|V_MOVE|V_RCM_SETNNB,
- "[count]L",
- " L move to screen bottom"},
-/* 115 M */
- {v_middle, V_CNT|V_LMODE|V_MOVE|V_RCM_SETNNB,
- "M",
- " M move to screen middle"},
-/* 116 N */
- {v_searchN, V_ABS|V_MOVE|V_RCM_SET,
- "n",
- " N reverse last search"},
-/* 117 O */
- {v_iO, V_CNT|V_DOT|V_RCM_SET,
- "[count]O",
- " O insert above line"},
-/* 120 P */
- {v_Put, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer]P",
- " P insert before cursor from buffer"},
-/* 121 Q */
- {v_exmode, 0,
- "Q",
- " Q switch to ex mode"},
-/* 122 R */
- {v_Replace, V_CNT|V_DOT|V_RCM_SET,
- "[count]R",
- " R replace characters"},
-/* 123 S */
- {v_Subst, V_CNT|V_DOT|V_LMODE|V_OBUF|V_RCM_SET,
- "[buffer][count]S",
- " S substitute for the line(s)"},
-/* 124 T */
- {v_chT, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
- "[count]T character",
- " T before character in line backward search"},
-/* 125 U */
- {v_Undo, V_RCM_SET,
- "U",
- " U Restore the current line"},
-/* 126 V */
- {NULL},
-/* 127 W */
- {v_wordW, V_CNT|V_MOVE|V_RCM_SET,
- "[count]W",
- " W move to next bigword"},
-/* 130 X */
- {v_Xchar, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer][count]X",
- " X delete character before cursor"},
-/* 131 Y */
- {v_Yank, V_CNT|V_LMODE|V_OBUF,
- "[buffer][count]Y",
- " Y copy line"},
-/* 132 Z */
- {v_exit, 0,
- "ZZ",
- "ZZ save file and exit"},
-/* 133 [ */
- {v_sectionb, V_ABS|V_LMODE|V_MOVE|V_RCM_SET,
- "[[",
- "[[ move back section"},
-/* 134 \ */
- {NULL},
-/* 135 ] */
- {v_sectionf, V_ABS|V_LMODE|V_MOVE|V_RCM_SET,
- "]]",
- "]] move forward section"},
-/* 136 ^ */
- /*
- * DON'T set the V_RCM_SETFNB flag, the function has to do
- * the work anyway, in case it's a motion component. DO set
- * V_RCM_SET, so that any motion that's part of a command is
- * preserved.
- */
- {v_first, V_CNT|V_MOVE|V_RCM_SET,
- "^",
- " ^ move to first non-blank"},
-/* 137 _ */
- /*
- * DON'T set the V_RCM_SETFNB flag, the function has to do
- * the work anyway, in case it's a motion component. DO set
- * V_RCM_SET, so that any motion that's part of a command is
- * preserved.
- */
- {v_cfirst, V_CNT|V_MOVE|V_RCM_SET,
- "_",
- " _ move to first non-blank"},
-/* 140 ` */
- {v_gomark, V_ABS|V_CHAR|V_MOVE|V_RCM_SET,
- "`[`a-z]",
- " ` move to mark"},
-/* 141 a */
- {v_ia, V_CNT|V_DOT|V_RCM_SET,
- "[count]a",
- " a append after cursor"},
-/* 142 b */
- {v_wordb, V_CNT|V_MOVE|V_RCM_SET,
- "[count]b",
- " b move back word"},
-/* 143 c */
- {v_change, V_CNT|V_DOT|V_MOTION|V_OBUF|V_RCM_SET|VC_C,
- "[buffer][count]c[count]motion",
- " c change to motion"},
-/* 144 d */
- {v_delete, V_CNT|V_DOT|V_MOTION|V_OBUF|V_RCM_SET|VC_D,
- "[buffer][count]d[count]motion",
- " d delete to motion"},
-/* 145 e */
- {v_worde, V_CNT|V_MOVE|V_RCM_SET,
- "[count]e",
- " e move to end of word"},
-/* 146 f */
- {v_chf, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
- "[count]f character",
- " f character in line forward search"},
-/* 147 g */
- {NULL},
-/* 150 h */
- {v_left, V_CNT|V_MOVE|V_RCM_SET,
- "[count]h",
- " h move left by columns"},
-/* 151 i */
- {v_ii, V_CNT|V_DOT|V_RCM_SET,
- "[count]i",
- " i insert before cursor"},
-/* 152 j */
- {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM,
- "[count]j",
- " j move down by lines"},
-/* 153 k */
- {v_up, V_CNT|V_LMODE|V_MOVE|V_RCM,
- "[count]k",
- " k move up by lines"},
-/* 154 l */
- {v_right, V_CNT|V_MOVE|V_RCM_SET,
- "[count]l",
- " l move right by columns"},
-/* 155 m */
- {v_mark, V_CHAR,
- "m[a-z]",
- " m set mark"},
-/* 156 n */
- {v_searchn, V_ABS|V_MOVE|V_RCM_SET,
- "n",
- " n repeat last search"},
-/* 157 o */
- {v_io, V_CNT|V_DOT|V_RCM_SET,
- "[count]o",
- " o append after line"},
-/* 160 p */
- {v_put, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer]p",
- " p insert after cursor from buffer"},
-/* 161 q */
- {NULL},
-/* 162 r */
- {v_replace, V_CNT|V_DOT|V_RCM_SET,
- "[count]r character",
- " r replace character"},
-/* 163 s */
- {v_subst, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer][count]s",
- " s substitute character"},
-/* 164 t */
- {v_cht, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
- "[count]t character",
- " t before character in line forward search"},
-/* 165 u */
- /*
- * DON'T set the V_DOT flag, it' more complicated than that.
- * See vi/vi.c for details.
- */
- {v_undo, V_RCM_SET,
- "u",
- " u undo last change"},
-/* 166 v */
- {NULL},
-/* 167 w */
- {v_wordw, V_CNT|V_MOVE|V_RCM_SET,
- "[count]w",
- " w move to next word"},
-/* 170 x */
- {v_xchar, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
- "[buffer][count]x",
- " x delete character"},
-/* 171 y */
- {v_yank, V_CNT|V_MOTION|V_OBUF|V_RCM_SET|VC_Y,
- "[buffer][count]y[count]motion",
- " y copy text to motion into a cut buffer"},
-/* 172 z */
- /*
- * DON'T set the V_CHAR flag, the char isn't required,
- * so it's handled specially in getcmd().
- */
- {v_z, V_CNT|V_RCM_SETFNB,
- "[line]z[window_size][-|.|+|^|<CR>]",
- " z redraw window"},
-/* 173 { */
- {v_paragraphb, V_ABS|V_CNT|V_LMODE|V_MOVE|V_RCM_SET,
- "[count]{",
- " { move back paragraph"},
-/* 174 | */
- {v_ncol, V_ABS|V_CNT|V_MOVE|V_RCM_SET,
- "[count]|",
- " | move to column"},
-/* 175 } */
- {v_paragraphf, V_ABS|V_CNT|V_LMODE|V_MOVE|V_RCM_SET,
- "[count]}",
- " } move forward paragraph"},
-/* 176 ~ */
- {v_ulcase, V_CNT|V_DOT|V_RCM_SET,
- "[count]~",
- " ~ reverse case"},
-};
diff --git a/usr.bin/vi/nvi/vcmd.h b/usr.bin/vi/nvi/vcmd.h
deleted file mode 100644
index d48fa26acf5e..000000000000
--- a/usr.bin/vi/nvi/vcmd.h
+++ /dev/null
@@ -1,274 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- *
- * @(#)vcmd.h 8.23 (Berkeley) 1/8/94
- */
-
-typedef struct _vikeys VIKEYS;
-
-/* Structure passed around to functions implementing vi commands. */
-typedef struct _vicmdarg {
-#define vp_startzero buffer /* START ZERO OUT. */
- CHAR_T buffer; /* Buffer. */
- CHAR_T character; /* Character. */
- u_long count; /* Count. */
- u_long count2; /* Second count (only used by z). */
- int key; /* Command key. */
- VIKEYS const *kp; /* VIKEYS key. */
- VIKEYS const *mkp; /* VIKEYS motion key. */
- size_t klen; /* Keyword length. */
-
-/*
- * Historic vi allowed "dl" when the cursor was on the last column, deleting
- * the last character, and similarly allowed "dw" when the cursor was on the
- * last column of the file. It didn't allow "dh" when the cursor was on
- * column 1, although these cases are not strictly analogous. The point is
- * that some movements would succeed if they were associated with a motion
- * command, and fail otherwise. This is part of the off-by-1 schizophrenia
- * that plagued vi. Other examples are that "dfb" deleted everything up to
- * and including the next 'b' character, but "d/b" only deleted everything
- * up to the next 'b' character. While this implementation regularizes the
- * interface to the extent possible, there are many special cases that can't
- * be fixed. This is implemented by setting special flags per command so that
- * the motion routines know what's really going on.
- *
- * Note, the VC_COMMASK flags are set in the vikeys array, and therefore
- * must have values not used in the set of flags declared in the VIKEYS
- * structure below.
- */
-#define VC_C 0x0001 /* The 'c' command. */
-#define VC_D 0x0002 /* The 'd' command. */
-#define VC_SH 0x0004 /* The '>' command. */
-#define VC_Y 0x0008 /* The 'y' command. */
-#define VC_COMMASK 0x000f /* Mask for special flags. */
-
-#define VC_BUFFER 0x0010 /* Buffer set. */
-#define VC_C1SET 0x0020 /* Count 1 set. */
-#define VC_C1RESET 0x0040 /* Reset the C1SET flag for dot commands. */
-#define VC_C2SET 0x0080 /* Count 2 set. */
-#define VC_LMODE 0x0100 /* Motion is line oriented. */
-#define VC_ISDOT 0x0200 /* Command was the dot command. */
-#define VC_REVMOVE 0x0400 /* Movement was before the cursor. */
-
- u_int flags;
-
-#define vp_endzero keyword /* END ZERO OUT. */
- char *keyword; /* Keyword. */
- size_t kbuflen; /* Keyword buffer length. */
-} VICMDARG;
-
-/* Vi command structure. */
-struct _vikeys { /* Underlying function. */
- int (*func) __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, MARK *));
-
-#define V_DONTUSE1 0x000001 /* VC_C */
-#define V_DONTUSE2 0x000002 /* VC_D */
-#define V_DONTUSE3 0x000004 /* VC_SH */
-#define V_DONTUSE4 0x000008 /* VC_Y */
-#define V_ABS 0x000010 /* Absolute movement, set '' mark. */
-#define V_CHAR 0x000020 /* Character (required, trailing). */
-#define V_CNT 0x000040 /* Count (optional, leading). */
-#define V_DOT 0x000080 /* On success, sets dot command. */
-#define V_KEYNUM 0x000100 /* Cursor referenced number. */
-#define V_KEYW 0x000200 /* Cursor referenced word. */
-#define V_LMODE 0x000400 /* Motion is line oriented. */
-#define V_MOTION 0x000800 /* Motion (required, trailing). */
-#define V_MOVE 0x001000 /* Command defines movement. */
-#define V_OBUF 0x002000 /* Buffer (optional, leading). */
-#define V_RBUF 0x004000 /* Buffer (required, trailing). */
-#define V_RCM 0x008000 /* Use relative cursor movment (RCM). */
-#define V_RCM_SET 0x010000 /* RCM: set to current position. */
-#define V_RCM_SETFNB 0x020000 /* RCM: set to first non-blank (FNB). */
-#define V_RCM_SETLAST 0x040000 /* RCM: set to last character. */
-#define V_RCM_SETLFNB 0x080000 /* RCM: set to FNB if line moved. */
-#define V_RCM_SETNNB 0x100000 /* RCM: set to next non-blank. */
- u_long flags;
- char *usage; /* Usage line. */
- char *help; /* Help line. */
-};
-#define MAXVIKEY 126 /* List of vi commands. */
-extern VIKEYS const vikeys[MAXVIKEY + 1];
-
-/* Definition of a "word". */
-#define inword(ch) (isalnum(ch) || (ch) == '_')
-
-/* Character stream structure, prototypes. */
-typedef struct _vcs {
- recno_t cs_lno; /* Line. */
- size_t cs_cno; /* Column. */
- char *cs_bp; /* Buffer. */
- size_t cs_len; /* Length. */
- int cs_ch; /* Character. */
-#define CS_EMP 1 /* Empty line. */
-#define CS_EOF 2 /* End-of-file. */
-#define CS_EOL 3 /* End-of-line. */
-#define CS_SOF 4 /* Start-of-file. */
- int cs_flags; /* Return flags. */
-} VCS;
-
-int cs_bblank __P((SCR *, EXF *, VCS *));
-int cs_fblank __P((SCR *, EXF *, VCS *));
-int cs_fspace __P((SCR *, EXF *, VCS *));
-int cs_init __P((SCR *, EXF *, VCS *));
-int cs_next __P((SCR *, EXF *, VCS *));
-int cs_prev __P((SCR *, EXF *, VCS *));
-
-/* Vi private, per-screen memory. */
-typedef struct _vi_private {
- VICMDARG sdot; /* Saved dot, motion command. */
- VICMDARG sdotmotion;
-
- CHAR_T rlast; /* Last 'r' command character. */
-
- char *rep; /* Input replay buffer. */
- size_t rep_len; /* Input replay buffer length. */
- size_t rep_cnt; /* Input replay buffer characters. */
-
- CHAR_T inc_lastch; /* Last increment character. */
- long inc_lastval; /* Last increment value. */
-
- char *paragraph; /* Paragraph search list. */
- size_t paragraph_len; /* Paragraph search list length. */
-
- u_long u_ccnt; /* Undo command count. */
-} VI_PRIVATE;
-
-#define VIP(sp) ((VI_PRIVATE *)((sp)->vi_private))
-
-/* Vi function prototypes. */
-int txt_auto __P((SCR *, EXF *, recno_t, TEXT *, size_t, TEXT *));
-int v_buildparagraph __P((SCR *));
-int v_end __P((SCR *));
-void v_eof __P((SCR *, EXF *, MARK *));
-void v_eol __P((SCR *, EXF *, MARK *));
-int v_exwrite __P((void *, const char *, int));
-int v_init __P((SCR *, EXF *));
-int v_isempty __P((char *, size_t));
-int v_msgflush __P((SCR *));
-int v_ntext __P((SCR *, EXF *, TEXTH *, MARK *,
- const char *, const size_t, MARK *, int, recno_t, u_int));
-int v_optchange __P((SCR *, int));
-int v_screen_copy __P((SCR *, SCR *));
-int v_screen_end __P((SCR *));
-void v_sof __P((SCR *, MARK *));
-int vi __P((SCR *, EXF *));
-
-#define VIPROTO(type, name) \
- type name __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, MARK *))
-
-VIPROTO(int, v_again);
-VIPROTO(int, v_at);
-VIPROTO(int, v_bottom);
-VIPROTO(int, v_cfirst);
-VIPROTO(int, v_Change);
-VIPROTO(int, v_change);
-VIPROTO(int, v_chF);
-VIPROTO(int, v_chf);
-VIPROTO(int, v_chrepeat);
-VIPROTO(int, v_chrrepeat);
-VIPROTO(int, v_chT);
-VIPROTO(int, v_cht);
-VIPROTO(int, v_cr);
-VIPROTO(int, v_Delete);
-VIPROTO(int, v_delete);
-VIPROTO(int, v_dollar);
-VIPROTO(int, v_down);
-VIPROTO(int, v_ex);
-VIPROTO(int, v_exit);
-VIPROTO(int, v_exmode);
-VIPROTO(int, v_filter);
-VIPROTO(int, v_first);
-VIPROTO(int, v_gomark);
-VIPROTO(int, v_home);
-VIPROTO(int, v_hpagedown);
-VIPROTO(int, v_hpageup);
-VIPROTO(int, v_iA);
-VIPROTO(int, v_ia);
-VIPROTO(int, v_iI);
-VIPROTO(int, v_ii);
-VIPROTO(int, v_increment);
-VIPROTO(int, v_iO);
-VIPROTO(int, v_io);
-VIPROTO(int, v_join);
-VIPROTO(int, v_left);
-VIPROTO(int, v_lgoto);
-VIPROTO(int, v_linedown);
-VIPROTO(int, v_lineup);
-VIPROTO(int, v_mark);
-VIPROTO(int, v_match);
-VIPROTO(int, v_middle);
-VIPROTO(int, v_ncol);
-VIPROTO(int, v_pagedown);
-VIPROTO(int, v_pageup);
-VIPROTO(int, v_paragraphb);
-VIPROTO(int, v_paragraphf);
-VIPROTO(int, v_Put);
-VIPROTO(int, v_put);
-VIPROTO(int, v_redraw);
-VIPROTO(int, v_Replace);
-VIPROTO(int, v_replace);
-VIPROTO(int, v_right);
-VIPROTO(int, v_screen);
-VIPROTO(int, v_searchb);
-VIPROTO(int, v_searchf);
-VIPROTO(int, v_searchN);
-VIPROTO(int, v_searchn);
-VIPROTO(int, v_searchw);
-VIPROTO(int, v_sectionb);
-VIPROTO(int, v_sectionf);
-VIPROTO(int, v_sentenceb);
-VIPROTO(int, v_sentencef);
-VIPROTO(int, v_shiftl);
-VIPROTO(int, v_shiftr);
-VIPROTO(int, v_status);
-VIPROTO(int, v_stop);
-VIPROTO(int, v_Subst);
-VIPROTO(int, v_subst);
-VIPROTO(int, v_switch);
-VIPROTO(int, v_tagpop);
-VIPROTO(int, v_tagpush);
-VIPROTO(int, v_ulcase);
-VIPROTO(int, v_Undo);
-VIPROTO(int, v_undo);
-VIPROTO(int, v_up);
-VIPROTO(int, v_wordB);
-VIPROTO(int, v_wordb);
-VIPROTO(int, v_wordE);
-VIPROTO(int, v_worde);
-VIPROTO(int, v_wordW);
-VIPROTO(int, v_wordw);
-VIPROTO(int, v_Xchar);
-VIPROTO(int, v_xchar);
-VIPROTO(int, v_Yank);
-VIPROTO(int, v_yank);
-VIPROTO(int, v_z);
-VIPROTO(int, v_zero);
diff --git a/usr.bin/vi/nvi/vi.c b/usr.bin/vi/nvi/vi.c
deleted file mode 100644
index f969d78cfabf..000000000000
--- a/usr.bin/vi/nvi/vi.c
+++ /dev/null
@@ -1,780 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)vi.c 8.45 (Berkeley) 1/22/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static int getcmd __P((SCR *, EXF *,
- VICMDARG *, VICMDARG *, VICMDARG *, int *));
-static inline int
- getcount __P((SCR *, ARG_CHAR_T, u_long *));
-static inline int
- getkey __P((SCR *, CH *, u_int));
-static int getkeyword __P((SCR *, EXF *, VICMDARG *, u_int));
-static int getmotion __P((SCR *, EXF *,
- VICMDARG *, VICMDARG *, MARK *, MARK *));
-
-/*
- * Side-effect:
- * The dot structure can be set by the underlying vi functions,
- * see v_Put() and v_put().
- */
-#define DOT (&VIP(sp)->sdot)
-#define DOTMOTION (&VIP(sp)->sdotmotion)
-
-/*
- * vi --
- * Main vi command loop.
- */
-int
-vi(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- MARK abs, fm, tm, m;
- VICMDARG cmd, *vp;
- u_int flags, saved_mode;
- int comcount, eval;
-
- /* Start vi. */
- if (v_init(sp, ep))
- return (1);
-
- /* Paint the screen. */
- if (sp->s_refresh(sp, ep)) {
- (void)v_end(sp);
- return (1);
- }
-
- /* Command initialization. */
- memset(&cmd, 0, sizeof(VICMDARG));
-
- for (eval = 0, vp = &cmd;;) {
- if (!MAPPED_KEYS_WAITING(sp) && log_cursor(sp, ep))
- goto err;
-
- /*
- * We get a command, which may or may not have an associated
- * motion. If it does, we get it too, calling its underlying
- * function to get the resulting mark. We then call the
- * command setting the cursor to the resulting mark.
- */
- if (getcmd(sp, ep, DOT, vp, NULL, &comcount))
- goto err;
-
- /*
- * Historical practice: if a dot command gets a new count,
- * any motion component goes away, i.e. "d3w2." deletes a
- * total of 5 words.
- */
- if (F_ISSET(vp, VC_ISDOT) && comcount)
- DOTMOTION->count = 1;
-
- /* Get any associated keyword. */
- flags = vp->kp->flags;
- if (LF_ISSET(V_KEYNUM | V_KEYW) &&
- getkeyword(sp, ep, vp, flags))
- goto err;
-
- /* If a non-relative movement, copy the future absolute mark. */
- if (LF_ISSET(V_ABS)) {
- abs.lno = sp->lno;
- abs.cno = sp->cno;
- }
-
- /*
- * Do any required motion; getmotion sets the from MARK
- * and the line mode flag.
- */
- if (LF_ISSET(V_MOTION)) {
- if (getmotion(sp, ep, DOTMOTION, vp, &fm, &tm))
- goto err;
- } else {
- /*
- * Set everything to the current cursor position.
- * Line commands (ex: Y) default to the current line.
- */
- tm.lno = fm.lno = sp->lno;
- tm.cno = fm.cno = sp->cno;
-
- /*
- * Set line mode flag, for example, "yy".
- *
- * If a count is set, we set the to MARK here relative
- * to the cursor/from MARK. This is done for commands
- * that take both counts and motions, i.e. "4yy" and
- * "y%" -- there's no way the command can known which
- * the user did, so we have to do it here. There are
- * other commands that are line mode commands and take
- * counts ("#G", "#H") and for which this calculation
- * is either meaningless or wrong. Each command must
- * do its own validity checking of the value.
- */
- if (F_ISSET(vp->kp, V_LMODE)) {
- F_SET(vp, VC_LMODE);
- if (F_ISSET(vp, VC_C1SET)) {
- tm.lno = sp->lno + vp->count - 1;
- tm.cno = sp->cno;
- }
- }
- }
-
- /* Increment the command count. */
- ++sp->ccnt;
-
- /*
- * Call the function. Set the return cursor to the current
- * cursor position first -- the underlying routines don't
- * bother to do the work if it doesn't move.
- */
- m.lno = sp->lno;
- m.cno = sp->cno;
- saved_mode = F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE);
- if ((vp->kp->func)(sp, ep, vp, &fm, &tm, &m))
- goto err;
-#ifdef DEBUG
- /* Make sure no function left the temporary space locked. */
- if (F_ISSET(sp->gp, G_TMP_INUSE)) {
- msgq(sp, M_ERR,
- "Error: vi: temporary buffer not released.");
- return (1);
- }
-#endif
- /*
- * If that command took us out of vi or changed the screen,
- * then exit the loop without further action.
- */
- if (saved_mode != F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE))
- break;
-
- /* Set the absolute mark. */
- if (LF_ISSET(V_ABS) && mark_set(sp, ep, ABSMARK1, &abs, 1))
- goto err;
-
- /* Set the dot command structure. */
- if (LF_ISSET(V_DOT)) {
- *DOT = cmd;
- F_SET(DOT, VC_ISDOT);
- /*
- * If a count was supplied for both the command and
- * its motion, the count was used only for the motion.
- * Turn the count back on for the dot structure.
- */
- if (F_ISSET(vp, VC_C1RESET))
- F_SET(DOT, VC_C1SET);
- }
-
- /*
- * Some vi row movements are "attracted" to the last position
- * set, i.e. the V_RCM commands are moths to the V_RCM_SET
- * commands' candle. It's broken into two parts. Here we deal
- * with the command flags. In sp->relative(), we deal with the
- * screen flags. If the movement is to the EOL the vi command
- * handles it. If it's to the beginning, we handle it here.
- *
- * Note, some commands (e.g. _, ^) don't set the V_RCM_SETFNB
- * flag, but do the work themselves. The reason is that they
- * have to modify the column in case they're being used as a
- * motion component. Other similar commands (e.g. +, -) don't
- * have to modify the column because they are always line mode
- * operations when used as motions, so the column number isn't
- * of any interest.
- *
- * Does this totally violate the screen and editor layering?
- * You betcha. As they say, if you think you understand it,
- * you don't.
- */
- switch (LF_ISSET(V_RCM | V_RCM_SETFNB |
- V_RCM_SETLAST | V_RCM_SETLFNB | V_RCM_SETNNB)) {
- case 0:
- break;
- case V_RCM:
- m.cno = sp->s_relative(sp, ep, m.lno);
- break;
- case V_RCM_SETLAST:
- sp->rcmflags = RCM_LAST;
- break;
- case V_RCM_SETLFNB:
- if (fm.lno != m.lno) {
- if (nonblank(sp, ep, m.lno, &m.cno))
- goto err;
- sp->rcmflags = RCM_FNB;
- }
- break;
- case V_RCM_SETFNB:
- m.cno = 0;
- /* FALLTHROUGH */
- case V_RCM_SETNNB:
- if (nonblank(sp, ep, m.lno, &m.cno))
- goto err;
- sp->rcmflags = RCM_FNB;
- break;
- default:
- abort();
- }
-
- /* Update the cursor. */
- sp->lno = m.lno;
- sp->cno = m.cno;
-
- if (!MAPPED_KEYS_WAITING(sp)) {
- (void)msg_rpt(sp, 1);
-
- if (0)
-err: term_map_flush(sp, "Vi error");
- }
-
- /* Refresh the screen. */
- if (sp->s_refresh(sp, ep)) {
- eval = 1;
- break;
- }
-
- /* Set the new favorite position. */
- if (LF_ISSET(V_RCM_SET)) {
- sp->rcmflags = 0;
- (void)sp->s_column(sp, ep, &sp->rcm);
- }
- }
-
- return (v_end(sp) || eval);
-}
-
-#define KEY(key, map) { \
- if (getkey(sp, &ikey, map)) \
- return (1); \
- key = ikey.ch; \
-}
-
-/*
- * getcmd --
- *
- * The command structure for vi is less complex than ex (and don't think
- * I'm not grateful!) The command syntax is:
- *
- * [count] [buffer] [count] key [[motion] | [buffer] [character]]
- *
- * and there are several special cases. The motion value is itself a vi
- * command, with the syntax:
- *
- * [count] key [character]
- */
-static int
-getcmd(sp, ep, dp, vp, ismotion, comcountp)
- SCR *sp;
- EXF *ep;
- VICMDARG *dp, *vp;
- VICMDARG *ismotion; /* Previous key if getting motion component. */
- int *comcountp;
-{
- VIKEYS const *kp;
- u_int flags;
- CH ikey;
- CHAR_T key;
-
- /* Refresh the command structure. */
- memset(&vp->vp_startzero, 0,
- (char *)&vp->vp_endzero - (char *)&vp->vp_startzero);
-
- /* An escape bells the user if in command mode. */
- if (getkey(sp, &ikey, TXT_MAPCOMMAND)) {
- if (ikey.value == K_ESCAPE && ismotion == NULL)
- msgq(sp, M_BERR, "Already in command mode");
- return (1);
- }
-
- key = ikey.ch;
- if (key > MAXVIKEY) {
- msgq(sp, M_BERR, "%s isn't a vi command", charname(sp, key));
- return (1);
- }
-
- /* Pick up optional buffer. */
- if (key == '"') {
- KEY(vp->buffer, 0);
- F_SET(vp, VC_BUFFER);
- KEY(key, TXT_MAPCOMMAND);
- }
-
- /*
- * Pick up optional count, where a leading 0 is not a count,
- * it's a command.
- */
- if (isdigit(key) && key != '0') {
- if (getcount(sp, key, &vp->count))
- return (1);
- F_SET(vp, VC_C1SET);
- *comcountp = 1;
- KEY(key, TXT_MAPCOMMAND);
- } else
- *comcountp = 0;
-
- /* Pick up optional buffer. */
- if (key == '"') {
- if (F_ISSET(vp, VC_BUFFER)) {
- msgq(sp, M_ERR, "Only one buffer can be specified.");
- return (1);
- }
- KEY(vp->buffer, 0);
- F_SET(vp, VC_BUFFER);
- KEY(key, TXT_MAPCOMMAND);
- }
-
- /*
- * Find the command. The only legal command with no underlying
- * function is dot.
- */
- kp = vp->kp = &vikeys[vp->key = key];
- if (kp->func == NULL) {
- if (key != '.') {
- msgq(sp, M_ERR,
- "%s isn't a command", charname(sp, key));
- return (1);
- }
-
- /* If called for a motion command, stop now. */
- if (dp == NULL)
- goto usage;
-
- /* A repeatable command must have been executed. */
- if (!F_ISSET(dp, VC_ISDOT)) {
- msgq(sp, M_ERR, "No command to repeat.");
- return (1);
- }
-
- /*
- * !!!
- * If a '.' is immediately entered after an undo command, we
- * replay the log instead of redoing the last command. This
- * is necessary because 'u' can't set the dot command -- see
- * vi/v_undo.c:v_undo for details.
- */
- if (VIP(sp)->u_ccnt == sp->ccnt) {
- vp->kp = &vikeys['u'];
- F_SET(vp, VC_ISDOT);
- return (0);
- }
-
- /* Set new count/buffer, if any, and return. */
- if (F_ISSET(vp, VC_C1SET)) {
- F_SET(dp, VC_C1SET);
- dp->count = vp->count;
- }
- if (F_ISSET(vp, VC_BUFFER))
- dp->buffer = vp->buffer;
- *vp = *dp;
- return (0);
- }
-
- flags = kp->flags;
-
- /* Check for illegal count. */
- if (F_ISSET(vp, VC_C1SET) && !LF_ISSET(V_CNT))
- goto usage;
-
- /* Illegal motion command. */
- if (ismotion == NULL) {
- /* Illegal buffer. */
- if (!LF_ISSET(V_OBUF) && F_ISSET(vp, VC_BUFFER))
- goto usage;
-
- /* Required buffer. */
- if (LF_ISSET(V_RBUF))
- KEY(vp->buffer, 0);
-
- /*
- * Special case: '[', ']' and 'Z' commands. Doesn't the
- * fact that the *single* characters don't mean anything
- * but the *doubled* characters do just frost your shorts?
- */
- if (vp->key == '[' || vp->key == ']' || vp->key == 'Z') {
- KEY(key, TXT_MAPCOMMAND);
- if (vp->key != key)
- goto usage;
- }
- /* Special case: 'z' command. */
- if (vp->key == 'z') {
- KEY(vp->character, 0);
- if (isdigit(vp->character)) {
- if (getcount(sp, vp->character, &vp->count2))
- return (1);
- F_SET(vp, VC_C2SET);
- KEY(vp->character, 0);
- }
- }
- }
-
- /*
- * Commands that have motion components can be doubled to
- * imply the current line.
- */
- else if (ismotion->key != key && !LF_ISSET(V_MOVE)) {
-usage: msgq(sp, M_ERR, "Usage: %s", ismotion != NULL ?
- vikeys[ismotion->key].usage : kp->usage);
- return (1);
- }
-
- /* Required character. */
- if (LF_ISSET(V_CHAR))
- KEY(vp->character, 0);
-
- return (0);
-}
-
-/*
- * getmotion --
- *
- * Get resulting motion mark.
- */
-static int
-getmotion(sp, ep, dm, vp, fm, tm)
- SCR *sp;
- EXF *ep;
- VICMDARG *dm, *vp;
- MARK *fm, *tm;
-{
- MARK m;
- VICMDARG motion;
- u_long cnt;
- int notused;
-
- /* If '.' command, use the dot motion, else get the motion command. */
- if (F_ISSET(vp, VC_ISDOT)) {
- motion = *dm;
- F_SET(&motion, VC_ISDOT);
- } else if (getcmd(sp, ep, NULL, &motion, vp, &notused))
- return (1);
-
- /*
- * A count may be provided both to the command and to the motion, in
- * which case the count is multiplicative. For example, "3y4y" is the
- * same as "12yy". This count is provided to the motion command and
- * not to the regular function.
- */
- cnt = motion.count = F_ISSET(&motion, VC_C1SET) ? motion.count : 1;
- if (F_ISSET(vp, VC_C1SET)) {
- motion.count *= vp->count;
- F_SET(&motion, VC_C1SET);
-
- /*
- * Set flags to restore the original values of the command
- * structure so dot commands can change the count values,
- * e.g. "2dw" "3." deletes a total of five words.
- */
- F_CLR(vp, VC_C1SET);
- F_SET(vp, VC_C1RESET);
- }
-
- /*
- * Some commands can be repeated to indicate the current line. In
- * this case, or if the command is a "line command", set the flags
- * appropriately. If not a doubled command, run the function to get
- * the resulting mark.
- */
- if (vp->key == motion.key) {
- F_SET(vp, VC_LMODE);
-
- /*
- * Set the end of the command; the column is after the line.
- *
- * If the current line is missing, i.e. the file is empty,
- * historic vi permitted a "cc" or "!!" command to insert
- * text.
- */
- tm->lno = sp->lno + motion.count - 1;
- if (file_gline(sp, ep, tm->lno, &tm->cno) == NULL) {
- if (tm->lno != 1 || vp->key != 'c' && vp->key != '!') {
- m.lno = sp->lno;
- m.cno = sp->cno;
- v_eof(sp, ep, &m);
- return (1);
- }
- tm->cno = 0;
- }
-
- /* Set the origin of the command. */
- fm->lno = sp->lno;
- fm->cno = 0;
- } else {
- /*
- * Motion commands change the underlying movement (*snarl*).
- * For example, "l" is illegal at the end of a line, but "dl"
- * is not. Set flags so the function knows the situation.
- */
- F_SET(&motion, vp->kp->flags & VC_COMMASK);
-
- /*
- * Everything starts at the current position. This permits
- * commands like 'j' and 'k', that are line oriented motions
- * and have special cursor suck semantics when they are used
- * as standalone commands, to ignore column positioning.
- */
- fm->lno = tm->lno = sp->lno;
- fm->cno = tm->cno = sp->cno;
- if ((motion.kp->func)(sp, ep, &motion, fm, NULL, tm))
- return (1);
-
- /*
- * If the underlying motion was a line motion, set the flag
- * in the command structure. Underlying commands can also
- * flag the movement as a line motion (see v_sentence).
- */
- if (F_ISSET(motion.kp, V_LMODE) || F_ISSET(&motion, VC_LMODE))
- F_SET(vp, VC_LMODE);
-
- /*
- * If the motion is in the reverse direction, switch the from
- * and to MARK's so that it's always in a forward direction.
- * Because the motion is always from the from MARK to, but not
- * including, the to MARK, the function may have modified the
- * from MARK, so that it gets the one-past-the-place semantics
- * we use; see v_match() for an example. Also set a flag so
- * that the underlying function knows that we did this; v_yank,
- * for example, has to know so it gets the return cursor right.
- */
- if (tm->lno < fm->lno ||
- tm->lno == fm->lno && tm->cno < fm->cno) {
- m = *fm;
- *fm = *tm;
- *tm = m;
- F_SET(vp, VC_REVMOVE);
- }
- }
-
- /*
- * If the command sets dot, save the motion structure. The
- * motion count was changed above and needs to be reset, that's
- * why this is done here, and not in the calling routine.
- */
- if (F_ISSET(vp->kp, V_DOT)) {
- *dm = motion;
- dm->count = cnt;
- }
-
- /* Let the underlying function know what motion command was used. */
- vp->mkp = motion.kp;
- return (0);
-}
-
-#define innum(c) (isdigit(c) || strchr("abcdefABCDEF", c))
-
-/*
- * getkeyword --
- * Get the "word" the cursor is on.
- */
-static int
-getkeyword(sp, ep, kp, flags)
- SCR *sp;
- EXF *ep;
- VICMDARG *kp;
- u_int flags;
-{
- recno_t lno;
- size_t beg, end, len;
- char *p;
-
- if ((p = file_gline(sp, ep, sp->lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_eof(sp, ep, NULL);
- else
- GETLINE_ERR(sp, sp->lno);
- return (1);
- }
- beg = sp->cno;
-
- /* May not be a keyword at all. */
- if (p == NULL || len == 0 ||
- LF_ISSET(V_KEYW) && !inword(p[beg]) ||
- LF_ISSET(V_KEYNUM) && !innum(p[beg]) &&
- p[beg] != '-' && p[beg] != '+') {
-noword: msgq(sp, M_BERR, "Cursor not in a %s",
- LF_ISSET(V_KEYW) ? "word" : "number");
- return (1);
- }
-
- /*
- * !!!
- * Find the beginning/end of the keyword. Keywords (V_KEYW) are
- * used for cursor-word searching and for tags. Historical vi
- * only used the word in a tag search from the cursor to the end
- * of the word, i.e. if the cursor was on the 'b' in " abc ", the
- * tag was "bc". For no particular reason, we make cursor word
- * searches follow the same rule.
- */
- if (beg != 0)
- if (LF_ISSET(V_KEYW)) {
-#ifdef MOVE_TO_KEYWORD_BEGINNING
- for (;;) {
- --beg;
- if (!inword(p[beg])) {
- ++beg;
- break;
- }
- if (beg == 0)
- break;
- }
-#endif
- } else {
- for (;;) {
- --beg;
- if (!innum(p[beg])) {
- if (beg > 0 && p[beg - 1] == '0' &&
- (p[beg] == 'X' || p[beg] == 'x'))
- --beg;
- else
- ++beg;
- break;
- }
- if (beg == 0)
- break;
- }
-
- /* Skip possible leading sign. */
- if (beg != 0 && p[beg] != '0' &&
- (p[beg - 1] == '+' || p[beg - 1] == '-'))
- --beg;
- }
-
- if (LF_ISSET(V_KEYW)) {
- for (end = sp->cno; ++end < len && inword(p[end]););
- --end;
- } else {
- for (end = sp->cno; ++end < len;) {
- if (p[end] == 'X' || p[end] == 'x') {
- if (end != beg + 1 || p[beg] != '0')
- break;
- continue;
- }
- if (!innum(p[end]))
- break;
- }
-
- /* Just a sign isn't a number. */
- if (end == beg && (p[beg] == '+' || p[beg] == '-'))
- goto noword;
- --end;
- }
-
- /*
- * Getting a keyword implies moving the cursor to its beginning.
- * Refresh now.
- */
- if (beg != sp->cno) {
- sp->cno = beg;
- sp->s_refresh(sp, ep);
- }
-
- /*
- * XXX
- * 8-bit clean problem. Numeric keywords are handled using strtol(3)
- * and friends. This would have to be fixed in v_increment and here
- * to not depend on a trailing NULL.
- */
- len = (end - beg) + 2; /* XXX */
- kp->klen = (end - beg) + 1;
- BINC_RET(sp, kp->keyword, kp->kbuflen, len);
- memmove(kp->keyword, p + beg, kp->klen);
- kp->keyword[kp->klen] = '\0'; /* XXX */
- return (0);
-}
-
-/*
- * getcount --
- * Return the next count.
- */
-static inline int
-getcount(sp, fkey, countp)
- SCR *sp;
- ARG_CHAR_T fkey;
- u_long *countp;
-{
- u_long count, tc;
- CH ikey;
-
- ikey.ch = fkey;
- count = tc = 0;
- do {
- /* Assume that overflow results in a smaller number. */
- tc = count * 10 + ikey.ch - '0';
- if (count > tc) {
- /* Toss to the next non-digit. */
- do {
- if (getkey(sp, &ikey,
- TXT_MAPCOMMAND | TXT_MAPNODIGIT))
- return (1);
- } while (isdigit(ikey.ch));
- msgq(sp, M_ERR, "Number larger than %lu", ULONG_MAX);
- return (1);
- }
- count = tc;
- if (getkey(sp, &ikey, TXT_MAPCOMMAND | TXT_MAPNODIGIT))
- return (1);
- } while (isdigit(ikey.ch));
- *countp = count;
- return (0);
-}
-
-/*
- * getkey --
- * Return the next key.
- */
-static inline int
-getkey(sp, ikeyp, map)
- SCR *sp;
- CH *ikeyp;
- u_int map;
-{
- switch (term_key(sp, ikeyp, map)) {
- case INP_OK:
- break;
- case INP_EOF:
- F_SET(sp, S_EXIT_FORCE);
- /* FALLTHROUGH */
- case INP_ERR:
- return (1);
- }
- return (ikeyp->value == K_ESCAPE);
-}