summaryrefslogtreecommitdiffstats
path: root/usr.bin/vi
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-11-01 08:25:51 +0000
committerpeter <peter@FreeBSD.org>1996-11-01 08:25:51 +0000
commit06307f2449abde34bb67dd6f9b1e5db429fabe68 (patch)
tree9aaf1268bc7ef64d0f9bf55ac3a5197fcb588904 /usr.bin/vi
parent8f6032f5087b75bb6e0a34abeca7d693cdde5fa0 (diff)
downloadFreeBSD-src-06307f2449abde34bb67dd6f9b1e5db429fabe68.zip
FreeBSD-src-06307f2449abde34bb67dd6f9b1e5db429fabe68.tar.gz
Remove the old nvi-1.34, it has served us well but it's time has come..
(It was tagged immediately prior to removal with the tag "nvi_1_34_final")
Diffstat (limited to 'usr.bin/vi')
-rw-r--r--usr.bin/vi/README200
-rw-r--r--usr.bin/vi/USD.doc/edit/Makefile18
-rw-r--r--usr.bin/vi/USD.doc/edit/edit.vindex115
-rw-r--r--usr.bin/vi/USD.doc/edit/edittut.ms2322
-rw-r--r--usr.bin/vi/USD.doc/exref/Makefile14
-rw-r--r--usr.bin/vi/USD.doc/exref/ex.rm2230
-rw-r--r--usr.bin/vi/USD.doc/exref/ex.summary734
-rw-r--r--usr.bin/vi/USD.doc/vi.man/Makefile14
-rw-r--r--usr.bin/vi/USD.doc/vi.man/vi.0798
-rw-r--r--usr.bin/vi/USD.doc/vi.man/vi.0.ps1063
-rw-r--r--usr.bin/vi/USD.doc/vi.man/vi.11294
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/Makefile25
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/ex.cmd.roff1776
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/merge.awk16
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/ref.so127
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/set.opt.roff949
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/spell.ok270
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/vi.cmd.roff2984
-rw-r--r--usr.bin/vi/USD.doc/vi.ref/vi.ref1270
-rw-r--r--usr.bin/vi/USD.doc/vitut/Makefile17
-rw-r--r--usr.bin/vi/USD.doc/vitut/vi.apwh.ms1079
-rw-r--r--usr.bin/vi/USD.doc/vitut/vi.chars644
-rw-r--r--usr.bin/vi/USD.doc/vitut/vi.in2064
-rw-r--r--usr.bin/vi/USD.doc/vitut/vi.summary468
-rw-r--r--usr.bin/vi/common/Makefile108
-rw-r--r--usr.bin/vi/common/args.h53
-rw-r--r--usr.bin/vi/common/cut.c366
-rw-r--r--usr.bin/vi/common/cut.h96
-rw-r--r--usr.bin/vi/common/delete.c195
-rw-r--r--usr.bin/vi/common/exf.c837
-rw-r--r--usr.bin/vi/common/exf.h128
-rw-r--r--usr.bin/vi/common/gs.h107
-rw-r--r--usr.bin/vi/common/line.c492
-rw-r--r--usr.bin/vi/common/log.c698
-rw-r--r--usr.bin/vi/common/log.h53
-rw-r--r--usr.bin/vi/common/main.c720
-rw-r--r--usr.bin/vi/common/mark.c272
-rw-r--r--usr.bin/vi/common/mark.h73
-rw-r--r--usr.bin/vi/common/mem.h194
-rw-r--r--usr.bin/vi/common/msg.c428
-rw-r--r--usr.bin/vi/common/msg.h82
-rw-r--r--usr.bin/vi/common/options.awk9
-rw-r--r--usr.bin/vi/common/options.c890
-rw-r--r--usr.bin/vi/common/options.h.stub108
-rw-r--r--usr.bin/vi/common/options_f.c518
-rw-r--r--usr.bin/vi/common/pathnames.h45
-rw-r--r--usr.bin/vi/common/put.c254
-rw-r--r--usr.bin/vi/common/recover.c869
-rw-r--r--usr.bin/vi/common/screen.c311
-rw-r--r--usr.bin/vi/common/screen.h342
-rw-r--r--usr.bin/vi/common/search.c833
-rw-r--r--usr.bin/vi/common/search.h54
-rw-r--r--usr.bin/vi/common/seq.c351
-rw-r--r--usr.bin/vi/common/seq.h79
-rw-r--r--usr.bin/vi/common/signal.c569
-rw-r--r--usr.bin/vi/common/term.c732
-rw-r--r--usr.bin/vi/common/term.h205
-rw-r--r--usr.bin/vi/common/trace.c84
-rw-r--r--usr.bin/vi/common/util.c213
-rw-r--r--usr.bin/vi/common/vi.h124
-rw-r--r--usr.bin/vi/docs/README200
-rw-r--r--usr.bin/vi/docs/bugs.current44
-rw-r--r--usr.bin/vi/docs/changelog528
-rw-r--r--usr.bin/vi/docs/ev55
-rw-r--r--usr.bin/vi/docs/features87
-rw-r--r--usr.bin/vi/docs/internals/autowrite88
-rw-r--r--usr.bin/vi/docs/internals/context32
-rw-r--r--usr.bin/vi/docs/internals/gdb.script77
-rw-r--r--usr.bin/vi/docs/internals/input350
-rw-r--r--usr.bin/vi/docs/internals/quoting219
-rw-r--r--usr.bin/vi/docs/internals/structures61
-rw-r--r--usr.bin/vi/docs/tutorial/vi.advanced1458
-rw-r--r--usr.bin/vi/docs/tutorial/vi.beginner741
-rwxr-xr-xusr.bin/vi/docs/tutorial/vi.tut.csh24
-rw-r--r--usr.bin/vi/ex/ex.c1866
-rw-r--r--usr.bin/vi/ex/ex_abbrev.c129
-rw-r--r--usr.bin/vi/ex/ex_append.c220
-rw-r--r--usr.bin/vi/ex/ex_args.c263
-rw-r--r--usr.bin/vi/ex/ex_argv.c609
-rw-r--r--usr.bin/vi/ex/ex_at.c118
-rw-r--r--usr.bin/vi/ex/ex_bang.c242
-rw-r--r--usr.bin/vi/ex/ex_cd.c223
-rw-r--r--usr.bin/vi/ex/ex_delete.c92
-rw-r--r--usr.bin/vi/ex/ex_digraph.c324
-rw-r--r--usr.bin/vi/ex/ex_display.c169
-rw-r--r--usr.bin/vi/ex/ex_edit.c122
-rw-r--r--usr.bin/vi/ex/ex_equal.c86
-rw-r--r--usr.bin/vi/ex/ex_exit.c79
-rw-r--r--usr.bin/vi/ex/ex_file.c103
-rw-r--r--usr.bin/vi/ex/ex_global.c400
-rw-r--r--usr.bin/vi/ex/ex_init.c202
-rw-r--r--usr.bin/vi/ex/ex_join.c200
-rw-r--r--usr.bin/vi/ex/ex_map.c160
-rw-r--r--usr.bin/vi/ex/ex_mark.c66
-rw-r--r--usr.bin/vi/ex/ex_mkexrc.c130
-rw-r--r--usr.bin/vi/ex/ex_move.c222
-rw-r--r--usr.bin/vi/ex/ex_open.c75
-rw-r--r--usr.bin/vi/ex/ex_preserve.c128
-rw-r--r--usr.bin/vi/ex/ex_print.c212
-rw-r--r--usr.bin/vi/ex/ex_put.c78
-rw-r--r--usr.bin/vi/ex/ex_read.c300
-rw-r--r--usr.bin/vi/ex/ex_screen.c155
-rw-r--r--usr.bin/vi/ex/ex_script.c582
-rw-r--r--usr.bin/vi/ex/ex_set.c70
-rw-r--r--usr.bin/vi/ex/ex_shell.c150
-rw-r--r--usr.bin/vi/ex/ex_shift.c204
-rw-r--r--usr.bin/vi/ex/ex_source.c66
-rw-r--r--usr.bin/vi/ex/ex_stop.c76
-rw-r--r--usr.bin/vi/ex/ex_subst.c1001
-rw-r--r--usr.bin/vi/ex/ex_tag.c905
-rw-r--r--usr.bin/vi/ex/ex_undo.c103
-rw-r--r--usr.bin/vi/ex/ex_usage.c197
-rw-r--r--usr.bin/vi/ex/ex_util.c189
-rw-r--r--usr.bin/vi/ex/ex_version.c71
-rw-r--r--usr.bin/vi/ex/ex_visual.c137
-rw-r--r--usr.bin/vi/ex/ex_write.c327
-rw-r--r--usr.bin/vi/ex/ex_yank.c69
-rw-r--r--usr.bin/vi/ex/ex_z.c180
-rw-r--r--usr.bin/vi/ex/excmd.awk6
-rw-r--r--usr.bin/vi/ex/excmd.c458
-rw-r--r--usr.bin/vi/ex/excmd.h.stub285
-rw-r--r--usr.bin/vi/ex/filter.c414
-rw-r--r--usr.bin/vi/ex/script.h45
-rw-r--r--usr.bin/vi/ex/tag.h58
-rw-r--r--usr.bin/vi/install/recover.script46
-rw-r--r--usr.bin/vi/sex/sex_confirm.c86
-rw-r--r--usr.bin/vi/sex/sex_get.c514
-rw-r--r--usr.bin/vi/sex/sex_refresh.c140
-rw-r--r--usr.bin/vi/sex/sex_screen.c340
-rw-r--r--usr.bin/vi/sex/sex_screen.h79
-rw-r--r--usr.bin/vi/sex/sex_term.c217
-rw-r--r--usr.bin/vi/sex/sex_util.c148
-rw-r--r--usr.bin/vi/sex/sex_window.c196
-rw-r--r--usr.bin/vi/svi/svi_confirm.c95
-rw-r--r--usr.bin/vi/svi/svi_curses.c252
-rw-r--r--usr.bin/vi/svi/svi_ex.c650
-rw-r--r--usr.bin/vi/svi/svi_get.c161
-rw-r--r--usr.bin/vi/svi/svi_line.c441
-rw-r--r--usr.bin/vi/svi/svi_refresh.c818
-rw-r--r--usr.bin/vi/svi/svi_relative.c334
-rw-r--r--usr.bin/vi/svi/svi_screen.c336
-rw-r--r--usr.bin/vi/svi/svi_screen.h262
-rw-r--r--usr.bin/vi/svi/svi_smap.c1216
-rw-r--r--usr.bin/vi/svi/svi_split.c635
-rw-r--r--usr.bin/vi/svi/svi_term.c310
-rw-r--r--usr.bin/vi/svi/svi_util.c347
-rw-r--r--usr.bin/vi/vi/getc.c268
-rw-r--r--usr.bin/vi/vi/v_ch.c340
-rw-r--r--usr.bin/vi/vi/v_delete.c160
-rw-r--r--usr.bin/vi/vi/v_ex.c352
-rw-r--r--usr.bin/vi/vi/v_increment.c163
-rw-r--r--usr.bin/vi/vi/v_init.c256
-rw-r--r--usr.bin/vi/vi/v_left.c287
-rw-r--r--usr.bin/vi/vi/v_mark.c210
-rw-r--r--usr.bin/vi/vi/v_match.c198
-rw-r--r--usr.bin/vi/vi/v_ntext.c1899
-rw-r--r--usr.bin/vi/vi/v_paragraph.c370
-rw-r--r--usr.bin/vi/vi/v_put.c168
-rw-r--r--usr.bin/vi/vi/v_redraw.c67
-rw-r--r--usr.bin/vi/vi/v_replace.c194
-rw-r--r--usr.bin/vi/vi/v_right.c162
-rw-r--r--usr.bin/vi/vi/v_screen.c90
-rw-r--r--usr.bin/vi/vi/v_scroll.c486
-rw-r--r--usr.bin/vi/vi/v_search.c414
-rw-r--r--usr.bin/vi/vi/v_section.c280
-rw-r--r--usr.bin/vi/vi/v_sentence.c386
-rw-r--r--usr.bin/vi/vi/v_status.c73
-rw-r--r--usr.bin/vi/vi/v_stop.c75
-rw-r--r--usr.bin/vi/vi/v_text.c886
-rw-r--r--usr.bin/vi/vi/v_ulcase.c212
-rw-r--r--usr.bin/vi/vi/v_undo.c162
-rw-r--r--usr.bin/vi/vi/v_util.c159
-rw-r--r--usr.bin/vi/vi/v_word.c570
-rw-r--r--usr.bin/vi/vi/v_xchar.c136
-rw-r--r--usr.bin/vi/vi/v_yank.c94
-rw-r--r--usr.bin/vi/vi/v_z.c159
-rw-r--r--usr.bin/vi/vi/v_zexit.c82
-rw-r--r--usr.bin/vi/vi/vcmd.c533
-rw-r--r--usr.bin/vi/vi/vcmd.h346
-rw-r--r--usr.bin/vi/vi/vi.c937
-rw-r--r--usr.bin/vi/xaw/xaw_screen.c98
181 files changed, 0 insertions, 67408 deletions
diff --git a/usr.bin/vi/README b/usr.bin/vi/README
deleted file mode 100644
index 0fe3a12..0000000
--- a/usr.bin/vi/README
+++ /dev/null
@@ -1,200 +0,0 @@
-# @(#)README 8.86 (Berkeley) 8/17/94
-
-This is the README for version 1.34 of nex/nvi, a freely redistributable
-replacement for the Berkeley ex and vi text editors. The compressed or
-gzip'd archives for this and future versions, can be retrieved by using
-anonymous ftp to ftp.cs.berkeley.edu, from the file ucb/4bsd/nvi.tar.Z,
-or ucb/4bsd/nvi.tar.gz.
-
-If you have any questions about nvi, or problems making it work, please
-contact me by electronic mail at one of the following addresses:
-
- uunet!bostic
- bostic@cs.berkeley.edu
-
-Keith Bostic
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-o Redistribution:
-
-This software is copyrighted by the The Regents of the University of
-California, but may be freely redistributed (or sold, or used to line
-your birdcage) under the following conditions:
-
-/*-
- * Copyright (c) 1991, 1992, 1993, 1994
- * 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.
- */
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-o Credit where it's due:
-
- This software was originally derived from software contributed
- to the University of California, Berkeley by Steve Kirkendall,
- the author of the vi clone elvis. Without his work, this work
- would have been far more difficult.
-
- POSIX 1003.2 style regular expression support is courtesy of
- Henry Spencer, for which I am *very* grateful.
-
- The curses library was originally done by Ken Arnold. Scrolling
- and general reworking for 4.4BSD was done by Elan Amir.
-
-o From the original vi acknowledgements, by William Joy and Mark Horton:
-
- Bruce Englar encouraged the early development of this display
- editor. Peter Kessler helped bring sanity to version 2's
- command layout. Bill Joy wrote versions 1 and 2.0 through 2.7,
- and created the framework that users see in the present editor.
- Mark Horton added macros and other features and made the editor
- work on a large number of terminals and Unix systems.
-
-o And...
- The financial support of UUNET Communications Services is gratefully
- acknowledged.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Status:
-
-This software is in beta test, and it's pretty stable. Almost all of
-the historic functionality in ex/vi is there, the only major missing
-pieces are open mode and the lisp option. (Also, the options hardtabs,
-optimize, redraw, and slowopen are recognized, but ignored.)
-
-Nvi is mostly 8-bit clean. This isn't difficult to fix, and was left
-in during initial development to keep things simple. Wide character
-support will be integrated at the same time that it is made fully 8-bit
-clean.
-
-There aren't a lot of new features in nex/nvi, but there are a few things
-you might like. The "Additional Features" section of the reference page
-(USD.doc/vi.ref/vi.ref.txt, USD.doc/vi.ref/vi.ref.ps) has more information.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Porting information:
-
-The directory "PORT" has directories for specific OS/machine combinations,
-including V7-style Makefiles, for building nex/nvi on different machines.
-See the file PORT/README for detailed information.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Debugging:
-
-Code fixes are appreciated, of course, but if you can't provide them,
-please email me as much information as you can as to how to reproduce
-the bug, and I'll try to fix it locally. Stack traces of core dumps
-are only rarely helpful -- an example file with a set of keystrokes that
-causes the problem is almost invariably necessary.
-
-Please include the following in the bug report;
-
- o The version of nvi you're running (use :version to get it).
- o The row/column dimensions of the screen (80 x 32).
- o Unless you're confident that they're not part of the problem,
- your startup files (.exrc, .nexrc) and the environment variable
- (EXININT, NEXINIT) values. (Cutting and pasting the output
- of ":set all" is usually sufficient.)
-
-If you're running a memory checker (e.g. Purify) on nvi, you will want
-to recompile everything with "-DPURIFY" in the CFLAGS, first. By
-default, allocated pages are not initialized by the DB code, and they
-will show up as reads of uninitialized memory in the buffer write routines.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Directory layout:
-
-nvi/USD.doc:
- Ex/vi documentation, both historic and current.
-
- edit/ Roff source for "Edit: A tutorial", USD:14 in the
- 4.3BSD manuals.
- ex/ Roff source for "Ex Reference Manual -- Version
- 3.7", USD:16 in the 4.3BSD manuals.
- vi/ Roff source for "An Introduction to Display
- Editing with Vi", USD:15 in the 4.3BSD manuals.
- Includes the "Vi Quick Reference" card.
- vi.man/ Manual page for nex/nvi; an updated version of
- the document distributed with 4.4BSD-Lite.
- vi.ref/ Reference document for nex/nvi; an updated version
- of the document distributed with 4.4BSD-Lite.
-
-nvi/common:
- Source files for pieces of code that are shared by all the editors,
- like searching and logging code or code translating line numbers
- into requests to the dbopen(3) database code. It also has the
- interface code for modifying "records" in the underlying database.
-
-nvi/docs:
- Random nvi documentation:
-
- README -- Nvi main README file.
- bugs.current -- Major known bugs in the current nvi.
- changelog -- Log of changes from version to version.
- features -- Todo list, suggested features list.
- internals/
- autowrite -- Vi autowrite option discussion.
- gdb.script -- GDB debugging scripts.
- input -- Vi maps, executable buffers, and input discussion.
- quoting -- Vi quoting discussion.
- structures -- Out-of-date nvi internal structure description.
- tutorial/ -- Historic vi tutorial(s), of unknown quality.
-
-nvi/ex:
- The ex source code. Because vi has the colon command, lots of
- this code is used by vi. Generally, if functionality is shared
- by both ex and vi, it's in nvi/ex. If it's vi only, it's in
- nvi/vi. Files are generally named by the command(s) they support,
- but occasionally with a name that describes their functionality.
-
-nvi/install:
- Things to install on the local system.
-
- recover.script -- Vi recovery script.
-
-nvi/PORT:
- Porting directories, one per OS/architecture combination. See
- nvi/PORT/README for porting information.
-
- curses/ -- 4.4BSD curses implementation
- db/ -- 4.4BSD DB routines.
- regex/ -- Henry Spencer's POSIX.2 RE support.
-
-nvi/sex:
- The screen support for the ex editor.
-
-nvi/svi:
- The screen support for a curses based vi editor.
-
-nvi/vi:
- The vi source code.
-
-nvi/xaw:
- Place reserved for an X11 (Athena Widget) screen.
diff --git a/usr.bin/vi/USD.doc/edit/Makefile b/usr.bin/vi/USD.doc/edit/Makefile
deleted file mode 100644
index 3d30bc9..0000000
--- a/usr.bin/vi/USD.doc/edit/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-# @(#)Makefile 8.1 (Berkeley) 6/8/93
-
-DIR= usd/11.edit
-SRCS= edittut.ms
-MACROS= -msU
-
-paper.ps: ${SRCS}
- ${TBL} ${SRCS} | ${ROFF} > ${.TARGET}
-
-# index for versatec is different from the one in edit.tut
-# because the fonts are different and entries reference page
-# rather than section numbers. if you have a typesetter
-# you should just use the index in edit.tut, and ignore editvindex.
-
-editvindex:
- ${TROFF} ${MACROS} -n22 edit.vindex
-
-.include <bsd.doc.mk>
diff --git a/usr.bin/vi/USD.doc/edit/edit.vindex b/usr.bin/vi/USD.doc/edit/edit.vindex
deleted file mode 100644
index 2098f14..0000000
--- a/usr.bin/vi/USD.doc/edit/edit.vindex
+++ /dev/null
@@ -1,115 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)edit.vindex 8.1 (Berkeley) 6/8/93
-.\"
-.bd I
-.ND
-.TL
-Index
-.sp 3
-.2C
-.nf
-addressing, \fIsee\fR line numbers
-append mode, 4
-backslash (\\), 18
-buffer, 2
-command mode, 4
-context search, 8, 10, 13, 18
-control characters (``^'' notation), 8
-control-d, 6
-current filename, 19, 20
-current line (.), 9, 15
-diagnostic messages, 4
-disk, 2
-documentation, 21
-edit (to begin editing session), 3, 7
-editing commands:
-.in +2
-append (a), 4, 7
-change (c), 16
-copy (co), 13
-delete (d), 13-14
-edit (e), 12
-file (f), 19
-global (g), 18-19
-move (m), 12-13
-number (nu), 9
-preserve (pre), 20-21
-print (p), 8
-quit (q), 5, 11
-quit! (q!), 11
-read (r), 20
-recover (rec), 20
-substitute (s), 9-10, 17, 18
-undo (u), 14, 17
-write (w), 5-6, 11, 19-20
-z, 11
-.sp 10i
-! (shell escape), 19
-$= , 15
-+, 15
-\-, 15
-//, 8, 18
-??, 18
-\&\fB.\fR, 9, 15
-\&\fB.\fR=, 9, 15
-.in -2
-erasing
-.ti +2
-characters (#), 8
-.ti +2
-lines (@), 8
-ex (text editor), 21
-\fIEx Reference Manual\fR, 21
-file, 1
-file recovery, 20
-filename, 2
-Interrupt (message), 7
-line numbers, \fIsee also\fR current line
-.ti +2
-dollar sign ($), 8, 12-13, 15
-.ti +2
-dot (.), 9, 15
-.ti +2
-relative (+ and \-), 15, 16
-logging out, 6
-login procedure, 2
-``magic'' characters, 21
-non-printing characters, 8
-``not found'' (message), 3
-program, 1
-recovery \fIsee\fR file recovery
-shell, 18
-shell escape (!), 19
-special characters (^, $, \e), 18
-text input mode, 4
-UNIX, 1
diff --git a/usr.bin/vi/USD.doc/edit/edittut.ms b/usr.bin/vi/USD.doc/edit/edittut.ms
deleted file mode 100644
index 5f4c28c..0000000
--- a/usr.bin/vi/USD.doc/edit/edittut.ms
+++ /dev/null
@@ -1,2322 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)edittut.ms 8.1 (Berkeley) 6/8/93
-.\"
-.EH 'USD:11-%''Edit: A Tutorial'
-.OH 'Edit: A Tutorial''USD:11-%'
-.LP
-.ds u \s-2UNIX\s0
-.ll 5i
-.nr LL 5i
-.ND
-.sp 4
-.ce
-\f3\s+2Edit: A Tutorial\s0\f1
-.sp
-.ce 3
-.I
-Ricki Blau
-.sp
-James Joyce
-.R
-.sp
-.ce 3
-Computing Services
-University of California
-Berkeley, California 94720
-.sp 3
-.ce
-.I
-ABSTRACT
-.R
-.sp
-.LP
-This narrative introduction to the use of the text editor
-.I edit
-assumes no prior familiarity with computers or with text editing.
-Its aim is to lead the beginning \s-2UNIX\(dg\s+2 user through the
-.FS
-\(dgUNIX is a trademark of Bell Laboratories.
-.FE
-fundamental steps of writing and revising a file of text.
-Edit,
-a version of the text editor
-.I ex,
-was designed to provide an informative environment
-for new and casual users.
-.PP
-We welcome comments and suggestions about this tutorial
-and the \s-2UNIX\s+2 documentation in general.
-.sp .5v
-September 1981
-.bp
-.ll 6.5i
-.nr LL 6.5i
-.nr LT 6.5i
-.ds u \s-2UNIX\s0
-.ce
-\s+2\f3Contents\f1\s0
-.LP
-.nf
-Introduction\ \ \ 3
-.sp
-Session 1\ \ \4
-.in +.5i
-Making contact with \s-2UNIX\s+2\ \ \ 4
-Logging in\ \ \4
-Asking for \fIedit\fR\ \ \ 4
-The ``Command not found'' message\ \ \ 5
-A summary\ \ \5
-Entering text\ \ \ 5
-Messages from \fIedit\fR\ \ \ 5
-Text input mode\ \ \ 6
-Making corrections\ \ \ 6
-Writing text to disk\ \ \ 7
-Signing off\ \ \7
-.in -.5i
-.sp
-Session 2\ \ \ 8
-.in +.5i
-Adding more text to the file\ \ \ 8
-Interrupt\ \ \ 8
-Making corrections\ \ \ 8
-Listing what's in the buffer (p)\ \ \ 9
-Finding things in the buffer\ \ \ 9
-The current line\ \ \ 10
-Numbering lines (nu)\ \ \ 10
-Substitute command (s)\ \ \ 10
-Another way to list what's in the buffer (z)\ \ \ 11
-Saving the modified text\ \ \ 12
-.in -.5i
-.sp
-Session 3\ \ \ 13
-.in +.5i
-Bringing text into the buffer (e)\ \ \ 13
-Moving text in the buffer (m)\ \ \ 13
-Copying lines (copy)\ \ \ 14
-Deleting lines (d)\ \ \ 14
-A word or two of caution\ \ \ 15
-Undo (u) to the rescue\ \ \ 15
-More about the dot (.) and buffer end ($)\ \ \ 16
-Moving around in the buffer (+ and \-)\ \ \ 16
-Changing lines (c)\ \ \ 17
-.in -.5i
-.sp
-Session 4\ \ \ 18
-.in +.5i
-Making commands global (g)\ \ \ 18
-More about searching and substituting\ \ \ 19
-Special characters\ \ \ 19
-Issuing \s-2UNIX\s+2 commands from the editor\ \ \ 20
-Filenames and file manipulation\ \ \ 20
-The file (f) command\ \ \ 20
-Reading additional files (r)\ \ \ 21
-Writing parts of the buffer\ \ \ 21
-Recovering files\ \ \ 21
-Other recovery techniques\ \ \ 21
-Further reading and other information\ \ \ 22
-Using \fIex\fR\ \ \ 22
-.in -.5i
-.sp
-Index\ \ \ 23
-.bp
-.SH
-.ce
-\s+2Introduction\s0
-.PP
-Text editing using a terminal connected to a computer
-allows you to create, modify, and print text
-easily.
-A
-.I
-text editor
-.R
-is a program
-that assists you
-as you create and modify text.
-The text editor you will learn here is named
-.I edit.
-Creating text using edit is as easy as typing it
-on an electric typewriter.
-Modifying text involves telling the text editor
-what you want to add, change, or delete.
-You can review your text
-by typing a command
-to print the file contents
-as they are currently.
-Another program (which we do not discuss in this
-document), a text formatter,
-rearranges your text
-for you into ``finished form.''
-.PP
-These lessons assume no prior familiarity with computers
-or with text editing.
-They consist of a series of text editing sessions
-which lead you through the fundamental steps
-of creating and revising text.
-After scanning each lesson and before beginning the next,
-you should try the examples at a terminal to get a feeling
-for the actual process of text editing.
-If you set aside some time for experimentation,
-you will soon become familiar with using the
-computer to write and modify text.
-In addition to the actual use of the text editor,
-other features of \s-2UNIX\s0 will be very important to your work.
-You can begin to
-learn about these other features by
-reading one of the other tutorials
-that provide a general introduction to the system.
-You will be ready to proceed with this lesson as soon as
-you are familiar with (1) your terminal and its special keys,
-(2) how to login,
-(3) and the ways of correcting typing errors.
-Let's first define some terms:
-.sp .5
-.IP program 12
-A set of instructions, given to the computer,
-describing the sequence of steps the computer performs
-in order to accomplish a specific task.
-The task must be specific,
-such as balancing your checkbook
-or editing your text.
-A general task,
-such as working for world peace,
-is something we can all do,
-but not something we can currently write programs to do.
-.IP UNIX
-\s-2UNIX\s0 is a special type of program,
-called an operating system, that supervises the machinery
-and all other programs comprising the total
-computer system.
-.IP edit
-.I edit
-is the name of the \s-2UNIX\s0 text editor you will be learning to use,
-and is a program that aids you in writing or revising text.
-Edit was designed for beginning users,
-and is a simplified version of an editor named
-.I ex.
-.IP file
-Each \s-2UNIX\s0 account is allotted
-space for the permanent storage of information,
-such as programs, data or text.
-A file is a logical unit of data,
-for example, an essay, a program,
-or a chapter from a book,
-which is stored on a computer system.
-Once you create a file,
-it is kept until you instruct the system to remove it.
-You may create a file during one \s-2UNIX\s0 session,
-end the session,
-and return to use it at a later time.
-Files contain anything you choose to write and store in them.
-The sizes of files vary to suit your needs;
-one file might hold only a single number,
-yet another might contain
-a very long document or program.
-The only way to save
-information from one session to the next is to store it in a file,
-which you will learn in Session 1.
-.IP filename
-Filenames are used to distinguish one file from another,
-serving the same purpose as the labels of manila
-folders in a file cabinet.
-In order to write or access information in a file,
-you use the name of that file in a \s-2UNIX\s0 command,
-and the system will automatically locate the file.
-.IP disk
-Files are stored on an input/output device called a disk,
-which looks something like a stack of phonograph records.
-Each surface is coated with a material similar to that
-on magnetic recording tape,
-and information is recorded on it.
-.IP buffer
-A temporary work space, made available to the user
-for the duration of a session of text editing
-and used for creating and modifying
-the text file.
-We can think of the buffer as a blackboard that is
-erased after each class, where each session with the editor
-is a class.
-.bp
-.SH
-.ce 1
-\s+2Session 1\s0
-.sp 1
-.SH
-Making contact with \s-1UNIX\s0
-.PP
-To use the editor you must first make contact with the computer
-by logging in to \s-2UNIX\s0.
-We'll quickly review the standard \s-2UNIX\s0 login procedure
-for the two ways you can make contact:
-on a terminal that is directly linked to the computer,
-or over a telephone line where the computer answers your call.
-.SH
-Directly-linked terminals
-.PP
-Turn on your terminal and press the \s-1RETURN\s0 key.
-You are now ready to login.
-.SH
-Dial-up terminals
-.PP
-If your terminal connects with the computer over a telephone line,
-turn on the terminal, dial the system access number,
-and, when you hear a high-pitched tone, place the
-telephone handset in the acoustic coupler, if you are using one.
-You are now ready to login.
-.SH
-Logging in
-.PP
-The message inviting you to login is:
-.DS I 1i
-login:
-.DE
-.LP
-Type your login name, which identifies you to \s-2UNIX\s0,
-on the same line as the login message,
-and press \s-2RETURN\s+2.
-If the terminal you are using
-has both upper and lower case,
-.B
-be sure you enter your login name in lower case;
-.R
-otherwise \s-2UNIX\s0 assumes your terminal
-has only upper case and will not recognize lower case
-letters you may type.
-\s-2UNIX\s0 types ``login:'' and you reply
-with your login name, for example ``susan'':
-.DS I 1i
-login: \fBsusan\fR \fI(and press the \s-2RETURN\s0 key)\fR
-.DE
-(In the examples, input you would type appears in
-.B "bold face"
-to distinguish it from the responses from \s-2UNIX\s0.)
-.PP
-\s-2UNIX\s0 will next respond with a request for a password
-as an additional precaution to prevent
-unauthorized people from using your account.
-The password will not appear when you type it,
-to prevent others from seeing it.
-The message is:
-.DS I 1i
-Password: \fI(type your password and press \s-2RETURN\s+2)\fR
-.DE
-If any of the information you gave during the login
-sequence was mistyped or incorrect,
-\s-2UNIX\s0 will respond with
-.DS I 1i
-Login incorrect.
-.if t .sp .2v
-.if n .sp 1
-login:
-.DE
-in which case you should start the login process anew.
-Assuming that you have successfully
-logged in, \s-2UNIX\s0
-will print the message of the day and eventually will present
-you with a % at the beginning of a fresh line.
-The % is the \s-2UNIX\s0 prompt symbol
-which tells you that \s-2UNIX\s0 is ready to accept a command.
-.bd I 3
-.SH
-Asking for \fIedit\fP
-.fl
-.bd I
-.PP
-You are ready to tell \s-2UNIX\s0 that you
-want to work with edit, the text editor.
-Now is a convenient time to choose
-a name for the file of text you are about to create.
-To begin your editing session,
-type
-.B edit
-followed by a space and then the filename
-you have selected; for example, ``text''.
-After that,
-press the \s-2RETURN\s0 key and wait for edit's response:
-.DS I 1i
-% \fBedit text\fP \fI(followed by a \s-2RETURN\s+2)\fR
-"text" No such file or directory
-:
-.DE
-If you typed the command correctly,
-you will now be in communication with edit.
-Edit has set aside a buffer for use as
-a temporary working space during your current editing session.
-Since ``text'' is a new file we are about to create
-the editor was unable to find that file, which it
-confirms by saying:
-.DS I 1i
-"text" No such file or directory
-.DE
-On the next line appears edit's prompt ``:'',
-announcing that you are in \f2command mode\f1 and
-edit expects a command from you.
-You may now begin to create the new file.
-.SH
-The ``Command not found'' message
-.PP
-If you misspelled edit by typing, say, ``editor'',
-this might appear:
-.DS I 1i
-% \fBeditor\fP
-editor: Command not found
-%
-.DE
-Your mistake in calling edit ``editor'' was
-treated by \s-2UNIX\s0 as a request
-for a program named ``editor''.
-Since there is no program
-named ``editor'',
-\s-2UNIX\s0 reported that the program was ``not found''.
-A new % indicates that \s-2UNIX\s0 is ready for another command,
-and you may then enter the correct command.
-.SH
-A summary
-.PP
-Your exchange with \s-2UNIX\s0 as you logged in and made contact with edit
-should look something like this:
-.DS I 1i
-login: \fBsusan\fP
-Password:
-\&... A Message of General Interest ...
-% \fBedit text\fP
-"text" No such file or directory
-:
-.DE
-.SH
-Entering text
-.PP
-You may now begin entering text into the buffer.
-This is done by \fIappending\fP (or adding) text to whatever
-is currently in the buffer.
-Since there is nothing in the buffer at the moment,
-you are appending text to nothing;
-in effect,
-since you are adding text to nothing
-you are creating text.
-Most edit commands have two equivalent forms:
-a word that suggests what the command does,
-and a shorter abbreviation of that word.
-Many beginners find the full command names
-easier to remember at first,
-but once you are familiar with editing you may
-prefer to type the shorter abbreviations.
-The command to input text is ``append''.
-(It may be abbreviated ``a''.)
-Type
-.B append
-and press the \s-2RETURN\s0 key.
-.DS I 1i
-% \fBedit text
-\fR:\|\fBappend
-.R
-.DE
-.SH
-.bd I 3
-Messages from
-.I edit
-.fl
-.bd I
-.PP
-If you make a mistake in entering a command and
-type something that edit does not recognize,
-edit will respond with a message
-intended to help you diagnose your error.
-For example, if you misspell the command to input text by typing,
-perhaps, ``add'' instead of ``append'' or ``a'',
-you will receive this message:
-.DS I 1i
-:\|\fBadd\fR
-add: Not an editor command
-:
-.DE
-When you receive a diagnostic message,
-check what you typed in order to determine what
-part of your command confused edit.
-The message above means that edit
-was unable to recognize your mistyped command
-and, therefore, did not execute it.
-Instead, a new ``:''
-appeared to let you know that
-edit is again ready to execute a command.
-.SH
-Text input mode
-.PP
-By giving the command ``append'' (or using the abbreviation ``a''),
-you entered
-.I
-text input mode,
-.R
-also known as
-.I
-append mode.
-.R
-When you enter text input mode,
-edit stops sending you a prompt.
-You will not receive any prompts
-or error messages
-while in text input mode.
-You can enter
-pretty much anything you want on the lines.
-The lines are transmitted one by one to the buffer
-and held there during the editing session.
-You may append as much text as you want, and
-.I
-when you wish to stop entering text lines you should
-type a period as the only character on the line
-and press the \s-2RETURN\s0 key.
-.R
-When you type the period and press \s-2RETURN\s0,
-you signal that you want to stop appending text,
-and edit responds by allowing
-you to exit text input mode and reenter command mode.
-Edit will again
-prompt you for a command by printing ``:''.
-.PP
-Leaving append mode does not destroy the text in
-the buffer.
-You have to leave append
-mode to do any of the other kinds of editing,
-such as changing, adding, or printing text.
-If you type a period as the first character and
-type any other character on the same line,
-edit will believe you want to remain in append mode
-and will not let you out.
-As this can be very frustrating,
-be sure to type
-.B only
-the period and the \s-2RETURN\s0 key.
-.PP
-This is a good place to learn an important
-lesson about computers and text: a blank space is
-a character as far as a computer is concerned.
-If you so much as type a period followed by a blank
-(that is, type a period and then the space bar on the keyboard),
-you will remain in append mode with the last line of text
-being:
-.DS I 1i
-.B
-.ps +2
-\&.
-.ps -2
-.R
-.DE
-Let's say that you enter the lines
-(try to type
-.B exactly
-what you see, including ``thiss''):
-.DS I 1i
-.B
-This is some sample text.
-And thiss is some more text.
-Text editing is strange, but nice.
-\&.
-.R
-.DE
-The last line is the period followed by a \s-2RETURN\s0
-that gets you out of append mode.
-.SH
-Making corrections
-.PP
-If you have read a general introduction to \s-2UNIX\s0,
-you will recall that it is possible to erase individual
-letters that you have typed.
-This is done by typing the designated erase character
-as many times as there are characters
-you want to erase.
-.PP
-The usual erase character varies from place to place and
-user to user. Often it
-is the backspace (control-H),
-so you can correct typing errors
-in the line you are typing
-by holding down the \s-1CTRL\s+1 key
-and typing the ``H'' key. (Sometimes it is the DEL key.)
-If you type the erase character
-you will notice
-that the terminal backspaces in the line you are on.
-You can backspace over your error,
-and then type what you want to be the rest of the line.
-.PP
-If you make a bad start
-in a line
-and would like to begin again,
-you can either backspace to the beginning of the line
-or you can use the at-sign ``@'' to erase everything on the line:
-.DS I 1i
-.B
-Text edtiing is strange, but@
-Text editing is strange, but nice.
-.R
-.fl
-.bd S
-.DE
-When you type the at-sign (@), you erase
-the entire line typed so far
-and are given a fresh line to type on.
-You may immediately begin to retype the line.
-This, unfortunately, does not work after you type the
-line and press \s-2RETURN\s+2.
-To make corrections in lines that have been completed,
-it is necessary to use the editing commands
-covered in the next sessions.
-.SH
-Writing text to disk
-.PP
-You are now ready to edit the text. One common operation
-is to write the text to disk as a file for safekeeping
-after the session is over.
-This is the only way to save information from one session to the next,
-since the editor's buffer is temporary and will last only until the
-end of the editing session.
-Learning how to write a file to disk is second in
-importance only to entering the text.
-To write the contents of the buffer to a disk
-file, use the command ``write''
-(or its abbreviation ``w''):
-.DS I 1i
-:\|\fBwrite
-.R
-.DE
-Edit will copy the contents of the buffer to a disk file.
-If the file does not yet exist,
-a new file will be created automatically
-and the presence of a ``[New file]'' will be noted.
-The newly-created file will be given the name specified when
-you entered the editor, in this case ``text''.
-To confirm that the disk file has been successfully written,
-edit will repeat the filename and give
-the number of lines and the total
-number of characters in the file.
-The buffer remains unchanged by the ``write'' command.
-All of the lines that were written to disk will still be
-in the buffer,
-should you want to modify or add to them.
-.PP
-Edit must have a name for the file to be written.
-If you forgot to indicate the name of the file
-when you began to edit,
-edit will print in response to your write command:
-.DS I 1i
-No current filename
-.DE
-If this happens, you can specify the filename in a new write command:
-.DS I 1i
-:\|\fBwrite text
-.R
-.DE
-After the ``write'' (or ``w''), type a space and then the name of the file.
-.SH
-Signing off
-.PP
-We have done enough for this first lesson on using the
-\s-2UNIX\s0 text editor, and are ready to quit the session with edit.
-To do this we type ``quit'' (or ``q'') and press \s-2RETURN\s+2:
-.DS I 1i
-:\|\fBwrite
-.R
-"text" [New file] 3 lines, 90 characters
-:\|\fBquit\fR
-%
-.DE
-The % is from \s-2UNIX\s0 to tell you that your session with edit is
-over and you may command \s-2UNIX\s0 further.
-Since we want
-to end the entire session at the terminal, we also need to
-exit from \s-2UNIX\s0.
-In response to the \s-2UNIX\s0 prompt of ``\|%\|''
-type the command
-.DS I 1i
-%\|\fBlogout\fR
-.DE
-This will end your session with \s-2UNIX\s0, and will ready the
-terminal for the next user.
-It is always important to type \fBlogout\fR at the end of a session
-to make absolutely sure no one
-could accidentally stumble into your abandoned
-session and thus gain access to your files,
-tempting even the most honest of souls.
-.sp 1
-.PP
-This is the end of the first session on \s-2UNIX\s0 text editing.
-.bp
-.TL
-Session 2
-.sp
-.PP
-Login with \s-2UNIX\s0 as in the first session:
-.DS I 1i
-login: \fBsusan\fP \fI(carriage return)\fR
-Password: \fI(give password and carriage return)\fR
-.if t .sp .2v
-.if n .sp 1
-\&... A Message of General Interest ...
-%
-.DE
-When you indicate you want to edit,
-you can specify the name of the file you worked on last time.
-This will
-start edit working, and it will fetch the contents of the
-file into the buffer, so that you can resume editing the same file.
-When edit has copied the file into the buffer, it
-will repeat its name and tell
-you the number of lines and characters it contains.
-Thus,
-.DS I 1i
-.B
-% edit text
-.R
-"text" 3 lines, 90 characters
-:
-.DE
-means you asked edit to fetch
-the file named ``text'' for editing,
-causing it to copy the
-90 characters of text into the buffer.
-Edit awaits
-your further instructions,
-and indicates this by its prompt character, the colon (:).
-In this session, we will append more text to our file,
-print the contents of the buffer, and learn to change the text of a line.
-.SH
-Adding more text to the file
-.PP
-If you want to add more to the end of your
-text you may do so by using the append command to enter text input mode.
-When ``append'' is the first command
-of your editing session,
-the lines you enter
-are placed at the end of the buffer.
-Here we'll use the abbreviation for the append command, ``a'':
-.DS I 1i
-:\|\fBa
-This is text added in Session 2.
-It doesn't mean much here, but
-it does illustrate the editor.
-\|\fB\s+2\&.\s-2
-.R
-.DE
-You may recall that once you enter append mode
-using the ``a'' (or ``append'') command,
-you need to type a line containing only a period (.)
-to exit append mode.
-.SH
-Interrupt
-.PP
-Should you press the \s-2RUB\s+2 key (sometimes labelled \s-2DELETE\s+2)
-while working with edit,
-it will send this message to you:
-.DS I 1i
-Interrupt
-:
-.DE
-Any command that edit might be executing
-is terminated by rub or delete,
-causing edit to prompt you for a new command.
-If you are appending text at the time,
-you will exit from append mode
-and be expected to give another command.
-The line of text you were typing
-when the append command was interrupted
-will not be entered into the buffer.
-.SH
-Making corrections
-.PP
-If while typing the line you hit an incorrect key,
-recall that
-you may delete the incorrect character
-or cancel the entire line of input by erasing in the usual way.
-Refer either
-to the last few pages of Session 1
-if you need to review
-the procedures for making a correction.
-The most important idea to remember is that
-erasing a character or cancelling a line must be done
-before you press the \s-2RETURN\s+2 key.
-.SH
-Listing what's in the buffer (p)
-.PP
-Having appended text to what you wrote in Session 1,
-you might want to see all the lines in the buffer.
-To print the contents of the buffer, type the command:
-.DS I 1i
-:\|\fB1,$p
-.R
-.DE
-The ``1''\(dg
-.FS
-\(dgThe numeral ``one'' is the top left-most key,
-and should not be confused with the letter ``el''.
-.FE
-stands for line 1 of the buffer,
-the ``$'' is a special symbol designating the last line
-of the buffer,
-and ``p'' (or \fBprint\fR) is the command to print from line 1
-to the end of the buffer.
-The command ``1,$p'' gives you:
-.DS I 1i
-This is some sample text.
-And thiss is some more text.
-Text editing is strange, but nice.
-This is text added in Session 2.
-It doesn't mean much here, but
-it does illustrate the editor.
-.DE
-Occasionally, you may accidentally
-type a character that can't be printed,
-which can be done by striking a key
-while the \s-2CTRL\s0 key is pressed.
-In printing lines, edit uses a special notation to
-show the existence of non-printing characters.
-Suppose you had introduced the non-printing character ``control-A''
-into the word ``illustrate''
-by accidently pressing the \s-2CTRL\s0 key while
-typing ``a''.
-This can happen on many terminals
-because the \s-2CTRL\s+2 key and the ``A'' key
-are beside each other.
-If your finger presses between the two keys,
-control-A results.
-When asked to print the contents of the buffer,
-edit would display
-.DS I 1i
-it does illustr^Ate the editor.
-.DE
-To represent the control-A, edit shows ``^A''.
-The sequence ``^'' followed by a capital
-letter stands for the one character
-entered by holding down the \s-2CTRL\s0 key and typing the letter
-which appears after the ``^''.
-We'll soon discuss the commands that can be used
-to correct this typing error.
-.PP
-In looking over the text we see that
-``this'' is typed as ``thiss'' in the second line,
-a deliberate error so we can learn to make corrections.
-Let's correct the spelling.
-.SH
-Finding things in the buffer
-.PP
-In order to change something in the buffer we first need to
-find it.
-We can find ``thiss'' in the text we have
-entered by looking at a listing
-of the lines.
-Physically speaking, we search the lines
-of text looking for ``thiss'' and stop searching when
-we have found it.
-The way to tell edit to search for something
-is to type it inside slash marks:
-.DS I 1i
-:\|\fB/thiss/
-.R
-.DE
-By typing
-.B /thiss/
-and pressing \s-1RETURN\s0,
-you instruct edit to search for ``thiss''.
-If you ask edit to look for a pattern of characters
-which it cannot find in the buffer,
-it will respond ``Pattern not found''.
-When edit finds
-the characters ``thiss'', it will print the line of text
-for your inspection:
-.DS I 1i
-And thiss is some more text.
-.DE
-Edit is now positioned in the buffer at the
-line it just printed,
-ready to make a change in the line.
-.bp
-.SH
-The current line
-.PP
-Edit keeps track of the line in the buffer where it is located
-at all times during an editing session.
-In general, the line that has been most recently
-printed, entered, or changed
-is the current location in the buffer.
-The editor is prepared to make changes
-at the current location in the buffer,
-unless you direct it to another location.
-.PP
-In particular,
-when you bring a file into the buffer,
-you will be located at the last line in the file,
-where the editor left off copying the lines
-from the file to the buffer.
-If your first editing command is ``append'',
-the lines you enter are added
-to the end of the file,
-after the current line \(em
-the last line in the file.
-.PP
-You can refer to your current location in the buffer by the
-symbol
-period (.) usually known by the name ``dot''.
-If you type ``.'' and carriage
-return you will be instructing edit to print the current line:
-.DS I 1i
-:\|\fB\s+2\&.\s-2
-.R
-And thiss is some more text.
-.DE
-.PP
-If you want to know the number of the current line,
-you can type
-.B \&.=
-and press \s-2RETURN\s+2,
-and edit will respond with the line number:
-.DS I 1i
-:\|\fB\s+2.\s-2=
-.R
-2
-.DE
-If you type the number of any line and press \s-2RETURN\s+2,
-edit will position you at that line and
-print its contents:
-.DS I 1i
-:\|\fB2
-.R
-And thiss is some more text.
-.DE
-You should experiment with these commands
-to gain experience in using them to make changes.
-.SH
-Numbering lines (nu)
-.PP
-The
-.B
-number (nu)
-.R
-command is similar to print,
-giving both the number and the text of each printed line.
-To see the number and the text of the current line type
-.DS I 1i
-:\|\fBnu
-.R
-\0\0\0\0\02\0\0And thiss is some more text.
-.DE
-Note that the shortest abbreviation for the number command is
-``nu'' (and not ``n'', which is used for a different command).
-You may specify a range of lines
-to be listed by the number command in the same way that lines
-are specified for print.
-For example, \f31,$nu\f1 lists all lines in the buffer with their
-corresponding line numbers.
-.SH
-Substitute command (s)
-.PP
-Now that you have found the misspelled word,
-you can change it from ``thiss'' to ``this''.
-As far as edit is concerned,
-changing things is a matter of
-substituting one thing for another.
-As
-.I a
-stood for
-.I append,
-so
-.I s
-stands for
-.I substitute.
-We will use the abbreviation ``s'' to reduce the chance
-of mistyping the substitute command.
-This command will instruct edit to make the change:
-.DS I 1i
-\f32s/thiss/this/\f1
-.DE
-We first indicate the line to be changed, line 2,
-and then
-type an ``s'' to indicate we want
-edit to make a substitution.
-Inside the first set of slashes
-are the characters that we want to change,
-followed by the characters to replace them,
-and then a closing slash mark.
-To summarize:
-.DS I 1i
-2s/ \fIwhat is to be changed\fR / \fIwhat to change it to \fR/
-.DE
-If edit finds an exact match of the characters to be
-changed it will make the change
-.B only
-in the first occurrence of the characters.
-If it does not find the characters
-to be changed, it will respond:
-.DS I 1i
-Substitute pattern match failed
-.DE
-indicating that your instructions could not be carried out.
-When edit does find the characters that you want to change,
-it will make the substitution and automatically print
-the changed line, so that you can check that the correct substitution
-was made.
-In the example,
-.DS I 1i
-:\|\fB2s/thiss/this/
-.R
-And this is some more text.
-.DE
-line 2 (and line 2 only) will be searched for the characters
-``thiss'', and when the first exact match is found, ``thiss''
-will be changed to ``this''.
-Strictly speaking, it was not necessary above to
-specify the number of the line to be changed.
-In
-.DS I 1i
-:\|\fBs/thiss/this/
-.R
-.DE
-edit will assume that we mean to change
-the line where we are currently located (``.'').
-In this case,
-the command without a line number would have produced the same result
-because we were already located
-at the line we wished to change.
-.PP
-For another illustration of the substitute command,
-let us choose the line:
-.DS I 1i
-Text editing is strange, but nice.
-.DE
-You can make this line a bit more positive
-by taking out the characters ``strange, but\ '' so the line
-reads:
-.DS I 1i
-Text editing is nice.
-.DE
-A command that will first position edit at the desired line
-and then make the substitution is:
-.DS I 1i
-:\|\fB/strange/s/strange, but //
-.R
-.DE
-.LP
-What we have done here is combine our search with
-our substitution.
-Such combinations are perfectly legal,
-and speed up editing quite a bit
-once you get used to them.
-That is, you do not necessarily have to use
-line numbers to identify a line to edit.
-Instead, you may identify the line you want to change
-by asking edit to search for a specified pattern of letters
-that occurs in that line.
-The parts of the above command are:
-.TS
-.in +1i
-.nr 35 \n(.u
-.nf
-.ds #d .d
-.if \(ts\n(.z\(ts\(ts .ds #d nl
-.nr 80 0
-.nr 38 \w\f3/strange/\fP
-.if \n(80<\n(38 .nr 80 \n(38
-.nr 38 \w\f3s\fP
-.if \n(80<\n(38 .nr 80 \n(38
-.nr 38 \w\f3/strange, but //\fP
-.if \n(80<\n(38 .nr 80 \n(38
-.nr 81 0
-.nr 38 \wtells edit to find the characters ``strange'' in the text
-.if \n(81<\n(38 .nr 81 \n(38
-.nr 38 \wtells edit to make a substitution
-.if \n(81<\n(38 .nr 81 \n(38
-.nr 38 \wsubstitutes nothing at all for the characters ``strange, but ''
-.if \n(81<\n(38 .nr 81 \n(38
-.nr 38 1n
-.nr 79 0
-.nr 40 \n(79+(0*\n(38)
-.nr 80 +\n(40
-.nr 41 \n(80+(3*\n(38)
-.nr 81 +\n(41
-.nr TW \n(81
-.if t .if (\n(TW+\n(.o)>7.75i .tm Table at line 307 file ed2.tbl is too wide - \n(TW units
-.fc  
-.nr #T 0
-.eo
-.de T#
-.ds #d .d
-.if \(ts\n(.z\(ts\(ts .ds #d nl
-.mk ##
-.nr ## -1v
-..
-.ec
-.ta \n(80u \n(81u
-\&\h'|\n(40u'\f3/strange/\fP\h'|\n(41u'tells edit to find the characters ``strange'' in the text
-.ta \n(80u \n(81u
-\&\h'|\n(40u'\f3s\fP\h'|\n(41u'tells edit to make a substitution
-.ta \n(80u \n(81u
-\&\h'|\n(40u'\f3/strange, but //\fP\h'|\n(41u'substitutes nothing at all for the characters ``strange, but ''
-.fc
-.nr T. 1
-.T# 1
-.if \n(35>0 .fi
-.in -1i
-.TE
-.PP
-You should note the space after ``but'' in ``/strange, but /''.
-If you do not indicate that the space is to be taken out,
-your line will read:
-.DS I 1i
-.if t Text editing is nice.
-.if n Text editing is nice.
-.DE
-which looks a little funny
-because of the extra space between ``is'' and ``nice''.
-Again, we realize from this that a blank space
-is a real character to a computer, and in editing text
-we need to be aware of spaces
-within a line just as we would be aware of an ``a'' or
-a ``4''.
-.SH
-Another way to list what's in the buffer (z)
-.PP
-Although the print command is useful for looking at specific lines
-in the buffer,
-other commands may be more convenient for
-viewing large sections of text.
-You can ask to see a screen full of text at a time
-by using the command
-.B z.
-If you type
-.DS I 1i
-:\|\fB1z
-.R
-.DE
-edit will start with line 1 and continue printing lines,
-stopping either when the screen of
-your terminal is full
-or when the last line in the buffer has been printed.
-If you want to read the next segment of text, type the command
-.DS I 1i
-:\|\fBz
-.DE
-If no starting line number is given for the z command,
-printing will start at the ``current'' line, in this case the
-last line printed.
-Viewing lines in the buffer one screen full at a time
-is known as \fIpaging\fR.
-Paging can also be used to print
-a section of text on a hard-copy terminal.
-.SH
-Saving the modified text
-.PP
-This seems to be a good place to pause in our work,
-and so we should end the second session.
-If you (in haste) type ``q'' to quit the session
-your dialogue with edit will be:
-.DS I 1i
-:\|\fBq
-.R
-No write since last change (:quit! overrides)
-:
-.DE
-This is edit's warning that you have not written
-the modified contents of the buffer to disk.
-You run the risk of losing the work you did
-during the editing session since you typed the latest write
-command.
-Because in this lesson we have not written
-to disk at all, everything we have done
-would have been lost
-if edit had obeyed the \fBq\fR command.
-If you did not want to save the work done during
-this editing session, you would have to type ``q!''
-or (``quit!'')
-to confirm that you indeed wanted to end the session
-immediately,
-leaving the file as it was
-after the most recent ``write'' command.
-However,
-since you want to save what
-you have edited, you need to type:
-.DS I 1i
-:\|\fBw
-.R
-"text" 6 lines, 171 characters
-.DE
-and then follow with the commands to quit and logout:
-.DS I 1i
-:\|\fBq
-% \fBlogout\fR
-.DE
-and hang up the phone or turn off the terminal when
-\s-2UNIX\s0 asks for a name.
-Terminals connected to the port selector
-will stop after the logout command,
-and pressing keys on the keyboard will do nothing.
-.sp 1
-.PP
-This is the end of the second session on \s-2UNIX\s0 text editing.
-.bp
-.TL
-Session 3
-.SH
-Bringing text into the buffer (e)
-.PP
-Login to \s-2UNIX\s0 and make contact with edit.
-You should try to login without
-looking at the notes, but if you must
-then by all means do.
-.PP
-Did you remember to give the name of the file
-you wanted to edit?
-That is, did you type
-.DS I 1i
-% \fBedit text\fR
-.DE
-or simply
-.DS I 1i
-% \fBedit\fR
-.DE
-Both ways get you in contact with edit, but the first way
-will bring a copy of the file named ``text'' into
-the buffer.
-If you did forget to tell edit the name of your file,
-you can get it into the buffer by
-typing:
-.DS I 1i
-:\|\fBe text
-.R
-"text" 6 lines, 171 characters
-.DE
-The command
-.B edit,
-which may be abbreviated \fBe\fR,
-tells edit that you want
-to erase anything that might already be in
-the buffer and bring a copy of the file ``text'' into the buffer
-for editing.
-You may also use the edit (e) command to change files in
-the middle of an editing session,
-or to give edit the name of a new file that you want to create.
-Because the edit command clears the buffer,
-you will receive a warning if you try to edit a new file without
-having saved a copy of the old file.
-This gives you a chance to write the contents of the buffer to disk
-before editing the next file.
-.SH
-Moving text in the buffer (m)
-.PP
-Edit allows you to move lines of text
-from one location in the buffer to another
-by means of the
-.B move
-(\fBm\fR) command.
-The first two examples are for illustration only,
-though after you have read this Session
-you are welcome to return to them for practice.
-The command
-.DS I 1i
-:\|\fB2,4m$
-.R
-.DE
-directs edit to move lines 2, 3, and 4
-to the end of the buffer ($).
-The format for the move command is that you specify
-the first line to be moved, the last line to be moved,
-the move command ``m'', and the line after which
-the moved text is to be placed.
-So,
-.DS I 1i
-:\|\fB1,3m6
-.R
-.DE
-would instruct edit to move lines 1 through 3 (inclusive)
-to a location after line 6 in the buffer.
-To move only one line, say, line 4,
-to a location in the buffer after line 5,
-the command would be ``4m5''.
-.PP
-Let's move some text using the command:
-.DS I 1i
-:\|\fB5,$m1
-.R
-2 lines moved
-it does illustrate the editor.
-.DE
-After executing a command that moves more than one line of the buffer,
-edit tells how many lines were affected by the move
-and prints the last moved line for your inspection.
-If you want to see more than just the last line,
-you can then
-use the print (p), z, or number (nu) command to view more text.
-The buffer should now contain:
-.DS I 1i
-This is some sample text.
-It doesn't mean much here, but
-it does illustrate the editor.
-And this is some more text.
-Text editing is nice.
-This is text added in Session 2.
-.DE
-You can restore the original order by typing:
-.DS I 1i
-:\|\fB4,$m1
-.R
-.DE
-or, combining context searching and the move command:
-.DS I 1i
-:\|\fB/And this is some/,/This is text/m/This is some sample/
-.R
-.DE
-(Do not type both examples here!)
-The problem with combining context searching
-with the move command
-is that your chance of making a typing error
-in such a long command is greater than
-if you type line numbers.
-.SH
-Copying lines (copy)
-.PP
-The
-.B copy
-command
-is used to make a second copy of specified lines,
-leaving the original lines where they were.
-Copy
-has the same format as the move command, for example:
-.DS I 1i
-:\|\fB2,5copy $
-.R
-.DE
-makes a copy of lines 2 through 5,
-placing the added lines after the buffer's end ($).
-Experiment with the copy command
-so that you can become familiar with how it works.
-Note that the shortest abbreviation for copy is
-\f3co\f1 (and
-not the letter ``c'', which has another meaning).
-.SH
-Deleting lines (d)
-.PP
-Suppose you want to delete
-the line
-.DS I 1i
-This is text added in Session 2.
-.DE
-from the buffer.
-If you know the number of the line to be deleted,
-you can type
-that number followed by
-\fBdelete\fR or \fBd\fR.
-This example deletes line 4,
-which is ``This is text added in Session 2.''
-if you typed the commands
-suggested so far.
-.DS I 1i
-:\|\fB4d
-.R
-It doesn't mean much here, but
-.DE
-Here ``4'' is the number of the line to be deleted,
-and ``delete'' or ``d'' is the command to delete the line.
-After executing the delete command,
-edit prints the line that has become the current line (``.'').
-.PP
-If you do not happen to know the line number
-you can search for the line and then delete it using this
-sequence of commands:
-.DS I 1i
-:\|\fB/added in Session 2./
-.R
-This is text added in Session 2.
-:\|\fBd
-.R
-It doesn't mean much here, but
-.DE
-The ``/added in Session 2./''
-asks edit to locate and print
-the line containing the indicated text,
-starting its search at the current line
-and moving line by line
-until it finds the text.
-Once you are sure that you have correctly specified the line
-you want to delete,
-you can enter the delete (d) command.
-In this case it is not necessary to
-specify a line number before the ``d''.
-If no line number is given,
-edit deletes the current line (``.''),
-that is, the line found by our search.
-After the deletion, your buffer should contain:
-.DS I 1i
-This is some sample text.
-And this is some more text.
-Text editing is nice.
-It doesn't mean much here, but
-it does illustrate the editor.
-And this is some more text.
-Text editing is nice.
-This is text added in Session 2.
-It doesn't mean much here, but
-.DE
-To delete both lines 2 and 3:
-.DS I 1i
-And this is some more text.
-Text editing is nice.
-.DE
-you type
-.DS I 1i
-:\|\f32,3d\f1
-2 lines deleted
-.DE
-which specifies the range of lines from 2 to 3,
-and the operation on those lines \(em ``d'' for delete.
-If you delete more than one line
-you will receive a message
-telling you the number of lines deleted,
-as indicated in the example above.
-.PP
-The previous example assumes that you know the line numbers for
-the lines to be deleted.
-If you do not you might combine the search command
-with the delete command:
-.DS I 1i
-:\|\fB/And this is some/,/Text editing is nice./d
-.R
-.DE
-.SH
-A word or two of caution
-.PP
-In using the search function to locate lines to
-be deleted you should be
-.B
-absolutely sure
-.R
-the characters you give as the basis for the search
-will take edit to the line you want deleted.
-Edit will search for the first
-occurrence of the characters starting from where
-you last edited \-
-that is, from the line you see printed if you type dot (.).
-.PP
-A search based on too few
-characters may result in the wrong lines being deleted,
-which edit will do as easily as if you had meant it.
-For this reason, it is usually safer
-to specify the search and then delete in two separate steps,
-at least until you become familiar enough with using the editor
-that you understand how best to specify searches.
-For a beginner it is not a bad idea to double-check
-each command before pressing \s-2RETURN\s+2 to send the command on its way.
-.SH
-Undo (u) to the rescue
-.PP
-The
-.B
-undo (u)
-.R
-command has the ability to
-reverse the effects of the last command that changed the buffer.
-To undo the previous command, type
-``u'' or ``undo''.
-Undo can rescue
-the contents of the buffer from many an unfortunate mistake.
-However, its powers are not unlimited,
-so it is still wise to be reasonably
-careful about the commands you give.
-.PP
-It is possible to undo only commands which
-have the power to change the buffer \(em for example,
-delete, append, move, copy, substitute, and even undo itself.
-The commands write (w) and edit (e), which interact with disk files,
-cannot be undone, nor can commands that do not change
-the buffer, such as print.
-Most importantly,
-the
-.B only
-command that can be reversed by undo
-is the
-last ``undo-able'' command you typed.
-You can use control-H and @ to change
-commands while you are typing them,
-and undo to reverse the effect of the commands
-after you have typed them and pressed \s-2RETURN\s+2.
-.PP
-To illustrate,
-let's issue an undo command.
-Recall that the last buffer-changing command we gave deleted
-the lines formerly numbered 2 and 3.
-Typing undo at this moment will reverse the effects
-of the deletion, causing those two lines to be
-replaced in the buffer.
-.DS I 1i
-:\|\fBu
-.R
-2 more lines in file after undo
-And this is some more text.
-.DE
-Here again, edit informs you if the command affects more
-than one line,
-and prints
-the text of the line which is now ``dot'' (the current line).
-.SH
-More about the dot (.) and buffer end ($)
-.PP
-The function assumed by the symbol dot depends on its context.
-It can be used:
-.IP
-1. to exit from append mode; we type dot (and only a dot) on
-a line and press \s-2RETURN\s+2;
-.IP
-2. to refer to the line we are at in the buffer.
-.LP
-Dot can also be combined with the equal sign to get
-the number of the line currently being edited:
-.DS I 1i
-:\|\fB\&.=
-.R
-.DE
-If we type ``\fB.\fR='' we are asking for the number of the line,
-and if we type ``\fB.\fR'' we are asking for the text of the line.
-.PP
-In this editing session and the last, we used the dollar
-sign to indicate the end of the buffer
-in commands such as print, copy, and move.
-The dollar sign as a command asks edit to print the last
-line in the buffer.
-If the dollar sign is combined with the equal sign (\f3$=\f1)
-edit will print the line number corresponding to the
-last line in the buffer.
-.PP
-``\fB.\fR'' and ``$'', then, represent line numbers.
-Whenever appropriate, these symbols can be used in
-place of line numbers in commands.
-For example
-.DS I 1i
-:\|\fB\s+2.\s-2,$d
-.R
-.DE
-instructs edit to delete all lines from the current line (\fB.\fR)
-to the end of the buffer.
-.SH
-Moving around in the buffer (+ and \-)
-.PP
-When you are editing
-you often want
-to go back and re-read a previous line.
-You could specify a context search for a line you want to
-read if you remember some of its text,
-but if you simply want to see what was written a few, say 3, lines
-ago, you can type
-.DS I 1i
-\-3p
-.DE
-This tells edit to move back to a position 3 lines
-before the current line (.)
-and print that line.
-You can move forward in the buffer similarly:
-.DS I 1i
-+2p
-.DE
-instructs edit to print the line that is 2
-ahead of your current position.
-.PP
-You may use ``+'' and ``\-'' in any command where edit
-accepts line numbers.
-Line numbers specified with ``+'' or ``\-''
-can be combined to print a range of lines.
-The command
-.DS I 1i
-:\|\fB\-1,+2copy$
-.R
-.DE
-makes a copy of 4 lines: the current line, the line before it,
-and the two after it.
-The copied lines will be placed after the last line
-in the buffer ($),
-and the original lines referred to by ``\-1'' and ``+2''
-remain where they are.
-.PP
-Try typing only ``\-''; you will move back one line just as
-if you had typed ``\-1p''.
-Typing the command ``+'' works similarly.
-You might also try typing a few plus or minus signs in a row
-(such as ``+++'') to see edit's response.
-Typing \s-2RETURN\s+2 alone on a line is the equivalent
-of typing ``+1p''; it will move you one line ahead in the buffer
-and print that line.
-.PP
-If you are at the last line of the buffer and try
-to move further ahead, perhaps by typing a ``+'' or
-a carriage return alone on the line,
-edit will remind you that you are at the end of the buffer:
-.sp
-.nf
-.ti 1i
-At end-of-file
-.br
-or
-.ti 1i
-Not that many lines in buffer
-.fi
-.LP
-Similarly, if you try to move to a position before the first line,
-edit will print one of these messages:
-.sp
-.nf
-.ti 1i
-Nonzero address required on this command
-.br
-or
-.ti 1i
-Negative address \- first buffer line is 1
-.fi
-.LP
-The number associated with a buffer line is the line's ``address'',
-in that it can be used to locate the line.
-.SH
-Changing lines (c)
-.PP
-You can also delete certain lines and
-insert new text in their place.
-This can be accomplished easily with the
-.B "change (c)"
-command.
-The change command instructs edit to delete specified lines
-and then switch to text input mode to
-accept the text that will replace them.
-Let's say you want to change the first two lines in the buffer:
-.DS I 1i
-This is some sample text.
-And this is some more text.
-.DE
-to read
-.DS I 1i
-This text was created with the \s-2UNIX\s0 text editor.
-.DE
-To do so, you type:
-.DS I 1i
-:\|\fB1,2c
-.R
-2 lines changed
-.B
-This text was created with the \s-2UNIX\s0 text editor.
-\s+2\&.\s-2
-.R
-:
-.DE
-In the command
-.B 1,2c
-we specify that we want to change
-the range of lines beginning with 1 and ending with 2
-by giving line numbers as with the print command.
-These lines will be deleted.
-After you type \s-2RETURN\s+2 to end the change command,
-edit notifies you if more than one line will be changed
-and places you in text input mode.
-Any text typed on the following lines will be inserted into
-the position where lines were deleted by the change command.
-.B
-You will remain in text input mode until you exit in the usual way,
-by typing a period alone on a line.
-.R
-Note that the number of lines added to the buffer need not be
-the same as the number of lines deleted.
-.sp 1
-.PP
-This is the end of the third session on text editing with \s-2UNIX\s0.
-.bp
-.SH
-.ce 1
-\s+2Session 4\s0
-.sp
-.PP
-This lesson covers several topics, starting with
-commands that apply throughout the buffer,
-characters with special meanings,
-and how to issue \s-2UNIX\s0 commands while in the editor.
-The next topics deal with files:
-more on reading and writing,
-and methods of recovering files lost in a crash.
-The final section suggests sources of further information.
-.SH
-Making commands global (g)
-.PP
-One disadvantage to the commands we have used for
-searching or substituting is that if you
-have a number of instances of a word to change
-it appears that you have to type the command
-repeatedly, once for
-each time the change needs to be made.
-Edit, however, provides a way to make commands
-apply to the entire contents of the buffer \-
-the
-.B
-global (g)
-.R
-command.
-.PP
-To print all lines
-containing a certain sequence of characters
-(say, ``text'')
-the command is:
-.DS I 1i
-:\|\fBg/text/p
-.R
-.DE
-The ``g'' instructs edit to
-make a global search for all lines
-in the buffer containing the characters ``text''.
-The ``p'' prints the lines found.
-.PP
-To issue a global command, start by typing a ``g'' and then a search
-pattern identifying
-the lines to be affected.
-Then, on the same line, type the command to be
-executed for the identified lines.
-Global substitutions are frequently useful.
-For example,
-to change all instances of the word ``text'' to the word ``material''
-the command would be a combination of the global search and the
-substitute command:
-.DS I 1i
-:\|\fBg/text/s/text/material/g
-.R
-.DE
-Note the ``g'' at the end of the global command,
-which instructs edit to change
-each and every instance of ``text'' to ``material''.
-If you do not type the ``g'' at the end of the command
-only the
-.I first
-instance of ``text'' \fIin each line\fR will be changed
-(the normal result of the substitute command).
-The ``g'' at the end of the command is independent of the ``g''
-at the beginning.
-You may give a command such as:
-.DS I 1i
-:\|\fB5s/text/material/g
-.R
-.DE
-to change every instance of ``text'' in line 5 alone.
-Further, neither command will change ``text'' to ``material''
-if ``Text'' begins with a capital rather than a lower-case
-.I t.
-.PP
-Edit does not automatically print the lines modified by a
-global command.
-If you want the lines to be printed, type a ``p''
-at the end of the global command:
-.DS I 1i
-:\|\fBg/text/s/text/material/gp
-.R
-.DE
-You should be careful
-about using the global command in combination with any other \-
-in essence, be sure of what you are telling edit to do
-to the entire buffer.
-For example,
-.DS I 1i
-:\|\fBg/ /d
-.R
-72 less lines in file after global
-.DE
-will delete every line containing a blank anywhere in it.
-This could adversely affect
-your document, since most lines have spaces between words
-and thus would be deleted.
-After executing the global command,
-edit will print a warning if the command added or deleted more than one line.
-Fortunately, the undo command can reverse
-the effects of a global command.
-You should experiment with the global command
-on a small file of text to see what it can do for you.
-.SH
-More about searching and substituting
-.PP
-In using slashes to identify a character string
-that we want to search for or change,
-we have always specified the exact characters.
-There is a less tedious way to
-repeat the same string of characters.
-To change ``text'' to ``texts'' we may type either
-.DS I 1i
-:\|\fB/text/s/text/texts/
-.R
-.DE
-as we have done in the past,
-or a somewhat abbreviated command:
-.DS I 1i
-:\|\fB/text/s//texts/
-.R
-.DE
-In this example, the characters to be changed
-are not specified \-
-there are no characters, not even a space,
-between the two slash marks
-that indicate what is to be changed.
-This lack of characters between the slashes
-is taken by the editor to mean
-``use the characters we last searched for as the characters to be changed.''
-.PP
-Similarly, the last context search may be repeated
-by typing a pair of slashes with nothing between them:
-.DS I 1i
-:\|\fB/does/
-.R
-It doesn't mean much here, but
-:\|\fB//
-.R
-it does illustrate the editor.
-.DE
-(You should note that the search command found the characters ``does''
-in the word ``doesn't'' in the first search request.)
-Because no characters are specified for the second search,
-the editor scans the buffer for the next occurrence of the
-characters ``does''.
-.PP
-Edit normally searches forward through the buffer,
-wrapping around from the end of the buffer to the beginning,
-until the specified character string is found.
-If you want to search in the reverse direction,
-use question marks (?) instead of slashes
-to surround the characters you are searching for.
-.PP
-It is also possible
-to repeat the last substitution
-without having to retype the entire command.
-An ampersand (&) used as a command
-repeats the most recent substitute command,
-using the same search and replacement patterns.
-After altering the current line by typing
-.DS I 1i
-:\|\fBs/text/texts/
-.R
-.DE
-you type
-.DS I 1i
-:\|\fB/text/&
-.R
-.DE
-or simply
-.DS I 1i
-:\|\fB//&
-.R
-.DE
-to make the same change on the next line in the buffer
-containing the characters ``text''.
-.SH
-Special characters
-.PP
-Two characters have special meanings when
-used in specifying searches: ``$'' and ``^''.
-``$'' is taken by the editor to mean ``end of the line''
-and is used to identify strings
-that occur at the end of a line.
-.DS I 1i
-:\|\fBg/text.$/s//material./p
-.R
-.DE
-tells the editor to search for all lines ending in ``text.''
-(and nothing else, not even a blank space),
-to change each final ``text.'' to ``material.'',
-and print the changed lines.
-.PP
-The symbol ``^'' indicates the beginning of a line.
-Thus,
-.DS I 1i
-:\|\fBs/^/1. /
-.R
-.DE
-instructs the editor to insert ``1.'' and a space at the beginning
-of the current line.
-.PP
-The characters ``$'' and ``^'' have special meanings only in the context
-of searching.
-At other times, they are ordinary characters.
-If you ever need to search for a character that has a special meaning,
-you must indicate that the
-character is to lose temporarily
-its special significance by typing another special character,
-the backslash (\\), before it.
-.DS I 1i
-:\|\fBs/\\\\\&$/dollar/
-.R
-.DE
-looks for the character ``$'' in the current
-line and replaces it by the word ``dollar''.
-Were it not for the backslash, the ``$'' would have represented
-``the end of the line'' in your search
-rather than the character ``$''.
-The backslash retains its special significance
-unless it is preceded by another backslash.
-.SH
-Issuing \s-2UNIX\s0 commands from the editor
-.PP
-After creating several files with the editor,
-you may want to delete files
-no longer useful to you or ask for a list of your files.
-Removing and listing files are not functions of the editor,
-and so they require the use of \s-2UNIX\s0 system commands
-(also referred to as ``shell'' commands, as
-``shell'' is the name of the program that processes \s-2UNIX\s0 commands).
-You do not need to quit the editor to execute a \s-2UNIX\s0 command
-as long as you indicate that it
-is to be sent to the shell for execution.
-To use the \s-2UNIX\s0 command
-.B rm
-to remove the file named ``junk'' type:
-.DS I 1i
-:\|\fB!rm junk
-.R
-!
-:
-.DE
-The exclamation mark (!)
-indicates that the rest of the line is to be processed as a shell command.
-If the buffer contents have not been written since the last change,
-a warning will be printed before the command is executed:
-.DS I 1i
-[No write since last change]
-.DE
-The editor prints a ``!'' when the command is completed.
-Other tutorials describe useful features of the system,
-of which an editor is only one part.
-.SH
-Filenames and file manipulation
-.PP
-Throughout each editing session,
-edit keeps track of the name of the file being edited as the
-.I "current filename."
-Edit remembers as the current filename the name given
-when you entered the editor.
-The current filename changes whenever the edit (e) command
-is used to specify a new file.
-Once edit has recorded a current filename,
-it inserts that name into any command where a filename has been omitted.
-If a write command does not specify a file,
-edit, as we have seen, supplies the current filename.
-If you are editing a file named ``draft3'' having 283 lines in it,
-you can have the editor write onto a different file
-by including its name in the write command:
-.DS I 1i
-:\fB\|w chapter3
-.R
-"chapter3" [new file] 283 lines, 8698 characters
-.DE
-The current filename remembered by the editor
-.I
-will not be changed as a result of the write command.
-.R
-Thus, if the next write command
-does not specify a name,
-edit will write onto the current file (``draft3'')
-and not onto the file ``chapter3''.
-.SH
-The file (f) command
-.PP
-To ask for the current filename, type
-.B file
-(or
-.B f ).
-In response, the editor provides current information about the buffer,
-including the filename, your current position, the number of
-lines in the buffer,
-and the percent of the distance through the file
-your current location is.
-.DS I 1i
-:\|\fBf
-.R
-"text" [Modified] line 3 of 4 --75%--
-.DE
-.\"The expression ``[Edited]'' indicates that the buffer contains
-.\"either the editor's copy of the existing file ``text''
-.\"or a file which you are just now creating.
-If the contents of the buffer have changed
-since the last time the file was written,
-the editor will tell you that the file has been ``[Modified]''.
-After you save the changes by writing onto a disk file,
-the buffer will no longer be considered modified:
-.DS I 1i
-:\|\fBw
-.R
-"text" 4 lines, 88 characters
-:\|\fBf
-.R
-"text" line 3 of 4 --75%--
-.DE
-.SH
-Reading additional files (r)
-.PP
-The
-\f3read (r)\f1 command allows you to add the contents of a file
-to the buffer
-at a specified location,
-essentially copying new lines
-between two existing lines.
-To use it, specify the line after which the new text will be placed,
-the \f3read (r)\f1 command,
-and then the name of the file.
-If you have a file named ``example'', the command
-.DS I 1i
-:\|\fB$r example
-.R
-"example" 18 lines, 473 characters
-.DE
-reads the file ``example''
-and adds it to the buffer after the last line.
-The current filename is not changed by the read command.
-.SH
-Writing parts of the buffer
-.PP
-The
-.B
-write (w)
-.R
-command can write all or part of the buffer
-to a file you specify.
-We are already familiar with
-writing the entire contents of the
-buffer to a disk file.
-To write only part of the buffer onto a file,
-indicate the beginning and ending lines before the write command,
-for example
-.DS I 1i
-:\|\fB45,$w ending
-.R
-.DE
-Here all lines from 45 through the end of the buffer
-are written onto the file named
-.I ending.
-The lines remain in the buffer
-as part of the document you are editing,
-and you may continue to edit the entire buffer.
-Your original file is unaffected
-by your command to write part of the buffer
-to another file.
-Edit still remembers whether you have saved changes to the buffer
-in your original file or not.
-.SH
-Recovering files
-.PP
-Although it does not happen very often,
-there are times \s-2UNIX\s+2 stops working
-because of some malfunction.
-This situation is known as a \fIcrash\fR.
-Under most circumstances,
-edit's crash recovery feature
-is able to save work to within a few lines of changes
-before a crash (or an accidental phone hang up).
-If you lose the contents of an editing buffer in a system crash,
-you will normally receive mail when you login that gives
-the name of the recovered file.
-To recover the file,
-enter the editor and type the command
-.B recover
-(\fBrec\fR),
-followed by the name of the lost file.
-For example,
-to recover the buffer for an edit session
-involving the file ``chap6'', the command is:
-.DS I 1i
-.R
-:\|\fBrecover chap6
-.R
-.DE
-Recover is sometimes unable to save the entire buffer successfully,
-so always check the contents of the saved buffer carefully
-before writing it back onto the original file.
-For best results,
-write the buffer to a new file temporarily
-so you can examine it without risk to the original file.
-Unfortunately,
-you cannot use the recover command
-to retrieve a file you removed
-using the shell command \f3rm\f1.
-.SH
-Other recovery techniques
-.PP
-If something goes wrong when you are using the editor,
-it may be possible to save your work by using the command
-.B preserve
-(\fBpre\fR),
-which saves the buffer as if the system had crashed.
-If you are writing a file and you get the message
-``Quota exceeded'', you have tried to use more disk storage
-than is allotted to your account.
-.I
-Proceed with caution
-.R
-because it is likely that only a part
-of the editor's buffer is now present in the file you tried to write.
-In this case you should use the shell escape from the editor (!)
-to remove some files you don't need and try to write
-the file again.
-If this is not possible and you cannot find someone to help you,
-enter the command
-.DS I 1i
-:\|\fBpreserve
-.R
-.DE
-and wait for the reply,
-.DS I 1i
-File preserved.
-.DE
-If you do not receive this reply,
-seek help immediately.
-Do not simply leave the editor.
-If you do, the buffer will be lost,
-and you may not be able to save your file.
-If the reply is ``File preserved.''
-you can leave the editor
-(or logout)
-to remedy the situation.
-After a preserve, you can use the recover command
-once the problem has been corrected,
-or the \fB\-r\fR option of the edit command
-if you leave the editor and want to return.
-.PP
-If you make an undesirable change to the buffer
-and type a write command before discovering your mistake,
-the modified version will replace any previous version of the file.
-Should you ever lose a good version of a document in this way,
-do not panic and leave the editor.
-As long as you stay in the editor,
-the contents of the buffer remain accessible.
-Depending on the nature of the problem,
-it may be possible
-to restore the buffer to a more complete
-state with the undo command.
-After fixing the damaged buffer, you can again write the file
-to disk.
-.SH
-Further reading and other information
-.PP
-Edit is an editor designed for beginning and casual users.
-It is actually a version of a more powerful editor called
-.I ex.
-These lessons are intended to introduce you to the editor
-and its more commonly-used commands.
-We have not covered all of the editor's commands,
-but a selection of commands
-that should be sufficient to accomplish most of your editing tasks.
-You can find out more about the editor in the
-.I
-Ex Reference Manual,
-.R
-which is applicable to both
-.I ex
-and
-.I edit.
-One way to become familiar with the manual is to begin by reading
-the description of commands that you already know.
-.bd I 3
-.SH
-Using
-.I ex
-.fl
-.bd I
-.PP
-As you become more experienced with using the editor,
-you may still find that edit continues to meet your needs.
-However, should you become interested in using
-.I ex,
-it is easy to switch.
-To begin an editing session with
-.I ex,
-use the name
-.B ex
-in your command instead of
-.B edit.
-.PP
-Edit commands also work in
-.I ex,
-but the editing environment is somewhat different.
-You should be aware of a few differences
-between
-.I ex
-and
-.I edit.
-In edit, only the characters ``^'', ``$'', and ``\\'' have
-special meanings in searching the buffer
-or indicating characters to be changed by a substitute command.
-Several additional characters have special
-meanings in ex, as described in the
-.I
-Ex Reference Manual.
-.R
-Another feature of the edit environment prevents users from
-accidently entering two alternative modes of editing,
-.I open
-and
-.I visual,
-in which
-the editor behaves quite differently from normal command mode.
-If you are using ex and you encounter strange behavior,
-you may have accidently entered open mode by typing ``o''.
-Type the \s-2ESC\s0 key and then a ``Q''
-to get out of open or visual mode and back into
-the regular editor command mode.
-The document
-.I
-An Introduction to Display Editing with Vi\|\|
-.R
-provide full details of visual mode.
-.bp
-.SH
-.ce 1
-\s+2Index\s0
-.LP
-.sp 2
-.2C
-.nf
-addressing, \fIsee\fR line numbers
-ampersand, 20
-append mode, 6-7
-append (a) command, 6, 7, 9
-``At end of file'' (message), 18
-backslash (\\), 21
-buffer, 3
-caret (^), 10, 20
-change (c) command, 18
-command mode, 5-6
-``Command not found'' (message), 6
-context search, 10-12, 19-21
-control characters (``^'' notation), 10
-control-H, 7
-copy (co) command, 15
-corrections, 7, 16
-current filename, 21
-current line (\|.\|), 11, 17
-delete (d) command, 15-16
-dial-up, 5
-disk, 3
-documentation, 3, 23
-dollar ($), 10, 11, 17, 20-21
-dot (\f3\|.\|\f1) 11, 17
-edit (text editor), 3, 5, 23
-edit (e) command, 5, 9, 14
-editing commands:
-.in +.25i
-append (a), 6, 7, 9
-change (c), 18
-copy (co), 15
-delete (d), 15-16
-edit (text editor), 3, 5, 23
-edit (e), 5, 9, 14
-file (f), 21-22
-global (g), 19
-move (m), 14-15
-number (nu), 11
-preserve (pre), 22-23
-print (p), 10
-quit (q), 8, 13
-read (r), 22
-recover (rec), 22, 23
-substitute (s), 11-12, 19, 20
-undo (u), 16-17, 23
-write (w), 8, 13, 21, 22
-z, 12-13
-! (shell escape), 21
-$=, 17
-+, 17
-\-, 17
-//, 12, 20
-??, 20
-\&., 11, 17
-\&.=, 11, 17
-.in -.25i
-entering text, 3, 6-7
-erasing
-.in +.25i
-characters (^H), 7
-lines (@), 7
-.in -.25i
-error corrections, 7, 16
-ex (text editor), 23
-\fIEx Reference Manual\fR, 23
-exclamation (!), 21
-file, 3
-file (f) command, 21-22
-file recovery, 22-23
-filename, 3, 21
-global (g) command, 19
-input mode, 6-7
-Interrupt (message), 9
-line numbers, \fIsee also\fR current line
-.in +.25i
-dollar sign ($), 10, 11, 17
-dot (\|.\|), 11, 17
-relative (+ and \-), 17
-.in -.25i
-list, 10
-logging in, 4-6
-logging out, 8
-``Login incorrect'' (message), 5
-minus (\-), 17
-move (m) command, 14-15
-``Negative address\(emfirst buffer line is 1'' (message), 18
-``No current filename'' (message), 8
-``No such file or directory'' (message), 5, 6
-``No write since last change'' (message), 21
-non-printing characters, 10
-``Nonzero address required'' (message), 18
-``Not an editor command'' (message), 6
-``Not that many lines in buffer'' (message), 18
-number (nu) command, 11
-password, 5
-period (\|.\|), 11, 17
-plus (+), 17
-preserve (pre) command, 22-23
-print (p) command, 10
-program, 3
-prompts
-.in .25i
-% (\s-2UNIX\s0), 5
-: (edit), 5, 6, 7
-\0 (append), 7
-.in -.25i
-question (?), 20
-quit (q) command, 8, 13
-read (r) command, 22
-recover (rec) command, 22, 23
-recovery, \fIsee\fR\| file recovery
-references, 3, 23
-remove (rm) command, 21, 22
-reverse command effects (undo), 16-17, 23
-searching, 10-12, 19-21
-shell, 21
-shell escape (!), 21
-slash (/), 11-12, 20
-special characters (^, $, \\), 10, 11, 17, 20-21
-substitute (s) command, 11-12, 19, 20
-terminals, 4-5
-text input mode, 7
-undo (u) command, 16-17, 23
-\s-1UNIX\s0, 3
-write (w) command, 8, 13, 21, 22
-z command, 12-13
-
diff --git a/usr.bin/vi/USD.doc/exref/Makefile b/usr.bin/vi/USD.doc/exref/Makefile
deleted file mode 100644
index 11f4e66..0000000
--- a/usr.bin/vi/USD.doc/exref/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-# @(#)Makefile 8.1 (Berkeley) 6/8/93
-
-DIR= usd/13.ex
-SRCS= ex.rm
-MACROS= -msU
-CLEANFILES=summary.*
-
-paper.ps: ${SRCS} summary.ps
- ${ROFF} ${SRCS} > ${.TARGET}
-
-summary.ps: ex.summary
- ${TBL} ex.summary | ${ROFF} > ${.TARGET}
-
-.include <bsd.doc.mk>
diff --git a/usr.bin/vi/USD.doc/exref/ex.rm b/usr.bin/vi/USD.doc/exref/ex.rm
deleted file mode 100644
index 79670c2..0000000
--- a/usr.bin/vi/USD.doc/exref/ex.rm
+++ /dev/null
@@ -1,2230 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)ex.rm 8.1 (Berkeley) 6/8/93
-.\"
-.EH 'USD:13-%''Ex Reference Manual'
-.OH 'Ex Reference Manual''USD:13-%'
-.de ZP
-.nr pd \\n()P
-.nr )P 0
-.if \\n(.$=0 .IP
-.if \\n(.$=1 .IP "\\$1"
-.if \\n(.$>=2 .IP "\\$1" "\\$2"
-.nr )P \\n(pd
-.rm pd
-..
-.de LC
-.br
-.sp .1i
-.ne 4
-.LP
-.ta 4.0i
-..
-.bd S B 3
-.\".RP
-.TL
-Ex Reference Manual
-.br
-Version 3.7
-.AU
-William Joy
-.AU
-Mark Horton
-.AI
-Computer Science Division
-Department of Electrical Engineering and Computer Science
-University of California, Berkeley
-Berkeley, Ca. 94720
-.AB
-.I Ex
-a line oriented text editor, which supports both command and display
-oriented editing.
-This reference manual describes the command oriented part of
-.I ex;
-the display editing features of
-.I ex
-are described in
-.I "An Introduction to Display Editing with Vi."
-Other documents about the editor include the introduction
-.I "Edit: A tutorial",
-the
-.I "Ex/edit Command Summary",
-and a
-.I "Vi Quick Reference"
-card.
-.AE
-.NH 1
-Starting ex
-.PP
-.FS
-The financial support of an \s-2IBM\s0 Graduate Fellowship and the National
-Science Foundation under grants MCS74-07644-A03 and MCS78-07291 is gratefully
-acknowledged.
-.FE
-Each instance of the editor has a set of options,
-which can be set to tailor it to your liking.
-The command
-.I edit
-invokes a version of
-.I ex
-designed for more casual or beginning
-users by changing the default settings of some of these options.
-To simplify the description which follows we
-assume the default settings of the options.
-.PP
-When invoked,
-.I ex
-determines the terminal type from the \s-2TERM\s0 variable in the environment.
-It there is a \s-2TERMCAP\s0 variable in the environment, and the type
-of the terminal described there matches the \s-2TERM\s0 variable,
-then that description
-is used. Also if the \s-2TERMCAP\s0 variable contains a pathname (beginning
-with a \fB/\fR) then the editor will seek the description of the terminal
-in that file (rather than the default /etc/termcap).
-If there is a variable \s-2EXINIT\s0 in the environment, then the editor
-will execute the commands in that variable,
-otherwise if there is a file
-.I \&.exrc
-in your \s-2HOME\s0 directory
-.I ex
-reads commands from that file, simulating a
-.I source
-command.
-Option setting commands placed in
-\s-2EXINIT\s0 or
-.I \&.exrc
-will be executed before each editor session.
-.PP
-A command to enter
-.I ex
-has the following prototype:\(dg
-.FS
-\(dg Brackets `[' `]' surround optional parameters here.
-.FE
-.DS
-\fBex\fP [ \fB\-\fP ] [ \fB\-v\fP ] [ \fB\-t\fP \fItag\fP ] [ \fB\-r\fP ] [ \fB\-l\fP ] [ \fB\-w\fP\fIn\fP ] [ \fB\-x\fP ] [ \fB\-R\fP ] [ \fB+\fP\fIcommand\fP ] name ...
-.DE
-The most common case edits a single file with no options, i.e.:
-.DS
-\fBex\fR name
-.DE
-The
-.B \-
-command line option
-option suppresses all interactive-user feedback
-and is useful in processing editor scripts in command files.
-The
-.B \-v
-option is equivalent to using
-.I vi
-rather than
-.I ex.
-The
-.B \-t
-option is equivalent to an initial
-.I tag
-command, editing the file containing the
-.I tag
-and positioning the editor at its definition.
-The
-.B \-r
-option is used in recovering after an editor or system crash,
-retrieving the last saved version of the named file or,
-if no file is specified,
-typing a list of saved files.
-The
-.B \-l
-option sets up for editing \s-2LISP\s0, setting the
-.I showmatch
-and
-.I lisp
-options.
-The
-.B \-w
-option sets the default window size to
-.I n,
-and is useful on dialups to start in small windows.
-The
-.B \-x
-option causes
-.I ex
-to prompt for a
-.I key ,
-which is used to encrypt and decrypt the contents of the file,
-which should already be encrypted using the same key,
-see
-.I crypt (1).
-The
-.B \-R
-option sets the
-.I readonly
-option at the start.
-.I Name
-arguments indicate files to be edited.
-An argument of the form
-\fB+\fIcommand\fR
-indicates that the editor should begin by executing the specified command.
-If
-.I command
-is omitted, then it defaults to ``$'', positioning the editor at the last
-line of the first file initially. Other useful commands here are scanning
-patterns of the form ``/pat'' or line numbers, e.g. ``+100'' starting
-at line 100.
-.NH 1
-File manipulation
-.NH 2
-Current file
-.PP
-.I Ex
-is normally editing the contents of a single file,
-whose name is recorded in the
-.I current
-file name.
-.I Ex
-performs all editing actions in a buffer
-(actually a temporary file)
-into which the text of the file is initially read.
-Changes made to the buffer have no effect on the file being
-edited unless and until the buffer contents are written out to the
-file with a
-.I write
-command.
-After the buffer contents are written,
-the previous contents of the written file are no longer accessible.
-When a file is edited,
-its name becomes the current file name,
-and its contents are read into the buffer.
-.PP
-The current file is almost always considered to be
-.I edited.
-This means that the contents of the buffer are logically
-connected with the current file name,
-so that writing the current buffer contents onto that file,
-even if it exists,
-is a reasonable action.
-If the current file is not
-.I edited
-then
-.I ex
-will not normally write on it if it already exists.*
-.FS
-* The
-.I file
-command will say ``[Not edited]'' if the current file is not considered
-edited.
-.FE
-.NH 2
-Alternate file
-.PP
-Each time a new value is given to the current file name,
-the previous current file name is saved as the
-.I alternate
-file name.
-Similarly if a file is mentioned but does not become the current file,
-it is saved as the alternate file name.
-.NH 2
-Filename expansion
-.PP
-Filenames within the editor may be specified using the normal
-shell expansion conventions.
-In addition,
-the character `%' in filenames is replaced by the
-.I current
-file name and the character
-`#' by the
-.I alternate
-file name.\(dg
-.FS
-\(dg This makes it easy to deal alternately with
-two files and eliminates the need for retyping the
-name supplied on an
-.I edit
-command after a
-.I "No write since last change"
-diagnostic is received.
-.FE
-.NH 2
-Multiple files and named buffers
-.PP
-If more than one file is given on the command line,
-then the first file is edited as described above.
-The remaining arguments are placed with the first file in the
-.I "argument list."
-The current argument list may be displayed with the
-.I args
-command.
-The next file in the argument list may be edited with the
-.I next
-command.
-The argument list may also be respecified by specifying
-a list of names to the
-.I next
-command.
-These names are expanded,
-the resulting list of names becomes the new argument list,
-and
-.I ex
-edits the first file on the list.
-.PP
-For saving blocks of text while editing, and especially when editing
-more than one file,
-.I ex
-has a group of named buffers.
-These are similar to the normal buffer, except that only a limited number
-of operations are available on them.
-The buffers have names
-.I a
-through
-.I z.\(dd
-.FS
-\(dd It is also possible to refer to
-.I A
-through
-.I Z;
-the upper case buffers are the same as the lower but commands
-append to named buffers rather than replacing
-if upper case names are used.
-.FE
-.NH 2
-Read only
-.PP
-It is possible to use
-.I ex
-in
-.I "read only"
-mode to look at files that you have no intention of modifying.
-This mode protects you from accidently overwriting the file.
-Read only mode is on when the
-.I readonly
-option is set.
-It can be turned on with the
-.B \-R
-command line option,
-by the
-.I view
-command line invocation,
-or by setting the
-.I readonly
-option.
-It can be cleared by setting
-.I noreadonly .
-It is possible to write, even while in read only mode, by indicating
-that you really know what you are doing.
-You can write to a different file, or can use the ! form of write,
-even while in read only mode.
-.NH 1
-Exceptional Conditions
-.NH 2
-Errors and interrupts
-.PP
-When errors occur
-.I ex
-(optionally) rings the terminal bell and, in any case, prints an error
-diagnostic. If the primary input is from a file, editor processing
-will terminate. If an interrupt signal is received,
-.I ex
-prints ``Interrupt'' and returns to its command level. If the primary
-input is a file, then
-.I ex
-will exit when this occurs.
-.NH 2
-Recovering from hangups and crashes
-.PP
-If a hangup signal is received and the buffer has been modified since
-it was last written out, or if the system crashes, either the editor
-(in the first case) or the system (after it reboots in the second) will
-attempt to preserve the buffer. The next time you log in you should be
-able to recover the work you were doing, losing at most a few lines of
-changes from the last point before the hangup or editor crash. To
-recover a file you can use the
-.B \-r
-option. If you were editing the file
-.I resume,
-then you should change
-to the directory where you were when the crash occurred, giving the command
-.DS
-\fBex \-r\fP\fI resume\fP
-.DE
-After checking that the retrieved file is indeed ok, you can
-.I write
-it over the previous contents of that file.
-.PP
-You will normally get mail from the system telling you when a file has
-been saved after a crash. The command
-.DS
-\fBex\fP \-\fBr\fP
-.DE
-will print a list of the files which have been saved for you.
-(In the case of a hangup,
-the file will not appear in the list,
-although it can be recovered.)
-.NH 1
-Editing modes
-.PP
-.I Ex
-has five distinct modes. The primary mode is
-.I command
-mode. Commands are entered in command mode when a `:' prompt is
-present, and are executed each time a complete line is sent. In
-.I "text input"
-mode
-.I ex
-gathers input lines and places them in the file. The
-.I append,
-.I insert,
-and
-.I change
-commands use text input mode.
-No prompt is printed when you are in text input mode.
-This mode is left by typing a `.' alone at the beginning of a line, and
-.I command
-mode resumes.
-.PP
-The last three modes are
-.I open
-and
-.I visual
-modes, entered by the commands of the same name, and, within open and
-visual modes
-.I "text insertion"
-mode.
-.I Open
-and
-.I visual
-modes allow local editing operations to be performed on the text in the
-file. The
-.I open
-command displays one line at a time on any terminal while
-.I visual
-works on \s-2CRT\s0 terminals with random positioning cursors, using the
-screen as a (single) window for file editing changes.
-These modes are described (only) in
-.I "An Introduction to Display Editing with Vi."
-.NH
-Command structure
-.PP
-Most command names are English words,
-and initial prefixes of the words are acceptable abbreviations.
-The ambiguity of abbreviations is resolved in favor of the more commonly
-used commands.*
-.FS
-* As an example, the command
-.I substitute
-can be abbreviated `s'
-while the shortest available abbreviation for the
-.I set
-command is `se'.
-.FE
-.NH 2
-Command parameters
-.PP
-Most commands accept prefix addresses specifying the lines in the file
-upon which they are to have effect.
-The forms of these addresses will be discussed below.
-A number of commands also may take a trailing
-.I count
-specifying the number of lines to be involved in the command.\(dg
-.FS
-\(dg Counts are rounded down if necessary.
-.FE
-Thus the command ``10p'' will print the tenth line in the buffer while
-``delete 5'' will delete five lines from the buffer,
-starting with the current line.
-.PP
-Some commands take other information or parameters,
-this information always being given after the command name.\(dd
-.FS
-\(dd Examples would be option names in a
-.I set
-command i.e. ``set number'',
-a file name in an
-.I edit
-command,
-a regular expression in a
-.I substitute
-command,
-or a target address for a
-.I copy
-command, i.e. ``1,5 copy 25''.
-.FE
-.NH 2
-Command variants
-.PP
-A number of commands have two distinct variants.
-The variant form of the command is invoked by placing an
-`!' immediately after the command name.
-Some of the default variants may be controlled by options;
-in this case, the `!' serves to toggle the default.
-.NH 2
-Flags after commands
-.PP
-The characters `#', `p' and `l' may be placed after many commands.**
-.FS
-**
-A `p' or `l' must be preceded by a blank or tab
-except in the single special case `dp'.
-.FE
-In this case, the command abbreviated by these characters
-is executed after the command completes.
-Since
-.I ex
-normally prints the new current line after each change, `p' is rarely necessary.
-Any number of `+' or `\-' characters may also be given with these flags.
-If they appear, the specified offset is applied to the current line
-value before the printing command is executed.
-.NH 2
-Comments
-.PP
-It is possible to give editor commands which are ignored.
-This is useful when making complex editor scripts
-for which comments are desired.
-The comment character is the double quote: ".
-Any command line beginning with " is ignored.
-Comments beginning with " may also be placed at the ends
-of commands, except in cases where they could be confused as part
-of text (shell escapes and the substitute and map commands).
-.NH 2
-Multiple commands per line
-.PP
-More than one command may be placed on a line by separating each pair
-of commands by a `|' character.
-However the
-.I global
-commands,
-comments,
-and the shell escape `!'
-must be the last command on a line, as they are not terminated by a `|'.
-.NH 2
-Reporting large changes
-.PP
-Most commands which change the contents of the editor buffer give
-feedback if the scope of the change exceeds a threshold given by the
-.I report
-option.
-This feedback helps to detect undesirably large changes so that they may
-be quickly and easily reversed with an
-.I undo.
-After commands with more global effect such as
-.I global
-or
-.I visual,
-you will be informed if the net change in the number of lines
-in the buffer during this command exceeds this threshold.
-.NH 1
-Command addressing
-.NH 2
-Addressing primitives
-.IP \fB.\fR 20
-The current line.
-Most commands leave the current line as the last line which they affect.
-The default address for most commands is the current line,
-thus `\fB.\fR' is rarely used alone as an address.
-.IP \fIn\fR 20
-The \fIn\fRth line in the editor's buffer, lines being numbered
-sequentially from 1.
-.IP \fB$\fR 20
-The last line in the buffer.
-.IP \fB%\fR 20
-An abbreviation for ``1,$'', the entire buffer.
-.IP \fI+n\fR\ \fI\-n\fR 20
-An offset relative to the current buffer line.\(dg
-.FS
-\(dg
-The forms `.+3' `+3' and `+++' are all equivalent;
-if the current line is line 100 they all address line 103.
-.FE
-.IP \fB/\fIpat\fR\fB/\fR\ \fB?\fIpat\fR\fB?\fR 20
-Scan forward and backward respectively for a line containing \fIpat\fR, a
-regular expression (as defined below). The scans normally wrap around the end
-of the buffer.
-If all that is desired is to print the next line containing \fIpat\fR, then
-the trailing \fB/\fR or \fB?\fR may be omitted.
-If \fIpat\fP is omitted or explicitly empty, then the last
-regular expression specified is located.\(dd
-.FS
-\(dd The forms \fB\e/\fP and \fB\e?\fP scan
-using the last regular expression used in a scan; after a substitute
-\fB//\fP and \fB??\fP would scan using the substitute's regular expression.
-.FE
-.IP \fB\(aa\(aa\fP\ \fB\(aa\fP\fIx\fP 20
-Before each non-relative motion of the current line `\fB.\fP',
-the previous current line is marked with a tag, subsequently referred to as
-`\(aa\(aa'.
-This makes it easy to refer or return to this previous context.
-Marks may also be established by the
-.I mark
-command, using single lower case letters
-.I x
-and the marked lines referred to as
-`\(aa\fIx\fR'.
-.NH 2
-Combining addressing primitives
-.PP
-Addresses to commands consist of a series of addressing primitives,
-separated by `,' or `;'.
-Such address lists are evaluated left-to-right.
-When addresses are separated by `;' the current line `\fB.\fR'
-is set to the value of the previous addressing expression
-before the next address is interpreted.
-If more addresses are given than the command requires,
-then all but the last one or two are ignored.
-If the command takes two addresses, the first addressed line must
-precede the second in the buffer.\(dg
-.FS
-\(dg Null address specifications are permitted in a list of addresses,
-the default in this case is the current line `.';
-thus `,100' is equivalent to `\fB.\fR,100'.
-It is an error to give a prefix address to a command which expects none.
-.FE
-.NH 1
-Command descriptions
-.PP
-The following form is a prototype for all
-.I ex
-commands:
-.DS
-\fIaddress\fR \fBcommand\fR \fI! parameters count flags\fR
-.DE
-All parts are optional; the degenerate case is the empty command which prints
-the next line in the file. For sanity with use from within
-.I visual
-mode,
-.I ex
-ignores a ``:'' preceding any command.
-.PP
-In the following command descriptions, the
-default addresses are shown in parentheses,
-which are
-.I not,
-however,
-part of the command.
-.LC
-\fBabbreviate\fR \fIword rhs\fP abbr: \fBab\fP
-.ZP
-Add the named abbreviation to the current list.
-When in input mode in visual, if
-.I word
-is typed as a complete word, it will be changed to
-.I rhs .
-.LC
-( \fB.\fR ) \fBappend\fR abbr: \fBa\fR
-.br
-\fItext\fR
-.br
-\&\fB.\fR
-.ZP
-Reads the input text and places it after the specified line.
-After the command, `\fB.\fR'
-addresses the last line input or the
-specified line if no lines were input.
-If address `0' is given,
-text is placed at the beginning of the buffer.
-.LC
-\fBa!\fR
-.br
-\fItext\fR
-.br
-\&\fB.\fR
-.ZP
-The variant flag to
-.I append
-toggles the setting for the
-.I autoindent
-option during the input of
-.I text.
-.LC
-\fBargs\fR
-.ZP
-The members of the argument list are printed, with the current argument
-delimited by `[' and `]'.
-.ig
-.PP
-\fBcd\fR \fIdirectory\fR
-.ZP
-The
-.I cd
-command is a synonym for
-.I chdir.
-..
-.LC
-( \fB.\fP , \fB.\fP ) \fBchange\fP \fIcount\fP abbr: \fBc\fP
-.br
-\fItext\fP
-.br
-\&\fB.\fP
-.ZP
-Replaces the specified lines with the input \fItext\fP.
-The current line becomes the last line input;
-if no lines were input it is left as for a
-\fIdelete\fP.
-.LC
-\fBc!\fP
-.br
-\fItext\fP
-.br
-\&\fB.\fP
-.ZP
-The variant toggles
-.I autoindent
-during the
-.I change.
-.ig
-.LC
-\fBchdir\fR \fIdirectory\fR
-.ZP
-The specified \fIdirectory\fR becomes the current directory.
-If no directory is specified, the current value of the
-.I home
-option is used as the target directory.
-After a
-.I chdir
-the current file is not considered to have been
-edited so that write restrictions on pre-existing files apply.
-..
-.LC
-( \fB.\fP , \fB.\fP )\|\fBcopy\fP \fIaddr\fP \fIflags\fP abbr: \fBco\fP
-.ZP
-A
-.I copy
-of the specified lines is placed after
-.I addr,
-which may be `0'.
-The current line
-`\fB.\fR'
-addresses the last line of the copy.
-The command
-.I t
-is a synonym for
-.I copy.
-.LC
-( \fB.\fR , \fB.\fR )\|\fBdelete\fR \fIbuffer\fR \fIcount\fR \fIflags\fR abbr: \fBd\fR
-.ZP
-Removes the specified lines from the buffer.
-The line after the last line deleted becomes the current line;
-if the lines deleted were originally at the end,
-the new last line becomes the current line.
-If a named
-.I buffer
-is specified by giving a letter,
-then the specified lines are saved in that buffer,
-or appended to it if an upper case letter is used.
-.LC
-\fBedit\fR \fIfile\fR abbr: \fBe\fR
-.br
-\fBex\fR \fIfile\fR
-.ZP
-Used to begin an editing session on a new file.
-The editor
-first checks to see if the buffer has been modified since the last
-.I write
-command was issued.
-If it has been,
-a warning is issued and the
-command is aborted.
-The
-command otherwise deletes the entire contents of the editor buffer,
-makes the named file the current file and prints the new filename.
-After insuring that this file is sensible\(dg
-.FS
-\(dg I.e., that it is not a binary file such as a directory,
-a block or character special file other than
-.I /dev/tty,
-a terminal,
-or a binary or executable file
-(as indicated by the first word).
-.FE
-the editor reads the file into its buffer.
-.IP
-If the read of the file completes without error,
-the number of lines and characters read is typed.
-If there were any non-\s-2ASCII\s0 characters
-in the file they are stripped of their non-\s-2ASCII\s0
-high bits,
-and any null characters in the file are discarded.
-If none of these errors occurred, the file is considered
-.I edited.
-If the last line of the input file is missing the trailing
-newline character, it will be supplied and a complaint will be issued.
-This command leaves the current line `\fB.\fR' at the last line read.\(dd
-.FS
-\(dd If executed from within
-.I open
-or
-.I visual,
-the current line is initially the first line of the file.
-.FE
-.LC
-\fBe!\fR \fIfile\fR
-.ZP
-The variant form suppresses the complaint about modifications having
-been made and not written from the editor buffer, thus
-discarding all changes which have been made before editing the new file.
-.LC
-\fBe\fR \fB+\fIn\fR \fIfile\fR
-.ZP
-Causes the editor to begin at line
-.I n
-rather than at the last line;
-\fIn\fR may also be an editor command containing no spaces, e.g.: ``+/pat''.
-.LC
-\fBfile\fR abbr: \fBf\fR
-.ZP
-Prints the current file name,
-whether it has been `[Modified]' since the last
-.I write
-command,
-whether it is
-.I "read only" ,
-the current line,
-the number of lines in the buffer,
-and the percentage of the way through the buffer of the current line.*
-.FS
-* In the rare case that the current file is `[Not edited]' this is
-noted also; in this case you have to use the form \fBw!\fR to write to
-the file, since the editor is not sure that a \fBwrite\fR will not
-destroy a file unrelated to the current contents of the buffer.
-.FE
-.LC
-\fBfile\fR \fIfile\fR
-.ZP
-The current file name is changed to
-.I file
-which is considered
-`[Not edited]'.
-.LC
-( 1 , $ ) \fBglobal\fR /\fIpat\|\fR/ \fIcmds\fR abbr: \fBg\fR
-.ZP
-First marks each line among those specified which matches
-the given regular expression.
-Then the given command list is executed with `\fB.\fR' initially
-set to each marked line.
-.IP
-The command list consists of the remaining commands on the current
-input line and may continue to multiple lines by ending all but the
-last such line with a `\e'.
-If
-.I cmds
-(and possibly the trailing \fB/\fR delimiter) is omitted, each line matching
-.I pat
-is printed.
-.I Append,
-.I insert,
-and
-.I change
-commands and associated input are permitted;
-the `\fB.\fR' terminating input may be omitted if it would be on the
-last line of the command list.
-.I Open
-and
-.I visual
-commands are permitted in the command list and take input from the terminal.
-.IP
-The
-.I global
-command itself may not appear in
-.I cmds.
-The
-.I undo
-command is also not permitted there,
-as
-.I undo
-instead can be used to reverse the entire
-.I global
-command.
-The options
-.I autoprint
-and
-.I autoindent
-are inhibited during a
-.I global,
-(and possibly the trailing \fB/\fR delimiter) and the value of the
-.I report
-option is temporarily infinite,
-in deference to a \fIreport\fR for the entire global.
-Finally, the context mark `\'\'' is set to the value of
-`.' before the global command begins and is not changed during a global
-command,
-except perhaps by an
-.I open
-or
-.I visual
-within the
-.I global.
-.LC
-\fBg!\fR \fB/\fIpat\fB/\fR \fIcmds\fR abbr: \fBv\fR
-.IP
-The variant form of \fIglobal\fR runs \fIcmds\fR at each line not matching
-\fIpat\fR.
-.LC
-( \fB.\fR )\|\fBinsert\fR abbr: \fBi\fR
-.br
-\fItext\fR
-.br
-\&\fB.\fR
-.ZP
-Places the given text before the specified line.
-The current line is left at the last line input;
-if there were none input it is left at the line before the addressed line.
-This command differs from
-.I append
-only in the placement of text.
-.KS
-.LC
-\fBi!\fR
-.br
-\fItext\fR
-.br
-\&\fB.\fR
-.ZP
-The variant toggles
-.I autoindent
-during the
-.I insert.
-.KE
-.LC
-( \fB.\fR , \fB.\fR+1 ) \fBjoin\fR \fIcount\fR \fIflags\fR abbr: \fBj\fR
-.ZP
-Places the text from a specified range of lines
-together on one line.
-White space is adjusted at each junction to provide at least
-one blank character, two if there was a `\fB.\fR' at the end of the line,
-or none if the first following character is a `)'.
-If there is already white space at the end of the line,
-then the white space at the start of the next line will be discarded.
-.LC
-\fBj!\fR
-.ZP
-The variant causes a simpler
-.I join
-with no white space processing; the characters in the lines are simply
-concatenated.
-.LC
-( \fB.\fR ) \fBk\fR \fIx\fR
-.ZP
-The
-.I k
-command is a synonym for
-.I mark.
-It does not require a blank or tab before the following letter.
-.LC
-( \fB.\fR , \fB.\fR ) \fBlist\fR \fIcount\fR \fIflags\fR
-.ZP
-Prints the specified lines in a more unambiguous way:
-tabs are printed as `^I'
-and the end of each line is marked with a trailing `$'.
-The current line is left at the last line printed.
-.LC
-\fBmap\fR \fIlhs\fR \fIrhs\fR
-.ZP
-The
-.I map
-command is used to define macros for use in
-.I visual
-mode.
-.I Lhs
-should be a single character, or the sequence ``#n'', for n a digit,
-referring to function key \fIn\fR. When this character or function key
-is typed in
-.I visual
-mode, it will be as though the corresponding \fIrhs\fR had been typed.
-On terminals without function keys, you can type ``#n''.
-See section 6.9 of the ``Introduction to Display Editing with Vi''
-for more details.
-.LC
-( \fB.\fR ) \fBmark\fR \fIx\fR
-.ZP
-Gives the specified line mark
-.I x,
-a single lower case letter.
-The
-.I x
-must be preceded by a blank or a tab.
-The addressing form `\'x' then addresses this line.
-The current line is not affected by this command.
-.LC
-( \fB.\fR , \fB.\fR ) \fBmove\fR \fIaddr\fR abbr: \fBm\fR
-.ZP
-The
-.I move
-command repositions the specified lines to be after
-.I addr .
-The first of the moved lines becomes the current line.
-.LC
-\fBnext\fR abbr: \fBn\fR
-.ZP
-The next file from the command line argument list is edited.
-.LC
-\fBn!\fR
-.ZP
-The variant suppresses warnings about the modifications to the buffer not
-having been written out, discarding (irretrievably) any changes which may
-have been made.
-.LC
-\fBn\fR \fIfilelist\fR
-.br
-\fBn\fR \fB+\fIcommand\fR \fIfilelist\fR
-.ZP
-The specified
-.I filelist
-is expanded and the resulting list replaces the
-current argument list;
-the first file in the new list is then edited.
-If
-.I command
-is given (it must contain no spaces), then it is executed after editing the first such file.
-.LC
-( \fB.\fR , \fB.\fR ) \fBnumber\fR \fIcount\fR \fIflags\fR abbr: \fB#\fR or \fBnu\fR
-.ZP
-Prints each specified line preceded by its buffer line
-number.
-The current line is left at the last line printed.
-.KS
-.LC
-( \fB.\fR ) \fBopen\fR \fIflags\fR abbr: \fBo\fR
-.br
-( \fB.\fR ) \fBopen\fR /\fIpat\|\fR/ \fIflags\fR
-.ZP
-Enters intraline editing \fIopen\fR mode at each addressed line.
-If
-.I pat
-is given,
-then the cursor will be placed initially at the beginning of the
-string matched by the pattern.
-To exit this mode use Q.
-See
-.I "An Introduction to Display Editing with Vi"
-for more details.
-.KE
-.LC
-\fBpreserve\fR
-.ZP
-The current editor buffer is saved as though the system had just crashed.
-This command is for use only in emergencies when a
-.I write
-command has resulted in an error and you don't know how to save your work.
-After a
-.I preserve
-you should seek help.
-.LC
-( \fB.\fR , \fB.\fR )\|\fBprint\fR \fIcount\fR abbr: \fBp\fR or \fBP\fR
-.ZP
-Prints the specified lines
-with non-printing characters printed as control characters `^\fIx\fR\|';
-delete (octal 177) is represented as `^?'.
-The current line is left at the last line printed.
-.LC
-( \fB.\fR )\|\fBput\fR \fIbuffer\fR abbr: \fBpu\fR
-.ZP
-Puts back
-previously
-.I deleted
-or
-.I yanked
-lines.
-Normally used with
-.I delete
-to effect movement of lines,
-or with
-.I yank
-to effect duplication of lines.
-If no
-.I buffer
-is specified, then the last
-.I deleted
-or
-.I yanked
-text is restored.*
-.FS
-* But no modifying commands may intervene between the
-.I delete
-or
-.I yank
-and the
-.I put,
-nor may lines be moved between files without using a named buffer.
-.FE
-By using a named buffer, text may be restored that was saved there at any
-previous time.
-.LC
-\fBquit\fR abbr: \fBq\fR
-.ZP
-Causes
-.I ex
-to terminate.
-No automatic write of the editor buffer to a file is performed.
-However,
-.I ex
-issues a warning message if the file has changed
-since the last
-.I write
-command was issued, and does not
-.I quit.\(dg
-.FS
-\(dg \fIEx\fR
-will also issue a diagnostic if there are more files in the argument
-list.
-.FE
-Normally, you will wish to save your changes, and you
-should give a \fIwrite\fR command;
-if you wish to discard them, use the \fBq!\fR command variant.
-.LC
-\fBq!\fR
-.ZP
-Quits from the editor, discarding changes to the buffer without complaint.
-.LC
-( \fB.\fR ) \fBread\fR \fIfile\fR abbr: \fBr\fR
-.ZP
-Places a copy of the text of the given file in the
-editing buffer after the specified line.
-If no
-.I file
-is given the current file name is used.
-The current file name is not changed unless there is none in which
-case
-.I file
-becomes the current name.
-The sensibility restrictions for the
-.I edit
-command apply here also.
-If the file buffer is empty and there is no current name then
-.I ex
-treats this as an
-.I edit
-command.
-.IP
-Address `0' is legal for this command and causes the file to be read at
-the beginning of the buffer.
-Statistics are given as for the
-.I edit
-command when the
-.I read
-successfully terminates.
-After a
-.I read
-the current line is the last line read.\(dd
-.FS
-\(dd Within
-.I open
-and
-.I visual
-the current line is set to the first line read rather than the last.
-.FE
-.LC
-( \fB.\fR ) \fBread\fR \fB!\fR\fIcommand\fR
-.ZP
-Reads the output of the command
-.I command
-into the buffer after the specified line.
-This is not a variant form of the command, rather a read
-specifying a
-.I command
-rather than a
-.I filename;
-a blank or tab before the \fB!\fR is mandatory.
-.LC
-\fBrecover \fIfile\fR
-.ZP
-Recovers
-.I file
-from the system save area.
-Used after a accidental hangup of the phone**
-.FS
-** The system saves a copy of the file you were editing only if you
-have made changes to the file.
-.FE
-or a system crash** or
-.I preserve
-command.
-Except when you use
-.I preserve
-you will be notified by mail when a file is saved.
-.LC
-\fBrewind\fR abbr: \fBrew\fR
-.ZP
-The argument list is rewound, and the first file in the list is edited.
-.LC
-\fBrew!\fR
-.ZP
-Rewinds the argument list discarding any changes made to the current buffer.
-.LC
-\fBset\fR \fIparameter\fR
-.ZP
-With no arguments, prints those options whose values have been
-changed from their defaults;
-with parameter
-.I all
-it prints all of the option values.
-.IP
-Giving an option name followed by a `?'
-causes the current value of that option to be printed.
-The `?' is unnecessary unless the option is Boolean valued.
-Boolean options are given values either by the form
-`set \fIoption\fR' to turn them on or
-`set no\fIoption\fR' to turn them off;
-string and numeric options are assigned via the form
-`set \fIoption\fR=value'.
-.IP
-More than one parameter may be given to
-.I set \|;
-they are interpreted left-to-right.
-.LC
-\fBshell\fR abbr: \fBsh\fR
-.IP
-A new shell is created.
-When it terminates, editing resumes.
-.LC
-\fBsource\fR \fIfile\fR abbr: \fBso\fR
-.IP
-Reads and executes commands from the specified file.
-.I Source
-commands may be nested.
-.LC
-( \fB.\fR , \fB.\fR ) \fBsubstitute\fR /\fIpat\fR\|/\fIrepl\fR\|/ \fIoptions\fR \fIcount\fR \fIflags\fR abbr: \fBs\fR
-.IP
-On each specified line, the first instance of pattern
-.I pat
-is replaced by replacement pattern
-.I repl.
-If the
-.I global
-indicator option character `g'
-appears, then all instances are substituted;
-if the
-.I confirm
-indication character `c' appears,
-then before each substitution the line to be substituted
-is typed with the string to be substituted marked
-with `\(ua' characters.
-By typing an `y' one can cause the substitution to be performed,
-any other input causes no change to take place.
-After a
-.I substitute
-the current line is the last line substituted.
-.IP
-Lines may be split by substituting
-new-line characters into them.
-The newline in
-.I repl
-must be escaped by preceding it with a `\e'.
-Other metacharacters available in
-.I pat
-and
-.I repl
-are described below.
-.LC
-.B stop
-.ZP
-Suspends the editor, returning control to the top level shell.
-If
-.I autowrite
-is set and there are unsaved changes,
-a write is done first unless the form
-.B stop !
-is used.
-This commands is only available where supported by the teletype driver
-and operating system.
-.LC
-( \fB.\fR , \fB.\fR ) \fBsubstitute\fR \fIoptions\fR \fIcount\fR \fIflags\fR abbr: \fBs\fR
-.ZP
-If
-.I pat
-and
-.I repl
-are omitted, then the last substitution is repeated.
-This is a synonym for the
-.B &
-command.
-.LC
-( \fB.\fR , \fB.\fR ) \fBt\fR \fIaddr\fR \fIflags\fR
-.ZP
-The
-.I t
-command is a synonym for
-.I copy .
-.LC
-\fBta\fR \fItag\fR
-.ZP
-The focus of editing switches to the location of
-.I tag,
-switching to a different line in the current file where it is defined,
-or if necessary to another file.\(dd
-.FS
-\(dd If you have modified the current file before giving a
-.I tag
-command, you must write it out; giving another
-.I tag
-command, specifying no
-.I tag
-will reuse the previous tag.
-.FE
-.IP
-The tags file is normally created by a program such as
-.I ctags,
-and consists of a number of lines with three fields separated by blanks
-or tabs. The first field gives the name of the tag,
-the second the name of the file where the tag resides, and the third
-gives an addressing form which can be used by the editor to find the tag;
-this field is usually a contextual scan using `/\fIpat\fR/' to be immune
-to minor changes in the file. Such scans are always performed as if
-.I nomagic
-was set.
-.PP
-The tag names in the tags file must be sorted alphabetically.
-.LC
-\fBunabbreviate\fR \fIword\fP abbr: \fBuna\fP
-.ZP
-Delete
-.I word
-from the list of abbreviations.
-.LC
-\fBundo\fR abbr: \fBu\fR
-.ZP
-Reverses the changes made in the buffer by the last
-buffer editing command.
-Note that
-.I global
-commands are considered a single command for the purpose of
-.I undo
-(as are
-.I open
-and
-.I visual.)
-Also, the commands
-.I write
-and
-.I edit
-which interact with the
-file system cannot be undone.
-.I Undo
-is its own inverse.
-.IP
-.I Undo
-always marks the previous value of the current line `\fB.\fR'
-as `\'\''.
-After an
-.I undo
-the current line is the first line restored
-or the line before the first line deleted if no lines were restored.
-For commands with more global effect
-such as
-.I global
-and
-.I visual
-the current line regains it's pre-command value after an
-.I undo.
-.LC
-\fBunmap\fR \fIlhs\fR
-.ZP
-The macro expansion associated by
-.I map
-for
-.I lhs
-is removed.
-.LC
-( 1 , $ ) \fBv\fR /\fIpat\fR\|/ \fIcmds\fR
-.ZP
-A synonym for the
-.I global
-command variant \fBg!\fR, running the specified \fIcmds\fR on each
-line which does not match \fIpat\fR.
-.LC
-\fBversion\fR abbr: \fBve\fR
-.ZP
-Prints the current version number of the editor
-as well as the date the editor was last changed.
-.LC
-( \fB.\fR ) \fBvisual\fR \fItype\fR \fIcount\fR \fIflags\fR abbr: \fBvi\fR
-.ZP
-Enters visual mode at the specified line.
-.I Type
-is optional and may be `\-' , `\(ua' or `\fB.\fR'
-as in the
-.I z
-command to specify the placement of the specified line on the screen.
-By default, if
-.I type
-is omitted, the specified line is placed as the first on the screen.
-A
-.I count
-specifies an initial window size; the default is the value of the option
-.I window.
-See the document
-.I "An Introduction to Display Editing with Vi"
-for more details.
-To exit this mode, type Q.
-.LC
-\fBvisual\fP file
-.br
-\fBvisual\fP +\fIn\fP file
-.ZP
-From visual mode,
-this command is the same as edit.
-.LC
-( 1 , $ ) \fBwrite\fR \fIfile\fR abbr: \fBw\fR
-.ZP
-Writes changes made back to \fIfile\fR, printing the number of lines and
-characters written.
-Normally \fIfile\fR is omitted and the text goes back where it came from.
-If a \fIfile\fR is specified, then text will be written to that file.*
-.FS
-* The editor writes to a file only if it is
-the current file and is
-.I edited ,
-if the file does not exist,
-or if the file is actually a teletype,
-.I /dev/tty,
-.I /dev/null.
-Otherwise, you must give the variant form \fBw!\fR to force the write.
-.FE
-If the file does not exist it is created.
-The current file name is changed only if there is no current file
-name; the current line is never changed.
-.IP
-If an error occurs while writing the current and
-.I edited
-file, the editor
-considers that there has been ``No write since last change''
-even if the buffer had not previously been modified.
-.LC
-( 1 , $ ) \fBwrite>>\fR \fIfile\fR abbr: \fBw>>\fR
-.ZP
-Writes the buffer contents at the end of
-an existing file.
-.IP
-.LC
-\fBw!\fR \fIname\fR
-.ZP
-Overrides the checking of the normal \fIwrite\fR command,
-and will write to any file which the system permits.
-.LC
-( 1 , $ ) \fBw\fR \fB!\fR\fIcommand\fR
-.ZP
-Writes the specified lines into
-.I command.
-Note the difference between \fBw!\fR which overrides checks and
-\fBw\ \ !\fR which writes to a command.
-.LC
-\fBwq\fR \fIname\fR
-.ZP
-Like a \fIwrite\fR and then a \fIquit\fR command.
-.LC
-\fBwq!\fR \fIname\fR
-.ZP
-The variant overrides checking on the sensibility of the
-.I write
-command, as \fBw!\fR does.
-.LC
-\fBxit\fP \fIname\fR
-.ZP
-If any changes have been made and not written, writes the buffer out.
-Then, in any case, quits.
-.LC
-( \fB.\fR , \fB.\fR )\|\fByank\fR \fIbuffer\fR \fIcount\fR abbr: \fBya\fR
-.ZP
-Places the specified lines in the named
-.I buffer,
-for later retrieval via
-.I put.
-If no buffer name is specified, the lines go to a more volatile place;
-see the \fIput\fR command description.
-.LC
-( \fB.+1\fR ) \fBz\fR \fIcount\fR
-.ZP
-Print the next \fIcount\fR lines, default \fIwindow\fR.
-.LC
-( \fB.\fR ) \fBz\fR \fItype\fR \fIcount\fR
-.ZP
-Prints a window of text with the specified line at the top.
-If \fItype\fR is `\-' the line is placed at the bottom; a `\fB.\fR' causes
-the line to be placed in the center.*
-A count gives the number of lines to be displayed rather than
-double the number specified by the \fIscroll\fR option.
-On a \s-2CRT\s0 the screen is cleared before display begins unless a
-count which is less than the screen size is given.
-The current line is left at the last line printed.
-.FS
-* Forms `z=' and `z\(ua' also exist; `z=' places the current line in the
-center, surrounds it with lines of `\-' characters and leaves the current
-line at this line. The form `z\(ua' prints the window before `z\-'
-would. The characters `+', `\(ua' and `\-' may be repeated for cumulative
-effect.
-On some v2 editors, no
-.I type
-may be given.
-.FE
-.LC
-\fB!\fR \fIcommand\fR\fR
-.ZP
-The remainder of the line after the `!' character is sent to a shell
-to be executed.
-Within the text of
-.I command
-the characters
-`%' and `#' are expanded as in filenames and the character
-`!' is replaced with the text of the previous command.
-Thus, in particular,
-`!!' repeats the last such shell escape.
-If any such expansion is performed, the expanded line will be echoed.
-The current line is unchanged by this command.
-.IP
-If there has been ``[No\ write]'' of the buffer contents since the last
-change to the editing buffer, then a diagnostic will be printed
-before the command is executed as a warning.
-A single `!' is printed when the command completes.
-.LC
-( \fIaddr\fR , \fIaddr\fR ) \fB!\fR \fIcommand\fR\fR
-.ZP
-Takes the specified address range and supplies it as
-standard input to
-.I command;
-the resulting output then replaces the input lines.
-.LC
-( $ ) \fB=\fR
-.ZP
-Prints the line number of the
-addressed line.
-The current line is unchanged.
-.KS
-.LC
-( \fB.\fR , \fB.\fR ) \fB>\fR \fIcount\fR \fIflags\fR
-.br
-( \fB.\fR , \fB.\fR ) \fB<\fR \fIcount\fR \fIflags\fR
-.IP
-Perform intelligent shifting on the specified lines;
-\fB<\fR shifts left and \fB>\fR shift right.
-The quantity of shift is determined by the
-.I shiftwidth
-option and the repetition of the specification character.
-Only white space (blanks and tabs) is shifted;
-no non-white characters are discarded in a left-shift.
-The current line becomes the last line which changed due to the
-shifting.
-.KE
-.LC
-\fB^D\fR
-.ZP
-An end-of-file from a terminal input scrolls through the file.
-The
-.I scroll
-option specifies the size of the scroll, normally a half screen of text.
-.LC
-( \fB.\fR+1 , \fB.\fR+1 )
-.br
-( \fB.\fR+1 , \fB.\fR+1 ) |
-.ZP
-An address alone causes the addressed lines to be printed.
-A blank line prints the next line in the file.
-.LC
-( \fB.\fR , \fB.\fR ) \fB&\fR \fIoptions\fR \fIcount\fR \fIflags\fR
-.ZP
-Repeats the previous
-.I substitute
-command.
-.LC
-( \fB.\fR , \fB.\fR ) \fB\s+2~\s0\fR \fIoptions\fR \fIcount\fR \fIflags\fR
-.ZP
-Replaces the previous regular expression with the previous
-replacement pattern from a substitution.
-.NH 1
-Regular expressions and substitute replacement patterns
-.NH 2
-Regular expressions
-.PP
-A regular expression specifies a set of strings of characters.
-A member of this set of strings is said to be
-.I matched
-by the regular expression.
-.I Ex
-remembers two previous regular expressions:
-the previous regular expression used in a
-.I substitute
-command
-and the previous regular expression used elsewhere
-(referred to as the previous \fIscanning\fR regular expression.)
-The previous regular expression
-can always be referred to by a null \fIre\fR, e.g. `//' or `??'.
-.NH 2
-Magic and nomagic
-.PP
-The regular expressions allowed by
-.I ex
-are constructed in one of two ways depending on the setting of
-the
-.I magic
-option.
-The
-.I ex
-and
-.I vi
-default setting of
-.I magic
-gives quick access to a powerful set of regular expression
-metacharacters.
-The disadvantage of
-.I magic
-is that the user must remember that these metacharacters are
-.I magic
-and precede them with the character `\e'
-to use them as ``ordinary'' characters.
-With
-.I nomagic,
-the default for
-.I edit,
-regular expressions are much simpler,
-there being only two metacharacters.
-The power of the other metacharacters is still available by preceding
-the (now) ordinary character with a `\e'.
-Note that `\e' is thus always a metacharacter.
-.PP
-The remainder of the discussion of regular expressions assumes
-that
-that the setting of this option is
-.I magic.\(dg
-.FS
-\(dg To discern what is true with
-.I nomagic
-it suffices to remember that the only
-special characters in this case will be `\(ua' at the beginning
-of a regular expression,
-`$' at the end of a regular expression,
-and `\e'.
-With
-.I nomagic
-the characters `\s+2~\s0' and `&' also lose their special meanings
-related to the replacement pattern of a substitute.
-.FE
-.NH 2
-Basic regular expression summary
-.PP
-The following basic constructs are used to construct
-.I magic
-mode regular expressions.
-.IP \fIchar\fR 15
-An ordinary character matches itself.
-The characters `\(ua' at the beginning of a line,
-`$' at the end of line,
-`*' as any character other than the first,
-`.', `\e', `[', and `\s+2~\s0' are not ordinary characters and
-must be escaped (preceded) by `\e' to be treated as such.
-.IP \fB\(ua\fR
-At the beginning of a pattern
-forces the match to succeed only at the beginning of a line.
-.IP \fB$\fR
-At the end of a regular expression forces the match to
-succeed only at the end of the line.
-.IP \&\fB.\fR
-Matches any single character except
-the new-line character.
-.IP \fB\e<\fR
-Forces the match
-to occur only at the beginning of a ``variable'' or ``word'';
-that is, either at the beginning of a line, or just before
-a letter, digit, or underline and after a character not one of
-these.
-.IP \fB\e>\fR
-Similar to `\e<', but matching the end of a ``variable''
-or ``word'', i.e. either the end of the line or before character
-which is neither a letter, nor a digit, nor the underline character.
-.IP \fB[\fIstring\fR]\fR
-Matches any (single) character in the class defined by
-.I string.
-Most characters in
-.I string
-define themselves.
-A pair of characters separated by `\-' in
-.I string
-defines the set of characters collating between the specified lower and upper
-bounds, thus `[a\-z]' as a regular expression matches
-any (single) lower-case letter.
-If the first character of
-.I string
-is an `\(ua' then the construct
-matches those characters which it otherwise would not;
-thus `[\(uaa\-z]' matches anything but a lower-case letter (and of course a
-newline).
-To place any of the characters
-`\(ua', `[', or `\-' in
-.I string
-you must escape them with a preceding `\e'.
-.NH 2
-Combining regular expression primitives
-.PP
-The concatenation of two regular expressions matches the leftmost and
-then longest string
-which can be divided with the first piece matching the first regular
-expression and the second piece matching the second.
-Any of the (single character matching) regular expressions mentioned
-above may be followed by the character `*' to form a regular expression
-which matches any number of adjacent occurrences (including 0) of characters
-matched by the regular expression it follows.
-.PP
-The character `\s+2~\s0' may be used in a regular expression,
-and matches the text which defined the replacement part
-of the last
-.I substitute
-command.
-A regular expression may be enclosed between the sequences
-`\e(' and `\e)' with side effects in the
-.I substitute
-replacement patterns.
-.NH 2
-Substitute replacement patterns
-.PP
-The basic metacharacters for the replacement pattern are
-`&' and `~'; these are
-given as `\e&' and `\e~' when
-.I nomagic
-is set.
-Each instance of `&' is replaced by the characters
-which the regular expression matched.
-The metacharacter `~' stands, in the replacement pattern,
-for the defining text of the previous replacement pattern.
-.PP
-Other metasequences possible in the replacement pattern
-are always introduced by the escaping character `\e'.
-The sequence `\e\fIn\fR' is replaced by the text matched
-by the \fIn\fR-th regular subexpression enclosed between
-`\e(' and `\e)'.\(dg
-.FS
-\(dg When nested, parenthesized subexpressions are present,
-\fIn\fR is determined by counting occurrences of `\e(' starting from the left.
-.FE
-The sequences `\eu' and `\el' cause the immediately following character in
-the replacement to be converted to upper- or lower-case respectively
-if this character is a letter.
-The sequences `\eU' and `\eL' turn such conversion on, either until
-`\eE' or `\ee' is encountered, or until the end of the replacement pattern.
-.de LC
-.br
-.sp .1i
-.ne 4
-.LP
-.ta 3i
-..
-.NH 1
-Option descriptions
-.PP
-.LC
-\fBautoindent\fR, \fBai\fR default: noai
-.ZP
-Can be used to ease the preparation of structured program text.
-At the beginning of each
-.I append ,
-.I change
-or
-.I insert
-command
-or when a new line is
-.I opened
-or created by an
-.I append ,
-.I change ,
-.I insert ,
-or
-.I substitute
-operation within
-.I open
-or
-.I visual
-mode,
-.I ex
-looks at the line being appended after,
-the first line changed
-or the line inserted before and calculates the amount of white space
-at the start of the line.
-It then aligns the cursor at the level of indentation so determined.
-.IP
-If the user then types lines of text in,
-they will continue to be justified at the displayed indenting level.
-If more white space is typed at the beginning of a line,
-the following line will start aligned with the first non-white character
-of the previous line.
-To back the cursor up to the preceding tab stop one can hit
-\fB^D\fR.
-The tab stops going backwards are defined at multiples of the
-.I shiftwidth
-option.
-You
-.I cannot
-backspace over the indent,
-except by sending an end-of-file with a \fB^D\fR.
-.IP
-Specially processed in this mode is a line with no characters added
-to it, which turns into a completely blank line (the white
-space provided for the
-.I autoindent
-is discarded.)
-Also specially processed in this mode are lines beginning with
-an `\(ua' and immediately followed by a \fB^D\fR.
-This causes the input to be repositioned at the beginning of the line,
-but retaining the previous indent for the next line.
-Similarly, a `0' followed by a \fB^D\fR
-repositions at the beginning but without
-retaining the previous indent.
-.IP
-.I Autoindent
-doesn't happen in
-.I global
-commands or when the input is not a terminal.
-.LC
-\fBautoprint\fR, \fBap\fR default: ap
-.ZP
-Causes the current line to be printed after each
-.I delete ,
-.I copy ,
-.I join ,
-.I move ,
-.I substitute ,
-.I t ,
-.I undo
-or
-shift command.
-This has the same effect as supplying a trailing `p'
-to each such command.
-.I Autoprint
-is suppressed in globals,
-and only applies to the last of many commands on a line.
-.LC
-\fBautowrite\fR, \fBaw\fR default: noaw
-.ZP
-Causes the contents of the buffer to be written to the current file
-if you have modified it and give a
-.I next,
-.I rewind,
-.I stop,
-.I tag,
-or
-.I !
-command, or a \fB^\(ua\fR (switch files) or \fB^]\fR (tag goto) command
-in
-.I visual.
-Note, that the
-.I edit
-and
-.I ex
-commands do
-.B not
-autowrite.
-In each case, there is an equivalent way of switching when autowrite
-is set to avoid the
-.I autowrite
-(\fIedit\fR
-for
-.I next ,
-.I rewind!
-for .I rewind ,
-.I stop!
-for
-.I stop ,
-.I tag!
-for
-.I tag ,
-.I shell
-for
-.I ! ,
-and
-\fB:e\ #\fR and a \fB:ta!\fR command from within
-.I visual).
-.LC
-\fBbeautify\fR, \fBbf\fR default: nobeautify
-.ZP
-Causes all control characters except tab, newline and form-feed
-to be discarded from the input.
-A complaint is registered the first time a
-backspace character is discarded.
-.I Beautify
-does not apply to command input.
-.LC
-\fBdirectory\fR, \fBdir\fR default: dir=/tmp
-.ZP
-Specifies the directory in which
-.I ex
-places its buffer file.
-If this directory in not
-writable, then the editor will exit abruptly when it fails to be
-able to create its buffer there.
-.LC
-\fBedcompatible\fR default: noedcompatible
-.ZP
-Causes the presence of absence of
-.B g
-and
-.B c
-suffixes on substitute commands to be remembered, and to be toggled
-by repeating the suffices. The suffix
-.B r
-makes the substitution be as in the
-.I ~
-command, instead of like
-.I &.
-.LC
-\fBerrorbells\fR, \fBeb\fR default: noeb
-.ZP
-Error messages are preceded by a bell.*
-.FS
-* Bell ringing in
-.I open
-and
-.I visual
-on errors is not suppressed by setting
-.I noeb.
-.FE
-If possible the editor always places the error message in a standout mode of the
-terminal (such as inverse video) instead of ringing the bell.
-.LC
-\fBhardtabs\fR, \fBht\fR default: ht=8
-.ZP
-Gives the boundaries on which terminal hardware tabs are set (or
-on which the system expands tabs).
-.LC
-\fBignorecase\fR, \fBic\fR default: noic
-.ZP
-All upper case characters in the text are mapped to lower case in regular
-expression matching.
-In addition, all upper case characters in regular expressions are mapped
-to lower case except in character class specifications.
-.LC
-\fBlisp\fR default: nolisp
-.ZP
-\fIAutoindent\fR indents appropriately for
-.I lisp
-code, and the \fB( ) { } [[\fR and \fB]]\fR commands in
-.I open
-and
-.I visual
-are modified to have meaning for \fIlisp\fR.
-.LC
-\fBlist\fR default: nolist
-.ZP
-All printed lines will be displayed (more) unambiguously,
-showing tabs and end-of-lines as in the
-.I list
-command.
-.LC
-\fBmagic\fR default: magic for \fIex\fR and \fIvi\fR\(dg
-.FS
-\(dg \fINomagic\fR for \fIedit\fR.
-.FE
-.ZP
-If
-.I nomagic
-is set, the number of regular expression metacharacters is greatly reduced,
-with only `\(ua' and `$' having special effects.
-In addition the metacharacters
-`~'
-and
-`&'
-of the replacement pattern are treated as normal characters.
-All the normal metacharacters may be made
-.I magic
-when
-.I nomagic
-is set by preceding them with a `\e'.
-.LC
-\fBmesg\fR default: mesg
-.ZP
-Causes write permission to be turned off to the terminal
-while you are in visual mode, if
-.I nomesg
-is set.
-.LC
-\fBmodeline\fR default: nomodeline
-.ZP
-If
-.I modeline
-is set, then the first 5 lines and the last five lines of the file
-will be checked for ex command lines and the comands issued.
-To be recognized as a command line, the line must have the string
-.B ex:
-or
-.B vi:
-preceeded by a tab or a space. This string may be anywhere in the
-line and anything after the
-.I :
-is interpeted as editor commands. This option defaults to off because
-of unexpected behavior when editting files such as
-.I /etc/passwd.
-.LC
-\fBnumber, nu\fR default: nonumber
-.ZP
-Causes all output lines to be printed with their
-line numbers.
-In addition each input line will be prompted for by supplying the line number
-it will have.
-.LC
-\fBopen\fR default: open
-.ZP
-If \fInoopen\fR, the commands
-.I open
-and
-.I visual
-are not permitted.
-This is set for
-.I edit
-to prevent confusion resulting from accidental entry to
-open or visual mode.
-.LC
-\fBoptimize, opt\fR default: optimize
-.ZP
-Throughput of text is expedited by setting the terminal
-to not do automatic carriage returns
-when printing more than one (logical) line of output,
-greatly speeding output on terminals without addressable
-cursors when text with leading white space is printed.
-.LC
-\fBparagraphs,\ para\fR default: para=IPLPPPQPP\0LIbp
-.ZP
-Specifies the paragraphs for the \fB{\fR and \fB}\fR operations in
-.I open
-and
-.I visual.
-The pairs of characters in the option's value are the names
-of the macros which start paragraphs.
-.LC
-\fBprompt\fR default: prompt
-.ZP
-Command mode input is prompted for with a `:'.
-.LC
-\fBredraw\fR default: noredraw
-.ZP
-The editor simulates (using great amounts of output), an intelligent
-terminal on a dumb terminal (e.g. during insertions in
-.I visual
-the characters to the right of the cursor position are refreshed
-as each input character is typed.)
-Useful only at very high speed.
-.LC
-\fBremap\fP default: remap
-.ZP
-If on, macros are repeatedly tried until they are unchanged.
-For example, if
-.B o
-is mapped to
-.B O ,
-and
-.B O
-is mapped to
-.B I ,
-then if
-.I remap
-is set,
-.B o
-will map to
-.B I ,
-but if
-.I noremap
-is set, it will map to
-.B O .
-.LC
-\fBreport\fR default: report=5\(dg
-.FS
-\(dg 2 for \fIedit\fR.
-.FE
-.ZP
-Specifies a threshold for feedback from commands.
-Any command which modifies more than the specified number of lines
-will provide feedback as to the scope of its changes.
-For commands such as
-.I global ,
-.I open ,
-.I undo ,
-and
-.I visual
-which have potentially more far reaching scope,
-the net change in the number of lines in the buffer is
-presented at the end of the command, subject to this same threshold.
-Thus notification is suppressed during a
-.I global
-command on the individual commands performed.
-.LC
-\fBscroll\fR default: scroll=\(12 window
-.ZP
-Determines the number of logical lines scrolled when an end-of-file
-is received from a terminal input in command mode,
-and the number of lines printed by a command mode
-.I z
-command (double the value of
-.I scroll ).
-.LC
-\fBsections\fR default: sections=SHNHH\0HU
-.ZP
-Specifies the section macros for the \fB[[\fR and \fB]]\fR operations
-in
-.I open
-and
-.I visual.
-The pairs of characters in the options's value are the names
-of the macros which start paragraphs.
-.LC
-\fBshell\fR, \fBsh\fR default: sh=/bin/sh
-.ZP
-Gives the path name of the shell forked for
-the shell escape command `!', and by the
-.I shell
-command.
-The default is taken from SHELL in the environment, if present.
-.LC
-\fBshiftwidth\fR, \fBsw\fR default: sw=8
-.ZP
-Gives the width a software tab stop,
-used in reverse tabbing with \fB^D\fR when using
-.I autoindent
-to append text,
-and by the shift commands.
-.LC
-\fBshowmatch, sm\fR default: nosm
-.ZP
-In
-.I open
-and
-.I visual
-mode, when a \fB)\fR or \fB}\fR is typed, move the cursor to the matching
-\fB(\fR or \fB{\fR for one second if this matching character is on the
-screen. Extremely useful with
-.I lisp.
-.LC
-\fBslowopen, slow\fR terminal dependent
-.ZP
-Affects the display algorithm used in
-.I visual
-mode, holding off display updating during input of new text to improve
-throughput when the terminal in use is both slow and unintelligent.
-See
-.I "An Introduction to Display Editing with Vi"
-for more details.
-.LC
-\fBtabstop,\ ts\fR default: ts=8
-.ZP
-The editor expands tabs in the input file to be on
-.I tabstop
-boundaries for the purposes of display.
-.LC
-\fBtaglength,\ tl\fR default: tl=0
-.ZP
-Tags are not significant beyond this many characters.
-A value of zero (the default) means that all characters are significant.
-.LC
-\fBtags\fR default: tags=tags /usr/lib/tags
-.ZP
-A path of files to be used as tag files for the
-.I tag
-command.
-A requested tag is searched for in the specified files, sequentially.
-By default, files called
-.B tags
-are searched for in the current directory and in /usr/lib
-(a master file for the entire system).
-.LC
-\fBterm\fR from environment TERM
-.ZP
-The terminal type of the output device.
-.LC
-\fBterse\fR default: noterse
-.ZP
-Shorter error diagnostics are produced for the experienced user.
-.LC
-\fBwarn\fR default: warn
-.ZP
-Warn if there has been `[No write since last change]' before a `!'
-command escape.
-.LC
-\fBwindow\fR default: window=speed dependent
-.ZP
-The number of lines in a text window in the
-.I visual
-command.
-The default is 8 at slow speeds (600 baud or less),
-16 at medium speed (1200 baud),
-and the full screen (minus one line) at higher speeds.
-.LC
-\fBw300,\ w1200\, w9600\fR
-.ZP
-These are not true options but set
-.B window
-only if the speed is slow (300), medium (1200), or high (9600),
-respectively.
-They are suitable for an EXINIT
-and make it easy to change the 8/16/full screen rule.
-.LC
-\fBwrapscan\fR, \fBws\fR default: ws
-.ZP
-Searches using the regular expressions in addressing
-will wrap around past the end of the file.
-.LC
-\fBwrapmargin\fR, \fBwm\fR default: wm=0
-.ZP
-Defines a margin for automatic wrapover of text during input in
-.I open
-and
-.I visual
-modes. See
-.I "An Introduction to Text Editing with Vi"
-for details.
-.LC
-\fBwriteany\fR, \fBwa\fR default: nowa
-.IP
-Inhibit the checks normally made before
-.I write
-commands, allowing a write to any file which the system protection
-mechanism will allow.
-.NH 1
-Limitations
-.PP
-Editor limits that the user is likely to encounter are as follows:
-1024 characters per line,
-256 characters per global command list,
-128 characters per file name,
-128 characters in the previous inserted and deleted text in
-.I open
-or
-.I visual,
-100 characters in a shell escape command,
-63 characters in a string valued option,
-and 30 characters in a tag name, and
-a limit of 250000 lines in the file is silently enforced.
-.PP
-The
-.I visual
-implementation limits the number of macros defined with map to
-32, and the total number of characters in macros to be less than 512.
-.LP
-.LP
-.I Acknowledgments.
-Chuck Haley contributed greatly to the early development of
-.I ex.
-Bruce Englar encouraged the redesign which led to
-.I ex
-version 1.
-Bill Joy wrote versions 1 and 2.0 through 2.7,
-and created the framework that users see in the present editor.
-Mark Horton added macros and other features and made the
-editor work on a large number of terminals and Unix systems.
diff --git a/usr.bin/vi/USD.doc/exref/ex.summary b/usr.bin/vi/USD.doc/exref/ex.summary
deleted file mode 100644
index 618da07..0000000
--- a/usr.bin/vi/USD.doc/exref/ex.summary
+++ /dev/null
@@ -1,734 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)ex.summary 8.1 (Berkeley) 6/8/93
-.\"
-.ds p \v'-0.2'.\v'+0.2'
-.ds U \s-2UNIX\s+2
-.ds c \v'-0.2':\v'+0.2'
-.nr PO .25i
-.nr LL 6.75i
-.lt 6.75i
-.ll 6.75i
-.ds CH
-.ds LF Computing Services, U.C. Berkeley
-.ds RF April 3, 1979
-.de SP
-.sp 1v
-..
-.nr PI 3n
-.nr PD 0
-.ND
-.ps 12
-.ft B
-.ce 1
-Ex/Edit Command Summary (Version 2.0)
-.ft R
-.nr VS 11
-.nr PS 9
-.nr HM 0.5i
-.nr CW
-.2C
-.PP
-.I Ex
-and
-.I edit
-are text editors, used for creating
-and modifying files of text on the \*U
-computer system.
-.I Edit
-is a variant of
-.I ex
-with features designed to
-make it less complicated
-to learn and use.
-In terms of command syntax and effect
-the editors are essentially identical,
-and this command summary applies to both.
-.PP
-The summary is meant as a quick reference
-for users already acquainted
-with
-.I edit
-or \fIex\fP.
-Fuller explanations of the editors are available
-in the documents
-.I
-Edit: A Tutorial
-.R
-(a self-teaching introduction) and the
-.I
-Ex Reference Manual
-.R
-(the comprehensive reference source for
-both \fIedit\fP and \fIex\fP).
-Both of these writeups are available in the
-Computing Services Library.
-.PP
-In the examples included with the
-summary, commands and text entered by
-the user are printed in \fBboldface\fR to
-distinguish them from responses printed
-by the computer.
-.sp 0.45v
-.LP
-.B
-The Editor Buffer
-.PP
-In order to perform its tasks
-the editor sets aside a temporary
-work space,
-called a \fIbuffer\fR,
-separate from the user's permanent
-file.
-Before starting to work on an existing
-file the editor makes a copy of it in the
-buffer, leaving the original untouched.
-All editing changes are made to the
-buffer copy, which must then
-be written back to the permanent
-file in order to update the
-old version.
-The buffer disappears
-at the end of the editing session.
-.sp 0.45v
-.LP
-.B
-Editing: Command and Text Input Modes
-.PP
-.R
-During an editing session there are
-two usual modes of operation:
-\fIcommand\fP mode and \fItext input\fP
-mode.
-(This disregards, for the moment,
-.I open
-and
-.I visual
-modes, discussed below.)
-In command mode, the editor issues a
-colon prompt (:)
-to show that it is ready to
-accept and execute a command.
-In text input mode, on the other hand, there is
-no prompt and the editor merely accepts text to
-be added to the buffer.
-Text input mode is initiated by the commands
-\fIappend\fP, \fIinsert\fP, and \fIchange\fP,
-and is terminated by typing a period as the
-first and only character on a line.
-.sp 0.45v
-.LP
-.B
-Line Numbers and Command Syntax
-.PP
-.R
-The editor keeps track of lines of text
-in the buffer by numbering them consecutively
-starting with 1 and renumbering
-as lines are added or deleted.
-At any given time the editor is positioned
-at one of these lines; this position is
-called the \fIcurrent line\fP.
-Generally, commands that change the
-contents of the buffer print the
-new current line at the end of their
-execution.
-.PP
-Most commands can be preceded by one or two
-line-number addresses which indicate the lines
-to be affected.
-If one number is given the command operates on
-that line only; if two, on an inclusive range
-of lines.
-Commands that can take line-number prefixes also
-assume default prefixes if none are given.
-The default assumed by each command is designed
-to make it convenient to use in many instances
-without any line-number prefix.
-For the most part, a command used without a
-prefix operates on the current line,
-though exceptions to this rule should be noted.
-The \fIprint\fP command
-by itself, for instance, causes
-one line, the current line, to be
-printed at the terminal.
-.PP
-The summary shows the number of line addresses
-that can be
-prefixed to each command as well as
-the defaults assumed if they are omitted.
-For example,
-.I (.,.)
-means that up to 2 line-numbers may be given,
-and that if none is given the
-command operates on the current line.
-(In the address prefix notation, ``.'' stands
-for the current line and ``$'' stands for
-the last line of the buffer.)
-If no such notation appears, no
-line-number prefix may be used.
-.PP
-Some commands take trailing
-information;
-only
-the more important instances of this
-are mentioned in the summary.
-.sp 0.25v
-.LP
-.B
-Open and Visual Modes
-.PP
-.R
-Besides command and text input modes,
-.I ex
-and
-.I edit
-provide on some CRT terminals other modes of editing,
-.I open
-and
-.I visual .
-In these modes the cursor can
-be moved to individual words
-or characters in a line.
-The commands then given are very different
-from the standard editor commands; most do not appear on the screen when
-typed.
-.I
-An Introduction to Display Editing with Vi
-.R
-provides a full discussion.
-.sp 0.25v
-.LP
-.B
-Special Characters
-.PP
-.R
-.fi
-Some characters take on special meanings
-when used in context searches
-and in patterns given to the \fIsubstitute\fP command.
-For \fIedit\fR, these are ``^'' and ``$'',
-meaning the beginning and end of a line,
-respectively.
-.I Ex
-has the following additional special characters:
-.B
-.ce 1
-\&. & * [ ] ~
-.R
-To use one of the special characters as its
-simple graphic representation
-rather than with its special meaning,
-precede it by a backslash (\\).
-The backslash always has a special meaning.
-.1C
-.rm LF
-.rm RF
-.rm CF
-.nr FM 0.4
-.TS
-cp10 cp10 cp10 cp10
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-Name Abbr Description Examples
-.sp 1.75
-(.)\fBappend a T{
-Begins text input mode,
-adding lines to the buffer after
-the line specified. Appending continues
-until ``.'' is typed alone at the
-beginning of a new line, followed by
-a carriage return. \fI0a\fR places
-lines at the beginning of the buffer.
-T} T{
-.nf
-\fR:\fBa
-Three lines of text
-are added to the buffer
-after the current line.
-\*p
-.R
-\*c
-.fi
-T}
-.SP
-\fR(.,.)\fBchange c T{
-Deletes indicated line(s) and
-initiates text input mode to
-replace them with new text which follows.
-New text is terminated the same way
-as with \fIappend\fR.
-T} T{
-.nf
-:\fB5,6c
-Lines 5 and 6 are
-deleted and replaced by
-these three lines.
-\*p
-.R
-\*c
-.fi
-T}
-.SP
-\fR(.,.)\fBcopy \fIaddr co T{
-Places a copy of the specified lines
-after the line indicated by \fIaddr\fR.
-The example places a copy of lines 8 through
-12, inclusive, after line 25.
-T} T{
-.nf
-\fR:\fB8,12co 25
-\fRLast line copied is printed
-\fR\*c
-.fi
-T}
-.SP
-\fR(.,.)\fBdelete d T{
-Removes lines from the buffer
-and prints the current line after the deletion.
-T} T{
-.nf
-\fR:\fB13,15d
-\fRNew current line is printed
-\*c
-.fi
-T}
-.TE
-.sp 0.5v
-.TS
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-T{
-\fBedit \fIfile\fP
-.br
-\fBedit! \fIfile\fP
-T} T{
-e
-.br
-e!
-T} T{
-.fi
-\fRClears the editor buffer and then
-copies into it the named \fIfile\fR,
-which becomes the current file.
-This is a way of shifting to a different
-file
-without leaving the editor.
-The editor issues a warning
-message if this command is used before
-saving changes
-made to the file already in the buffer;
-using the form \fBe!\fR overrides this protective mechanism.
-T} T{
-.nf
-\fR:\fBe ch10\fR
-No write since last change
-:\fBe! ch10\fR
-"ch10" 3 lines, 62 characters
-\*c
-.fi
-T}
-.SP
-\fBfile \fIname\fR f T{
-\fRIf followed by a \fIname\fR, renames
-the current file to \fIname\fR.
-If used without \fIname\fR, prints
-the name of the current file.
-T} T{
-.nf
-\fR:\fBf ch9
-\fR"ch9" [Modified] 3 lines ...
-:\fBf
-\fR"ch9" [Modified] 3 lines ...
-\*c
-.fi
-T}
-.SP
-(1,$)\fBglobal g \fBglobal/\fIpattern\fB/\fIcommands T{
-.nf
-:\fBg/nonsense/d
-\fR\*c
-.fi
-T}
-\fR(1,$)\fBglobal! g!\fR or \fBv T{
-Searches the entire buffer (unless a smaller
-range is specified by line-number prefixes) and
-executes \fIcommands\fR on every line with
-an expression matching \fIpattern\fR.
-The second form, abbreviated
-either \fBg!\fR or \fBv\fR,
-executes \fIcommands\fR on lines that \fIdo
-not\fR contain the expression \fIpattern\fR.
-T} \^
-.SP
-\fR(.)\fBinsert i T{
-Inserts new lines of text immediately before the specified line.
-Differs from
-.I append
-only in that text is placed before, rather than after, the indicated line.
-In other words, \fB1i\fR has the same effect as \fB0a\fR.
-T} T{
-.nf
-:\fB1i
-These lines of text will
-be added prior to line 1.
-\&.
-\fR:
-.fi
-T} \^
-.SP
-\fR(.,.+1)\fBjoin j T{
-Join lines together, adjusting white space (spaces
-and tabs) as necessary.
-T} T{
-.nf
-:\fB2,5j\fR
-Resulting line is printed
-:
-.fi
-T} \^
-.TE
-.bp
-.TS
-cp10 cp10 cp10 cp10
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-Name Abbr Description Examples
-.sp 1.75
-\fR(.,.)\fBlist l T{
-\fRPrints lines in a more
-unambiguous way than the \fIprint\fR
-command does. The end of a line,
-for example, is marked with a ``$'',
-and tabs printed as ``^I''.
-T} T{
-.nf
-:\fB9l
-\fRThis is line 9$
-\*c
-.fi
-T}
-.TE
-.sp 0.5v
-.TS
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-\fR(.,.)\fBmove \fIaddr\fB m T{
-\fRMoves the specified lines
-to a position after the line
-indicated by \fIaddr\fR.
-T} T{
-.nf
-\fR:\fB12,15m 25\fR
-New current line is printed
-\*c
-.fi
-T}
-.SP
-\fR(.,.)\fBnumber nu T{
-Prints each line preceded
-by its buffer line number.
-T} T{
-.nf
-\fR:\fBnu
-\0\0\fR10\0 This is line 10
-\*c
-.fi
-T}
-.SP
-\fR(.)\fBopen o T{
-Too involved to discuss here,
-but if you enter open mode
-accidentally, press
-the \s-2ESC\s0 key followed by
-\fBq\fR to
-get back into normal editor
-command mode.
-\fIEdit\fP is designed to
-prevent accidental use of
-the open command.
-T}
-.SP
-\fBpreserve pre T{
-Saves a copy of the current buffer contents as though the system had
-just crashed. This is for use in an emergency when a
-.I write
-command has failed and you don't know how else to save your work.\(dg
-T} T{
-.nf
-:\fBpreserve\fR
-File preserved.
-:
-.fi
-T}
-.SP
-\fR(.,.)\fBprint p Prints the text of line(s). T{
-.nf
-:\fB+2,+3p\fR
-The second and third lines
-after the current line
-:
-.fi
-T}
-.TE
-.FS
-\(dg Seek assistance from a consultant as soon as possible
-after saving a file with the
-.I preserve
-command, because the file is saved on system storage space for only one week.
-.FE
-.SP
-.nf
-.TS
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-T{
-.nf
-\fBquit
-quit!
-.fi
-T} T{
-.nf
-q
-q!
-T} T{
-.fi
-\fREnds the editing session.
-You will receive a
-warning if you have changed the buffer
-since last writing its contents
-to the file. In this event you
-must either type \fBw\fR to write,
-or type \fBq!\fR to exit from
-the editor without saving your changes.
-T} T{
-.nf
-\fR:\fBq
-\fRNo write since last change
-:\fBq!
-\fR%
-.fi
-T}
-.SP
-\fR(.)\fBread \fIfile\fP r T{
-.fi
-\fRPlaces a copy of \fIfile\fR in the
-buffer after the specified line.
-Address 0 is permissible and causes
-the copy of \fIfile\fR to be placed
-at the beginning of the buffer.
-The \fIread\fP command does not
-erase any text already in the buffer.
-If no line number is specified,
-\fIfile\fR is placed after the
-current line.
-T} T{
-.nf
-\fR:\fB0r newfile
-\fR"newfile" 5 lines, 86 characters
-\*c
-.fi
-T}
-.SP
-\fBrecover \fIfile\fP rec T{
-.fi
-Retrieves a copy of the editor buffer
-after a system crash, editor crash,
-phone line disconnection, or
-\fIpreserve\fR command.
-T}
-.SP
-\fR(.,.)\fBsubstitute s T{
-.nf
-\fBsubstitute/\fIpattern\fB/\fIreplacement\fB/
-substitute/\fIpattern\fB/\fIreplacement\fB/gc
-.fi
-\fRReplaces the first occurrence of \fIpattern\fR
-on a line
-with \fIreplacement\fP.
-Including a \fBg\fR after the command
-changes all occurrences of \fIpattern\fP
-on the line.
-The \fBc\fR option allows the user to
-confirm each substitution before it is
-made; see the manual for details.
-T} T{
-.nf
-:\fB3p
-\fRLine 3 contains a misstake
-:\fBs/misstake/mistake/
-\fRLine 3 contains a mistake
-\*c
-.fi
-T}
-.TE
-.bp
-.TS
-cp10 cp10 cp10 cp10
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-Name Abbr Description Examples
-.sp 1.75
-\fBundo u T{
-.fi
-\fRReverses the changes made in
-the buffer by the last buffer-editing
-command.
-Note that this example contains
-a notification about the number of
-lines affected.
-T} T{
-.nf
-\fR:\fB1,15d
-\fR15 lines deleted
-new line number 1 is printed
-:\fBu
-\fR15 more lines in file ...
-old line number 1 is printed
-\*c
-.fi
-T}
-.SP
-\fR(1,$)\fBwrite \fIfile\fR w T{
-.fi
-\fRCopies data from the buffer onto
-a permanent file. If no \fIfile\fR
-is named, the current filename
-is used.
-The file is automatically created
-if it does not yet exist.
-A response containing the number of
-lines and characters in the file
-indicates that the write
-has been completed successfully.
-The editor's built-in protections
-against overwriting existing files
-will in some circumstances
-inhibit a write.
-The form \fBw!\fR forces the
-write, confirming that
-an existing file is to be overwritten.
-T} T{
-.nf
-\fR:\fBw
-\fR"file7" 64 lines, 1122 characters
-:\fBw file8
-\fR"file8" File exists ...
-:\fBw! file8
-\fR"file8" 64 lines, 1122 characters
-\*c
-.fi
-T}
-\fR(1,$)\fBwrite! \fIfile\fP w! \^ \^
-.TE
-.sp 0.5v
-.TS
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-\fR(.)\fBz \fIcount\fP z T{
-.fi
-\fRPrints a screen full of text starting
-with the line indicated;
-or, if \fIcount\fR is specified,
-prints that number of lines.
-Variants of the \fIz\fR command
-are described in the manual.
-T}
-.SP
-\fB!\fIcommand T{
-.fi
-Executes the remainder of the line
-after \fB!\fR as a \*U command.
-The buffer is unchanged by this, and
-control is returned to the editor when
-the execution of \fIcommand\fR is complete.
-T} T{
-.nf
-\fR:\fB!date
-\fRFri Jun 9 12:15:11 PDT 1978
-!
-\*c
-.fi
-T}
-.SP
-\fRcontrol-d T{
-.fi
-Prints the next \fIscroll\fR of text,
-normally half of a screen. See the
-manual for details of the \fIscroll\fR
-option.
-T}
-.SP
-\fR(.+1)<cr> T{
-.fi
-An address alone followed by a carriage
-return causes the line to be printed.
-A carriage return by itself prints the
-line following the current line.
-T} T{
-.nf
-:\fR<cr>
-the line after the current line
-\*c
-.fi
-T}
-.TE
-.sp 0.5v
-.TS
-ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
-\fB/\fIpattern\fB/ T{
-.fi
-\fRSearches for the next line in which
-\fIpattern\fR occurs and prints it.
-T} T{
-.nf
-\fR:\fB/This pattern/
-\fRThis pattern next occurs here.
-\*c
-.fi
-T}
-.SP
-\fB// T{
-Repeats the most recent search.
-T} T{
-.nf
-\fR:\fB//
-\fRThis pattern also occurs here.
-\*c
-.fi
-T}
-.SP
-\fB?\fIpattern\fB? T{
-Searches in the reverse direction
-for \fIpattern\fP.
-T}
-.SP
-\fB?? T{
-Repeats the most recent search,
-moving in the reverse direction
-through the buffer.
-T}
-.TE
-
diff --git a/usr.bin/vi/USD.doc/vi.man/Makefile b/usr.bin/vi/USD.doc/vi.man/Makefile
deleted file mode 100644
index fd89b8e..0000000
--- a/usr.bin/vi/USD.doc/vi.man/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-# @(#)Makefile 8.5 (Berkeley) 7/16/94
-
-SRCS= vi.1
-DOCS= vi.0 vi.0.ps
-
-all: ${DOCS}
-
-vi.0: vi.1
- groff -man -Tascii < vi.1 > $@
-vi.0.ps: vi.1
- groff -man < vi.1 > $@
-
-clean:
- rm -f ${DOCS}
diff --git a/usr.bin/vi/USD.doc/vi.man/vi.0 b/usr.bin/vi/USD.doc/vi.man/vi.0
deleted file mode 100644
index e6d9972..0000000
--- a/usr.bin/vi/USD.doc/vi.man/vi.0
+++ /dev/null
@@ -1,798 +0,0 @@
-EX/VI(1) BSD Reference Manual EX/VI(1)
-
-NNAAMMEE
- eexx,, vvii,, vviieeww - text editors
-
-SSYYNNOOPPSSIISS
- eexx [--eeFFRRrrssvv] [--cc _c_m_d] [--tt _t_a_g] [--ww _s_i_z_e] [_f_i_l_e _._._.]
- vvii [--eeFFRRrrvv] [--cc _c_m_d] [--tt _t_a_g] [--ww _s_i_z_e] [_f_i_l_e _._._.]
- vviieeww [--eeFFRRrrvv] [--cc _c_m_d] [--tt _t_a_g] [--ww _s_i_z_e] [_f_i_l_e _._._.]
-
-DDEESSCCRRIIPPTTIIOONN
- VVii is a screen oriented text editor. EExx is a line-oriented text editor.
- EExx and vvii are different interfaces to the same program, and it is possi-
- ble to switch back and forth during an edit session. VViieeww is the equiva-
- lent of using the --RR (read-only) option of vvii.
-
- This manual page is the one provided with the nneexx//nnvvii versions of the
- eexx//vvii text editors. NNeexx//nnvvii are intended as bug-for-bug compatible re-
- placements for the original Fourth Berkeley Software Distribution (4BSD)
- eexx and vvii programs. For the rest of this manual page, nneexx//nnvvii is used
- only when it's necessary to distinguish it from the historic implementa-
- tions of eexx//vvii.
-
- This manual page is intended for users already familiar with eexx//vvii. Any-
- one else should almost certainly read a good tutorial on the editor be-
- fore this manual page. If you're in an unfamiliar environment, and you
- absolutely have to get work done immediately, read the section after the
- options description, entitled ``Fast Startup''. It's probably enough to
- get you going.
-
- The following options are available:
-
- --cc Execute _c_m_d immediately after starting the edit session. Partic-
- ularly useful for initial positioning in the file, however _c_m_d is
- not limited to positioning commands. This is the POSIX 1003.2
- interface for the historic ``+cmd'' syntax. NNeexx//nnvvii supports
- both the old and new syntax.
-
- --ee Start editing in ex mode, as if the command name were eexx.
-
- --FF Don't copy the entire file when first starting to edit. (The de-
- fault is to make a copy in case someone else modifies the file
- during your edit session.)
-
- --RR Start editing in read-only mode, as if the command name was vviieeww,
- or the readonly option was set.
-
- --rr Recover the specified files, or, if no files are specified, list
- the files that could be recovered. If no recoverable files by
- the specified name exist, the file is edited as if the --rr option
- had not been specified.
-
- --ss Enter batch mode; applicable only to eexx edit sessions. Batch
- mode is useful when running eexx scripts. Prompts, informative
- messages and other user oriented message are turned off, and no
- startup files or environmental variables are read. This is the
- POSIX 1003.2 interface for the historic ``-'' argument. NNeexx//nnvvii
- supports both the old and new syntax.
-
- --tt Start editing at the specified tag. (See ctags(1)).
-
- --ww Set the initial window size to the specified number of lines.
-
-
-
- --vv Start editing in vi mode, as if the command name was vvii or vviieeww.
-
- --XX Reserved for X11 interfaces. _N_o _X_1_1 _s_u_p_p_o_r_t _i_s _c_u_r_r_e_n_t_l_y
- _i_m_p_l_e_m_e_n_t_e_d_.
-
- Command input for eexx//vvii is read from the standard input. In the vvii in-
- terface, it is an error if standard input is not a terminal. In the eexx
- interface, if standard input is not a terminal, eexx will read commands
- from it regardless, however, the session will be a batch mode session,
- exactly as if the --ss option had been specified.
-
- EExx//vvii exits 0 on success, and greater than 0 if an error occurs.
-
-FFAASSTT SSTTAARRTTUUPP
- This section will tell you the minimum amount that you need to do simple
- editing tasks using vvii. If you've never used any screen editor before,
- you're likely to have problems even with this simple introduction. In
- that case you should find someone that already knows vvii and have them
- walk you through this section.
-
- VVii is a screen editor. This means that it takes up almost the entire
- screen, displaying part of the file on each screen line, except for the
- last line of the screen. The last line of the screen is used for you to
- give commands to vvii, and for vvii to give information to you.
-
- The other fact that you need to understand is that vvii is a modeful edi-
- tor, i.e. you are either entering text or you are executing commands, and
- you have to be in the right mode to do one or the other. You will be in
- command mode when you first start editing a file. There are commands
- that switch you into input mode. There is only one key that takes you
- out of input mode, and that is the <escape> key. (Key names are written
- using less-than and greater-than signs, e.g. <escape> means the
- ``escape'' key, usually labeled ``esc'' on your terminal's keyboard.) If
- you're ever confused as to which mode you're in, keep entering the <es-
- cape> key until vvii beeps at you. (Generally, vvii will beep at you if you
- try and do something that's not allowed. It will also display error mes-
- sages.)
-
- To start editing a file, enter the command ``vi file_name<carriage-
- return>''. The command you should enter as soon as you start editing is
- ``:set verbose showmode<carriage-return>''. This will make the editor
- give you verbose error messages and display the current mode at the bot-
- tom of the screen.
-
- The commands to move around the file are:
- hh Move the cursor left one character.
- jj Move the cursor down one line.
- kk Move the cursor up one line.
- ll Move the cursor right one character.
- <<ccuurrssoorr--aarrrroowwss>>
- The cursor arrow keys should work, too.
- //tteexxtt<<ccaarrrriiaaggee--rreettuurrnn>>
- Search for the string ``text'' in the file, and move the cursor to
- its first character.
-
- The commands to enter new text are:
- aa Append new text, _a_f_t_e_r the cursor.
- ii Insert new text, _b_e_f_o_r_e the cursor.
- oo Open a new line below the line the cursor is on, and start entering
- text.
- OO Open a new line above the line the cursor is on, and start entering
- text.
- <<eessccaappee>>
- Once you've entered input mode using the one of the aa, ii, OO, or oo
- commands, use <<eessccaappee>> to quit entering text and return to command
- mode.
-
- The commands to copy text are:
- yyyy Copy the line the cursor is on.
- pp Append the copied line after the line the cursor is on.
-
- The commands to delete text are:
- dddd Delete the line the cursor is on.
- xx Delete the character the cursor is on.
-
- The commands to write the file are:
- ::ww<<ccaarrrriiaaggee--rreettuurrnn>>
- Write the file back to the file with the name that you originally
- used as an argument on the vvii command line.
- ::ww ffiillee__nnaammee<<ccaarrrriiaaggee--rreettuurrnn>>
- Write the file back to the file with the name ``file_name''.
-
- The commands to quit editing and exit the editor are:
- ::qq<<ccaarrrriiaaggee--rreettuurrnn>>
- Quit editing and leave vi (if you've modified the file, but not
- saved your changes, vvii will refuse to quit).
- ::qq!!<<ccaarrrriiaaggee--rreettuurrnn>>
- Quit, discarding any modifications that you may have made.
-
- One final caution. Unusual characters can take up more than one column
- on the screen, and long lines can take up more than a single screen line.
- The above commands work on ``physical'' characters and lines, i.e. they
- affect the entire line no matter how many screen lines it takes up and
- the entire character no matter how many screen columns it takes up.
-
-VVII CCOOMMMMAANNDDSS
- The following section describes the commands available in the command
- mode of the vvii editor. In each entry below, the tag line is a usage syn-
- opsis for the command character.
-
- [[ccoouunntt]] <<ccoonnttrrooll--AA>>
- Search forward count times for the current word.
- [[ccoouunntt]] <<ccoonnttrrooll--BB>>
- Page backwards count screens.
- [[ccoouunntt]] <<ccoonnttrrooll--DD>>
- Scroll forward count lines.
- [[ccoouunntt]] <<ccoonnttrrooll--EE>>
- Scroll forward count lines, leaving the current line and column as
- is, if possible.
- [[ccoouunntt]] <<ccoonnttrrooll--FF>>
- Page forward count screens.
- <<ccoonnttrrooll--GG>>
- Display the file information.
- <<ccoonnttrrooll--HH>>
- [[ccoouunntt]] hh
- Move the cursor back count characters in the current line.
- [[ccoouunntt]] <<ccoonnttrrooll--JJ>>
- [[ccoouunntt]] <<ccoonnttrrooll--NN>>
- [[ccoouunntt]] jj
- Move the cursor down count lines without changing the current col-
- umn.
- <<ccoonnttrrooll--LL>>
- <<ccoonnttrrooll--RR>>
- Repaint the screen.
- [[ccoouunntt]] <<ccoonnttrrooll--MM>>
- [[ccoouunntt]] ++
- Move the cursor down count lines to the first nonblank character of
- that line.
- [[ccoouunntt]] <<ccoonnttrrooll--PP>>
- [[ccoouunntt]] kk
- Move the cursor up count lines, without changing the current col-
-
- umn.
- <<ccoonnttrrooll--TT>>
- Return to the most recent tag context.
- <<ccoonnttrrooll--UU>>
- Scroll backwards count lines.
- <<ccoonnttrrooll--WW>>
- Switch to the next lower screen in the window, or, to the first
- screen if there are no lower screens in the window.
- <<ccoonnttrrooll--YY>>
- Scroll backwards count lines, leaving the current line and column
- as is, if possible.
- <<ccoonnttrrooll--ZZ>>
- Suspend the current editor session.
- <<eessccaappee>>
- Execute eexx commands or cancel partial commands.
- <<ccoonnttrrooll--]]>>
- Push a tag reference onto the tag stack.
- <<ccoonnttrrooll--^^>>
- Switch to the most recently edited file.
- [[ccoouunntt]] <<ssppaaccee>>
- [[ccoouunntt]] ll
- Move the cursor forward count characters without changing the cur-
- rent line.
- [[ccoouunntt]] !! mmoottiioonn sshheellll--aarrgguummeenntt((ss))
- Replace text with results from a shell command.
- [[ccoouunntt]] ## ++||--||##
- Increment or decrement the cursor number.
- [[ccoouunntt]] $$
- Move the cursor to the end of a line.
- %% Move to the matching character.
- && Repeat the previous substitution command on the current line.
- ''<<cchhaarraacctteerr>>
- ``<<cchhaarraacctteerr>>
- Return to a context marked by the character <character>.
- [[ccoouunntt]] ((
- Back up count sentences.
- [[ccoouunntt]] ))
- Move forward count sentences.
- [[ccoouunntt]] ,,
- Reverse find character count times.
- [[ccoouunntt]] --
- Move to first nonblank of the previous line, count times.
- [[ccoouunntt]] ..
- Repeat the last vvii command that modified text.
- //RREE<<ccaarrrriiaaggee--rreettuurrnn>>
- //RREE// [[ooffffsseett]]<<ccaarrrriiaaggee--rreettuurrnn>>
- ??RREE<<ccaarrrriiaaggee--rreettuurrnn>>
- ??RREE?? [[ooffffsseett]]<<ccaarrrriiaaggee--rreettuurrnn>>
- NN
- nn Search forward or backward for a regular expression.
- 00 Move to the first character in the current line.
- : Execute an ex command.
- [[ccoouunntt]] ;;
- Repeat the last character find count times.
- [[ccoouunntt]] << mmoottiioonn
- [[ccoouunntt]] >> mmoottiioonn
- Shift lines left or right.
- @@ bbuuffffeerr
- Execute a named buffer.
- [[ccoouunntt]] AA
- Enter input mode, appending the text after the end of the line.
- [[ccoouunntt]] BB
- Move backwards count bigwords.
- [[bbuuffffeerr]] [[ccoouunntt]] CC
-
-
- Change text from the current position to the end-of-line.
- [[bbuuffffeerr]] DD
- Delete text from the current position to the end-of-line.
- [[ccoouunntt]] EE
- Move forward count end-of-bigwords.
- [[ccoouunntt]] FF <<cchhaarraacctteerr>>
- Search count times backward through the current line for
- <character>.
- [[ccoouunntt]] GG
- Move to line count, or the last line of the file if count not spec-
- ified.
- [[ccoouunntt]] HH
- Move to the screen line count - 1 lines below the top of the
- screen.
- [[ccoouunntt]] II
- Enter input mode, inserting the text at the beginning of the line.
- [[ccoouunntt]] JJ
- Join lines.
- [[ccoouunntt]] LL
- Move to the screen line count - 1 lines above the bottom of the
- screen.
- MM Move to the screen line in the middle of the screen.
- [[ccoouunntt]] OO
- Enter input mode, appending text in a new line above the current
- line.
- [[bbuuffffeerr]] PP
- Insert text from a buffer.
- QQ Exit vvii (or visual) mode and switch to eexx mode.
- [[ccoouunntt]] RR
- Enter input mode, replacing the characters in the current line.
- [[bbuuffffeerr]] [[ccoouunntt]] SS
- Substitute count lines.
- [[ccoouunntt]] TT <<cchhaarraacctteerr>>
- Search backwards, count times, through the current line for the
- character _a_f_t_e_r the specified <character>.
- UU Restore the current line to its state before the cursor last moved
- to it.
- [[ccoouunntt]] WW
- Move forward count bigwords.
- [[bbuuffffeerr]] [[ccoouunntt]] XX
- Delete count characters before the cursor.
- [[bbuuffffeerr]] [[ccoouunntt]] YY
- Copy (or ``yank'') count lines into the specified buffer.
- ZZZZ Write the file and exit vvii.
- [[ccoouunntt]] [[[[
- Back up count section boundaries.
- [[ccoouunntt]] ]]]]
- Move forward count section boundaries.
- ^^ Move to first nonblank character on the current line.
- [[ccoouunntt]] __
- Move down count - 1 lines, to the first nonblank character.
- [[ccoouunntt]] aa
- Enter input mode, appending the text after the cursor.
- [[ccoouunntt]] bb
- Move backwards count words.
- [[bbuuffffeerr]] [[ccoouunntt]] cc mmoottiioonn
- Change a region of text.
- [[bbuuffffeerr]] [[ccoouunntt]] dd mmoottiioonn
- Delete a region of text.
- [[ccoouunntt]] ee
- Move forward count end-of-words.
- [[ccoouunntt]] ff<<cchhaarraacctteerr>>
- Search forward, count times, through the rest of the current line
- for <character>.
- [[ccoouunntt]] ii
-
- Enter input mode, inserting the text before the cursor.
- mm <<cchhaarraacctteerr>>
- Save the current context (line and column) as <character>.
- [[ccoouunntt]] oo
- Enter input mode, appending text in a new line under the current
- line.
- [[bbuuffffeerr]] pp
- Append text from a buffer.
- [[ccoouunntt]] rr <<cchhaarraacctteerr>>
- Replace count characters.
- [[bbuuffffeerr]] [[ccoouunntt]] ss
- Substitute count characters in the current line starting with the
- current character.
- [[ccoouunntt]] tt <<cchhaarraacctteerr>>
- Search forward, count times, through the current line for the char-
- acter immediately _b_e_f_o_r_e <character>.
- uu Undo the last change made to the file.
- [[ccoouunntt]] ww
- Move forward count words.
- [[bbuuffffeerr]] [[ccoouunntt]] xx
- Delete count characters.
- [[bbuuffffeerr]] [[ccoouunntt]] yy mmoottiioonn
- Copy (or ``yank'') a text region specified by the count and motion
- into a buffer.
- [[ccoouunntt11]] zz [[ccoouunntt22]] --||..||++||^^||<<ccaarrrriiaaggee--rreettuurrnn>>
- Redraw, optionally repositioning and resizing the screen.
- [[ccoouunntt]] {{
- Move backward count paragraphs.
- [[ccoouunntt]] ||
- Move to a specific _c_o_l_u_m_n position on the current line.
- [[ccoouunntt]] }}
- Move forward count paragraphs.
- [[ccoouunntt]] ~~
- Reverse the case of the next count character(s).
- [[ccoouunntt]] ~~ mmoottiioonn
- Reverse the case of the characters in a text region specified by
- the count and motion.
- <<iinntteerrrruupptt>>
- Interrupt the current operation.
-
-VVII TTEEXXTT IINNPPUUTT CCOOMMMMAANNDDSS
- The following section describes the commands available in the text input
- mode of the vvii editor.
-
- <<nnuull>>
- Replay the previous input.
- <<ccoonnttrrooll--DD>>
- Erase the previous autoindent character.
- ^^<<ccoonnttrrooll--DD>>
- Erase all of the autoindent characters, and reset the autoindent
- level.
- 00<<ccoonnttrrooll--DD>>
- Erase all of the autoindent characters.
- <<ccoonnttrrooll--TT>>
- Insert sufficient <tab> and <space> characters to move the cursor
- forward to a column immediately after the next column which is an
- even multiple of the sshhiiffttwwiiddtthh option.
- <<eerraassee>>
- <<ccoonnttrrooll--HH>>
- Erase the last character.
- <<lliitteerraall nneexxtt>>
- Quote the next character.
- <<eessccaappee>>
- Resolve all text input into the file, and return to command mode.
- <<lliinnee eerraassee>>
-
- Erase the current line.
- <<ccoonnttrrooll--WW>>
- <<wwoorrdd eerraassee>>
- Erase the last word. The definition of word is dependent on the
- aallttwweerraassee and ttttyywweerraassee options.
- <<ccoonnttrrooll--XX>>[[00--99AA--FFaa--ff]]**
- Insert a character with the specified hexadecimal value into the
- text.
- <<iinntteerrrruupptt>>
- Interrupt text input mode, returning to command mode.
-
-EEXX CCOOMMMMAANNDDSS
- The following section describes the commands available in the eexx editor.
- In each entry below, the tag line is a usage synopsis for the command.
-
- <<eenndd--ooff--ffiillee>>
- Scroll the screen.
- !! aarrgguummeenntt((ss))
- [[rraannggee]]!! aarrgguummeenntt((ss))
- Execute a shell command, or filter lines through a shell command.
- "" A comment.
- [[rraannggee]] nnuu[[mmbbeerr]] [[ccoouunntt]] [[ffllaaggss]]
- [[rraannggee]] ## [[ccoouunntt]] [[ffllaaggss]]
- Display the selected lines, each preceded with its line number.
- @@ bbuuffffeerr
- ** bbuuffffeerr
- Execute a buffer.
- [[rraannggee]] dd[[eelleettee]] [[bbuuffffeerr]] [[ccoouunntt]] [[ffllaaggss]]
- Delete the lines from the file.
- ddii[[ssppllaayy]] bb[[uuffffeerrss]] || ss[[ccrreeeennss]] || tt[[aaggss]]
- Display buffers, screens or tags.
- ee[[ddiitt]][[!!]] [[++ccmmdd]] [[ffiillee]]
- eexx[[!!]] [[++ccmmdd]] [[ffiillee]]
- Edit a different file.
- eexxuu[[ssaaggee]] [[ccoommmmaanndd]]
- Display usage for an eexx command.
- ff[[iillee]] [[ffiillee]]
- Display and optionally change the file name.
- ffgg [[nnaammee]]
- VVii mode only. Foreground the specified screen.
- [[rraannggee]] gg[[lloobbaall]] //ppaatttteerrnn// [[ccoommmmaannddss]]
- [[rraannggee]] vv //ppaatttteerrnn// [[ccoommmmaannddss]]
- Apply commands to lines matching (or not matching) a pattern.
- hhee[[llpp]]
- Display a help message.
- [[lliinnee]] ii[[nnsseerrtt]][[!!]]
- The input text is inserted before the specified line.
- [[rraannggee]] jj[[ooiinn]][[!!]] [[ccoouunntt]] [[ffllaaggss]]
- Join lines of text together.
- [[rraannggee]] ll[[iisstt]] [[ccoouunntt]] [[ffllaaggss]]
- Display the lines unambiguously.
- mmaapp[[!!]] [[llhhss rrhhss]]
- Define or display maps (for vvii only).
- [[lliinnee]] mmaa[[rrkk]] <<cchhaarraacctteerr>>
- [[lliinnee]] kk <<cchhaarraacctteerr>>
- Mark the line with the mark <character>.
- [[rraannggee]] mm[[oovvee]] lliinnee
- Move the specified lines after the target line.
- mmkk[[eexxrrcc]][[!!]] ffiillee
- Write the abbreviations, editor options and maps to the specified
- file.
- nn[[eexxtt]][[!!]] [[ffiillee ......]]
- Edit the next file from the argument list.
- [[lliinnee]] oo[[ppeenn]] //ppaatttteerrnn// [[ffllaaggss]]
-
-
- Enter open mode.
- pprree[[sseerrvvee]]
- Save the file in a form that can later be recovered using the eexx --rr
- option.
- pprreevv[[iioouuss]][[!!]]
- Edit the previous file from the argument list.
- [[rraannggee]] pp[[rriinntt]] [[ccoouunntt]] [[ffllaaggss]]
- Display the specified lines.
- [[lliinnee]] ppuu[[tt]] [[bbuuffffeerr]]
- Append buffer contents to the current line.
- qq[[uuiitt]][[!!]]
- End the editing session.
- [[lliinnee]] rr[[eeaadd]][[!!]] [[ffiillee]]
- Read a file.
- rreecc[[oovveerr]] ffiillee
- Recover file if it was previously saved.
- rreess[[iizzee]] [[++||--]]ssiizzee
- VVii mode only. Grow or shrink the current screen.
- rreeww[[iinndd]][[!!]]
- Rewind the argument list.
- ssee[[tt]] [[ooppttiioonn[[==[[vvaalluuee]]]] ......]] [[nnooooppttiioonn ......]] [[ooppttiioonn?? ......]] [[aallll]]
- Display or set editor options.
- sshh[[eellll]]
- Run a shell program.
- ssoo[[uurrccee]] ffiillee
- Read and execute eexx commands from a file.
- sspp[[lliitt]] [[ffiillee ......]]
- VVii mode only. Split the screen.
- [[rraannggee]] ss[[uubbssttiittuuttee]] [[//ppaatttteerrnn//rreeppllaaccee//]] [[ooppttiioonnss]] [[ccoouunntt]] [[ffllaaggss]]
- [[rraannggee]] && [[ooppttiioonnss]] [[ccoouunntt]] [[ffllaaggss]]
- [[rraannggee]] ~~ [[ooppttiioonnss]] [[ccoouunntt]] [[ffllaaggss]]
- Make substitutions.
- ssuu[[ssppeenndd]][[!!]]
- sstt[[oopp]][[!!]]
- <<ssuussppeenndd>>
- Suspend the edit session.
- ttaa[[gg]][[!!]] ttaaggssttrriinngg
- Edit the file containing the specified tag.
- ttaaggpp[[oopp]][[!!]] [[ffiillee || nnuummbbeerr]]
- Pop to the specified tag in the tags stack.
- uunnmm[[aapp]][[!!]] llhhss
- Unmap a mapped string.
- vvee[[rrssiioonn]]
- Display the version of the eexx//vvii editor.
- [[lliinnee]] vvii[[ssuuaall]] [[ttyyppee]] [[ccoouunntt]] [[ffllaaggss]]
- EExx mode only. Enter vvii.
- vvii[[ssuuaall]][[!!]] [[++ccmmdd]] [[ffiillee]]
- VVii mode only. Edit a new file.
- vviiuu[[ssaaggee]] [[ccoommmmaanndd]]
- Display usage for a vvii command.
- [[rraannggee]] ww[[rriittee]][[!!]] [[>>>>]] [[ffiillee]]
- [[rraannggee]] ww[[rriittee]] [[!!]] [[ffiillee]]
- [[rraannggee]] wwnn[[!!]] [[>>>>]] [[ffiillee]]
- [[rraannggee]] wwqq[[!!]] [[>>>>]] [[ffiillee]]
- Write the file.
- [[rraannggee]] xx[[iitt]][[!!]] [[ffiillee]]
- Write the file if it has been modified.
- [[rraannggee]] yyaa[[nnkk]] [[bbuuffffeerr]] [[ccoouunntt]]
- Copy the specified lines to a buffer.
- [[lliinnee]] zz [[ttyyppee]] [[ccoouunntt]] [[ffllaaggss]]
- Adjust the window.
-
-SSEETT OOPPTTIIOONNSS
- There are a large number of options that may be set (or unset) to change
- the editor's behavior. This section describes the options, their abbre-
- viations and their default values.
-
- In each entry below, the first part of the tag line is the full name of
- the option, followed by any equivalent abbreviations. The part in square
- brackets is the default value of the option. Most of the options are
- boolean, i.e. they are either on or off, and do not have an associated
- value.
-
- Options apply to both eexx and vvii modes, unless otherwise specified.
-
- aallttwweerraassee [[ooffff]]
- VVii only. Select an alternate word erase algorithm.
- aauuttooiinnddeenntt,, aaii [[ooffff]]
- Automatically indent new lines.
- aauuttoopprriinntt,, aapp [[ooffff]]
- EExx only. Display the current line automatically.
- aauuttoowwrriittee,, aaww [[ooffff]]
- Write modified files automatically when changing files.
- bbeeaauuttiiffyy,, bbff [[ooffff]]
- Discard control characters.
- ccddppaatthh [[eennvviirroonnmmeenntt vvaarriiaabbllee CCDDPPAATTHH,, oorr ccuurrrreenntt ddiirreeccttoorryy]]
- The directory paths used as path prefixes for the ccdd command.
- ccoolluummnnss,, ccoo [[8800]]
- Set the number of columns in the screen.
- ccoommmmeenntt [[ooffff]]
- VVii only. Skip leading comments in files.
- ddiirreeccttoorryy,, ddiirr [[eennvviirroonnmmeenntt vvaarriiaabbllee TTMMPPDDIIRR,, oorr //ttmmpp]]
- The directory where temporary files are created.
- eeddccoommppaattiibbllee,, eedd [[ooffff]]
- Remember the values of the ``c'' and ``g'' suffices to the
- ssuubbssttiittuuttee commands, instead of initializing them as unset for each
- new command.
- eerrrroorrbbeellllss,, eebb [[ooffff]]
- EExx only. Announce error messages with a bell.
- eexxrrcc,, eexx [[ooffff]]
- Never read startup files in the local directory.
- eexxtteennddeedd [[ooffff]]
- Regular expressions are extended (i.e. egrep(1) style) expres-
- sions.
- ffllaasshh [[oonn]]
- Flash the screen instead of beeping the keyboard on error.
- hhaarrddttaabbss,, hhtt [[88]]
- Set the spacing between hardware tab settings.
- iiggnnoorreeccaassee,, iicc [[ooffff]]
- Ignore case differences in regular expressions.
- kkeeyyttiimmee [[66]]
- The 10th's of a second eexx//vvii waits for a subsequent key to complete
- a key mapping.
- lleeffttrriigghhtt [[ooffff]]
- VVii only. Do left-right scrolling.
- lliinneess,, llii [[2244]]
- VVii only. Set the number of lines in the screen.
- lliisspp [[ooffff]]
- VVii only. Modify various search commands and options to work with
- Lisp.
-
- _T_h_i_s _o_p_t_i_o_n _i_s _n_o_t _y_e_t _i_m_p_l_e_m_e_n_t_e_d_.
- lliisstt [[ooffff]]
- Display lines in an unambiguous fashion.
- mmaaggiicc [[oonn]]
- Treat certain characters specially in regular expressions.
- mmaattcchhttiimmee [[77]]
- VVii only. The 10th's of a second eexx//vvii pauses on the matching char-
- acter when the sshhoowwmmaattcchh option is set.
- mmeessgg [[oonn]]
-
-
- Permit messages from other users.
- mmooddeelliinneess,, mmooddeelliinnee [[ooffff]]
- Read the first and last few lines of each file for eexx commands.
-
- _T_h_i_s _o_p_t_i_o_n _w_i_l_l _n_e_v_e_r _b_e _i_m_p_l_e_m_e_n_t_e_d_.
- nnuummbbeerr,, nnuu [[ooffff]]
- Precede each line displayed with its current line number.
- ooccttaall [[ooffff]]
- Display unknown characters as octal numbers, instead of the default
- hexadecimal.
- ooppeenn [[oonn]]
- EExx only. If this option is not set, the ooppeenn and vviissuuaall commands
- are disallowed.
- ooppttiimmiizzee,, oopptt [[oonn]]
- VVii only. Optimize text throughput to dumb terminals.
-
- _T_h_i_s _o_p_t_i_o_n _i_s _n_o_t _y_e_t _i_m_p_l_e_m_e_n_t_e_d_.
- ppaarraaggrraapphhss,, ppaarraa [[IIPPLLPPPPPPQQPPPP LLIIppppllppiippbbpp]]
- VVii only. Define additional paragraph boundaries for the {{ and }}
- commands.
- pprroommpptt [[oonn]]
- EExx only. Display a command prompt.
- rreeaaddoonnllyy,, rroo [[ooffff]]
- Mark the file as read-only.
- rreeccddiirr [[//vvaarr//ttmmpp//vvii..rreeccoovveerr]]
- The directory where recovery files are stored.
- rreeddrraaww,, rree [[ooffff]]
- VVii only. Simulate an intelligent terminal on a dumb one.
-
- _T_h_i_s _o_p_t_i_o_n _i_s _n_o_t _y_e_t _i_m_p_l_e_m_e_n_t_e_d_.
- rreemmaapp [[oonn]]
- Remap keys until resolved.
- rreeppoorrtt [[55]]
- Set the number of lines about which the editor reports changes or
- yanks.
- rruulleerr [[ooffff]]
- VVii only. Display a row/column ruler on the colon command line.
- ssccrroollll,, ssccrr [[wwiinnddooww // 22]]
- Set the number of lines scrolled.
- sseeccttiioonnss,, sseecctt [[NNHHSSHHHH HHUUnnhhsshh]]
- VVii only. Define additional section boundaries for the [[[[ and ]]]]
- commands.
- sshheellll,, sshh [[eennvviirroonnmmeenntt vvaarriiaabbllee SSHHEELLLL,, oorr //bbiinn//sshh]]
- Select the shell used by the editor.
- sshhiiffttwwiiddtthh,, ssww [[88]]
- Set the autoindent and shift command indentation width.
- sshhoowwddiirrttyy [[ooffff]]
- VVii only. Display an asterisk on the colon command line if the file
- has been modified.
- sshhoowwmmaattcchh,, ssmm [[ooffff]]
- VVii only. Note matching ``{'' and ``('' for ``}'' and ``)'' charac-
- ters.
- sshhoowwmmooddee [[ooffff]]
- VVii only. Display the current editor mode (command or input).
- ssiiddeessccrroollll [[1166]]
- VVii only. Set the amount a left-right scroll will shift.
- sslloowwooppeenn,, ssllooww [[ooffff]]
- Delay display updating during text input.
-
- _T_h_i_s _o_p_t_i_o_n _i_s _n_o_t _y_e_t _i_m_p_l_e_m_e_n_t_e_d_.
- ssoouurrcceeaannyy [[ooffff]]
- Read startup files not owned by the current user.
-
- _T_h_i_s _o_p_t_i_o_n _w_i_l_l _n_e_v_e_r _b_e _i_m_p_l_e_m_e_n_t_e_d_.
- ttaabbssttoopp,, ttss [[88]]
-
- This option sets tab widths for the editor display.
- ttaagglleennggtthh,, ttll [[00]]
- Set the number of significant characters in tag names.
- ttaaggss,, ttaagg [[ttaaggss //vvaarr//ddbb//lliibbcc..ttaaggss //ssyyss//kkeerrnn//ttaaggss]]
- Set the list of tags files.
- tteerrmm,, ttttyyttyyppee,, ttttyy [[eennvviirroonnmmeenntt vvaarriiaabbllee TTEERRMM]]
- Set the terminal type.
- tteerrssee [[ooffff]]
- This option has historically made editor messages less verbose. It
- has no effect in this implementation.
- ttiillddeeoopp
- Modify the ~~ command to take an associated motion.
- ttiimmeeoouutt,, ttoo [[oonn]]
- Time out on keys which may be mapped.
- ttttyywweerraassee [[ooffff]]
- VVii only. Select an alternate erase algorithm.
- vveerrbboossee [[ooffff]]
- only. Display an error message for every error.
- ww330000 [[nnoo ddeeffaauulltt]]
- VVii only. Set the window size if the baud rate is less than 1200
- baud.
- ww11220000 [[nnoo ddeeffaauulltt]]
- VVii only. Set the window size if the baud rate is equal to 1200
- baud.
- ww99660000 [[nnoo ddeeffaauulltt]]
- VVii only. Set the window size if the baud rate is greater than 1200
- baud.
- wwaarrnn [[oonn]]
- EExx only. This option causes a warning message to the terminal if
- the file has been modified, since it was last written, before a !!
- command.
- wwiinnddooww,, ww,, wwii [[eennvviirroonnmmeenntt vvaarriiaabbllee LLIINNEESS]]
- Set the window size for the screen.
- wwrraappmmaarrggiinn,, wwmm [[00]]
- VVii only. Break lines automatically when they reach the right-hand
- margin.
- wwrraappssccaann,, wwss [[oonn]]
- Set searches to wrap around the end or beginning of the file.
- wwrriitteeaannyy,, wwaa [[ooffff]]
- Turn off file-overwriting checks.
-
-EENNVVIIRROONNMMEENNTTAALL VVAARRIIAABBLLEESS
- COLUMNS The number of columns on the screen. This value overrides any
- system or terminal specific values. If the COLUMNS environ-
- mental variable is not set when eexx//vvii runs, or the ccoolluummnnss op-
- tion is explicitly reset by the user, eexx//vvii enters the value
- into the environment.
- EXINIT A list of eexx startup commands, read if the variable NEXINIT is
- not set.
- HOME The user's home directory, used as the initial directory path
- for the startup _$_H_O_M_E_/_._n_e_x_r_c and _$_H_O_M_E_/_._e_x_r_c files. This val-
- ue is also used as the default directory for the vvii ccdd com-
- mand.
- LINES The number of rows on the screen. This value overrides any
- system or terminal specific values. If the LINES environmen-
- tal variable is not set when eexx//vvii runs, or the lliinneess option
- is explicitly reset by the user, eexx//vvii enters the value into
- the environment.
- NEXINIT A list of eexx startup commands.
- SHELL The user's shell of choice (see also the sshheellll option).
- TERM The user's terminal type. The default is the type
- ``unknown''. If the TERM environmental variable is not set
- when eexx//vvii runs, or the tteerrmm option is explicitly reset by the
- user, eexx//vvii enters the value into the environment.
- TMPDIR The location used to stored temporary files (see also the
- ddiirreeccttoorryy option).
-
-AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
- SIGALRM VVii//eexx uses this signal for periodic backups of file modifica-
- tions and to display ``busy'' messages when operations are
- likely to take a long time.
- SIGHUP
- SIGTERM If the current buffer has changed since it was last written
- in its entirety, the editor attempts to save the modified
- file so it can be later recovered. See the vvii//eexx Reference
- manual section entitled ``Recovery'' for more information.
- SIGINT When an interrupt occurs, the current operation is halted,
- and the editor returns to the command level. If interrupted
- during text input, the text already input is resolved into
- the file as if the text input had been normally terminated.
- SIGWINCH The screen is resized. See the vvii//eexx Reference manual sec-
- tion entitled ``Sizing the Screen'' for more information.
- SIGCONT
- SIGQUIT
- SIGTSTP VVii//eexx ignores these signals.
-
-BBUUGGSS
- See the file _n_v_i_/_d_o_c_s_/_b_u_g_s_._c_u_r_r_e_n_t for a list of the known bugs in this
- version.
-
-FFIILLEESS
- /bin/sh The default user shell.
- /etc/vi.exrc System-wide vi startup file.
- /tmp Temporary file directory.
- /var/tmp/vi.recover The default recovery file directory.
- $HOME/.nexrc 1st choice for user's home directory startup file.
- $HOME/.exrc 2nd choice for user's home directory startup file.
- .nexrc 1st choice for local directory startup file.
- .exrc 2nd choice for local directory startup file.
-
-SSEEEE AALLSSOO
- ctags(1), more(1), curses(3), dbopen(3)
-
- The ``Vi Quick Reference'' card.
-
- ``An Introduction to Display Editing with Vi'', found in the ``UNIX
- User's Manual Supplementary Documents'' section of both the 4.3BSD and
- 4.4BSD manual sets. This document is the closest thing available to an
- introduction to the vvii screen editor.
-
- ``Ex Reference Manual (Version 3.7)'', found in the ``UNIX User's Manual
- Supplementary Documents'' section of both the 4.3BSD and 4.4BSD manual
- sets. This document is the final reference for the eexx editor, as dis-
- tributed in most historic 4BSD and System V systems.
-
- ``Edit: A tutorial'', found in the ``UNIX User's Manual Supplementary
- Documents'' section of the 4.3BSD manual set. This document is an intro-
- duction to a simple version of the eexx screen editor.
-
- ``Ex/Vi Reference Manual'', found in the ``UNIX User's Manual
- Supplementary Documents'' section of the 4.4BSD manual set. This docu-
- ment is the final reference for the nneexx//nnvvii text editors, as distributed
- in 4.4BSD and 4.4BSD-Lite.
-
- RRooffff source for all of these documents is distributed with nneexx//nnvvii in the
- _n_v_i_/_U_S_D_._d_o_c directory of the nneexx//nnvvii source code.
-
- The files ``autowrite'', ``input'', ``quoting'', and ``structures'',
- found in the _n_v_i_/_d_o_c_s_/_i_n_t_e_r_n_a_l_s directory of the nneexx//nnvvii source code.
-
-HHIISSTTOORRYY
- The nneexx//nnvvii replacements for the eexx//vvii editor first appeared in 4.4BSD.
-
-SSTTAANNDDAARRDDSS
- NNeexx//nnvvii is close to IEEE Std1003.2 (``POSIX''). That document differs
- from historical eexx//vvii practice in several places; there are changes to be
- made on both sides.
-
-4.4BSD July 15, 1994 13
diff --git a/usr.bin/vi/USD.doc/vi.man/vi.0.ps b/usr.bin/vi/USD.doc/vi.man/vi.0.ps
deleted file mode 100644
index f6cfc03..0000000
--- a/usr.bin/vi/USD.doc/vi.man/vi.0.ps
+++ /dev/null
@@ -1,1063 +0,0 @@
-%!PS-Adobe-3.0
-%%Creator: groff version 1.08
-%%DocumentNeededResources: font Times-Roman
-%%+ font Times-Bold
-%%+ font Courier-Bold
-%%+ font Courier-Oblique
-%%+ font Courier
-%%+ font Times-Italic
-%%+ font Symbol
-%%DocumentSuppliedResources: procset grops 1.08 0
-%%Pages: 14
-%%PageOrder: Ascend
-%%Orientation: Portrait
-%%EndComments
-%%BeginProlog
-%%BeginResource: procset grops 1.08 0
-/setpacking where{
-pop
-currentpacking
-true setpacking
-}if
-/grops 120 dict dup begin
-/SC 32 def
-/A/show load def
-/B{0 SC 3 -1 roll widthshow}bind def
-/C{0 exch ashow}bind def
-/D{0 exch 0 SC 5 2 roll awidthshow}bind def
-/E{0 rmoveto show}bind def
-/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
-/G{0 rmoveto 0 exch ashow}bind def
-/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
-/I{0 exch rmoveto show}bind def
-/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
-/K{0 exch rmoveto 0 exch ashow}bind def
-/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
-/M{rmoveto show}bind def
-/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
-/O{rmoveto 0 exch ashow}bind def
-/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
-/Q{moveto show}bind def
-/R{moveto 0 SC 3 -1 roll widthshow}bind def
-/S{moveto 0 exch ashow}bind def
-/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
-/SF{
-findfont exch
-[exch dup 0 exch 0 exch neg 0 0]makefont
-dup setfont
-[exch/setfont cvx]cvx bind def
-}bind def
-/MF{
-findfont
-[5 2 roll
-0 3 1 roll
-neg 0 0]makefont
-dup setfont
-[exch/setfont cvx]cvx bind def
-}bind def
-/level0 0 def
-/RES 0 def
-/PL 0 def
-/LS 0 def
-/PLG{
-gsave newpath clippath pathbbox grestore
-exch pop add exch pop
-}bind def
-/BP{
-/level0 save def
-1 setlinecap
-1 setlinejoin
-72 RES div dup scale
-LS{
-90 rotate
-}{
-0 PL translate
-}ifelse
-1 -1 scale
-}bind def
-/EP{
-level0 restore
-showpage
-}bind def
-/DA{
-newpath arcn stroke
-}bind def
-/SN{
-transform
-.25 sub exch .25 sub exch
-round .25 add exch round .25 add exch
-itransform
-}bind def
-/DL{
-SN
-moveto
-SN
-lineto stroke
-}bind def
-/DC{
-newpath 0 360 arc closepath
-}bind def
-/TM matrix def
-/DE{
-TM currentmatrix pop
-translate scale newpath 0 0 .5 0 360 arc closepath
-TM setmatrix
-}bind def
-/RC/rcurveto load def
-/RL/rlineto load def
-/ST/stroke load def
-/MT/moveto load def
-/CL/closepath load def
-/FL{
-currentgray exch setgray fill setgray
-}bind def
-/BL/fill load def
-/LW/setlinewidth load def
-/RE{
-findfont
-dup maxlength 1 index/FontName known not{1 add}if dict begin
-{
-1 index/FID ne{def}{pop pop}ifelse
-}forall
-/Encoding exch def
-dup/FontName exch def
-currentdict end definefont pop
-}bind def
-/DEFS 0 def
-/EBEGIN{
-moveto
-DEFS begin
-}bind def
-/EEND/end load def
-/CNT 0 def
-/level1 0 def
-/PBEGIN{
-/level1 save def
-translate
-div 3 1 roll div exch scale
-neg exch neg exch translate
-0 setgray
-0 setlinecap
-1 setlinewidth
-0 setlinejoin
-10 setmiterlimit
-[]0 setdash
-/setstrokeadjust where{
-pop
-false setstrokeadjust
-}if
-/setoverprint where{
-pop
-false setoverprint
-}if
-newpath
-/CNT countdictstack def
-userdict begin
-/showpage{}def
-}bind def
-/PEND{
-clear
-countdictstack CNT sub{end}repeat
-level1 restore
-}bind def
-end def
-/setpacking where{
-pop
-setpacking
-}if
-%%EndResource
-%%IncludeResource: font Times-Roman
-%%IncludeResource: font Times-Bold
-%%IncludeResource: font Courier-Bold
-%%IncludeResource: font Courier-Oblique
-%%IncludeResource: font Courier
-%%IncludeResource: font Times-Italic
-%%IncludeResource: font Symbol
-grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL
-792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron/scaron/zcaron
-/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef/.notdef/.notdef
-/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
-/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space
-/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft
-/parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four
-/five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/at/A/B/C
-/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash
-/bracketright/circumflex/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q
-/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase
-/guillemotleft/guillemotright/bullet/florin/fraction/perthousand/dagger
-/daggerdbl/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
-/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
-/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar
-/section/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus
-/registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu
-/paragraph/periodcentered/cedilla/onesuperior/ordmasculine/guilsinglright
-/onequarter/onehalf/threequarters/questiondown/Agrave/Aacute/Acircumflex/Atilde
-/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute
-/Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
-/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
-/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute
-/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve
-/oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex
-/udieresis/yacute/thorn/ydieresis]def/Times-Italic@0 ENC0/Times-Italic RE
-/Courier@0 ENC0/Courier RE/Courier-Oblique@0 ENC0/Courier-Oblique RE
-/Courier-Bold@0 ENC0/Courier-Bold RE/Times-Bold@0 ENC0/Times-Bold RE
-/Times-Roman@0 ENC0/Times-Roman RE
-%%EndProlog
-%%Page: 1 1
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Times-Bold@0 SF -.2(NA)72
-108 S(ME).2 E/F2 10/Courier-Bold@0 SF(ex, vi, view)102 120 Q F0 2.5<ad74>2.5 G
--.15(ex)187.42 120 S 2.5(te).15 G(ditors)206.43 120 Q F1(SYNOPSIS)72 144 Q F2
-(ex)102 156 Q F0([)3.333 E F2(\255eFRrsv)2.499 E F0 3.333(][).833 G F2<ad63>
--.834 E/F3 10/Courier-Oblique@0 SF(cmd)6 E F0 3.333(][).833 G F2<ad74>-.834 E
-F3(tag)6 E F0 3.333(][).833 G F2<ad77>-.834 E F3(size)6 E F0 3.333(][).833 G F3
-(file ...)330.796 156 Q F0(]).833 E F2(vi)102 168 Q F0([)3.333 E F2(\255eFRrv)
-2.499 E F0 3.333(][).833 G F2<ad63>-.834 E F3(cmd)6 E F0 3.333(][).833 G F2
-<ad74>-.834 E F3(tag)6 E F0 3.333(][).833 G F2<ad77>-.834 E F3(size)6 E F0
-3.333(][).833 G F3(file ...)324.796 168 Q F0(]).833 E F2(view)102 180 Q F0([)
-3.333 E F2(\255eFRrv)2.499 E F0 3.333(][).833 G F2<ad63>-.834 E F3(cmd)6 E F0
-3.333(][).833 G F2<ad74>-.834 E F3(tag)6 E F0 3.333(][).833 G F2<ad77>-.834 E
-F3(size)6 E F0 3.333(][).833 G F3(file ...)336.796 180 Q F0(]).833 E F1
-(DESCRIPTION)72 204 Q F2(Vi)102 216 Q F0 .176(is a screen oriented te)2.676 F
-.176(xt editor)-.15 F(.)-.55 E F2(Ex)5.176 E F0 .176(is a line-oriented te)
-2.676 F .175(xt editor)-.15 F(.)-.55 E F2(Ex)5.175 E F0(and)2.675 E F2(vi)2.675
-E F0 .175(are dif)2.675 F .175(ferent interf)-.25 F .175(aces to the)-.1 F .56
-(same program, and it is possible to switch back and forth during an edit sess\
-ion.)102 228 R F2(View)5.561 E F0 .561(is the equi)3.061 F -.25(va)-.25 G .561
-(lent of).25 F(using the)102 240 Q F2<ad52>4.166 E F0(\(read-only\) option of)
-2.5 E F2(vi)2.5 E F0(.)A .216(This manual page is the one pro)102 258 R .215
-(vided with the)-.15 F F2(nex/nvi)2.715 E F0 -.15(ve)2.715 G .215
-(rsions of the).15 F F2(ex/vi)2.715 E F0(te)2.715 E .215(xt editors.)-.15 F F2
-(Nex/nvi)5.215 E F0(are)2.715 E 1.937(intended as b)102 270 R(ug-for)-.2 E(-b)
--.2 E 1.937(ug compatible replacements for the original F)-.2 F 1.938
-(ourth Berk)-.15 F(ele)-.1 E 4.438(yS)-.15 G(oftw)456.982 270 Q 1.938
-(are Distrib)-.1 F(ution)-.2 E(\(4BSD\))102 282 Q F2(ex)3.008 E F0(and)3.008 E
-F2(vi)3.008 E F0 3.008(programs. F)3.008 F .508
-(or the rest of this manual page,)-.15 F F2(nex/nvi)3.008 E F0 .507
-(is used only when it')3.008 F 3.007(sn)-.55 G(ecessary)506.13 282 Q
-(to distinguish it from the historic implementations of)102 294 Q F2(ex/vi)2.5
-E F0(.)A .961(This manual page is intended for users already f)102 312 R .961
-(amiliar with)-.1 F F2(ex/vi)3.461 E F0 3.462(.A)C -.15(ny)397.982 312 S .962
-(one else should almost certainly).15 F .582
-(read a good tutorial on the editor before this manual page.)102 324 R .582
-(If you')5.582 F .581(re in an unf)-.5 F .581(amiliar en)-.1 F .581
-(vironment, and you)-.4 F .799(absolutely ha)102 336 R 1.099 -.15(ve t)-.2 H
-3.299(og).15 G .799(et w)184.317 336 R .799(ork done immediately)-.1 F 3.299
-(,r)-.65 G .8(ead the section after the options description, entitled `)299.803
-336 R(`F)-.74 E(ast)-.15 E(Startup')102 348 Q('. It')-.74 E 2.5(sp)-.55 G
-(robably enough to get you going.)162.09 348 Q(The follo)102 366 Q
-(wing options are a)-.25 E -.25(va)-.2 G(ilable:).25 E F2<ad63>103.666 384 Q F0
-(Ex)137 384 Q(ecute)-.15 E F3(cmd)2.675 E F0 .175
-(immediately after starting the edit session.)2.675 F -.15(Pa)5.175 G .174
-(rticularly useful for initial positioning in).15 F .624(the \214le, ho)137 396
-R(we)-.25 E -.15(ve)-.25 G(r).15 E F3(cmd)3.124 E F0 .625
-(is not limited to positioning commands.)3.124 F .625
-(This is the POSIX 1003.2 interf)5.625 F(ace)-.1 E(for the historic `)137 408 Q
-(`+cmd')-.74 E 2.5('s)-.74 G(yntax.)239.47 408 Q F2(Nex/nvi)5 E F0
-(supports both the old and ne)2.5 E 2.5(ws)-.25 G(yntax.)440.1 408 Q F2<ad65>
-103.666 426 Q F0(Start editing in e)137 426 Q 2.5(xm)-.15 G
-(ode, as if the command name were)218.52 426 Q F2(ex)2.5 E F0(.)A F2<ad46>
-103.666 444 Q F0(Don')137 444 Q 2.677(tc)-.18 G(op)167.267 444 Q 2.677(yt)-.1 G
-.177(he entire \214le when \214rst starting to edit.)187.624 444 R .177
-(\(The def)5.177 F .177(ault is to mak)-.1 F 2.677(eac)-.1 G(op)456.532 444 Q
-2.676(yi)-.1 G 2.676(nc)476.888 444 S .176(ase someone)489.004 444 R
-(else modi\214es the \214le during your edit session.\))137 456 Q F2<ad52>
-103.666 474 Q F0 .184
-(Start editing in read-only mode, as if the command name w)137 474 R(as)-.1 E
-F2(view)2.685 E F0 2.685(,o)C 2.685(rt)421.415 474 S .185(he readonly option w)
-430.21 474 R .185(as set.)-.1 F F2<ad72>103.666 492 Q F0(Reco)137 492 Q -.15
-(ve)-.15 G 2.627(rt).15 G .127(he speci\214ed \214les, or)175.427 492 R 2.627
-(,i)-.4 G 2.627(fn)263.305 492 S 2.627<6f8c>274.262 492 S .127
-(les are speci\214ed, list the \214les that could be reco)287.449 492 R -.15
-(ve)-.15 G 2.626(red. If).15 F .126(no re-)2.626 F(co)137 504 Q -.15(ve)-.15 G
-.4(rable \214les by the speci\214ed name e).15 F .401
-(xist, the \214le is edited as if the)-.15 F F2<ad72>4.567 E F0 .401
-(option had not been speci-)2.901 F(\214ed.)137 516 Q F2<ad73>103.666 534 Q F0
-1.621(Enter batch mode; applicable only to)137 534 R F2(ex)4.121 E F0 1.621
-(edit sessions.)4.121 F 1.62(Batch mode is useful when running)6.621 F F2(ex)
-4.12 E F0 2.647(scripts. Prompts,)137 546 R(informati)2.647 E .447 -.15(ve m)
--.25 H .147(essages and other user oriented message are turned of).15 F .148
-(f, and no start-)-.25 F .067(up \214les or en)137 558 R .067(vironmental v)-.4
-F .066(ariables are read.)-.25 F .066(This is the POSIX 1003.2 interf)5.066 F
-.066(ace for the historic `)-.1 F(`\255')-.74 E(')-.74 E(ar)137 570 Q(gument.)
--.18 E F2(Nex/nvi)5 E F0(supports both the old and ne)2.5 E 2.5(ws)-.25 G
-(yntax.)353 570 Q F2<ad74>103.666 588 Q F0
-(Start editing at the speci\214ed tag.)137 588 Q(\(See)5 E/F4 10/Courier@0 SF
-(ctags)2.5 E F0(\(1\)\).)A F2<ad77>103.666 606 Q F0(Set the initial windo)137
-606 Q 2.5(ws)-.25 G(ize to the speci\214ed number of lines.)231.2 606 Q F2
-<ad76>103.666 624 Q F0(Start editing in vi mode, as if the command name w)137
-624 Q(as)-.1 E F2(vi)2.5 E F0(or)2.5 E F2(view)2.5 E F0(.)A F2<ad58>103.666 642
-Q F0(Reserv)137 642 Q(ed for X11 interf)-.15 E(aces.)-.1 E/F5 10/Times-Italic@0
-SF(No X11 support is curr)5 E(ently implemented.)-.37 E F0 .35
-(Command input for)102 660 R F2(ex/vi)2.85 E F0 .35
-(is read from the standard input.)2.85 F .35(In the)5.35 F F2(vi)2.85 E F0
-(interf)2.85 E .35(ace, it is an error if standard in-)-.1 F .343
-(put is not a terminal.)102 672 R .343(In the)5.343 F F2(ex)2.843 E F0(interf)
-2.843 E .343(ace, if standard input is not a terminal,)-.1 F F2(ex)2.843 E F0
-.342(will read commands from it)2.843 F(re)102 684 Q -.05(ga)-.15 G .137
-(rdless, ho).05 F(we)-.25 E -.15(ve)-.25 G .937 -.4(r, t).15 H .137
-(he session will be a batch mode session, e).4 F .138(xactly as if the)-.15 F
-F2<ad73>4.304 E F0 .138(option had been speci\214ed.)2.638 F 172.465
-(4.4BSD July)72 750 R(15, 1994)2.5 E(1)535 750 Q EP
-%%Page: 2 2
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Courier-Bold@0 SF(Ex/vi)102
-96 Q F0 -.15(ex)2.5 G(its 0 on success, and greater than 0 if an error occurs.)
-.15 E/F2 10/Times-Bold@0 SF -.9(FA)72 120 S 1.666(ST ST).9 F(AR)-.9 E(TUP)-.4 E
-F0 .467(This section will tell you the minimum amount that you need to do simp\
-le editing tasks using)102 132 R F1(vi)2.966 E F0 2.966(.I)C 2.966(fy)506.584
-132 S(ou')517.88 132 Q -.15(ve)-.5 G(ne)102 144 Q -.15(ve)-.25 G 3.453(ru).15 G
-.953(sed an)132.263 144 R 3.453(ys)-.15 G .953(creen editor before, you')
-170.679 144 R .953(re lik)-.5 F .953(ely to ha)-.1 F 1.253 -.15(ve p)-.2 H .953
-(roblems e).15 F -.15(ve)-.25 G 3.453(nw).15 G .953
-(ith this simple introduction.)412.286 144 R(In)5.954 E
-(that case you should \214nd someone that already kno)102 156 Q(ws)-.25 E F1
-(vi)2.5 E F0(and ha)2.5 E .3 -.15(ve t)-.2 H(hem w).15 E
-(alk you through this section.)-.1 E F1(Vi)102 174 Q F0 .294
-(is a screen editor)2.794 F 5.294(.T)-.55 G .294(his means that it tak)198.51
-174 R .293
-(es up almost the entire screen, displaying part of the \214le on each)-.1 F
-.001(screen line, e)102 186 R .001(xcept for the last line of the screen.)-.15
-F .002(The last line of the screen is used for you to gi)5.001 F .302 -.15
-(ve c)-.25 H(ommands).15 E(to)102 198 Q F1(vi)2.5 E F0 2.5(,a)C(nd for)133.72
-198 Q F1(vi)2.5 E F0(to gi)2.5 E .3 -.15(ve i)-.25 H(nformation to you.).15 E
-.585(The other f)102 216 R .585(act that you need to understand is that)-.1 F
-F1(vi)3.085 E F0 .585(is a modeful editor)3.085 F 3.085(,i)-.4 G .584
-(.e. you are either entering te)406.125 216 R .584(xt or)-.15 F .836(you are e)
-102 228 R -.15(xe)-.15 G .836(cuting commands, and you ha).15 F 1.137 -.15
-(ve t)-.2 H 3.337(ob).15 G 3.337(ei)301.062 228 S 3.337(nt)311.619 228 S .837
-(he right mode to do one or the other)322.736 228 R 5.837(.Y)-.55 G .837
-(ou will be in)487.209 228 R 1.094
-(command mode when you \214rst start editing a \214le.)102 240 R 1.093
-(There are commands that switch you into input mode.)6.094 F .084
-(There is only one k)102 252 R .384 -.15(ey t)-.1 H .085(hat tak).15 F .085
-(es you out of input mode, and that is the <escape> k)-.1 F -.15(ey)-.1 G 5.085
-(.\()-.5 G -2.15 -.25(Ke y)449.895 252 T .085(names are written)2.835 F 1.473
-(using less-than and greater)102 264 R 1.473(-than signs, e.g.)-.2 F 1.473
-(<escape> means the `)6.473 F(`escape')-.74 E 3.973('k)-.74 G -.15(ey)420.59
-264 S 3.973(,u)-.5 G 1.473(sually labeled `)440.703 264 R(`esc')-.74 E 3.972
-('o)-.74 G(n)535 264 Q .553(your terminal')102 276 R 3.053(sk)-.55 G -.15(ey)
-171.336 276 S 3.053(board.\) If).15 F(you')3.053 E .554(re e)-.5 F -.15(ve)-.25
-G 3.054(rc).15 G .554(onfused as to which mode you')277.45 276 R .554(re in, k)
--.5 F .554(eep entering the <escape>)-.1 F -.1(ke)102 288 S 2.615(yu)-.05 G
-(ntil)123.805 288 Q F1(vi)2.615 E F0 .115(beeps at you.)2.615 F(\(Generally)
-5.115 E(,)-.65 E F1(vi)2.615 E F0 .115
-(will beep at you if you try and do something that')2.615 F 2.614(sn)-.55 G
-.114(ot allo)484.472 288 R 2.614(wed. It)-.25 F
-(will also display error messages.\))102 300 Q 2.057 -.8(To s)102 318 T .457
-(tart editing a \214le, enter the command `).8 F(`)-.74 E/F3 10/Courier@0 SF
-.458(vi file_name<carriage-return>)B F0 -.74('')C 2.958(.T).74 G .458
-(he command you)470.204 318 R .333
-(should enter as soon as you start editing is `)102 330 R(`)-.74 E F3 .333
-(:set verbose showmode<carriage-return>)B F0 -.74('')C 2.833(.T).74 G(his)
-528.33 330 Q 1.441(will mak)102 342 R 3.941(et)-.1 G 1.441(he editor gi)149.782
-342 R 1.741 -.15(ve y)-.25 H 1.441(ou v).15 F 1.441
-(erbose error messages and display the current mode at the bottom of the)-.15 F
-(screen.)102 354 Q(The commands to mo)102 372 Q .3 -.15(ve a)-.15 H
-(round the \214le are:).15 E F2(h)102 384 Q F0(Mo)131 384 Q .3 -.15(ve t)-.15 H
-(he cursor left one character).15 E(.)-.55 E F2(j)102 396 Q F0(Mo)131 396 Q .3
--.15(ve t)-.15 H(he cursor do).15 E(wn one line.)-.25 E F2(k)102 408 Q F0(Mo)
-131 408 Q .3 -.15(ve t)-.15 H(he cursor up one line.).15 E F2(l)102 420 Q F0
-(Mo)131 420 Q .3 -.15(ve t)-.15 H(he cursor right one character).15 E(.)-.55 E
-F2(<cursor)102 432 Q(-arr)-.37 E -.1(ow)-.18 G(s>).1 E F0(The cursor arro)131
-444 Q 2.5(wk)-.25 G -.15(ey)207.01 444 S 2.5(ss).15 G(hould w)226.58 444 Q
-(ork, too.)-.1 E F2(/text<carriage-r)102 456 Q(etur)-.18 E(n>)-.15 E F0
-(Search for the string `)131 468 Q(`te)-.74 E(xt')-.15 E 2.5('i)-.74 G 2.5(nt)
-246.84 468 S(he \214le, and mo)257.12 468 Q .3 -.15(ve t)-.15 H
-(he cursor to its \214rst character).15 E(.)-.55 E(The commands to enter ne)102
-486 Q 2.5(wt)-.25 G -.15(ex)220.34 486 S 2.5(ta).15 G(re:)239.35 486 Q F2(a)102
-498 Q F0(Append ne)131 498 Q 2.5(wt)-.25 G -.15(ex)186.85 498 S(t,).15 E/F4 10
-/Times-Italic@0 SF(after)2.5 E F0(the cursor)2.5 E(.)-.55 E F2(i)102 510 Q F0
-(Insert ne)131 510 Q 2.5(wt)-.25 G -.15(ex)177.96 510 S(t,).15 E F4(befor)2.5 E
-(e)-.37 E F0(the cursor)2.5 E(.)-.55 E F2(o)102 522 Q F0(Open a ne)131 522 Q
-2.5(wl)-.25 G(ine belo)183.79 522 Q 2.5(wt)-.25 G
-(he line the cursor is on, and start entering te)227.98 522 Q(xt.)-.15 E F2(O)
-102 534 Q F0(Open a ne)131 534 Q 2.5(wl)-.25 G(ine abo)183.79 534 Q .3 -.15
-(ve t)-.15 H(he line the cursor is on, and start entering te).15 E(xt.)-.15 E
-F2(<escape>)102 546 Q F0 .744(Once you')131 558 R 1.044 -.15(ve e)-.5 H .744
-(ntered input mode using the one of the).15 F F2(a)3.244 E F0(,)A F2(i)3.244 E
-F0(,)A F2(O)3.244 E F0 3.244(,o)C(r)390.542 558 Q F2(o)3.243 E F0 .743
-(commands, use)3.243 F F2(<escape>)3.243 E F0 .743(to quit)3.243 F(entering te)
-131 570 Q(xt and return to command mode.)-.15 E(The commands to cop)102 588 Q
-2.5(yt)-.1 G -.15(ex)200.78 588 S 2.5(ta).15 G(re:)219.79 588 Q F2(yy)102 600 Q
-F0(Cop)131 600 Q 2.5(yt)-.1 G(he line the cursor is on.)157.85 600 Q F2(p)102
-612 Q F0(Append the copied line after the line the cursor is on.)131 612 Q
-(The commands to delete te)102 630 Q(xt are:)-.15 E F2(dd)102 642 Q F0
-(Delete the line the cursor is on.)131 642 Q F2(x)102 654 Q F0
-(Delete the character the cursor is on.)131 654 Q
-(The commands to write the \214le are:)102 672 Q F2(:w<carriage-r)102 684 Q
-(etur)-.18 E(n>)-.15 E F0 .528(Write the \214le back to the \214le with the na\
-me that you originally used as an ar)131 696 R .528(gument on the)-.18 F F1(vi)
-3.028 E F0(com-)3.028 E 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(2)535 750 Q
-EP
-%%Page: 3 3
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R(mand line.)131 96 Q/F1 10
-/Times-Bold@0 SF(:w \214le_name<carriage-r)102 108 Q(etur)-.18 E(n>)-.15 E F0
-(Write the \214le back to the \214le with the name `)131 120 Q(`\214le_name')
--.74 E('.)-.74 E(The commands to quit editing and e)102 138 Q
-(xit the editor are:)-.15 E F1(:q<carriage-r)102 150 Q(etur)-.18 E(n>)-.15 E F0
-.848(Quit editing and lea)131 162 R 1.148 -.15(ve v)-.2 H 3.348(i\().15 G .848
-(if you')239.6 162 R 1.148 -.15(ve m)-.5 H .848(odi\214ed the \214le, b).15 F
-.848(ut not sa)-.2 F -.15(ve)-.2 G 3.348(dy).15 G .848(our changes,)415.454 162
-R/F2 10/Courier-Bold@0 SF(vi)3.347 E F0 .847(will refuse to)3.347 F(quit\).)131
-174 Q F1(:q!<carriage-r)102 186 Q(etur)-.18 E(n>)-.15 E F0(Quit, discarding an)
-131 198 Q 2.5(ym)-.15 G(odi\214cations that you may ha)222.51 198 Q .3 -.15
-(ve m)-.2 H(ade.).15 E .686(One \214nal caution.)102 216 R .686
-(Unusual characters can tak)5.686 F 3.187(eu)-.1 G 3.187(pm)302.483 216 S .687
-(ore than one column on the screen, and long lines can)318.45 216 R(tak)102 228
-Q 3.129(eu)-.1 G 3.129(pm)126.689 228 S .629(ore than a single screen line.)
-142.598 228 R .629(The abo)5.629 F .929 -.15(ve c)-.15 H .629(ommands w).15 F
-.629(ork on `)-.1 F(`ph)-.74 E(ysical')-.05 E 3.129('c)-.74 G .628
-(haracters and lines, i.e.)446.476 228 R(the)102 240 Q 2.74(ya)-.15 G -.25(ff)
-126.25 240 S .24(ect the entire line no matter ho).25 F 2.74(wm)-.25 G(an)
-273.79 240 Q 2.74(ys)-.15 G .241(creen lines it tak)294.71 240 R .241
-(es up and the entire character no matter ho)-.1 F(w)-.25 E(man)102 252 Q 2.5
-(ys)-.15 G(creen columns it tak)130.46 252 Q(es up.)-.1 E F1 1.666(VI COMMANDS)
-72 276 R F0 .186(The follo)102 288 R .186
-(wing section describes the commands a)-.25 F -.25(va)-.2 G .186
-(ilable in the command mode of the).25 F F2(vi)2.686 E F0(editor)2.686 E 5.186
-(.I)-.55 G 2.685(ne)498.54 288 S .185(ach en-)510.665 288 R(try belo)102 300 Q
-1.3 -.65(w, t)-.25 H(he tag line is a usage synopsis for the command character)
-.65 E(.)-.55 E F1([count] <contr)102 324 Q(ol-A>)-.18 E F0(Search forw)131 336
-Q(ard)-.1 E/F3 10/Courier@0 SF(count)2.5 E F0(times for the current w)2.5 E
-(ord.)-.1 E F1([count] <contr)102 348 Q(ol-B>)-.18 E F0 -.15(Pa)131 360 S
-(ge backw).15 E(ards)-.1 E F3(count)2.5 E F0(screens.)2.5 E F1([count] <contr)
-102 372 Q(ol-D>)-.18 E F0(Scroll forw)131 384 Q(ard)-.1 E F3(count)2.5 E F0
-(lines.)2.5 E F1([count] <contr)102 396 Q(ol-E>)-.18 E F0(Scroll forw)131 408 Q
-(ard)-.1 E F3(count)2.5 E F0(lines, lea)2.5 E
-(ving the current line and column as is, if possible.)-.2 E F1([count] <contr)
-102 420 Q(ol-F>)-.18 E F0 -.15(Pa)131 432 S(ge forw).15 E(ard)-.1 E F3(count)
-2.5 E F0(screens.)2.5 E F1(<contr)102 444 Q(ol-G>)-.18 E F0
-(Display the \214le information.)131 456 Q F1(<contr)102 468 Q(ol-H>)-.18 E
-([count] h)102 480 Q F0(Mo)131 492 Q .3 -.15(ve t)-.15 H(he cursor back).15 E
-F3(count)2.5 E F0(characters in the current line.)2.5 E F1([count] <contr)102
-504 Q(ol-J>)-.18 E([count] <contr)102 516 Q(ol-N>)-.18 E([count] j)102 528 Q F0
-(Mo)131 540 Q .3 -.15(ve t)-.15 H(he cursor do).15 E(wn)-.25 E F3(count)2.5 E
-F0(lines without changing the current column.)2.5 E F1(<contr)102 552 Q(ol-L>)
--.18 E(<contr)102 564 Q(ol-R>)-.18 E F0(Repaint the screen.)131 576 Q F1
-([count] <contr)102 588 Q(ol-M>)-.18 E([count] +)102 600 Q F0(Mo)131 612 Q .3
--.15(ve t)-.15 H(he cursor do).15 E(wn)-.25 E F3(count)2.5 E F0
-(lines to the \214rst nonblank character of that line.)2.5 E F1([count] <contr)
-102 624 Q(ol-P>)-.18 E([count] k)102 636 Q F0(Mo)131 648 Q .3 -.15(ve t)-.15 H
-(he cursor up).15 E F3(count)2.5 E F0
-(lines, without changing the current column.)2.5 E F1(<contr)102 660 Q(ol-T>)
--.18 E F0(Return to the most recent tag conte)131 672 Q(xt.)-.15 E F1(<contr)
-102 684 Q(ol-U>)-.18 E F0 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(3)535 750
-Q EP
-%%Page: 4 4
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R(Scroll backw)131 96 Q(ards)-.1 E
-/F1 10/Courier@0 SF(count)2.5 E F0(lines.)2.5 E/F2 10/Times-Bold@0 SF(<contr)
-102 108 Q(ol-W>)-.18 E F0 .635(Switch to the ne)131 120 R .635(xt lo)-.15 F
-.635(wer screen in the windo)-.25 F 1.935 -.65(w, o)-.25 H 1.435 -.4(r, t).65 H
-3.135(ot).4 G .635(he \214rst screen if there are no lo)353.205 120 R .635
-(wer screens in)-.25 F(the windo)131 132 Q -.65(w.)-.25 G F2(<contr)102 144 Q
-(ol-Y>)-.18 E F0(Scroll backw)131 156 Q(ards)-.1 E F1(count)2.5 E F0
-(lines, lea)2.5 E(ving the current line and column as is, if possible.)-.2 E F2
-(<contr)102 168 Q(ol-Z>)-.18 E F0(Suspend the current editor session.)131 180 Q
-F2(<escape>)102 192 Q F0(Ex)131 204 Q(ecute)-.15 E/F3 10/Courier-Bold@0 SF(ex)
-2.5 E F0(commands or cancel partial commands.)2.5 E F2(<contr)102 216 Q(ol-]>)
--.18 E F0(Push a tag reference onto the tag stack.)131 228 Q F2(<contr)102 240
-Q(ol-^>)-.18 E F0(Switch to the most recently edited \214le.)131 252 Q F2
-([count] <space>)102 264 Q([count] l)102 276 Q F0(Mo)131 288 Q .3 -.15(ve t)
--.15 H(he cursor forw).15 E(ard)-.1 E F1(count)2.5 E F0
-(characters without changing the current line.)2.5 E F2
-([count] ! motion shell-ar)102 300 Q(gument\(s\))-.1 E F0(Replace te)131 312 Q
-(xt with results from a shell command.)-.15 E F2([count] # +|-|#)102 324 Q F0
-(Increment or decrement the cursor number)131 336 Q(.)-.55 E F2([count] $)102
-348 Q F0(Mo)131 360 Q .3 -.15(ve t)-.15 H(he cursor to the end of a line.).15 E
-F2(%)102 372 Q F0(Mo)131 372 Q .3 -.15(ve t)-.15 H 2.5(ot).15 G
-(he matching character)169.59 372 Q(.)-.55 E F2(&)102 384 Q F0(Repeat the pre)
-131 384 Q(vious substitution command on the current line.)-.25 E F2
-('<character>)102 396 Q(`<character>)102 408 Q F0(Return to a conte)131 420 Q
-(xt mark)-.15 E(ed by the character)-.1 E F1(<character>)2.5 E F0(.)A F2
-([count] \()102 432 Q F0(Back up)131 444 Q F1(count)2.5 E F0(sentences.)2.5 E
-F2([count] \))102 456 Q F0(Mo)131 468 Q .3 -.15(ve f)-.15 H(orw).15 E(ard)-.1 E
-F1(count)2.5 E F0(sentences.)2.5 E F2([count] ,)102 480 Q F0(Re)131 492 Q -.15
-(ve)-.25 G(rse \214nd character).15 E F1(count)2.5 E F0(times.)2.5 E F2
-([count] -)102 504 Q F0(Mo)131 516 Q .3 -.15(ve t)-.15 H 2.5<6f8c>.15 G
-(rst nonblank of the pre)172.37 516 Q(vious line,)-.25 E F1(count)2.5 E F0
-(times.)2.5 E F2([count] .)102 528 Q F0(Repeat the last)131 540 Q F3(vi)2.5 E
-F0(command that modi\214ed te)2.5 E(xt.)-.15 E F2(/RE<carriage-r)102 552 Q
-(etur)-.18 E(n>)-.15 E(/RE/ [offset]<carriage-r)102 564 Q(etur)-.18 E(n>)-.15 E
-(?RE<carriage-r)102 576 Q(etur)-.18 E(n>)-.15 E(?RE? [offset]<carriage-r)102
-588 Q(etur)-.18 E(n>)-.15 E(N)102 600 Q(n)102 612 Q F0(Search forw)131 612 Q
-(ard or backw)-.1 E(ard for a re)-.1 E(gular e)-.15 E(xpression.)-.15 E F2(0)
-102 624 Q F0(Mo)131 624 Q .3 -.15(ve t)-.15 H 2.5(ot).15 G
-(he \214rst character in the current line.)169.59 624 Q 26.22(:E)102 636 S -.15
-(xe)137.11 636 S(cute an e).15 E 2.5(xc)-.15 G(ommand.)193.73 636 Q F2
-([count] ;)102 648 Q F0(Repeat the last character \214nd)131 660 Q F1(count)2.5
-E F0(times.)2.5 E F2([count] < motion)102 672 Q F0 172.465(4.4BSD July)72 750 R
-(15, 1994)2.5 E(4)535 750 Q EP
-%%Page: 5 5
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Times-Bold@0 SF
-([count] > motion)102 96 Q F0(Shift lines left or right.)131 108 Q F1 2.5(@b)
-102 120 S(uffer)119.16 120 Q F0(Ex)131 132 Q(ecute a named b)-.15 E(uf)-.2 E
-(fer)-.25 E(.)-.55 E F1([count] A)102 144 Q F0
-(Enter input mode, appending the te)131 156 Q(xt after the end of the line.)
--.15 E F1([count] B)102 168 Q F0(Mo)131 180 Q .3 -.15(ve b)-.15 H(ackw).15 E
-(ards)-.1 E/F2 10/Courier@0 SF(count)2.5 E F0(bigw)2.5 E(ords.)-.1 E F1([b)102
-192 Q(uffer] [count] C)-.2 E F0(Change te)131 204 Q
-(xt from the current position to the end-of-line.)-.15 E F1([b)102 216 Q
-(uffer] D)-.2 E F0(Delete te)131 228 Q
-(xt from the current position to the end-of-line.)-.15 E F1([count] E)102 240 Q
-F0(Mo)131 252 Q .3 -.15(ve f)-.15 H(orw).15 E(ard)-.1 E F2(count)2.5 E F0
-(end-of-bigw)2.5 E(ords.)-.1 E F1([count] F <character>)102 264 Q F0(Search)131
-276 Q F2(count)2.5 E F0(times backw)2.5 E(ard through the current line for)-.1
-E F2(<character>)2.5 E F0(.)A F1([count] G)102 288 Q F0(Mo)131 300 Q .3 -.15
-(ve t)-.15 H 2.5(ol).15 G(ine)169.59 300 Q F2(count)2.5 E F0 2.5(,o)C 2.5(rt)
-224.31 300 S(he last line of the \214le if)232.92 300 Q F2(count)2.5 E F0
-(not speci\214ed.)2.5 E F1([count] H)102 312 Q F0(Mo)131 324 Q .3 -.15(ve t)
--.15 H 2.5(ot).15 G(he screen line)169.59 324 Q F2(count - 1)2.5 E F0
-(lines belo)2.5 E 2.5(wt)-.25 G(he top of the screen.)334.43 324 Q F1
-([count] I)102 336 Q F0(Enter input mode, inserting the te)131 348 Q
-(xt at the be)-.15 E(ginning of the line.)-.15 E F1([count] J)102 360 Q F0
-(Join lines.)131 372 Q F1([count] L)102 384 Q F0(Mo)131 396 Q .3 -.15(ve t)-.15
-H 2.5(ot).15 G(he screen line)169.59 396 Q F2(count - 1)2.5 E F0(lines abo)2.5
-E .3 -.15(ve t)-.15 H(he bottom of the screen.).15 E F1(M)102 408 Q F0(Mo)131
-408 Q .3 -.15(ve t)-.15 H 2.5(ot).15 G
-(he screen line in the middle of the screen.)169.59 408 Q F1([count] O)102 420
-Q F0(Enter input mode, appending te)131 432 Q(xt in a ne)-.15 E 2.5(wl)-.25 G
-(ine abo)305.86 432 Q .3 -.15(ve t)-.15 H(he current line.).15 E F1([b)102 444
-Q(uffer] P)-.2 E F0(Insert te)131 456 Q(xt from a b)-.15 E(uf)-.2 E(fer)-.25 E
-(.)-.55 E F1(Q)102 468 Q F0(Exit)131 468 Q/F3 10/Courier-Bold@0 SF(vi)2.5 E F0
-(\(or visual\) mode and switch to)2.5 E F3(ex)2.5 E F0(mode.)2.5 E F1
-([count] R)102 480 Q F0
-(Enter input mode, replacing the characters in the current line.)131 492 Q F1
-([b)102 504 Q(uffer] [count] S)-.2 E F0(Substitute)131 516 Q F2(count)2.5 E F0
-(lines.)2.5 E F1([count] T <character>)102 528 Q F0 2.78(Search backw)131 540 R
-(ards,)-.1 E F2(count)5.28 E F0 2.779
-(times, through the current line for the character)5.28 F/F4 10/Times-Italic@0
-SF(after)5.279 E F0 2.779(the speci\214ed)5.279 F F2(<character>)131 552 Q F0
-(.)A F1(U)102 564 Q F0
-(Restore the current line to its state before the cursor last mo)131 564 Q -.15
-(ve)-.15 G 2.5(dt).15 G 2.5(oi)388.99 564 S(t.)399.27 564 Q F1([count] W)102
-576 Q F0(Mo)131 588 Q .3 -.15(ve f)-.15 H(orw).15 E(ard)-.1 E F2(count)2.5 E F0
-(bigw)2.5 E(ords.)-.1 E F1([b)102 600 Q(uffer] [count] X)-.2 E F0(Delete)131
-612 Q F2(count)2.5 E F0(characters before the cursor)2.5 E(.)-.55 E F1([b)102
-624 Q(uffer] [count] Y)-.2 E F0(Cop)131 636 Q 2.5(y\()-.1 G(or `)158.4 636 Q
-(`yank')-.74 E('\))-.74 E F2(count)2.5 E F0(lines into the speci\214ed b)2.5 E
-(uf)-.2 E(fer)-.25 E(.)-.55 E F1(ZZ)102 648 Q F0(Write the \214le and e)131 648
-Q(xit)-.15 E F3(vi)2.5 E F0(.)A F1([count] [[)102 660 Q F0(Back up)131 672 Q F2
-(count)2.5 E F0(section boundaries.)2.5 E F1([count] ]])102 684 Q F0 172.465
-(4.4BSD July)72 750 R(15, 1994)2.5 E(5)535 750 Q EP
-%%Page: 6 6
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R(Mo)131 96 Q .3 -.15(ve f)-.15 H
-(orw).15 E(ard)-.1 E/F1 10/Courier@0 SF(count)2.5 E F0(section boundaries.)2.5
-E/F2 10/Times-Bold@0 SF(^)102 108 Q F0(Mo)131 108 Q .3 -.15(ve t)-.15 H 2.5
-<6f8c>.15 G(rst nonblank character on the current line.)172.37 108 Q F2
-([count] _)102 120 Q F0(Mo)131 132 Q .3 -.15(ve d)-.15 H -.25(ow).15 G(n).25 E
-F1(count - 1)2.5 E F0(lines, to the \214rst nonblank character)2.5 E(.)-.55 E
-F2([count] a)102 144 Q F0(Enter input mode, appending the te)131 156 Q
-(xt after the cursor)-.15 E(.)-.55 E F2([count] b)102 168 Q F0(Mo)131 180 Q .3
--.15(ve b)-.15 H(ackw).15 E(ards)-.1 E F1(count)2.5 E F0 -.1(wo)2.5 G(rds.).1 E
-F2([b)102 192 Q(uffer] [count] c motion)-.2 E F0(Change a re)131 204 Q
-(gion of te)-.15 E(xt.)-.15 E F2([b)102 216 Q(uffer] [count] d motion)-.2 E F0
-(Delete a re)131 228 Q(gion of te)-.15 E(xt.)-.15 E F2([count] e)102 240 Q F0
-(Mo)131 252 Q .3 -.15(ve f)-.15 H(orw).15 E(ard)-.1 E F1(count)2.5 E F0
-(end-of-w)2.5 E(ords.)-.1 E F2([count] f<character>)102 264 Q F0(Search forw)
-131 276 Q(ard,)-.1 E F1(count)2.5 E F0
-(times, through the rest of the current line for)2.5 E F1(<character>)2.5 E F0
-(.)A F2([count] i)102 288 Q F0(Enter input mode, inserting the te)131 300 Q
-(xt before the cursor)-.15 E(.)-.55 E F2 2.5(m<)102 312 S(character>)118.53 312
-Q F0(Sa)131 324 Q .3 -.15(ve t)-.2 H(he current conte).15 E
-(xt \(line and column\) as)-.15 E F1(<character>)2.5 E F0(.)A F2([count] o)102
-336 Q F0(Enter input mode, appending te)131 348 Q(xt in a ne)-.15 E 2.5(wl)-.25
-G(ine under the current line.)305.86 348 Q F2([b)102 360 Q(uffer] p)-.2 E F0
-(Append te)131 372 Q(xt from a b)-.15 E(uf)-.2 E(fer)-.25 E(.)-.55 E F2
-([count] r <character>)102 384 Q F0(Replace)131 396 Q F1(count)2.5 E F0
-(characters.)2.5 E F2([b)102 408 Q(uffer] [count] s)-.2 E F0(Substitute)131 420
-Q F1(count)2.5 E F0
-(characters in the current line starting with the current character)2.5 E(.)
--.55 E F2([count] t <character>)102 432 Q F0 3.435(Search forw)131 444 R(ard,)
--.1 E F1(count)5.935 E F0 3.435
-(times, through the current line for the character immediately)5.935 F/F3 10
-/Times-Italic@0 SF(befor)5.935 E(e)-.37 E F1(<character>)131 456 Q F0(.)A F2(u)
-102 468 Q F0(Undo the last change made to the \214le.)131 468 Q F2([count] w)
-102 480 Q F0(Mo)131 492 Q .3 -.15(ve f)-.15 H(orw).15 E(ard)-.1 E F1(count)2.5
-E F0 -.1(wo)2.5 G(rds.).1 E F2([b)102 504 Q(uffer] [count] x)-.2 E F0(Delete)
-131 516 Q F1(count)2.5 E F0(characters.)2.5 E F2([b)102 528 Q
-(uffer] [count] y motion)-.2 E F0(Cop)131 540 Q 2.5(y\()-.1 G(or `)158.4 540 Q
-(`yank')-.74 E('\) a te)-.74 E(xt re)-.15 E(gion speci\214ed by the)-.15 E F1
-(count)2.5 E F0(and motion into a b)2.5 E(uf)-.2 E(fer)-.25 E(.)-.55 E F2
-([count1] z [count2] -|.|+|^|<carriage-r)102 552 Q(etur)-.18 E(n>)-.15 E F0
-(Redra)131 564 Q 1.3 -.65(w, o)-.15 H
-(ptionally repositioning and resizing the screen.).65 E F2([count] {)102 576 Q
-F0(Mo)131 588 Q .3 -.15(ve b)-.15 H(ackw).15 E(ard)-.1 E F1(count)2.5 E F0
-(paragraphs.)2.5 E F2([count] |)102 600 Q F0(Mo)131 612 Q .3 -.15(ve t)-.15 H
-2.5(oas).15 G(peci\214c)177.64 612 Q F3(column)2.5 E F0
-(position on the current line.)2.5 E F2([count] })102 624 Q F0(Mo)131 636 Q .3
--.15(ve f)-.15 H(orw).15 E(ard)-.1 E F1(count)2.5 E F0(paragraphs.)2.5 E F2
-([count] ~)102 648 Q F0(Re)131 660 Q -.15(ve)-.25 G(rse the case of the ne).15
-E(xt)-.15 E F1(count)2.5 E F0(character\(s\).)2.5 E F2([count] ~ motion)102 672
-Q F0 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(6)535 750 Q EP
-%%Page: 7 7
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R(Re)131 96 Q -.15(ve)-.25 G
-(rse the case of the characters in a te).15 E(xt re)-.15 E
-(gion speci\214ed by the)-.15 E/F1 10/Courier@0 SF(count)2.5 E F0(and)2.5 E F1
-(motion)2.5 E F0(.)A/F2 10/Times-Bold@0 SF(<interrupt>)102 108 Q F0
-(Interrupt the current operation.)131 120 Q F2 1.666(VI TEXT INPUT COMMANDS)72
-144 R F0(The follo)102 156 Q(wing section describes the commands a)-.25 E -.25
-(va)-.2 G(ilable in the te).25 E(xt input mode of the)-.15 E/F3 10
-/Courier-Bold@0 SF(vi)2.5 E F0(editor)2.5 E(.)-.55 E F2(<nul>)102 174 Q F0
-(Replay the pre)131 186 Q(vious input.)-.25 E F2(<contr)102 198 Q(ol-D>)-.18 E
-F0(Erase the pre)131 210 Q(vious autoindent character)-.25 E(.)-.55 E F2
-(^<contr)102 222 Q(ol-D>)-.18 E F0
-(Erase all of the autoindent characters, and reset the autoindent le)131 234 Q
--.15(ve)-.25 G(l.).15 E F2(0<contr)102 246 Q(ol-D>)-.18 E F0
-(Erase all of the autoindent characters.)131 258 Q F2(<contr)102 270 Q(ol-T>)
--.18 E F0 .076(Insert suf)131 282 R(\214cient)-.25 E F1(<tab>)2.576 E F0(and)
-2.576 E F1(<space>)2.576 E F0 .076(characters to mo)2.576 F .376 -.15(ve t)-.15
-H .076(he cursor forw).15 F .075(ard to a column immediate-)-.1 F
-(ly after the ne)131 294 Q(xt column which is an e)-.15 E -.15(ve)-.25 G 2.5
-(nm).15 G(ultiple of the)305.7 294 Q F2(shiftwidth)2.5 E F0(option.)2.5 E F2
-(<erase>)102 306 Q(<contr)102 318 Q(ol-H>)-.18 E F0(Erase the last character)
-131 330 Q(.)-.55 E F2(<literal next>)102 342 Q F0(Quote the ne)131 354 Q
-(xt character)-.15 E(.)-.55 E F2(<escape>)102 366 Q F0(Resolv)131 378 Q 2.5(ea)
--.15 G(ll te)170.01 378 Q
-(xt input into the \214le, and return to command mode.)-.15 E F2(<line erase>)
-102 390 Q F0(Erase the current line.)131 402 Q F2(<contr)102 414 Q(ol-W>)-.18 E
-(<w)102 426 Q(ord erase>)-.1 E F0(Erase the last w)131 438 Q 2.5(ord. The)-.1 F
-(de\214nition of w)2.5 E(ord is dependent on the)-.1 E F2(altwerase)2.5 E F0
-(and)2.5 E F2(ttywerase)2.5 E F0(options.)2.5 E F2(<contr)102 450 Q
-(ol-X>[0-9A-F)-.18 E(a-f])-.25 E/F4 10/Symbol SF(*)A F0
-(Insert a character with the speci\214ed he)131 462 Q(xadecimal v)-.15 E
-(alue into the te)-.25 E(xt.)-.15 E F2(<interrupt>)102 474 Q F0(Interrupt te)
-131 486 Q(xt input mode, returning to command mode.)-.15 E F2 1.666
-(EX COMMANDS)72 510 R F0 .163(The follo)102 522 R .163
-(wing section describes the commands a)-.25 F -.25(va)-.2 G .163(ilable in the)
-.25 F F3(ex)2.663 E F0(editor)2.663 E 5.163(.I)-.55 G 2.663(ne)405.333 522 S
-.164(ach entry belo)417.436 522 R 1.464 -.65(w, t)-.25 H .164(he tag line is)
-.65 F 2.5(au)102 534 S(sage synopsis for the command.)113.94 534 Q F2
-(<end-of-\214le>)102 558 Q F0(Scroll the screen.)131 570 Q F2 2.5(!a)102 582 S
--.1(rg)112.83 582 S(ument\(s\)).1 E([range]! ar)102 594 Q(gument\(s\))-.1 E F0
-(Ex)131 606 Q
-(ecute a shell command, or \214lter lines through a shell command.)-.15 E F2(")
-102 618 Q F0 2.5(Ac)131 618 S(omment.)145.16 618 Q F2
-([range] nu[mber] [count] [\215ags])102 630 Q([range] # [count] [\215ags])102
-642 Q F0(Display the selected lines, each preceded with its line number)131 654
-Q(.)-.55 E F2 2.5(@b)102 666 S(uffer)119.16 666 Q F4(*)102 678 Q F2 -.2(bu)2.5
-G(ffer).2 E F0 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(7)535 750 Q EP
-%%Page: 8 8
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R(Ex)131 96 Q(ecute a b)-.15 E(uf)
--.2 E(fer)-.25 E(.)-.55 E/F1 10/Times-Bold@0 SF([range] d[elete] [b)102 108 Q
-(uffer] [count] [\215ags])-.2 E F0(Delete the lines from the \214le.)131 120 Q
-F1(di[splay] b[uffers] | s[cr)102 132 Q(eens] | t[ags])-.18 E F0(Display b)131
-144 Q(uf)-.2 E(fers, screens or tags.)-.25 E F1(e[dit][!] [+cmd] [\214le])102
-156 Q(ex[!] [+cmd] [\214le])102 168 Q F0(Edit a dif)131 180 Q(ferent \214le.)
--.25 E F1(exu[sage] [command])102 192 Q F0(Display usage for an)131 204 Q/F2 10
-/Courier-Bold@0 SF(ex)2.5 E F0(command.)2.5 E F1(f[ile] [\214le])102 216 Q F0
-(Display and optionally change the \214le name.)131 228 Q F1(fg [name])102 240
-Q F2(Vi)131 252 Q F0(mode only)2.5 E 5(.F)-.65 G(ore)200.26 252 Q
-(ground the speci\214ed screen.)-.15 E F1([range] g[lobal] /patter)102 264 Q
-(n/ [commands])-.15 E([range] v /patter)102 276 Q(n/ [commands])-.15 E F0
-(Apply commands to lines matching \(or not matching\) a pattern.)131 288 Q F1
-(he[lp])102 300 Q F0(Display a help message.)131 312 Q F1([line] i[nsert][!])
-102 324 Q F0(The input te)131 336 Q
-(xt is inserted before the speci\214ed line.)-.15 E F1
-([range] j[oin][!] [count] [\215ags])102 348 Q F0(Join lines of te)131 360 Q
-(xt together)-.15 E(.)-.55 E F1([range] l[ist] [count] [\215ags])102 372 Q F0
-(Display the lines unambiguously)131 384 Q(.)-.65 E F1(map[!] [lhs rhs])102 396
-Q F0(De\214ne or display maps \(for)131 408 Q F2(vi)2.5 E F0(only\).)2.5 E F1
-([line] ma[rk] <character>)102 420 Q([line] k <character>)102 432 Q F0
-(Mark the line with the mark)131 444 Q/F3 10/Courier@0 SF(<character>)2.5 E F0
-(.)A F1([range] m[o)102 456 Q -.1(ve)-.1 G 2.5(]l).1 G(ine)170.11 456 Q F0(Mo)
-131 468 Q .3 -.15(ve t)-.15 H(he speci\214ed lines after the tar).15 E
-(get line.)-.18 E F1(mk[exr)102 480 Q(c][!] \214le)-.18 E F0(Write the abbre)
-131 492 Q(viations, editor options and maps to the speci\214ed \214le.)-.25 E
-F1(n[ext][!] [\214le ...])102 504 Q F0(Edit the ne)131 516 Q
-(xt \214le from the ar)-.15 E(gument list.)-.18 E F1([line] o[pen] /patter)102
-528 Q(n/ [\215ags])-.15 E F0(Enter open mode.)131 540 Q F1(pr)102 552 Q(e[ser)
--.18 E -.1(ve)-.1 G(]).1 E F0(Sa)131 564 Q .3 -.15(ve t)-.2 H
-(he \214le in a form that can later be reco).15 E -.15(ve)-.15 G(red using the)
-.15 E F2 -1.834(ex \255r)2.5 F F0(option.)2.5 E F1(pr)102 576 Q -.15(ev)-.18 G
-([ious][!]).15 E F0(Edit the pre)131 588 Q(vious \214le from the ar)-.25 E
-(gument list.)-.18 E F1([range] p[rint] [count] [\215ags])102 600 Q F0
-(Display the speci\214ed lines.)131 612 Q F1([line] pu[t] [b)102 624 Q(uffer])
--.2 E F0(Append b)131 636 Q(uf)-.2 E(fer contents to the current line.)-.25 E
-F1(q[uit][!])102 648 Q F0(End the editing session.)131 660 Q F1
-([line] r[ead][!] [\214le])102 672 Q F0 172.465(4.4BSD July)72 750 R(15, 1994)
-2.5 E(8)535 750 Q EP
-%%Page: 9 9
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R(Read a \214le.)131 96 Q/F1 10
-/Times-Bold@0 SF -.18(re)102 108 S(c[o).18 E -.1(ve)-.1 G(r] \214le).1 E F0
-(Reco)131 120 Q -.15(ve)-.15 G(r).15 E/F2 10/Courier@0 SF(file)2.5 E F0
-(if it w)2.5 E(as pre)-.1 E(viously sa)-.25 E -.15(ve)-.2 G(d.).15 E F1 -.18
-(re)102 132 S(s[ize] [+|-]size).18 E/F3 10/Courier-Bold@0 SF(Vi)131 144 Q F0
-(mode only)2.5 E 5(.G)-.65 G(ro)202.07 144 Q 2.5(wo)-.25 G 2.5(rs)224.87 144 S
-(hrink the current screen.)234.59 144 Q F1 -.18(re)102 156 S(w[ind][!]).18 E F0
-(Re)131 168 Q(wind the ar)-.25 E(gument list.)-.18 E F1(se[t] [option[=[v)102
-180 Q(alue]] ...] [nooption ...] [option? ...] [all])-.1 E F0
-(Display or set editor options.)131 192 Q F1(sh[ell])102 204 Q F0
-(Run a shell program.)131 216 Q F1(so[ur)102 228 Q(ce] \214le)-.18 E F0
-(Read and e)131 240 Q -.15(xe)-.15 G(cute).15 E F3(ex)2.5 E F0
-(commands from a \214le.)2.5 E F1(sp[lit] [\214le ...])102 252 Q F3(Vi)131 264
-Q F0(mode only)2.5 E 5(.S)-.65 G(plit the screen.)200.41 264 Q F1
-([range] s[ubstitute] [/patter)102 276 Q(n/r)-.15 E
-(eplace/] [options] [count] [\215ags])-.18 E
-([range] & [options] [count] [\215ags])102 288 Q
-([range] ~ [options] [count] [\215ags])102 300 Q F0(Mak)131 312 Q 2.5(es)-.1 G
-(ubstitutions.)160.06 312 Q F1(su[spend][!])102 324 Q(st[op][!])102 336 Q
-(<suspend>)102 348 Q F0(Suspend the edit session.)131 360 Q F1
-(ta[g][!] tagstring)102 372 Q F0
-(Edit the \214le containing the speci\214ed tag.)131 384 Q F1
-(tagp[op][!] [\214le | number])102 396 Q F0
-(Pop to the speci\214ed tag in the tags stack.)131 408 Q F1(unm[ap][!] lhs)102
-420 Q F0(Unmap a mapped string.)131 432 Q F1 -.1(ve)102 444 S([rsion]).1 E F0
-(Display the v)131 456 Q(ersion of the)-.15 E F3(ex/vi)2.5 E F0(editor)2.5 E(.)
--.55 E F1([line] vi[sual] [type] [count] [\215ags])102 468 Q F3(Ex)131 480 Q F0
-(mode only)2.5 E 5(.E)-.65 G(nter)200.96 480 Q F3(vi)2.5 E F0(.)A F1
-(vi[sual][!] [+cmd] [\214le])102 492 Q F3(Vi)131 504 Q F0(mode only)2.5 E 5(.E)
--.65 G(dit a ne)200.96 504 Q 2.5<778c>-.25 G(le.)245.43 504 Q F1
-(viu[sage] [command])102 516 Q F0(Display usage for a)131 528 Q F3(vi)2.5 E F0
-(command.)2.5 E F1([range] w[rite][!] [>>] [\214le])102 540 Q
-([range] w[rite] [!] [\214le])102 552 Q([range] wn[!] [>>] [\214le])102 564 Q
-([range] wq[!] [>>] [\214le])102 576 Q F0(Write the \214le.)131 588 Q F1
-([range] x[it][!] [\214le])102 600 Q F0
-(Write the \214le if it has been modi\214ed.)131 612 Q F1([range] ya[nk] [b)102
-624 Q(uffer] [count])-.2 E F0(Cop)131 636 Q 2.5(yt)-.1 G
-(he speci\214ed lines to a b)157.85 636 Q(uf)-.2 E(fer)-.25 E(.)-.55 E F1
-([line] z [type] [count] [\215ags])102 648 Q F0(Adjust the windo)131 660 Q -.65
-(w.)-.25 G 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(9)535 750 Q EP
-%%Page: 10 10
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Times-Bold@0 SF 1.666
-(SET OPTIONS)72 96 R F0 .519(There are a lar)102 108 R .518
-(ge number of options that may be set \(or unset\) to change the editor')-.18 F
-3.018(sb)-.55 G(eha)453.614 108 Q(vior)-.2 E 5.518(.T)-.55 G .518(his section)
-496.982 108 R(describes the options, their abbre)102 120 Q
-(viations and their def)-.25 E(ault v)-.1 E(alues.)-.25 E .095
-(In each entry belo)102 138 R 1.395 -.65(w, t)-.25 H .095
-(he \214rst part of the tag line is the full name of the option, follo).65 F
-.095(wed by an)-.25 F 2.595(ye)-.15 G(qui)487.915 138 Q -.25(va)-.25 G .095
-(lent ab-).25 F(bre)102 150 Q 3.034(viations. The)-.25 F .534
-(part in square brack)3.034 F .533(ets is the def)-.1 F .533(ault v)-.1 F .533
-(alue of the option.)-.25 F .533(Most of the options are boolean,)5.533 F
-(i.e. the)102 162 Q 2.5(ya)-.15 G(re either on or of)140.73 162 Q
-(f, and do not ha)-.25 E .3 -.15(ve a)-.2 H 2.5(na).15 G(ssociated v)298.14 162
-Q(alue.)-.25 E(Options apply to both)102 180 Q/F2 10/Courier-Bold@0 SF(ex)2.5 E
-F0(and)2.5 E F2(vi)2.5 E F0(modes, unless otherwise speci\214ed.)2.5 E F1
-(altwerase [off])102 204 Q F2(Vi)131 216 Q F0(only)2.5 E 5(.S)-.65 G
-(elect an alternate w)175.69 216 Q(ord erase algorithm.)-.1 E F1
-(autoindent, ai [off])102 228 Q F0(Automatically indent ne)131 240 Q 2.5(wl)
--.25 G(ines.)239.91 240 Q F1(autoprint, ap [off])102 252 Q F2(Ex)131 264 Q F0
-(only)2.5 E 5(.D)-.65 G(isplay the current line automatically)177.35 264 Q(.)
--.65 E F1(auto)102 276 Q(write, aw [off])-.1 E F0
-(Write modi\214ed \214les automatically when changing \214les.)131 288 Q F1
-(beautify)102 300 Q 2.5(,b)-.55 G 2.5(f[)147.01 300 S(off])156.17 300 Q F0
-(Discard control characters.)131 312 Q F1(cdpath [en)102 324 Q(vir)-.4 E
-(onment v)-.18 E(ariable CDP)-.1 E -.95(AT)-.74 G(H, or curr).95 E(ent dir)-.18
-E(ectory])-.18 E F0(The directory paths used as path pre\214x)131 336 Q
-(es for the)-.15 E F1(cd)2.5 E F0(command.)2.5 E F1(columns, co [80])102 348 Q
-F0(Set the number of columns in the screen.)131 360 Q F1(comment [off])102 372
-Q F2(Vi)131 384 Q F0(only)2.5 E 5(.S)-.65 G(kip leading comments in \214les.)
-175.69 384 Q F1(dir)102 396 Q(ectory)-.18 E 2.5(,d)-.55 G(ir [en)151.26 396 Q
-(vir)-.4 E(onment v)-.18 E(ariable TMPDIR, or /tmp])-.1 E F0
-(The directory where temporary \214les are created.)131 408 Q F1
-(edcompatible, ed [off])102 420 Q F0 .279(Remember the v)131 432 R .279
-(alues of the `)-.25 F(`c')-.74 E 2.779('a)-.74 G .279(nd `)270.344 432 R(`g')
--.74 E 2.779('s)-.74 G(uf)306.632 432 Q .279(\214ces to the)-.25 F F1
-(substitute)2.78 E F0 .28(commands, instead of initializing)2.78 F
-(them as unset for each ne)131 444 Q 2.5(wc)-.25 G(ommand.)246.27 444 Q F1(err)
-102 456 Q(orbells, eb [off])-.18 E F2(Ex)131 468 Q F0(only)2.5 E 5(.A)-.65 G
-(nnounce error messages with a bell.)177.35 468 Q F1(exr)102 480 Q(c, ex [off])
--.18 E F0(Ne)131 492 Q -.15(ve)-.25 G 2.5(rr).15 G
-(ead startup \214les in the local directory)160.86 492 Q(.)-.65 E F1
-(extended [off])102 504 Q F0(Re)131 516 Q(gular e)-.15 E(xpressions are e)-.15
-E(xtended \(i.e.)-.15 E/F3 10/Courier@0 SF(egrep)5 E F0(\(1\) style\) e)A
-(xpressions.)-.15 E F1(\215ash [on])102 528 Q F0
-(Flash the screen instead of beeping the k)131 540 Q -.15(ey)-.1 G
-(board on error).15 E(.)-.55 E F1(hardtabs, ht [8])102 552 Q F0
-(Set the spacing between hardw)131 564 Q(are tab settings.)-.1 E F1(ignor)102
-576 Q(ecase, ic [off])-.18 E F0(Ignore case dif)131 588 Q(ferences in re)-.25 E
-(gular e)-.15 E(xpressions.)-.15 E F1 -.1(ke)102 600 S(ytime [6]).1 E F0
-(The 10th')131 612 Q 2.5(so)-.55 G 2.5(fas)181 612 S(econd)197.66 612 Q F2
-(ex/vi)2.5 E F0 -.1(wa)2.5 G(its for a subsequent k).1 E .3 -.15(ey t)-.1 H 2.5
-(oc).15 G(omplete a k)379.5 612 Q .3 -.15(ey m)-.1 H(apping.).15 E F1
-(leftright [off])102 624 Q F2(Vi)131 636 Q F0(only)2.5 E 5(.D)-.65 G 2.5(ol)
-177.35 636 S(eft-right scrolling.)187.63 636 Q F1(lines, li [24])102 648 Q F2
-(Vi)131 660 Q F0(only)2.5 E 5(.S)-.65 G(et the number of lines in the screen.)
-175.69 660 Q F1(lisp [off])102 672 Q F2(Vi)131 684 Q F0(only)2.5 E 5(.M)-.65 G
-(odify v)179.02 684 Q(arious search commands and options to w)-.25 E
-(ork with Lisp.)-.1 E 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(10)530 750 Q
-EP
-%%Page: 11 11
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Times-Italic@0 SF
-(This option is not yet implemented.)131 96 Q/F2 10/Times-Bold@0 SF(list [off])
-102 108 Q F0(Display lines in an unambiguous f)131 120 Q(ashion.)-.1 E F2
-(magic [on])102 132 Q F0 -.35(Tr)131 144 S
-(eat certain characters specially in re).35 E(gular e)-.15 E(xpressions.)-.15 E
-F2(matchtime [7])102 156 Q/F3 10/Courier-Bold@0 SF(Vi)131 168 Q F0(only)2.885 E
-5.385(.T)-.65 G .385(he 10th')177.01 168 R 2.885(so)-.55 G 2.885(fas)221.67 168
-S(econd)239.1 168 Q F3(ex/vi)2.884 E F0 .384
-(pauses on the matching character when the)2.884 F F2(sho)2.884 E(wmatch)-.1 E
-F0(op-)2.884 E(tion is set.)131 180 Q F2(mesg [on])102 192 Q F0
-(Permit messages from other users.)131 204 Q F2(modelines, modeline [off])102
-216 Q F0(Read the \214rst and last fe)131 228 Q 2.5(wl)-.25 G
-(ines of each \214le for)240.18 228 Q F3(ex)2.5 E F0(commands.)2.5 E F1
-(This option will ne)131 246 Q(ver be implemented.)-.15 E F2(number)102 258 Q
-2.5(,n)-.92 G 2.5(u[)145.53 258 S(off])156.92 258 Q F0
-(Precede each line displayed with its current line number)131 270 Q(.)-.55 E F2
-(octal [off])102 282 Q F0(Display unkno)131 294 Q
-(wn characters as octal numbers, instead of the def)-.25 E(ault he)-.1 E
-(xadecimal.)-.15 E F2(open [on])102 306 Q F3(Ex)131 318 Q F0(only)2.5 E 5(.I)
--.65 G 2.5(ft)173.46 318 S(his option is not set, the)182.07 318 Q F2(open)2.5
-E F0(and)2.5 E F2(visual)2.5 E F0(commands are disallo)2.5 E(wed.)-.25 E F2
-(optimize, opt [on])102 330 Q F3(Vi)131 342 Q F0(only)2.5 E 5(.O)-.65 G
-(ptimize te)177.35 342 Q(xt throughput to dumb terminals.)-.15 E F1
-(This option is not yet implemented.)131 360 Q F2
-(paragraphs, para [IPLPPPQPP LIpplpipbp])102 372 Q F3(Vi)131 384 Q F0(only)2.5
-E 5(.D)-.65 G(e\214ne additional paragraph boundaries for the)177.35 384 Q F2
-({)2.5 E F0(and)2.5 E F2(})2.5 E F0(commands.)2.5 E F2(pr)102 396 Q(ompt [on])
--.18 E F3(Ex)131 408 Q F0(only)2.5 E 5(.D)-.65 G(isplay a command prompt.)
-177.35 408 Q F2 -.18(re)102 420 S(adonly).18 E 2.5(,r)-.55 G 2.5(o[)148.31 420
-S(off])159.14 420 Q F0(Mark the \214le as read-only)131 432 Q(.)-.65 E F2 -.18
-(re)102 444 S(cdir [/v).18 E(ar/tmp/vi.r)-.1 E(eco)-.18 E -.1(ve)-.1 G(r]).1 E
-F0(The directory where reco)131 456 Q -.15(ve)-.15 G(ry \214les are stored.).15
-E F2 -.18(re)102 468 S(draw).18 E 2.5(,r)-.55 G 2.5(e[)141.63 468 S(off])151.9
-468 Q F3(Vi)131 480 Q F0(only)2.5 E 5(.S)-.65 G
-(imulate an intelligent terminal on a dumb one.)175.69 480 Q F1
-(This option is not yet implemented.)131 498 Q F2 -.18(re)102 510 S(map [on])
-.18 E F0(Remap k)131 522 Q -.15(ey)-.1 G 2.5(su).15 G(ntil resolv)187.41 522 Q
-(ed.)-.15 E F2 -.18(re)102 534 S(port [5]).18 E F0
-(Set the number of lines about which the editor reports changes or yanks.)131
-546 Q F2(ruler [off])102 558 Q F3(Vi)131 570 Q F0(only)2.5 E 5(.D)-.65 G
-(isplay a ro)177.35 570 Q(w/column ruler on the colon command line.)-.25 E F2
-(scr)102 582 Q(oll, scr [windo)-.18 E 2.5(w/2)-.1 G(])194.77 582 Q F0
-(Set the number of lines scrolled.)131 594 Q F2(sections, sect [NHSHH HUnhsh])
-102 606 Q F3(Vi)131 618 Q F0(only)2.5 E 5(.D)-.65 G
-(e\214ne additional section boundaries for the)177.35 618 Q F2([[)2.5 E F0(and)
-2.5 E F2(]])2.5 E F0(commands.)2.5 E F2(shell, sh [en)102 630 Q(vir)-.4 E
-(onment v)-.18 E(ariable SHELL, or /bin/sh])-.1 E F0
-(Select the shell used by the editor)131 642 Q(.)-.55 E F2(shiftwidth, sw [8])
-102 654 Q F0(Set the autoindent and shift command indentation width.)131 666 Q
-F2(sho)102 678 Q(wdirty [off])-.1 E F0 172.465(4.4BSD July)72 750 R(15, 1994)
-2.5 E(11)530 750 Q EP
-%%Page: 12 12
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Courier-Bold@0 SF(Vi)131 96
-Q F0(only)2.5 E 5(.D)-.65 G(isplay an asterisk on the colon command line if th\
-e \214le has been modi\214ed.)177.35 96 Q/F2 10/Times-Bold@0 SF(sho)102 108 Q
-(wmatch, sm [off])-.1 E F1(Vi)131 120 Q F0(only)2.5 E 5(.N)-.65 G
-(ote matching `)177.35 120 Q(`{')-.74 E 2.5('a)-.74 G(nd `)255.37 120 Q(`\(')
--.74 E 2.5('f)-.74 G(or `)288.87 120 Q(`}')-.74 E 2.5('a)-.74 G(nd `)323.28 120
-Q(`\)')-.74 E 2.5('c)-.74 G(haracters.)357.89 120 Q F2(sho)102 132 Q
-(wmode [off])-.1 E F1(Vi)131 144 Q F0(only)2.5 E 5(.D)-.65 G
-(isplay the current editor mode \(command or input\).)177.35 144 Q F2(sidescr)
-102 156 Q(oll [16])-.18 E F1(Vi)131 168 Q F0(only)2.5 E 5(.S)-.65 G
-(et the amount a left-right scroll will shift.)175.69 168 Q F2(slo)102 180 Q
--.1(wo)-.1 G(pen, slo).1 E 2.5(w[)-.1 G(off])170.87 180 Q F0
-(Delay display updating during te)131 192 Q(xt input.)-.15 E/F3 10
-/Times-Italic@0 SF(This option is not yet implemented.)131 210 Q F2(sour)102
-222 Q(ceany [off])-.18 E F0(Read startup \214les not o)131 234 Q
-(wned by the current user)-.25 E(.)-.55 E F3(This option will ne)131 252 Q
-(ver be implemented.)-.15 E F2(tabstop, ts [8])102 264 Q F0
-(This option sets tab widths for the editor display)131 276 Q(.)-.65 E F2
-(taglength, tl [0])102 288 Q F0
-(Set the number of signi\214cant characters in tag names.)131 300 Q F2
-(tags, tag [tags /v)102 312 Q(ar/db/libc.tags /sys/k)-.1 E(er)-.1 E(n/tags])
--.15 E F0(Set the list of tags \214les.)131 324 Q F2(term, ttytype, tty [en)102
-336 Q(vir)-.4 E(onment v)-.18 E(ariable TERM])-.1 E F0(Set the terminal type.)
-131 348 Q F2(terse [off])102 360 Q F0 .759
-(This option has historically made editor messages less v)131 372 R 3.259
-(erbose. It)-.15 F .76(has no ef)3.259 F .76(fect in this implementa-)-.25 F
-(tion.)131 384 Q F2(tildeop)102 396 Q F0(Modify the)131 408 Q F2(~)2.5 E F0
-(command to tak)2.5 E 2.5(ea)-.1 G 2.5(na)259.77 408 S(ssociated motion.)271.71
-408 Q F2(timeout, to [on])102 420 Q F0 -.35(Ti)131 432 S(me out on k).35 E -.15
-(ey)-.1 G 2.5(sw).15 G(hich may be mapped.)209.84 432 Q F2(ttywerase [off])102
-444 Q F1(Vi)131 456 Q F0(only)2.5 E 5(.S)-.65 G
-(elect an alternate erase algorithm.)175.69 456 Q F2 -.1(ve)102 468 S
-(rbose [off]).1 E F0(only)131 480 Q 5(.D)-.65 G(isplay an error message for e)
-162.85 480 Q -.15(ve)-.25 G(ry error).15 E(.)-.55 E F2(w300 [no default])102
-492 Q F1(Vi)131 504 Q F0(only)2.5 E 5(.S)-.65 G(et the windo)175.69 504 Q 2.5
-(ws)-.25 G(ize if the baud rate is less than 1200 baud.)238.49 504 Q F2
-(w1200 [no default])102 516 Q F1(Vi)131 528 Q F0(only)2.5 E 5(.S)-.65 G
-(et the windo)175.69 528 Q 2.5(ws)-.25 G
-(ize if the baud rate is equal to 1200 baud.)238.49 528 Q F2
-(w9600 [no default])102 540 Q F1(Vi)131 552 Q F0(only)2.5 E 5(.S)-.65 G
-(et the windo)175.69 552 Q 2.5(ws)-.25 G
-(ize if the baud rate is greater than 1200 baud.)238.49 552 Q F2(war)102 564 Q
-2.5(n[)-.15 G(on])129.9 564 Q F1(Ex)131 576 Q F0(only)2.979 E 5.479(.T)-.65 G
-.479(his option causes a w)177.198 576 R .479
-(arning message to the terminal if the \214le has been modi\214ed, since it)-.1
-F -.1(wa)131 588 S 2.5(sl).1 G(ast written, before a)151.73 588 Q F2(!)2.5 E F0
-(command.)2.5 E F2(windo)102 600 Q 1.1 -.55(w, w, w)-.1 H 2.5(i[).55 G(en)
-167.19 600 Q(vir)-.4 E(onment v)-.18 E(ariable LINES])-.1 E F0(Set the windo)
-131 612 Q 2.5(ws)-.25 G(ize for the screen.)199.36 612 Q F2(wrapmar)102 624 Q
-(gin, wm [0])-.1 E F1(Vi)131 636 Q F0(only)2.5 E 5(.B)-.65 G
-(reak lines automatically when the)176.8 636 Q 2.5(yr)-.15 G
-(each the right-hand mar)321.9 636 Q(gin.)-.18 E F2(wrapscan, ws [on])102 648 Q
-F0(Set searches to wrap around the end or be)131 660 Q(ginning of the \214le.)
--.15 E F2(writeany)102 672 Q 2.5(,w)-.55 G 2.5(a[)151.44 672 S(off])162.27 672
-Q F0 -.45(Tu)131 684 S(rn of).45 E 2.5<668c>-.25 G(le-o)171.96 684 Q -.15(ve)
--.15 G(rwriting checks.).15 E 172.465(4.4BSD July)72 750 R(15, 1994)2.5 E(12)
-530 750 Q EP
-%%Page: 13 13
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R/F1 10/Times-Bold@0 SF(ENVIR)72 96
-Q(ONMENT)-.3 E 1.666(AL V)-.9 F(ARIABLES)-1.35 E/F2 10/Courier@0 SF(COLUMNS)102
-108 Q F0 .895(The number of columns on the screen.)161 108 R .896(This v)5.896
-F .896(alue o)-.25 F -.15(ve)-.15 G .896(rrides an).15 F 3.396(ys)-.15 G .896
-(ystem or terminal speci\214c)433.712 108 R -.25(va)161 120 S 5.317(lues. If)
-.25 F 2.816(the COLUMNS en)5.317 F 2.816(vironmental v)-.4 F 2.816
-(ariable is not set when)-.25 F/F3 10/Courier-Bold@0 SF(ex/vi)5.316 E F0 2.816
-(runs, or the)5.316 F F1(columns)161 132 Q F0(option is e)2.5 E
-(xplicitly reset by the user)-.15 E(,)-.4 E F3(ex/vi)2.5 E F0(enters the v)2.5
-E(alue into the en)-.25 E(vironment.)-.4 E F2(EXINIT)102 144 Q F0 2.5(Al)161
-144 S(ist of)173.5 144 Q F3(ex)2.5 E F0(startup commands, read if the v)2.5 E
-(ariable)-.25 E F2(NEXINIT)2.5 E F0(is not set.)2.5 E F2(HOME)102 156 Q F0 .677
-(The user')161 156 R 3.177(sh)-.55 G .677(ome directory)211.234 156 R 3.177(,u)
--.65 G .678(sed as the initial directory path for the startup)277.758 156 R F2
-($HOME/.nexrc)3.178 E F0(and)161 168 Q F2($HOME/.exrc)2.865 E F0 2.865
-(\214les. This)2.865 F -.25(va)2.865 G .365(lue is also used as the def).25 F
-.365(ault directory for the)-.1 F F3(vi)2.865 E F1(cd)2.865 E F0(com-)2.865 E
-(mand.)161 180 Q F2(LINES)102 192 Q F0 .629(The number of ro)161 192 R .629
-(ws on the screen.)-.25 F .629(This v)5.629 F .629(alue o)-.25 F -.15(ve)-.15 G
-.629(rrides an).15 F 3.13(ys)-.15 G .63(ystem or terminal speci\214c v)416.08
-192 R(al-)-.25 E 3.123(ues. If)161 204 R .623(the LINES en)3.123 F .623
-(vironmental v)-.4 F .623(ariable is not set when)-.25 F F3(ex/vi)3.122 E F0
-.622(runs, or the)3.122 F F1(lines)3.122 E F0 .622(option is)3.122 F -.15(ex)
-161 216 S(plicitly reset by the user).15 E(,)-.4 E F3(ex/vi)2.5 E F0
-(enters the v)2.5 E(alue into the en)-.25 E(vironment.)-.4 E F2(NEXINIT)102 228
-Q F0 2.5(Al)161 228 S(ist of)173.5 228 Q F3(ex)2.5 E F0(startup commands.)2.5 E
-F2(SHELL)102 240 Q F0(The user')161 240 Q 2.5(ss)-.55 G
-(hell of choice \(see also the)208.77 240 Q F1(shell)2.5 E F0(option\).)2.5 E
-F2(TERM)102 252 Q F0 1.338(The user')161 252 R 3.838(st)-.55 G 1.338
-(erminal type.)210.336 252 R 1.338(The def)6.338 F 1.338(ault is the type `)-.1
-F(`unkno)-.74 E(wn')-.25 E 1.339('. If the TERM en)-.74 F(vironmental)-.4 E
--.25(va)161 264 S .106(riable is not set when).25 F F3(ex/vi)2.606 E F0 .105
-(runs, or the)2.605 F F1(term)2.605 E F0 .105(option is e)2.605 F .105
-(xplicitly reset by the user)-.15 F(,)-.4 E F3(ex/vi)2.605 E F0(enters the v)
-161 276 Q(alue into the en)-.25 E(vironment.)-.4 E F2(TMPDIR)102 288 Q F0
-(The location used to stored temporary \214les \(see also the)161 288 Q F1(dir)
-2.5 E(ectory)-.18 E F0(option\).)2.5 E F1(ASYNCHR)72 312 Q 1.666(ONOUS EVENTS)
--.3 F F0(SIGALRM)102 324 Q F3(Vi/ex)167 324 Q F0 1.58(uses this signal for per\
-iodic backups of \214le modi\214cations and to display `)4.08 F(`b)-.74 E(usy')
--.2 E(')-.74 E(messages when operations are lik)167 336 Q(ely to tak)-.1 E 2.5
-(eal)-.1 G(ong time.)354.54 336 Q(SIGHUP)102 348 Q 18.61(SIGTERM If)102 360 R
-.12(the current b)2.62 F(uf)-.2 E .12(fer has changed since it w)-.25 F .12
-(as last written in its entirety)-.1 F 2.62(,t)-.65 G .12
-(he editor attempts to)457.7 360 R(sa)167 372 Q .493 -.15(ve t)-.2 H .193
-(he modi\214ed \214le so it can be later reco).15 F -.15(ve)-.15 G 2.693
-(red. See).15 F(the)2.694 E F3(vi/ex)2.694 E F0 .194(Reference manual section)
-2.694 F(entitled `)167 384 Q(`Reco)-.74 E -.15(ve)-.15 G(ry').15 E 2.5('f)-.74
-G(or more information.)255.19 384 Q 29.73(SIGINT When)102 396 R .594(an interr\
-upt occurs, the current operation is halted, and the editor returns to the com\
--)3.094 F .364(mand le)167 408 R -.15(ve)-.25 G 2.864(l. If).15 F .364
-(interrupted during te)2.864 F .364(xt input, the te)-.15 F .364
-(xt already input is resolv)-.15 F .365(ed into the \214le as)-.15 F(if the te)
-167 420 Q(xt input had been normally terminated.)-.15 E 12.51(SIGWINCH The)102
-432 R 2.772(screen is resized.)5.272 F 2.772(See the)7.772 F F3(vi/ex)5.272 E
-F0 2.771(Reference manual section entitled `)5.272 F 2.771(`Sizing the)-.74 F
-(Screen')167 444 Q 2.5('f)-.74 G(or more information.)205.96 444 Q(SIGCONT)102
-456 Q(SIGQ)102 468 Q(UIT)-.1 E(SIGTSTP)102 480 Q F3(Vi/ex)167 480 Q F0
-(ignores these signals.)2.5 E F1 -.1(BU)72 504 S(GS).1 E F0(See the \214le)102
-516 Q F2(nvi/docs/bugs.current)2.5 E F0(for a list of the kno)2.5 E(wn b)-.25 E
-(ugs in this v)-.2 E(ersion.)-.15 E F1(FILES)72 540 Q F2(/bin/sh)102 552 Q F0
-(The def)221 552 Q(ault user shell.)-.1 E F2(/etc/vi.exrc)102 564 Q F0
-(System-wide vi startup \214le.)221 564 Q F2(/tmp)102 576 Q F0 -.7(Te)221 576 S
-(mporary \214le directory).7 E(.)-.65 E F2(/var/tmp/vi.recover)102 588 Q F0
-(The def)5 E(ault reco)-.1 E -.15(ve)-.15 G(ry \214le directory).15 E(.)-.65 E
-F2($HOME/.nexrc)102 600 Q F0(1st choice for user')221 600 Q 2.5(sh)-.55 G
-(ome directory startup \214le.)308.76 600 Q F2($HOME/.exrc)102 612 Q F0
-(2nd choice for user')221 612 Q 2.5(sh)-.55 G(ome directory startup \214le.)
-312.09 612 Q F2(.nexrc)102 624 Q F0
-(1st choice for local directory startup \214le.)221 624 Q F2(.exrc)102 636 Q F0
-(2nd choice for local directory startup \214le.)221 636 Q F1 1.666(SEE ALSO)72
-660 R F2(ctags)102 672 Q F0(\(1\),)A F2(more)5 E F0(\(1\),)A F2(curses)5 E F0
-(\(3\),)A F2(dbopen)5 E F0(\(3\))A(The `)102 696 Q(`V)-.74 E 2.5(iQ)-.6 G
-(uick Reference')145.09 696 Q 2.5('c)-.74 G(ard.)218.2 696 Q 172.465
-(4.4BSD July)72 750 R(15, 1994)2.5 E(13)530 750 Q EP
-%%Page: 14 14
-%%BeginPageSetup
-BP
-%%EndPageSetup
-/F0 10/Times-Roman@0 SF -.834(EX/VI \( 1 \))72 48 R(BSD Reference Manual)
-258.235 48 Q -.834(EX/VI \( 1 \))496.682 48 R -.74(``)102 96 S
-(An Introduction to Display Editing with V).74 E(i')-.6 E(', found in the `)
--.74 E(`UNIX User')-.74 E 2.5(sM)-.55 G(anual Supplementary)412.2 96 Q
-(Documents')102 108 Q 2.5('s)-.74 G
-(ection of both the 4.3BSD and 4.4BSD manual sets.)159.86 108 Q
-(This document is the closest thing a)5 E -.25(va)-.2 G(il-).25 E
-(able to an introduction to the)102 120 Q/F1 10/Courier-Bold@0 SF(vi)2.5 E F0
-(screen editor)2.5 E(.)-.55 E -.74(``)102 144 S(Ex Reference Manual \(V).74 E
-(ersion 3.7\)')-1.11 E(', found in the `)-.74 E(`UNIX User')-.74 E 2.5(sM)-.55
-G(anual Supplementary Documents')381.92 144 Q 2.5('s)-.74 G(ec-)526.99 144 Q
-(tion of both the 4.3BSD and 4.4BSD manual sets.)102 156 Q
-(This document is the \214nal reference for the)5 E F1(ex)2.5 E F0(editor)2.5 E
-2.5(,a)-.4 G(s)528 156 Q(distrib)102 168 Q
-(uted in most historic 4BSD and System V systems.)-.2 E -.74(``)102 192 S
-(Edit: A tutorial').74 E(', found in the `)-.74 E(`UNIX User')-.74 E 2.5(sM)
--.55 G(anual Supplementary Documents')300.58 192 Q 2.5('s)-.74 G
-(ection of the 4.3BSD)445.65 192 Q(manual set.)102 204 Q
-(This document is an introduction to a simple v)5 E(ersion of the)-.15 E F1(ex)
-2.5 E F0(screen editor)2.5 E(.)-.55 E -.74(``)102 228 S(Ex/V).74 E 2.5(iR)-.6 G
-(eference Manual')140.38 228 Q(', found in the `)-.74 E(`UNIX User')-.74 E 2.5
-(sM)-.55 G(anual Supplementary Documents')339.39 228 Q 2.5('s)-.74 G
-(ection of the)484.46 228 Q(4.4BSD manual set.)102 240 Q
-(This document is the \214nal reference for the)5 E F1(nex/nvi)2.5 E F0(te)2.5
-E(xt editors, as distrib)-.15 E(uted in)-.2 E(4.4BSD and 4.4BSD-Lite.)102 252 Q
-F1(Roff)102 270 Q F0(source for all of these documents is distrib)2.5 E
-(uted with)-.2 E F1(nex/nvi)2.5 E F0(in the)2.5 E/F2 10/Courier@0 SF
-(nvi/USD.doc)2.5 E F0(directory of the)2.5 E F1(nex/nvi)102 282 Q F0
-(source code.)2.5 E(The \214les `)102 306 Q(`auto)-.74 E(write')-.25 E(', `)
--.74 E(`input')-.74 E(', `)-.74 E(`quoting')-.74 E(', and `)-.74 E
-(`structures')-.74 E(', found in the)-.74 E F2(nvi/docs/internals)2.5 E F0
-(direc-)2.5 E(tory of the)102 318 Q F1(nex/nvi)2.5 E F0(source code.)2.5 E/F3
-10/Times-Bold@0 SF(HIST)72 342 Q(OR)-.18 E(Y)-.35 E F0(The)102 354 Q F1
-(nex/nvi)2.5 E F0(replacements for the)2.5 E F1(ex/vi)2.5 E F0
-(editor \214rst appeared in 4.4BSD.)2.5 E F3(ST)72 378 Q(AND)-.9 E(ARDS)-.35 E
-F1(Nex/nvi)102 390 Q F0 .1(is close to IEEE Std1003.2 \(`)2.6 F(`POSIX')-.74 E
-2.6('\). That)-.74 F .1(document dif)2.6 F .1(fers from historical)-.25 F F1
-(ex/vi)2.6 E F0 .1(practice in)2.6 F(se)102 402 Q -.15(ve)-.25 G
-(ral places; there are changes to be made on both sides.).15 E 172.465
-(4.4BSD July)72 750 R(15, 1994)2.5 E(14)530 750 Q EP
-%%Trailer
-end
-%%EOF
diff --git a/usr.bin/vi/USD.doc/vi.man/vi.1 b/usr.bin/vi/USD.doc/vi.man/vi.1
deleted file mode 100644
index 25f2a2c..0000000
--- a/usr.bin/vi/USD.doc/vi.man/vi.1
+++ /dev/null
@@ -1,1294 +0,0 @@
-.\" Copyright (c) 1994
-.\" 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.
-.\"
-.\" @(#)vi.1 8.12 (Berkeley) 7/15/94
-.\"
-.Dd "July 15, 1994"
-.Dt EX/VI 1
-.Os
-.Sh NAME
-.Nm ex, vi, view
-.Nd text editors
-.Sh SYNOPSIS
-.Nm \&ex
-.Op Fl eFRrsv
-.Op Fl c Ar cmd
-.Op Fl t Ar tag
-.Op Fl w Ar size
-.\".Op Fl X Ar \&aw
-.Op Ar "file ..."
-.Nm \&vi
-.Op Fl eFRrv
-.Op Fl c Ar cmd
-.Op Fl t Ar tag
-.Op Fl w Ar size
-.\".Op Fl X Ar \&aw
-.Op Ar "file ..."
-.Nm view
-.Op Fl eFRrv
-.Op Fl c Ar cmd
-.Op Fl t Ar tag
-.Op Fl w Ar size
-.\".Op Fl X Ar \&aw
-.Op Ar "file ..."
-.Sh DESCRIPTION
-.Nm \&Vi
-is a screen oriented text editor.
-.Nm \&Ex
-is a line-oriented text editor.
-.Nm \&Ex
-and
-.Nm \&vi
-are different interfaces to the same program,
-and it is possible to switch back and forth during an edit session.
-.Nm View
-is the equivalent of using the
-.Fl R
-(read-only) option of
-.Nm \&vi .
-.Pp
-This manual page is the one provided with the
-.Nm nex/nvi
-versions of the
-.Nm ex/vi
-text editors.
-.Nm Nex/nvi
-are intended as bug-for-bug compatible replacements for the original
-Fourth Berkeley Software Distribution (4BSD)
-.Nm \&ex
-and
-.Nm \&vi
-programs.
-For the rest of this manual page,
-.Nm nex/nvi
-is used only when it's necessary to distinguish it from the historic
-implementations of
-.Nm ex/vi .
-.Pp
-This manual page is intended for users already familiar with
-.Nm ex/vi .
-Anyone else should almost certainly read a good tutorial on the
-editor before this manual page.
-If you're in an unfamiliar environment, and you absolutely have to
-get work done immediately, read the section after the options
-description, entitled
-.Dq "Fast Startup" .
-It's probably enough to get you going.
-.Pp
-The following options are available:
-.Bl -tag -width Ds
-.It Fl c
-Execute
-.Ar cmd
-immediately after starting the edit session.
-Particularly useful for initial positioning in the file, however
-.Ar cmd
-is not limited to positioning commands.
-This is the POSIX 1003.2 interface for the historic
-.Dq "+cmd"
-syntax.
-.Nm Nex/nvi
-supports both the old and new syntax.
-.It Fl e
-Start editing in ex mode, as if the command name were
-.Nm \&ex .
-.It Fl F
-Don't copy the entire file when first starting to edit.
-(The default is to make a copy in case someone else modifies
-the file during your edit session.)
-.It Fl R
-Start editing in read-only mode, as if the command name was
-.Nm view ,
-or the readonly option was set.
-.It Fl r
-Recover the specified files, or, if no files are specified,
-list the files that could be recovered.
-If no recoverable files by the specified name exist,
-the file is edited as if the
-.Fl r
-option had not been specified.
-.It Fl s
-Enter batch mode; applicable only to
-.Nm \&ex
-edit sessions.
-Batch mode is useful when running
-.Nm \&ex
-scripts.
-Prompts, informative messages and other user oriented message
-are turned off,
-and no startup files or environmental variables are read.
-This is the POSIX 1003.2 interface for the historic
-.Dq \&\-
-argument.
-.Nm \&Nex/nvi
-supports both the old and new syntax.
-.It Fl t
-Start editing at the specified tag.
-(See
-.Xr ctags 1 ).
-.It Fl w
-Set the initial window size to the specified number of lines.
-.It Fl v
-Start editing in vi mode, as if the command name was
-.Nm \&vi
-or
-.Nm view .
-.It Fl X
-Reserved for X11 interfaces.
-.Em "No X11 support is currently implemented."
-.El
-.Pp
-Command input for
-.Nm ex/vi
-is read from the standard input.
-In the
-.Nm \&vi
-interface, it is an error if standard input is not a terminal.
-In the
-.Nm \&ex
-interface, if standard input is not a terminal,
-.Nm \&ex
-will read commands from it regardless, however, the session will be a
-batch mode session, exactly as if the
-.Fl s
-option had been specified.
-.Pp
-.Nm Ex/vi
-exits 0 on success, and greater than 0 if an error occurs.
-.Sh FAST STARTUP
-This section will tell you the minimum amount that you need to
-do simple editing tasks using
-.Nm \&vi .
-If you've never used any screen editor before, you're likely to have
-problems even with this simple introduction.
-In that case you should find someone that already knows
-.Nm \&vi
-and have them walk you through this section.
-.Pp
-.Nm \&Vi
-is a screen editor.
-This means that it takes up almost the entire screen, displaying part
-of the file on each screen line, except for the last line of the screen.
-The last line of the screen is used for you to give commands to
-.Nm \&vi ,
-and for
-.Nm \&vi
-to give information to you.
-.Pp
-The other fact that you need to understand is that
-.Nm \&vi
-is a modeful editor, i.e. you are either entering text or you
-are executing commands, and you have to be in the right mode
-to do one or the other.
-You will be in command mode when you first start editing a file.
-There are commands that switch you into input mode.
-There is only one key that takes you out of input mode,
-and that is the <escape> key.
-(Key names are written using less-than and greater-than signs, e.g.
-<escape> means the
-.Dq escape
-key, usually labeled
-.Dq esc
-on your terminal's keyboard.)
-If you're ever confused as to which mode you're in,
-keep entering the <escape> key until
-.Nm \&vi
-beeps at you.
-(Generally,
-.Nm \&vi
-will beep at you if you try and do something that's not allowed.
-It will also display error messages.)
-.Pp
-To start editing a file, enter the command
-.Dq Li "vi file_name<carriage-return>" .
-The command you should enter as soon as you start editing is
-.Dq Li ":set verbose showmode<carriage-return>" .
-This will make the editor give you verbose error messages and display
-the current mode at the bottom of the screen.
-.Pp
-The commands to move around the file are:
-.Bl -tag -width XXXX -compact
-.It Sy h
-Move the cursor left one character.
-.It Sy j
-Move the cursor down one line.
-.It Sy k
-Move the cursor up one line.
-.It Sy l
-Move the cursor right one character.
-.It Sy <cursor-arrows>
-The cursor arrow keys should work, too.
-.It Sy /text<carriage-return>
-Search for the string
-.Dq text
-in the file, and move the cursor to its first character.
-.El
-.Pp
-The commands to enter new text are:
-.Bl -tag -width XXXX -compact
-.It Sy a
-Append new text,
-.Em after
-the cursor.
-.It Sy i
-Insert new text,
-.Em before
-the cursor.
-.It Sy o
-Open a new line below the line the cursor is on, and start
-entering text.
-.It Sy O
-Open a new line above the line the cursor is on, and start
-entering text.
-.It Sy <escape>
-Once you've entered input mode using the one of the
-.Sy \&a ,
-.Sy \&i ,
-.Sy \&O ,
-or
-.Sy \&o
-commands, use
-.Sy <escape>
-to quit entering text and return to command mode.
-.El
-.Pp
-The commands to copy text are:
-.Bl -tag -width XXXX -compact
-.It Sy yy
-Copy the line the cursor is on.
-.It Sy p
-Append the copied line after the line the cursor is on.
-.El
-.Pp
-The commands to delete text are:
-.Bl -tag -width XXXX -compact
-.It Sy dd
-Delete the line the cursor is on.
-.It Sy x
-Delete the character the cursor is on.
-.El
-.Pp
-The commands to write the file are:
-.Bl -tag -width XXXX -compact
-.It Sy :w<carriage-return>
-Write the file back to the file with the name that you originally used
-as an argument on the
-.Nm \&vi
-command line.
-.It Sy :w file_name<carriage-return>
-Write the file back to the file with the name
-.Dq file_name .
-.El
-.Pp
-The commands to quit editing and exit the editor are:
-.Bl -tag -width XXXX -compact
-.It Sy :q<carriage-return>
-Quit editing and leave vi (if you've modified the file, but not
-saved your changes,
-.Nm \&vi
-will refuse to quit).
-.It Sy :q!<carriage-return>
-Quit, discarding any modifications that you may have made.
-.El
-.Pp
-One final caution.
-Unusual characters can take up more than one column on the screen,
-and long lines can take up more than a single screen line.
-The above commands work on
-.Dq physical
-characters and lines, i.e. they affect the entire line no matter
-how many screen lines it takes up and the entire character no matter
-how many screen columns it takes up.
-.Sh VI COMMANDS
-The following section describes the commands available in the command
-mode of the
-.Nm \&vi
-editor.
-In each entry below, the tag line is a usage synopsis for the command
-character.
-.sp
-.Bl -tag -width "XXXX" -compact
-.It Sy "[count] <control-A>"
-Search forward
-.Li count
-times for the current word.
-.It Sy "[count] <control-B>"
-Page backwards
-.Li count
-screens.
-.It Sy "[count] <control-D>"
-Scroll forward
-.Li count
-lines.
-.It Sy "[count] <control-E>"
-Scroll forward
-.Li count
-lines, leaving the current line and column as is, if possible.
-.It Sy "[count] <control-F>"
-Page forward
-.Li count
-screens.
-.It Sy "<control-G>"
-Display the file information.
-.It Sy "<control-H>"
-.It Sy "[count] h"
-Move the cursor back
-.Li count
-characters in the current line.
-.It Sy "[count] <control-J>"
-.It Sy "[count] <control-N>"
-.It Sy "[count] j"
-Move the cursor down
-.Li count
-lines without changing the current column.
-.It Sy "<control-L>"
-.It Sy "<control-R>"
-Repaint the screen.
-.It Sy "[count] <control-M>"
-.It Sy "[count] +"
-Move the cursor down
-.Li count
-lines to the first nonblank character of that line.
-.It Sy "[count] <control-P>"
-.It Sy "[count] k"
-Move the cursor up
-.Li count
-lines, without changing the current column.
-.It Sy "<control-T>"
-Return to the most recent tag context.
-.It Sy "<control-U>"
-Scroll backwards
-.Li count
-lines.
-.It Sy "<control-W>"
-Switch to the next lower screen in the window, or, to the first
-screen if there are no lower screens in the window.
-.It Sy "<control-Y>"
-Scroll backwards
-.Li count
-lines, leaving the current line and column as is, if possible.
-.It Sy "<control-Z>"
-Suspend the current editor session.
-.It Sy "<escape>"
-Execute
-.Nm \&ex
-commands or cancel partial commands.
-.It Sy "<control-]>"
-Push a tag reference onto the tag stack.
-.It Sy "<control-^>"
-Switch to the most recently edited file.
-.It Sy "[count] <space>"
-.It Sy "[count] l"
-Move the cursor forward
-.Li count
-characters without changing the current line.
-.It Sy "[count] ! motion shell-argument(s)"
-Replace text with results from a shell command.
-.It Sy "[count] # +|-|#"
-Increment or decrement the cursor number.
-.It Sy "[count] $"
-Move the cursor to the end of a line.
-.It Sy "%"
-Move to the matching character.
-.It Sy "&"
-Repeat the previous substitution command on the current line.
-.It Sy "'<character>"
-.It Sy "`<character>"
-Return to a context marked by the character
-.Li <character> .
-.It Sy "[count] ("
-Back up
-.Li count
-sentences.
-.It Sy "[count] )"
-Move forward
-.Li count
-sentences.
-.It Sy "[count] ,"
-Reverse find character
-.Li count
-times.
-.It Sy "[count] -"
-Move to first nonblank of the previous line,
-.Li count
-times.
-.It Sy "[count] ."
-Repeat the last
-.Nm \&vi
-command that modified text.
-.It Sy "/RE<carriage-return>"
-.It Sy "/RE/ [offset]<carriage-return>"
-.It Sy "?RE<carriage-return>"
-.It Sy "?RE? [offset]<carriage-return>"
-.It Sy "N"
-.It Sy "n"
-Search forward or backward for a regular expression.
-.It Sy "0"
-Move to the first character in the current line.
-.It Sy ":"
-Execute an ex command.
-.It Sy "[count] ;"
-Repeat the last character find
-.Li count
-times.
-.It Sy "[count] < motion"
-.It Sy "[count] > motion"
-Shift lines left or right.
-.It Sy "@ buffer"
-Execute a named buffer.
-.It Sy "[count] A"
-Enter input mode, appending the text after the end of the line.
-.It Sy "[count] B"
-Move backwards
-.Li count
-bigwords.
-.It Sy "[buffer] [count] C"
-Change text from the current position to the end-of-line.
-.It Sy "[buffer] D"
-Delete text from the current position to the end-of-line.
-.It Sy "[count] E"
-Move forward
-.Li count
-end-of-bigwords.
-.It Sy "[count] F <character>"
-Search
-.Li count
-times backward through the current line for
-.Li <character> .
-.It Sy "[count] G"
-Move to line
-.Li count ,
-or the last line of the file if
-.Li count
-not specified.
-.It Sy "[count] H"
-Move to the screen line
-.Li "count - 1"
-lines below the top of the screen.
-.It Sy "[count] I"
-Enter input mode, inserting the text at the beginning of the line.
-.It Sy "[count] J"
-Join lines.
-.It Sy "[count] L"
-Move to the screen line
-.Li "count - 1"
-lines above the bottom of the screen.
-.It Sy " M"
-Move to the screen line in the middle of the screen.
-.It Sy "[count] O"
-Enter input mode, appending text in a new line above the current line.
-.It Sy "[buffer] P"
-Insert text from a buffer.
-.It Sy "Q"
-Exit
-.Nm \&vi
-(or visual) mode and switch to
-.Nm \&ex
-mode.
-.It Sy "[count] R"
-Enter input mode, replacing the characters in the current line.
-.It Sy "[buffer] [count] S"
-Substitute
-.Li count
-lines.
-.It Sy "[count] T <character>"
-Search backwards,
-.Li count
-times,
-through the current line for the character
-.Em after
-the specified
-.Li <character> .
-.It Sy "U"
-Restore the current line to its state before the cursor last
-moved to it.
-.It Sy "[count] W"
-Move forward
-.Li count
-bigwords.
-.It Sy "[buffer] [count] X"
-Delete
-.Li count
-characters before the cursor.
-.It Sy "[buffer] [count] Y"
-Copy (or
-.Dq yank )
-.Li count
-lines into the specified buffer.
-.It Sy "ZZ"
-Write the file and exit
-.Nm \&vi .
-.It Sy "[count] [["
-Back up
-.Li count
-section boundaries.
-.It Sy "[count] ]]"
-Move forward
-.Li count
-section boundaries.
-.It Sy "\&^"
-Move to first nonblank character on the current line.
-.It Sy "[count] _"
-Move down
-.Li "count - 1"
-lines, to the first nonblank character.
-.It Sy "[count] a"
-Enter input mode, appending the text after the cursor.
-.It Sy "[count] b"
-Move backwards
-.Li count
-words.
-.It Sy "[buffer] [count] c motion"
-Change a region of text.
-.It Sy "[buffer] [count] d motion"
-Delete a region of text.
-.It Sy "[count] e"
-Move forward
-.Li count
-end-of-words.
-.It Sy "[count] f<character>"
-Search forward,
-.Li count
-times, through the rest of the current line for
-.Li <character> .
-.It Sy "[count] i"
-Enter input mode, inserting the text before the cursor.
-.It Sy "m <character>"
-Save the current context (line and column) as
-.Li <character> .
-.It Sy "[count] o"
-Enter input mode, appending text in a new line under the current line.
-.It Sy "[buffer] p"
-Append text from a buffer.
-.It Sy "[count] r <character>
-Replace
-.Li count
-characters.
-.It Sy "[buffer] [count] s"
-Substitute
-.Li count
-characters in the current line starting with the current character.
-.It Sy "[count] t <character>"
-Search forward,
-.Li count
-times, through the current line for the character immediately
-.Em before
-.Li <character> .
-.It Sy "u"
-Undo the last change made to the file.
-.It Sy "[count] w"
-Move forward
-.Li count
-words.
-.It Sy "[buffer] [count] x"
-Delete
-.Li count
-characters.
-.It Sy "[buffer] [count] y motion"
-Copy (or
-.Dq yank )
-a text region specified by the
-.Li count
-and motion into a buffer.
-.It Sy "[count1] z [count2] -|.|+|^|<carriage-return>"
-Redraw, optionally repositioning and resizing the screen.
-.It Sy "[count] {"
-Move backward
-.Li count
-paragraphs.
-.It Sy "[count] |"
-Move to a specific
-.Em column
-position on the current line.
-.It Sy "[count] }"
-Move forward
-.Li count
-paragraphs.
-.It Sy "[count] ~"
-Reverse the case of the next
-.Li count
-character(s).
-.It Sy "[count] ~ motion"
-Reverse the case of the characters in a text region specified by the
-.Li count
-and
-.Li motion .
-.It Sy "<interrupt>"
-Interrupt the current operation.
-.El
-.Sh VI TEXT INPUT COMMANDS
-The following section describes the commands available in the text
-input mode of the
-.Nm \&vi
-editor.
-.Pp
-.Bl -tag -width "XXXX" -compact
-.It Sy "<nul>"
-Replay the previous input.
-.It Sy "<control-D>"
-Erase the previous autoindent character.
-.It Sy "^<control-D>"
-Erase all of the autoindent characters, and reset the autoindent level.
-.It Sy "0<control-D>"
-Erase all of the autoindent characters.
-.It Sy "<control-T>"
-Insert sufficient
-.Li <tab>
-and
-.Li <space>
-characters to move the cursor forward to a column immediately
-after the next column which is an even multiple of the
-.Sy shiftwidth
-option.
-.It Sy "<erase>
-.It Sy "<control-H>"
-Erase the last character.
-.It Sy "<literal next>"
-Quote the next character.
-.It Sy "<escape>
-Resolve all text input into the file, and return to command mode.
-.It Sy "<line erase>
-Erase the current line.
-.It Sy "<control-W>"
-.It Sy "<word erase>
-Erase the last word.
-The definition of word is dependent on the
-.Sy altwerase
-and
-.Sy ttywerase
-options.
-.It Sy "<control-X>[0-9A-Fa-f]*"
-Insert a character with the specified hexadecimal value into the text.
-.It Sy "<interrupt>"
-Interrupt text input mode, returning to command mode.
-.El
-.Sh EX COMMANDS
-The following section describes the commands available in the
-.Nm \&ex
-editor.
-In each entry below, the tag line is a usage synopsis for the command.
-.sp
-.Bl -tag -width "XXXX" -compact
-.It Sy "<end-of-file>"
-Scroll the screen.
-.It Sy "! argument(s)"
-.It Sy "[range]! argument(s)"
-Execute a shell command, or filter lines through a shell command.
-.It Sy \&"
-A comment.
-.It Sy "[range] nu[mber] [count] [flags]"
-.It Sy "[range] # [count] [flags]"
-Display the selected lines, each preceded with its line number.
-.It Sy "@ buffer"
-.It Sy "* buffer"
-Execute a buffer.
-.It Sy "[range] d[elete] [buffer] [count] [flags]"
-Delete the lines from the file.
-.It Sy "di[splay] b[uffers] | s[creens] | t[ags]"
-Display buffers, screens or tags.
-.It Sy "e[dit][!] [+cmd] [file]"
-.It Sy "ex[!] [+cmd] [file]"
-Edit a different file.
-.It Sy "exu[sage] [command]"
-Display usage for an
-.Nm \&ex
-command.
-.It Sy "f[ile] [file]"
-Display and optionally change the file name.
-.It Sy "fg [name]"
-.Nm \&Vi
-mode only.
-Foreground the specified screen.
-.It Sy "[range] g[lobal] /pattern/ [commands]"
-.It Sy "[range] v /pattern/ [commands]
-Apply commands to lines matching (or not matching) a pattern.
-.It Sy "he[lp]"
-Display a help message.
-.It Sy "[line] i[nsert][!]"
-The input text is inserted before the specified line.
-.It Sy "[range] j[oin][!] [count] [flags]"
-Join lines of text together.
-.It Sy "[range] l[ist] [count] [flags]"
-Display the lines unambiguously.
-.It Sy "map[!] [lhs rhs]"
-Define or display maps (for
-.Nm \&vi
-only).
-.It Sy "[line] ma[rk] <character>"
-.It Sy "[line] k <character>"
-Mark the line with the mark
-.Li <character> .
-.It Sy "[range] m[ove] line"
-Move the specified lines after the target line.
-.It Sy "mk[exrc][!] file"
-Write the abbreviations, editor options and maps to the specified
-file.
-.It Sy "n[ext][!] [file ...]"
-Edit the next file from the argument list.
-.It Sy "[line] o[pen] /pattern/ [flags]"
-Enter open mode.
-.It Sy "pre[serve]"
-Save the file in a form that can later be recovered using the
-.Nm \&ex
-.Fl r
-option.
-.It Sy "prev[ious][!]"
-Edit the previous file from the argument list.
-.It Sy "[range] p[rint] [count] [flags]"
-Display the specified lines.
-.It Sy "[line] pu[t] [buffer]"
-Append buffer contents to the current line.
-.It Sy "q[uit][!]"
-End the editing session.
-.It Sy "[line] r[ead][!] [file]"
-Read a file.
-.It Sy "rec[over] file"
-Recover
-.Li file
-if it was previously saved.
-.It Sy "res[ize] [+|-]size"
-.Nm \&Vi
-mode only.
-Grow or shrink the current screen.
-.It Sy "rew[ind][!]"
-Rewind the argument list.
-.It Sy "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
-Display or set editor options.
-.It Sy "sh[ell]"
-Run a shell program.
-.It Sy "so[urce] file"
-Read and execute
-.Nm \&ex
-commands from a file.
-.It Sy "sp[lit] [file ...]"
-.Nm \&Vi
-mode only.
-Split the screen.
-.It Sy "[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]"
-.It Sy "[range] & [options] [count] [flags]"
-.It Sy "[range] ~ [options] [count] [flags]"
-Make substitutions.
-.It Sy "su[spend][!]"
-.It Sy "st[op][!]"
-.It Sy <suspend>
-Suspend the edit session.
-.It Sy "ta[g][!] tagstring"
-Edit the file containing the specified tag.
-.It Sy "tagp[op][!] [file | number]"
-Pop to the specified tag in the tags stack.
-.It Sy "unm[ap][!] lhs"
-Unmap a mapped string.
-.It Sy "ve[rsion]"
-Display the version of the
-.Nm \&ex/vi
-editor.
-.It Sy "[line] vi[sual] [type] [count] [flags]"
-.Nm \&Ex
-mode only.
-Enter
-.Nm \&vi .
-.It Sy "vi[sual][!] [+cmd] [file]"
-.Nm \&Vi
-mode only.
-Edit a new file.
-.It Sy "viu[sage] [command]"
-Display usage for a
-.Nm \&vi
-command.
-.It Sy "[range] w[rite][!] [>>] [file]"
-.It Sy "[range] w[rite] [!] [file]"
-.It Sy "[range] wn[!] [>>] [file]"
-.It Sy "[range] wq[!] [>>] [file]"
-Write the file.
-.It Sy "[range] x[it][!] [file]"
-Write the file if it has been modified.
-.It Sy "[range] ya[nk] [buffer] [count]"
-Copy the specified lines to a buffer.
-.It Sy "[line] z [type] [count] [flags]"
-Adjust the window.
-.El
-.Sh SET OPTIONS
-There are a large number of options that may be set (or unset) to
-change the editor's behavior.
-This section describes the options, their abbreviations and their
-default values.
-.Pp
-In each entry below, the first part of the tag line is the full name
-of the option, followed by any equivalent abbreviations.
-The part in square brackets is the default value of the option.
-Most of the options are boolean, i.e. they are either on or off,
-and do not have an associated value.
-.Pp
-Options apply to both
-.Nm \&ex
-and
-.Nm \&vi
-modes, unless otherwise specified.
-.sp
-.Bl -tag -width "XXXX" -compact
-.It Sy "altwerase [off]"
-.Nm \&Vi
-only.
-Select an alternate word erase algorithm.
-.It Sy "autoindent, ai [off]"
-Automatically indent new lines.
-.It Sy "autoprint, ap [off]"
-.Nm \&Ex
-only.
-Display the current line automatically.
-.It Sy "autowrite, aw [off]"
-Write modified files automatically when changing files.
-.It Sy "beautify, bf [off]"
-Discard control characters.
-.It Sy "cdpath [environment variable CDPATH, or current directory]"
-The directory paths used as path prefixes for the
-.Sy cd
-command.
-.It Sy "columns, co [80]"
-Set the number of columns in the screen.
-.It Sy "comment [off]"
-.Nm \&Vi
-only.
-Skip leading comments in files.
-.It Sy "directory, dir [environment variable TMPDIR, or /tmp]"
-The directory where temporary files are created.
-.It Sy "edcompatible, ed [off]"
-Remember the values of the
-.Dq \&c
-and
-.Dq \&g
-suffices to the
-.Sy substitute
-commands, instead of initializing them as unset for each new
-command.
-.It Sy "errorbells, eb [off]"
-.Nm \&Ex
-only.
-Announce error messages with a bell.
-.It Sy "exrc, ex [off]"
-Never read startup files in the local directory.
-.It Sy "extended [off]"
-Regular expressions are extended (i.e.
-.Xr egrep 1
-style) expressions.
-.It Sy "flash [on]"
-Flash the screen instead of beeping the keyboard on error.
-.It Sy "hardtabs, ht [8]"
-Set the spacing between hardware tab settings.
-.It Sy "ignorecase, ic [off]"
-Ignore case differences in regular expressions.
-.It Sy "keytime [6]"
-The 10th's of a second
-.Nm ex/vi
-waits for a subsequent key to complete a key mapping.
-.It Sy "leftright [off]"
-.Nm \&Vi
-only.
-Do left-right scrolling.
-.It Sy "lines, li [24]"
-.Nm \&Vi
-only.
-Set the number of lines in the screen.
-.It Sy "lisp [off]"
-.Nm \&Vi
-only.
-Modify various search commands and options to work with Lisp.
-.Pp
-.Em "This option is not yet implemented."
-.It Sy "list [off]"
-Display lines in an unambiguous fashion.
-.It Sy "magic [on]"
-Treat certain characters specially in regular expressions.
-.It Sy "matchtime [7]"
-.Nm \&Vi
-only.
-The 10th's of a second
-.Nm ex/vi
-pauses on the matching character when the
-.Sy showmatch
-option is set.
-.It Sy "mesg [on]"
-Permit messages from other users.
-.It Sy "modelines, modeline [off]"
-Read the first and last few lines of each file for
-.Nm ex
-commands.
-.Pp
-.Em "This option will never be implemented."
-.It Sy "number, nu [off]"
-Precede each line displayed with its current line number.
-.It Sy "octal [off]"
-Display unknown characters as octal numbers, instead of the default
-hexadecimal.
-.It Sy "open [on]"
-.Nm \&Ex
-only.
-If this option is not set, the
-.Sy open
-and
-.Sy visual
-commands are disallowed.
-.It Sy "optimize, opt [on]"
-.Nm \&Vi
-only.
-Optimize text throughput to dumb terminals.
-.Pp
-.Em "This option is not yet implemented."
-.It Sy "paragraphs, para [IPLPPPQPP LIpplpipbp]"
-.Nm \&Vi
-only.
-Define additional paragraph boundaries for the
-.Sy \&{
-and
-.Sy \&}
-commands.
-.It Sy "prompt [on]"
-.Nm \&Ex
-only.
-Display a command prompt.
-.It Sy "readonly, ro [off]"
-Mark the file as read-only.
-.It Sy "recdir [/var/tmp/vi.recover]"
-The directory where recovery files are stored.
-.It Sy "redraw, re [off]"
-.Nm \&Vi
-only.
-Simulate an intelligent terminal on a dumb one.
-.Pp
-.Em "This option is not yet implemented."
-.It Sy "remap [on]"
-Remap keys until resolved.
-.It Sy "report [5]"
-Set the number of lines about which the editor reports changes
-or yanks.
-.It Sy "ruler [off]"
-.Nm \&Vi
-only.
-Display a row/column ruler on the colon command line.
-.It Sy "scroll, scr [window / 2]"
-Set the number of lines scrolled.
-.It Sy "sections, sect [NHSHH HUnhsh]"
-.Nm \&Vi
-only.
-Define additional section boundaries for the
-.Sy \&[[
-and
-.Sy \&]]
-commands.
-.It Sy "shell, sh [environment variable SHELL, or /bin/sh]"
-Select the shell used by the editor.
-.It Sy "shiftwidth, sw [8]"
-Set the autoindent and shift command indentation width.
-.It Sy "showdirty [off]"
-.Nm \&Vi
-only.
-Display an asterisk on the colon command line if the file has been modified.
-.It Sy "showmatch, sm [off]"
-.Nm \&Vi
-only.
-Note matching
-.Dq \&{
-and
-.Dq \&(
-for
-.Dq \&}
-and
-.Dq \&)
-characters.
-.It Sy "showmode [off]"
-.Nm \&Vi
-only.
-Display the current editor mode (command or input).
-.It Sy "sidescroll [16]"
-.Nm \&Vi
-only.
-Set the amount a left-right scroll will shift.
-.It Sy "slowopen, slow [off]"
-Delay display updating during text input.
-.Pp
-.Em "This option is not yet implemented."
-.It Sy "sourceany [off]"
-Read startup files not owned by the current user.
-.Pp
-.Em "This option will never be implemented."
-.It Sy "tabstop, ts [8]"
-This option sets tab widths for the editor display.
-.It Sy "taglength, tl [0]"
-Set the number of significant characters in tag names.
-.It Sy "tags, tag [tags /var/db/libc.tags /sys/kern/tags]"
-Set the list of tags files.
-.It Sy "term, ttytype, tty [environment variable TERM]"
-Set the terminal type.
-.It Sy "terse [off]"
-This option has historically made editor messages less verbose.
-It has no effect in this implementation.
-.It Sy "tildeop"
-Modify the
-.Sy \&~
-command to take an associated motion.
-.It Sy "timeout, to [on]"
-Time out on keys which may be mapped.
-.It Sy "ttywerase [off]"
-.Nm \&Vi
-only.
-Select an alternate erase algorithm.
-.It Sy "verbose [off]"
-.NM \&Vi
-only.
-Display an error message for every error.
-.It Sy "w300 [no default]"
-.Nm \&Vi
-only.
-Set the window size if the baud rate is less than 1200 baud.
-.It Sy "w1200 [no default]"
-.Nm \&Vi
-only.
-Set the window size if the baud rate is equal to 1200 baud.
-.It Sy "w9600 [no default]"
-.Nm \&Vi
-only.
-Set the window size if the baud rate is greater than 1200 baud.
-.It Sy "warn [on]"
-.Nm \&Ex
-only.
-This option causes a warning message to the terminal if the file has
-been modified, since it was last written, before a
-.Sy \&!
-command.
-.It Sy "window, w, wi [environment variable LINES]"
-Set the window size for the screen.
-.It Sy "wrapmargin, wm [0]"
-.Nm \&Vi
-only.
-Break lines automatically when they reach the right-hand margin.
-.It Sy "wrapscan, ws [on]"
-Set searches to wrap around the end or beginning of the file.
-.It Sy "writeany, wa [off]"
-Turn off file-overwriting checks.
-.El
-.Sh ENVIRONMENTAL VARIABLES
-.Bl -tag -width "COLUMNSXX" -compact
-.It Ev COLUMNS
-The number of columns on the screen.
-This value overrides any system or terminal specific values.
-If the COLUMNS environmental variable is not set when
-.Nm ex/vi
-runs, or the
-.Sy columns
-option is explicitly reset by the user,
-.Nm ex/vi
-enters the value into the environment.
-.It Ev EXINIT
-A list of
-.Nm \&ex
-startup commands, read if the variable
-.Ev NEXINIT
-is not set.
-.It Ev HOME
-The user's home directory, used as the initial directory path
-for the startup
-.Pa $HOME/.nexrc
-and
-.Pa $HOME/.exrc
-files.
-This value is also used as the default directory for the
-.Nm \&vi
-.Sy \&cd
-command.
-.It Ev LINES
-The number of rows on the screen.
-This value overrides any system or terminal specific values.
-If the LINES environmental variable is not set when
-.Nm ex/vi
-runs, or the
-.Sy lines
-option is explicitly reset by the user,
-.Nm ex/vi
-enters the value into the environment.
-.It Ev NEXINIT
-A list of
-.Nm \&ex
-startup commands.
-.It Ev SHELL
-The user's shell of choice (see also the
-.Sy shell
-option).
-.It Ev TERM
-The user's terminal type.
-The default is the type
-.Dq unknown .
-If the TERM environmental variable is not set when
-.Nm ex/vi
-runs, or the
-.Sy term
-option is explicitly reset by the user,
-.Nm ex/vi
-enters the value into the environment.
-.It Ev TMPDIR
-The location used to stored temporary files (see also the
-.Sy directory
-option).
-.El
-.Sh ASYNCHRONOUS EVENTS
-.Bl -tag -width "SIGWINCHXX" -compact
-.It SIGALRM
-.Nm \&Vi/ex
-uses this signal for periodic backups of file modifications
-and to display
-.Dq busy
-messages when operations are likely to take a long time.
-.It SIGHUP
-.It SIGTERM
-If the current buffer has changed since it was last written in its
-entirety, the editor attempts to save the modified file so it can
-be later recovered.
-See the
-.Nm \&vi/ex
-Reference manual section entitled
-.Dq Recovery
-for more information.
-.It SIGINT
-When an interrupt occurs,
-the current operation is halted,
-and the editor returns to the command level.
-If interrupted during text input,
-the text already input is resolved into the file as if the text
-input had been normally terminated.
-.It SIGWINCH
-The screen is resized.
-See the
-.Nm \&vi/ex
-Reference manual section entitled
-.Dq "Sizing the Screen"
-for more information.
-.It SIGCONT
-.It SIGQUIT
-.It SIGTSTP
-.Nm \&Vi/ex
-ignores these signals.
-.El
-.Sh BUGS
-See the file
-.Pa nvi/docs/bugs.current
-for a list of the known bugs in this version.
-.Sh FILES
-.Bl -tag -width /var/tmp/vi.recover -compact
-.It Pa /bin/sh
-The default user shell.
-.It Pa /etc/vi.exrc
-System-wide vi startup file.
-.It Pa /tmp
-Temporary file directory.
-.It Pa /var/tmp/vi.recover
-The default recovery file directory.
-.It Pa $HOME/.nexrc
-1st choice for user's home directory startup file.
-.It Pa $HOME/.exrc
-2nd choice for user's home directory startup file.
-.It Pa .nexrc
-1st choice for local directory startup file.
-.It Pa .exrc
-2nd choice for local directory startup file.
-.El
-.Sh SEE ALSO
-.Xr ctags 1 ,
-.Xr more 1 ,
-.Xr curses 3 ,
-.Xr dbopen 3
-.sp
-The
-.Dq "Vi Quick Reference"
-card.
-.sp
-.Dq "\&An Introduction to Display Editing with Vi" ,
-found in the
-.Dq "UNIX User's Manual Supplementary Documents"
-section of both the 4.3BSD and 4.4BSD manual sets.
-This document is the closest thing available to an introduction to the
-.Nm \&vi
-screen editor.
-.sp
-.Dq "\&Ex Reference Manual (Version 3.7)" ,
-found in the
-.Dq "UNIX User's Manual Supplementary Documents"
-section of both the 4.3BSD and 4.4BSD manual sets.
-This document is the final reference for the
-.Nm \&ex
-editor, as distributed in most historic 4BSD and System V systems.
-.sp
-.Dq "Edit: A tutorial" ,
-found in the
-.Dq "UNIX User's Manual Supplementary Documents"
-section of the 4.3BSD manual set.
-This document is an introduction to a simple version of the
-.Nm \&ex
-screen editor.
-.sp
-.Dq "\&Ex/Vi Reference Manual" ,
-found in the
-.Dq "UNIX User's Manual Supplementary Documents"
-section of the 4.4BSD manual set.
-This document is the final reference for the
-.Nm \&nex/nvi
-text editors, as distributed in 4.4BSD and 4.4BSD-Lite.
-.Pp
-.Nm Roff
-source for all of these documents is distributed with
-.Nm nex/nvi
-in the
-.Pa nvi/USD.doc
-directory of the
-.Nm nex/nvi
-source code.
-.sp
-The files
-.Dq autowrite ,
-.Dq input ,
-.Dq quoting ,
-and
-.Dq structures ,
-found in the
-.Pa nvi/docs/internals
-directory of the
-.Nm nex/nvi
-source code.
-.Sh HISTORY
-The
-.Nm nex/nvi
-replacements for the
-.Nm ex/vi
-editor first appeared in 4.4BSD.
-.Sh STANDARDS
-.Nm \&Nex/nvi
-is close to IEEE Std1003.2 (``POSIX'').
-That document differs from historical
-.Nm ex/vi
-practice in several places; there are changes to be made on both sides.
diff --git a/usr.bin/vi/USD.doc/vi.ref/Makefile b/usr.bin/vi/USD.doc/vi.ref/Makefile
deleted file mode 100644
index 2690f86..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# @(#)Makefile 8.16 (Berkeley) 8/15/94
-
-DIR= usd/13.viref
-SRCS= vi.ref ex.cmd.roff set.opt.roff vi.cmd.roff ref.so
-MACROS= -me
-CLEANFILES+=vi.ref.txt index index.so
-
-paper.ps: vi.ref index.so
- soelim vi.ref | ${TBL} | ${ROFF} > ${.TARGET}
-
-vi.ref.txt: vi.ref index.so
- soelim vi.ref | ${TBL} | groff ${MACROS} -Tascii > $@
-
-index.so: vi.ref
- # Build index.so, side-effect of building the paper.
- soelim vi.ref | ${TBL} | ${ROFF} > /dev/null
- sed -e 's/MINUSSIGN/\\-/' \
- -e 's/DOUBLEQUOTE/""/' \
- -e "s/SQUOTE/'/" \
- -e 's/ /__SPACE/g' < index | \
- sort -u '-t ' +0 -1 +1n | awk -f merge.awk | \
- sed -e 's/__SPACE/ /g' > index.so
- rm -f index
-
-.include <bsd.doc.mk>
diff --git a/usr.bin/vi/USD.doc/vi.ref/ex.cmd.roff b/usr.bin/vi/USD.doc/vi.ref/ex.cmd.roff
deleted file mode 100644
index a9cba6ae3..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/ex.cmd.roff
+++ /dev/null
@@ -1,1776 +0,0 @@
-.\" Copyright (c) 1994
-.\" 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.
-.\"
-.\" @(#)ex.cmd.roff 8.24 (Berkeley) 7/17/94
-.\"
-.SH 1 "Ex Description"
-.pp
-The following words have special meanings for
-.CO ex
-commands.
-.KY "<eof>"
-.IP "<eof>"
-The end-of-file character is used to scroll the screen in the
-.CO ex
-editor.
-This character is normally
-.LI <control-D> ,
-however, whatever character is set for the current terminal is used.
-.KY "line"
-.IP "line"
-A single-line address, given in any of the forms described in the
-section entitled
-.QB "Ex Addressing" .
-The default for
-.LI line
-is the current line.
-.KY "range"
-.IP "range"
-A line, or a pair of line addresses, separated by a comma or semicolon.
-(See the section entitled
-.QB "Ex Addressing"
-for more information.)
-The default for range is the current line
-.i only ,
-i.e.
-.QT \&.,. .
-A percent sign
-.PQ %
-stands for the range
-.QT 1,$ .
-The starting address must be less than, or equal to, the ending address.
-.KY "count"
-.IP "count"
-A positive integer, specifying the number of lines to be affected by
-the command; the default is 1.
-Generally, a count past the end-of-file may be specified, e.g. the
-command
-.QT "p 3000"
-in a 10 line file is acceptable, and will print from the current line
-through the last line in the file.
-.KY "flags"
-.IP "flags"
-One or more of the characters
-.QQ # ,
-.QQ p ,
-and
-.QQ l .
-When a command that accepts these flags completes, the addressed line(s)
-are written out as if by the corresponding
-.CO # ,
-.CO l
-or
-.CO p
-commands.
-In addition, any number of
-.QT +
-or
-.QT \-
-characters can be specified before, after, or during the flags, in which
-case the line written is not necessarily the one affected by the command,
-but rather the line addressed by the offset address specified.
-The default for
-.LI flags
-is none.
-.KY "file"
-.IP "file"
-A pattern used to derive a pathname; the default is the current file.
-File names are subjected to normal
-.XR sh 1
-word expansions.
-.pp
-Anywhere a file name is specified, it is also possible to use
-the special string
-.QT /tmp .
-This will be replaced with a temporary file name which can be used
-for temporary work, e.g.
-.QT ":e /tmp"
-creates and edits a new file.
-.pp
-If both a count and a range are specified for commands that use either,
-the starting line for the command is the
-.i last
-line addressed by the range, and
-.LI count - 1
-subsequent lines are affected by the command, e.g. the command
-.QT 2,3p4
-prints out lines 3, 4, 5 and 6.
-.pp
-When only a line or range is specified, with no command, the implied
-command is either a
-.CO list ,
-.CO number
-or
-.CO print
-command.
-The command used is the most recent of the three commands to have been
-used (including any use as a flag).
-If none of these commands have been used before, the
-.CO print
-command is the implied command.
-When no range or count is specified and the command line is a blank line,
-the current line is incremented by 1 and then the current line is displayed.
-.pp
-Zero or more whitespace characters may precede or follow the addresses,
-count, flags, or command name.
-Any object following a command name (such as buffer, file, etc.),
-that begins with an alphabetic character,
-should be separated from the command name by at least one whitespace
-character.
-.pp
-Any character, including
-.LI <carriage-return> ,
-.QT %
-and
-.QT #
-retain their literal value when preceded by a backslash.
-.SH 1 "Ex Commands"
-.pp
-The following section describes the commands available in the
-.CO ex
-editor.
-In each entry below, the tag line is a usage synopsis for the command.
-.pp
-Each command can be entered as the abbreviation
-(those characters in the synopsis command word preceding the
-.QQ [
-character),
-the full command (all characters shown for the command word,
-omitting the
-.QQ [
-and
-.QQ ]
-characters),
-or any leading subset of the full command down to the abbreviation.
-For example, the args command (shown as
-.QT ar[gs]
-in the synopsis)
-can be entered as
-.QT ar ,
-.QT arg
-or
-.QT args .
-.pp
-Each
-.CO ex
-command described below notes the new current line after it
-is executed, as well as any options that affect the command.
-.KY DOUBLEQUOTE
-.IP """"
-A comment.
-Command lines beginning with the double-quote character
-.PQ """"
-are ignored.
-This permits comments in editor scripts and startup files.
-.KY "<end-of-file>"
-.IP "<end-of-file>"
-Scroll the screen.
-Write the next N lines, where N is the value of the
-.OP scroll
-option.
-The command is the end-of-file terminal character, which may be
-different on different terminals.
-Traditionally, it is the
-.LI <control-D>
-key.
-.sp
-Historically, the
-.CO eof
-command ignored any preceding count, and the
-.LI <end-of-file>
-character was ignored unless it was entered as the first character
-of the command.
-This implementation treats it as a command
-.i only
-if entered as the first character of the command line, and otherwise
-treats it as any other character.
-.SS
-.SP Line:
-Set to the last line written.
-.SP Options:
-None.
-.SE
-.KY "!"
-.IP "! argument(s)"
-.Ip "[range]! argument(s)"
-Execute a shell command, or filter lines through a shell command.
-In the first synopsis, the remainder of the line after the
-.QT !
-character is passed to the program named by the
-.OP shell
-option, as a single argument.
-.sp
-Within the rest of the line,
-.QT %
-and
-.QT #
-are expanded into the current and alternate pathnames, respectively.
-The character
-.QT !
-is expanded with the command text of the previous
-.CO !
-command.
-(Therefore, the command
-.CO !!
-repeats the previous
-.CO !
-command.)
-The special meanings of
-.QT % ,
-.QT # ,
-and
-.QT !
-can be overridden by escaping them with a backslash.
-If no
-.CO !
-or
-.CO :!
-command has yet been executed, it is an error to use an unescaped
-.QT !
-character.
-The
-.CO !
-command does
-.i not
-do shell expansion on the strings provided as arguments.
-If any of the above expansions change the command the user entered,
-the command is redisplayed at the bottom of the screen.
-.sp
-.CO Ex
-then executes the program named by the
-.OP shell
-option, with a
-.b \-c
-flag followed by the arguments (which are bundled into a single argument).
-.sp
-The
-.CO !
-command is permitted in an empty file.
-.sp
-If the file has been modified since it was last completely written,
-the
-.Co !
-command will warn you.
-.sp
-A single
-.QT !
-character is displayed when the command completes.
-.sp
-In the second form of the
-.CO !
-command, the remainder of the line after the
-.QT !
-is passed to the program named by the
-.OP shell
-option, as described above.
-The specified lines are passed to the program as standard input,
-and the standard and standard error output of the program replace
-the original lines.
-.SS
-.SP Line:
-Unchanged if no range was specified, otherwise set to the first
-line of the range.
-.SP Options:
-Affected by the
-.OP autowrite
-and
-.OP writeany
-options.
-.SE
-.KY "number"
-.IP "[range] nu[mber] [count] [flags]"
-.KY "#"
-.Ip "[range] # [count] [flags]"
-Display the selected lines, each preceded with its line number.
-.sp
-The line number format is
-.QQ %6d ,
-followed by two spaces.
-.SS
-.SP Line:
-Set to the last line displayed.
-.SP Options:
-None.
-.SE
-.KY "@"
-.IP "@ buffer"
-.KY "*"
-.Ip "* buffer"
-Execute a buffer.
-Each line in the named buffer is executed as an
-.CO ex
-command.
-If no buffer is specified, or if the specified buffer is
-.QT @
-or
-.QT * ,
-the last buffer executed is used.
-.KY <
-.IP "[range] <[< ...] [count] [flags]"
-Shift lines left or right.
-The specified lines are shifted to the left (for the
-.CO <
-command) or right (for the
-.CO >
-command), by the number of columns specified by the
-.OP shiftwidth
-option.
-Only leading whitespace characters are deleted when shifting left;
-once the first column of the line contains a nonblank character,
-the
-.CO shift
-command will succeed, but the line will not be modified.
-.sp
-If the command character
-.CO <
-or
-.CO >
-is repeated more than once, the command is repeated once for each
-additional command character.
-.SS
-.SP Line:
-If the current line is set to one of the lines that are affected
-by the command, it is unchanged.
-Otherwise, it is set to the first nonblank character of the lowest
-numbered line shifted.
-.SP Options:
-Affected by the
-.OP shiftwidth
-option.
-.SE
-.KY =
-.IP "[line] = [flags]"
-Display the line number.
-Display the line number of
-.LI line
-(which defaults to the last line in the file).
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY >
-.IP "[range] >[> ...] [count] [flags]"
-Shift right.
-The specified lines are shifted to the right by the number of columns
-specified by the
-.OP shiftwidth
-option, by inserting tab and space characters.
-Empty lines are not changed.
-.sp
-If the command character
-.QT >
-is repeated more than once, the command is repeated once for each
-additional command character.
-.SS
-.SP Line:
-Set to the last line modified by the command.
-.SP Options:
-None.
-.SE
-.KY abbrev
-.IP "ab[brev] lhs rhs"
-Add an abbreviation to the current abbreviation list.
-In
-.CO vi ,
-if
-.LI lhs
-is entered such that it is preceded and followed by characters
-that cannot be part of a word, it is replaced by the string
-.LI rhs .
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY append
-.IP "[line] a[ppend][!]"
-The input text is appended to the specified line.
-If line 0 is specified, the text is inserted at the beginning of the file.
-Set to the last line input.
-If no lines are input, then set to
-.LI line ,
-or to the first line of the file if a
-.LI line
-of 0 was specified.
-Following the command name with a
-.QT !
-character causes the
-.OP autoindent
-option to be toggled for the duration of the command.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY args
-.IP "ar[gs]"
-Display the argument list.
-The current argument is displayed inside of
-.QT [
-and
-.QT ]
-characters.
-The argument list is the list of operands specified on startup,
-which can be replaced using the
-.CO next
-command.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY bg
-.IP bg
-.CO Vi
-mode only.
-Background the current screen.
-.SS
-.SP Line:
-Set to the current line when the screen was last edited.
-.SP Options:
-None.
-.SE
-.KY change
-.IP "[range] c[hange][!] [count]"
-Replace the lines with input text.
-Following the command name with a
-.QT !
-character causes the
-.OP autoindent
-option to be toggled for the duration of the command.
-.SS
-.SP Line:
-Set to the last line input, or, if no lines were input,
-set to the line before the target line, or to the first
-line of the file if there are no lines preceding the target line.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY cd
-.KY chdir
-.IP "chd[ir][!] [directory]"
-.Ip "cd[!] [directory]"
-Change the current working directory.
-The
-.LI directory
-argument is subjected to
-.XR sh 1
-word expansions.
-When invoked with no directory argument and the
-.LI HOME
-environment variable is set, the directory named by the
-.LI HOME
-environment variable becomes the new current directory.
-Otherwise, the new current directory becomes the directory returned
-by the
-.XR getpwent 3
-routine.
-.sp
-The
-.CO chdir
-command will fail if the file has been modified since the last complete
-write of the file.
-You can override this check by appending a
-.QT !
-character to the command.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-Affected by the
-.OP cdpath
-option.
-.SE
-.KY copy
-.KY t
-.IP "[range] co[py] line [flags]"
-.Ip "[range] t line [flags]"
-Copy the specified lines (range) after the destination line.
-Line 0 may be specified to insert the lines at the beginning of
-the file.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY delete
-.IP "[range] d[elete] [buffer] [count] [flags]"
-Delete the lines from the file.
-The deleted text is saved in the specified buffer, or, if no buffer
-is specified, in the unnamed buffer.
-If the command name is followed by a letter that could be interpreted
-as either a buffer name or a flag value (because neither a
-.LI count
-or
-.LI flags
-values were given),
-.CO ex
-treats the letter as a
-.LI flags
-value if the letter immediately follows the command name,
-without any whitespace separation.
-If the letter is preceded by whitespace characters,
-it treats it as a buffer name.
-.SS
-.SP Line:
-Set to the line following the deleted lines,
-or to the last line if the deleted lines were at the end.
-.SP Options:
-None.
-.SE
-.KY display
-.IP "di[splay] b[uffers] | s[creens] | t[ags]"
-Display buffers, screens or tags.
-The
-.CO display
-command takes one of three additional arguments, which are as follows:
-.SS
-.SP b[uffers]
-Display all buffers (including named, unnamed, and numeric)
-that contain text.
-.SP s[creens]
-Display the file names of all background screens.
-.SP t[ags]
-Display the tags stack.
-.SE
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY edit
-.IP "e[dit][!] [+cmd] [file]"
-.Ip "ex[!] [+cmd] [file]"
-Edit a different file.
-If the current buffer has been modified since the last complete write,
-the command will fail.
-You can override this by appending a
-.QT !
-character to the command name.
-.sp
-If the
-.QT +cmd
-option is specified, that
-.CO ex
-command will be executed in the new file.
-Any
-.CO ex
-command may be used, although the most common use of this feature is
-to specify a line number or search pattern to set the initial location
-in the new file.
-.SS
-.SP Line:
-If you have previously edited the file, the current line will be set
-to your last position in the file.
-If that position does not exist, or you have not previously edited the
-file, the current line will be set to the first line of the file if
-you are in
-.CO vi
-mode, and the last line of the file if you are in
-.CO ex .
-.SP Options:
-Affected by the
-.OP autowrite
-and
-.OP writeany
-options.
-.SE
-.KY exusage
-.IP "exu[sage] [command]"
-Display usage for an
-.CO ex
-command.
-If
-.LI command
-is specified, a usage statement for that command is displayed.
-Otherwise, usage statements for all
-.CO ex
-commands are displayed.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY file
-.IP "f[ile] [file]"
-Display and optionally change the file name.
-If a file name is specified, the current pathname is changed to the
-specified name.
-The current pathname, the number of lines, and the current position
-in the file are displayed.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY fg
-.IP "fg [name]"
-.CO Vi
-mode only.
-Foreground the specified screen.
-Swap the current screen with the specified backgrounded screen.
-If no screen is specified, the first background screen is foregrounded.
-.SS
-.SP Line:
-Set to the current line when the screen was last edited.
-.SP Options:
-None.
-.SE
-.KY global
-.IP "[range] g[lobal] /pattern/ [commands]"
-.KY v
-.Ip "[range] v /pattern/ [commands]"
-Apply commands to lines matching (or not matching) a pattern.
-The lines within the given range that match
-.PQ g[lobal] ,
-or do not match
-.PQ v
-the given pattern are selected.
-Then, the specified
-.CO ex
-command(s) are executed with the current line
-.PQ \&.
-set to each selected line.
-If no range is specified, the entire file is searched for matching,
-or not matching, lines.
-.sp
-Multiple commands can be specified, one per line, by escaping each
-.LI <newline>
-character with a backslash, or by separating commands with a
-.QT |
-character.
-If no commands are specified, the command defaults to the
-.CO print
-command.
-.sp
-For the
-.CO append ,
-.CO change
-and
-.CO insert
-commands, the input text must be part of the global command line.
-In this case, the terminating period can be omitted if it ends the commands.
-.sp
-The
-.CO visual
-command may also be specified as one of the
-.CO ex
-commands.
-In this mode, input is taken from the terminal.
-Entering a
-.CO Q
-command in
-.CO vi
-mode causes the next line matching the pattern to be selected and
-.CO vi
-to be reentered, until the list is exhausted.
-.sp
-The
-.CO global ,
-.CO v
-and
-.CO undo
-commands cannot be used as part of these commands.
-.sp
-The editor options
-.OP autoprint ,
-.OP autoindent ,
-and
-.OP report
-are turned off for the duration of the
-.CO global
-and
-.CO v
-commands.
-.SS
-.SP Line:
-The last line modified.
-.SP Options:
-None.
-.SE
-.KY help
-.IP "he[lp]"
-Display a help message.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY insert
-.IP "[line] i[nsert][!]"
-The input text is inserted before the specified line.
-Following the command name with a
-.QT !
-character causes the
-.OP autoindent
-option setting to be toggled for the duration of this command.
-.SS
-.SP Line:
-Set to the last line input; if no lines were input,
-set to the line before the target line, or to the first line
-of the file if there are no lines preceding the target line.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY join
-.IP "[range] j[oin][!] [count] [flags]"
-Join lines of text together.
-.sp
-A
-.LI count
-specified to the
-.Sy join
-command specifies that the last line of the
-.LI range
-plus
-.LI count
-subsequent lines will be joined.
-(Note, this differs by one from the general rule where only
-.LI count - 1
-subsequent lines are affected.)
-.sp
-If the current line ends with a whitespace character, all whitespace
-is stripped from the next line.
-Otherwise, if the next line starts with a open parenthesis
-.PQ ( ,
-do nothing.
-Otherwise, if the current line ends with a question mark
-.PQ ? ,
-period
-.PQ \&.
-or exclamation point
-.PQ ! ,
-insert two spaces.
-Otherwise, insert a single space.
-.sp
-Appending a
-.QT !
-character to the command name causes a simpler join with no
-white-space processing.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY list
-.IP "[range] l[ist] [count] [flags]"
-Display the lines unambiguously.
-Tabs are displayed as
-.QT ^I ,
-and the end of the line is marked with a
-.QT $
-character.
-.SS
-.SP Line:
-Set to the last line displayed.
-.SP Options:
-None.
-.SE
-.KY map
-.IP "map[!] [lhs rhs]"
-Define or display maps (for
-.CO vi
-only).
-.sp
-If
-.QT lhs
-and
-.QT rhs
-are not specified, the current set of command mode maps are displayed.
-If a
-.QT !
-character is appended to to the command,
-the text input mode maps are displayed.
-.sp
-Otherwise, when the
-.QT lhs
-character sequence is entered in
-.CO vi ,
-the action is as if the corresponding
-.QT rhs
-had been entered.
-If a
-.QT !
-character is appended to the command name,
-the mapping is effective during text input mode,
-otherwise, it is effective during command mode.
-This allows
-.QT lhs
-to have two different macro definitions at the same time: one for command
-mode and one for input mode.
-.sp
-Whitespace characters require escaping with a
-.LI <literal next>
-character to be entered in the
-.LI lhs
-string in visual mode.
-.sp
-Normally, keys in the
-.LI rhs
-string are remapped (see the
-.OP remap
-option),
-and it is possible to create infinite loops.
-However, keys which map to themselves are not further remapped,
-regardless of the setting of the
-.OP remap
-option.
-For example, the command
-.QT ":map n nz."
-maps the
-.QT n
-key to the
-.CO n
-and
-.CO z
-commands.
-.sp
-To exit an infinitely looping map, use the terminal
-.LI <interrupt>
-character.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY mark
-.KY k
-.IP "[line] ma[rk] <character>"
-.Ip "[line] k <character>"
-Mark the line with the mark
-.LI <character> .
-The expressions
-.QT '<character>
-and
-.QT `<character>
-can then be used as an address in any command that uses one.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY move
-.IP "[range] m[ove] line"
-Move the specified lines after the target line.
-A target line of 0 places the lines at the beginning of the file.
-.SS
-.SP Line:
-Set to the first of the moved lines.
-.SP Options:
-None.
-.SE
-.KY mkexrc
-.IP "mk[exrc][!] file"
-Write the abbreviations, editor options and maps to the specified
-file.
-Information is written in a form which can later be read back in
-using the
-.CO ex
-.CO source
-command.
-If
-.LI file
-already exists, the
-.CO mkexrc
-command will fail.
-This check can be overridden by appending a
-.QT !
-character to the command.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY next
-.IP "n[ext][!] [file ...]"
-Edit the next file from the argument list.
-The
-.CO next
-command will fail if the file has been modified since the last complete
-write.
-This check can be overridden by appending the
-.QT !
-character to the command name.
-The argument list can optionally be replaced by specifying a new one
-as arguments to this command.
-In this case, editing starts with the first file on the new list.
-.SS
-.SP Line:
-Set as described for the
-.CO edit
-command.
-.SP Options:
-Affected by the options
-.OP autowrite
-and
-.OP writeany .
-.SE
-.KY open
-.IP "[line] o[pen] /pattern/ [flags]"
-Enter open mode.
-Open mode is the same as being in
-.CO vi ,
-but with a one-line window.
-All the standard
-.CO vi
-commands are available.
-If a match is found for the optional RE argument,
-the cursor is set to the start of the matching pattern.
-.sp
-.i "This command is not yet implemented."
-.SS
-.SP Line:
-Unchanged, unless the optional RE is specified, in which case it is
-set to the line where the matching pattern is found.
-.SP Options:
-Affected by the
-.OP open
-option.
-.SE
-.KY preserve
-.IP "pre[serve]"
-Save the file in a form that can later be recovered using the
-.CO ex
-.b \-r
-option.
-When the file is preserved, an email message is sent to the user.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY previous
-.IP "prev[ious][!]"
-Edit the previous file from the argument list.
-The
-.CO previous
-command will fail if the file has been modified since the last complete
-write.
-This check can be overridden by appending the
-.QT !
-character to the command name.
-.SS
-.SP Line:
-Set as described for the
-.CO edit
-command.
-.SP Options:
-Affected by the options
-.OP autowrite
-and
-.OP writeany .
-None.
-.SE
-.KY print
-.IP "[range] p[rint] [count] [flags]"
-Display the specified lines.
-.SS
-.SP Line:
-Set to the last line displayed.
-.SP Options:
-None.
-.SE
-.KY put
-.IP "[line] pu[t] [buffer]"
-Append buffer contents to the current line.
-If a buffer is specified, its contents are appended to the line,
-otherwise, the contents of the unnamed buffer are used.
-.SS
-.SP Line:
-Set to the line after the current line.
-.SP Options:
-None.
-.SE
-.KY quit
-.IP "q[uit][!]"
-End the editing session.
-If the file has been modified since the last complete write, the
-.CO quit
-command will fail.
-This check may be overridden by appending a
-.QT !
-character to the command.
-.sp
-If there are more files to edit, the
-.CO quit
-command will fail.
-Appending a
-.QT !
-character to the command name or entering two
-.CO quit
-commands (i.e.
-.CO wq ,
-.CO quit ,
-.CO xit
-or
-.CO ZZ )
-in a row) will override this check and the editor will exit.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY read
-.IP "[line] r[ead][!] [file]"
-Read a file.
-A copy of the specified file is appended to the line.
-If
-.LI line
-is 0, the copy is inserted at the beginning of the file.
-If no file is specified, the current file is read; if there is no
-current file, then
-.LI file
-becomes the current file.
-If there is no current file and no
-.LI file
-is specified, then the
-.CO read
-command will fail.
-.sp
-If
-.LI file
-is preceded by a
-.QT !
-character,
-.LI file
-is treated as if it were a shell command, and passed to the program
-named by the
-.LI SHELL
-environment variable.
-The standard and standard error outputs of that command are read into
-the file after the specified line.
-The special meaning of the
-.QT !
-character can be overridden by escaping it with a backslash
-.PQ \e
-character.
-.SS
-.SP Line:
-When executed from
-.CO ex ,
-the current line is set to the last line read.
-When executed from
-.CO vi ,
-the current line is set to the first line read.
-.SP Options:
-None.
-.SE
-.KY recover
-.IP "rec[over] file"
-Recover
-.LI file
-if it was previously saved.
-If no saved file by that name exists, the
-.CO recover
-command behaves similarly to the
-.CO edit
-command.
-.SS
-.SP Line:
-Set as described for the
-.CO edit
-command.
-.SP Options:
-None.
-.SE
-.KY resize
-.IP "res[ize] [+|-]size"
-.CO Vi
-mode only.
-Grow or shrink the current screen.
-If
-.LI size
-is a positive, signed number, the current screen is grown by that many lines.
-If
-.LI size
-is a negative, signed number, the current screen is shrunk by that many lines.
-If
-.LI size
-is not signed, the current screen is set to the specified
-.LI size .
-Applicable only to split screens.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY rewind
-.IP "rew[ind][!]"
-Rewind the argument list.
-If the current file has been modified since the last complete write,
-the
-.CO rewind
-command will fail.
-This check may be overridden by appending the
-.QT !
-character to the command.
-.sp
-Otherwise, the current file is set to the first file in the argument
-list.
-.SS
-.SP Line:
-Set as described for the
-.CO edit
-command.
-.SP Options:
-Affected by the
-.OP autowrite
-and
-.OP writeany
-options.
-.SE
-.KY set
-.IP "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
-Display or set editor options.
-When no arguments are specified, the editor option
-.OP term ,
-and any editor options whose values have been changed from the
-default settings are displayed.
-If the argument
-.LI all
-is specified, the values of all of editor options are displayed.
-.sp
-Specifying an option name followed by the character
-.QT ?
-causes the current value of that option to be displayed.
-The
-.QT ?
-can be separated from the option name by whitespace characters.
-The
-.QT ?
-is necessary only for Boolean valued options.
-Boolean options can be given values by the form
-.QT "set option"
-to turn them on, or
-.QT "set nooption"
-to turn them off.
-String and numeric options can be assigned by the form
-.QT "set option=value" .
-Any whitespace characters in strings can be included literally by preceding
-each with a backslash.
-More than one option can be set or listed by a single set command,
-by specifying multiple arguments, each separated from the next by
-whitespace characters.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY shell
-.IP "sh[ell]"
-Run a shell program.
-The program named by the
-.OP shell
-option is run with a
-.b \-i
-(for interactive) flag.
-Editing is resumed when that program exits.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY source
-.IP "so[urce] file"
-Read and execute
-.CO ex
-commands from a file.
-.CO Source
-commands may be nested.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY split
-.IP "sp[lit] [file ...]"
-.CO Vi
-mode only.
-Split the screen.
-The current screen is split into two screens, of approximately equal size.
-If the cursor is in the lower half of the screen, the screen will split
-up, i.e. the new screen will be above the old one.
-If the cursor is in the upper half of the screen, the new screen will be
-below the old one.
-.sp
-If
-.LI file
-is specified, the new screen is editing that file, otherwise, both
-screens are editing the same file, and changes in each will be
-be reflected in the other.
-The argument list for the new screen consists of the list of files
-specified as arguments to this command, or, the current pathname if
-no files are specified.
-.SS
-.SP Line:
-If
-.LI file
-is specified, set as for the
-.CO edit
-command, otherwise unchanged.
-.SP Options:
-None.
-.SE
-.KY substitute
-.IP "[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]"
-.KY &
-.Ip "[range] & [options] [count] [flags]"
-.KY ~
-.Ip "[range] ~ [options] [count] [flags]"
-Make substitutions.
-Replace the first instance of
-.LI pattern
-with the string
-.LI replace
-on the specified line(s).
-If the
-.QT /pattern/repl/
-argument is not specified, the
-.QT /pattern/repl/
-from the previous
-.CO substitute
-command is used.
-.sp
-If
-.LI options
-includes the letter
-.QT c
-(confirm), you will be prompted for confirmation before each replacement
-is done.
-An affirmative response (in English, a
-.QT y
-character) causes the replacement to be made.
-A quit response (in English, a
-.QT q
-character) causes the
-.CO substitute
-command to be terminated.
-Any other response causes the replacement not to be made, and the
-.CO substitute
-command continues.
-If
-.LI options
-includes the letter
-.QT g
-(global), all nonoverlapping instances of
-.LI pattern
-in the line are replaced.
-.sp
-The
-.CO &
-version of the command is the same as not specifying a pattern
-or replacement string to the
-.CO substitute
-command, and the
-.QT &
-is replaced by the pattern and replacement information from the
-previous substitute command.
-.sp
-The
-.CO ~
-version of the command is the same as
-.CO &
-and
-.CO s ,
-except that the search pattern used is the last RE used in
-.i any
-command, not necessarily the one used in the last
-.CO substitute
-command.
-.sp
-For example, in the sequence
-.ft C
-.(b
-s/red/blue/
-/green
-~
-.)b
-.ft R
-the
-.QT ~
-is equivalent to
-.QT s/green/blue/ .
-.sp
-The
-.CO substitute
-command may be interrupted, using the terminal interrupt character.
-All substitutions completed before the interrupt are retained.
-.SS
-.SP Line:
-Set to the last line upon which a substitution was made.
-.SP Options:
-None.
-.SE
-.KY suspend
-.IP "su[spend][!]"
-.KY stop
-.Ip "st[op][!]"
-.KY <control-Z>
-.Ip <control-Z>
-Suspend the edit session.
-Appending a
-.QT !
-character to these commands turns off the
-.OP autowrite
-option for the command.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-Affected by the
-.OP autowrite
-option.
-.SE
-.KY tag
-.IP "ta[g][!] tagstring"
-Edit the file containing the specified tag.
-Search for the tagstring, which can be in a different file.
-If the tag is in a different file, then the new file is edited.
-If the current file has been modified since the last complete write,
-the
-.CO tag
-command will fail.
-This check can be overridden by appending the
-.QT !
-character to the command name.
-.sp
-The
-.CO tag
-command searches for
-.LI tagstring
-in the tags file(s) specified by the
-.Op tags
-option.
-(See
-.XR ctags 1
-for more information on tags files.)
-.SS
-.SP Line:
-Set to the line indicated by the tag.
-.SP Options:
-Affected by the
-.OP autowrite ,
-.OP taglength ,
-.OP tags
-and
-.OP writeany
-options.
-.SE
-.KY tagpop
-.IP "tagp[op][!] [file | number]"
-Pop to the specified tag in the tags stack.
-If neither
-.LI file
-or
-.LI number
-is specified, the
-.CO tagpop
-command pops to the most recent entry on the tags stack.
-If
-.LI file
-or
-.LI number
-is specified, the
-.CO tagpop
-command pops to the most recent entry in the tags stack for that file,
-or numbered entry in the tags stack, respectively.
-(See the
-.CO display
-command for information on displaying the tags stack.)
-.sp
-If the file has been modified since the last complete write, the
-.CO tagpop
-command will fail.
-This check may be overridden by appending a
-.QT !
-character to the command name.
-.SS
-.SP Line:
-Set to the line indicated by the tag.
-.SP Options:
-Affected by the
-.OP autowrite ,
-and
-.OP writeany
-options.
-.SE
-.KY tagtop
-.IP "tagt[op][!]"
-Pop to the least recent tag on the tags stack, clearing the tags stack.
-.sp
-If the file has been modified since the last complete write, the
-.CO tagpop
-command will fail.
-This check may be overridden by appending a
-.QT !
-character to the command name.
-.SS
-.SP Line:
-Set to the line indicated by the tag.
-.SP Options:
-Affected by the
-.OP autowrite ,
-and
-.OP writeany
-options.
-.SE
-.KY unabbrev
-.IP "una[bbrev] lhs"
-Delete an abbreviation.
-Delete
-.LI lhs
-from the current list of abbreviations.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY undo
-.IP "u[ndo]"
-Undo the last change made to the file.
-Changes made by
-.CO global ,
-.CO v ,
-.CO visual
-and map sequences are considered a single command.
-If repeated, the
-.CO u
-command alternates between these two states, and is its own inverse.
-.SS
-.SP Line:
-Set to the last line modified by the command.
-.SP Options:
-None.
-.SE
-.KY unmap
-.IP "unm[ap][!] lhs"
-Unmap a mapped string.
-Delete the command mode map definition for
-.LI lhs .
-If a
-.QT !
-character is appended to the command name, delete the text input mode
-map definition instead.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY version
-.IP "ve[rsion]"
-Display the version of the
-.CO ex/vi
-editor.
-.KY visual
-.IP "[line] vi[sual] [type] [count] [flags]"
-.CO Ex
-mode only.
-Enter
-.CO vi .
-The
-.LI type
-is optional, and can be
-.QT \- ,
-.QT +
-or
-.QT ^ ,
-as in the
-.CO ex
-.CO z
-command, to specify the the position of the specified line in the screen
-window.
-(The default is to place the line at the top of the screen window.)
-A
-.LI count
-specifies the number of lines that will initially be displayed.
-(The default is the value of the
-.OP window
-editor option.)
-.SS
-.SP Line:
-Unchanged unless
-.LI line
-is specified, in which case it is set to that line.
-.SP Options:
-None.
-.SE
-.KY visual
-.IP "vi[sual][!] [+cmd] [file]"
-.CO Vi
-mode only.
-Edit a new file.
-Identical to the
-.QT "edit[!] [+cmd] [file]"
-command.
-.KY viusage
-.IP "viu[sage] [command]"
-Display usage for a
-.CO vi
-command.
-If
-.LI command
-is specified, a usage statement for that command is displayed.
-Otherwise, usage statements for all
-.CO vi
-commands are displayed.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY write
-.IP "[range] w[rite][!] [>>] [file]"
-.Ip "[range] w[rite] [!] [file]"
-.KY wn
-.Ip "[range] wn[!] [>>] [file]"
-.KY wq
-.Ip "[range] wq[!] [>>] [file]"
-Write the file.
-The specified lines (the entire file, if no range is given) is written
-to
-.LI file .
-If
-.LI file
-is not specified, the current pathname is used.
-If
-.LI file
-is specified, and it exists, or if the current pathname was set using the
-.CO file
-command, and the file already exists, these commands will fail.
-Appending a
-.QT !
-character to the command name will override this check and the write
-will be attempted, regardless.
-.sp
-Specifying the optional
-.QT >>
-string will cause the write to be appended to the file, in which case
-no tests are made for the file already existing.
-.sp
-If the file is preceded by a
-.QT !
-character, the program named in the SHELL environment variable is
-invoked with file as its second argument, and the specified lines
-are passed as standard input to that command.
-The
-.QT !
-in this usage must be separated from command name by at least one
-whitespace character.
-The special meaning of the
-.QT !
-may be overridden by escaping it with a backslash
-.PQ \e
-character.
-.sp
-The
-.CO wq
-version of the write command will exit the editor after writing the file,
-if there are no further files to edit.
-Appending a
-.QT !
-character to the command name or entering two
-.QQ quit
-commands (i.e.
-.CO wq ,
-.CO quit ,
-.CO xit
-or
-.CO ZZ )
-in a row) will override this check and the editor will exit,
-ignoring any files that have not yet been edited.
-.sp
-The
-.CO wn
-version of the write command will move to the next file after writing
-the file, unless the write fails.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-Affected by the
-.OP readonly
-and
-.OP writeany
-options.
-.SE
-.KY xit
-.IP "[range] x[it][!] [file]"
-Write the file if it has been modified.
-The specified lines are written to
-.LI file ,
-if the file has been modified since the last complete write to any
-file.
-If no
-.LI range
-is specified, the entire file is written.
-.sp
-The
-.CO xit
-command will exit the editor after writing the file,
-if there are no further files to edit.
-Appending a
-.QT !
-character to the command name or entering two
-.QQ quit
-commands (i.e.
-.CO wq ,
-.CO quit ,
-.CO xit
-or
-.CO ZZ )
-in a row) will override this check and the editor will exit,
-ignoring any files that have not yet been edited.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-Affected by the
-.OP readonly
-and
-.OP writeany
-options.
-.SE
-.KY yank
-.IP "[range] ya[nk] [buffer] [count]"
-Copy the specified lines to a buffer.
-If no buffer is specified, the unnamed buffer is used.
-.SS
-.SP Line:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY z
-.IP "[line] z [type] [count] [flags]"
-Adjust the window.
-If no
-.LI type
-is specified, then
-.LI count
-lines following the specified line are displayed.
-The default
-.LI count
-is the value of the
-.OP window
-option.
-The
-.LI type
-argument changes the position at which
-.LI line
-is displayed on the screen by changing the number of lines
-displayed before and after
-.LI line .
-The following
-.LI type
-characters may be used:
-.SS
-.SP \-
-Place the line at the bottom of the screen.
-.SP +
-Place the line at the top of the screen.
-.SP \&.
-Place the line in the middle of the screen.
-.SP ^
-Write out count lines starting
-.LI "count * 2"
-lines before
-.LI line ;
-the net effect of this is that a
-.QT z^
-command following a
-.CO z
-command writes the previous page.
-.SP =
-Center
-.LI line
-on the screen with a line of hyphens displayed immediately before and
-after it.
-The number of preceding and following lines of text displayed are
-reduced to account for those lines.
-.SE
-.SS
-.SP Line:
-Set to the last line displayed, with the exception of the
-.Dq Li \&=
-.LI type ,
-where the current line is set to the line specified by the command.
-.SP Options:
-Affected by the
-.Sy window
-option.
-.SE
diff --git a/usr.bin/vi/USD.doc/vi.ref/merge.awk b/usr.bin/vi/USD.doc/vi.ref/merge.awk
deleted file mode 100644
index 16b5152..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/merge.awk
+++ /dev/null
@@ -1,16 +0,0 @@
-# @(#)merge.awk 8.3 (Berkeley) 5/26/94
-#
-# merge index entries into one line per label
-$1 == prev {
- printf ", %s", $2;
- next;
-}
-{
- if (NR != 1)
- printf "\n";
- printf "%s \t%s", $1, $2;
- prev = $1;
-}
-END {
- printf "\n"
-}
diff --git a/usr.bin/vi/USD.doc/vi.ref/ref.so b/usr.bin/vi/USD.doc/vi.ref/ref.so
deleted file mode 100644
index c0fddc3..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/ref.so
+++ /dev/null
@@ -1,127 +0,0 @@
-.\" Copyright (c) 1994
-.\" 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.
-.\"
-.\" @(#)ref.so 8.6 (Berkeley) 7/15/94
-.\"
-.\"
-.\" indented paragraph, with spaces between the items, bold font
-.de IP
-.\".tm arg 1 \\$1 arg 2 \\$2 arg 3 \\$3
-.sp 1
-.nr PS \\n(ps
-.nr ps 0
-.ip "\fB\\$1\fP" \\$2
-.nr ps \\n(PS
-.br
-..
-.\" indented paragraph, no spaces between the items, bold font
-.de Ip
-.\".tm arg 1 \\$1 arg 2 \\$2 arg 3 \\$3
-.nr PS \\n(ps
-.nr ps 0
-.ns
-.ip "\fB\\$1\fP" \\$2
-.nr ps \\n(PS
-.br
-..
-.\" start nested .IP
-.de SS
-.sp
-.ba +5n
-..
-.\" end nested .IP
-.de SE
-.ba -5n
-..
-.\" nested .IP, no spaces, normal font
-.de SP
-.\".tm arg 1 \\$1 arg 2 \\$2 arg 3 \\$3
-.nr PS \\n(ps
-.nr ps 0
-.ns
-.ip "\\$1" 9n
-.nr ps \\n(PS
-..
-.\" typewriter font
-.de LI
-\&\fC\\$1\fP\\$2
-..
-.\" ex/vi names in command font
-.de EV
-\&\fB\\$1\fP/\fB\\$2\fP\\$3
-..
-.\" command names
-.de CO
-\&\fB\\$1\fP\\$2
-..
-.\" key words for index
-.de KY
-.sy echo >>index '\\$1 \\n%'
-..
-.\" option names
-.de OP
-\&\fB\\$1\fP\\$2
-..
-.\" paren quoted (typewriter font)
-.de PQ
-(\*(lq\fC\\$1\fP\*(rq)\\$2
-..
-.\" quoted bold
-.de QB
-\*(lq\fB\\$1\fP\*(rq\\$2
-..
-.\" quoted command
-.de QC
-\*(lq\fB\\$1\fP\*(rq\\$2
-..
-.\" quoted option
-.de QO
-\*(lq\fB\\$1\fP\*(rq\\$2
-..
-.\" quoted (no font change)
-.de QQ
-\*(lq\\$1\*(rq\\$2
-..
-.\" quoted (typewriter font)
-.de QT
-\*(lq\fC\\$1\fP\*(rq\\$2
-..
-.\" section macro to build TOC
-.de SH
-.(x
-\\$2
-.)x
-.sh \\$1 "\\$2"
-..
-.\" manual section
-.de XR
-\&\fI\\$1\fP(\\$2)\\$3
-..
diff --git a/usr.bin/vi/USD.doc/vi.ref/set.opt.roff b/usr.bin/vi/USD.doc/vi.ref/set.opt.roff
deleted file mode 100644
index d59599d..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/set.opt.roff
+++ /dev/null
@@ -1,949 +0,0 @@
-.\" Copyright (c) 1994
-.\" 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.
-.\"
-.\" @(#)set.opt.roff 8.26 (Berkeley) 8/11/94
-.\"
-.SH 1 "Set Options"
-.pp
-There are a large number of options that may be set (or unset) to
-change the editor's behavior.
-This section describes the options, their abbreviations and their
-default values.
-.pp
-In each entry below, the first part of the tag line is the full name
-of the option, followed by any equivalent abbreviations.
-(Regardless of the abbreviations, it is only necessary to use the
-minimum number of characters necessary to distinguish an abbreviation
-from all other commands for it to be accepted, in
-.EV nex nvi .
-Historically, only the full name and the official abbreviations
-were accepted by
-.EV ex vi .
-Using full names in your startup files and environmental variables will
-probably make them more portable.)
-The part in square brackets is the default value of the option.
-Most of the options are boolean, i.e. they are either on or off,
-and do not have an associated value.
-.pp
-Options apply to both
-.CO ex
-and
-.CO vi
-modes, unless otherwise specified.
-.pp
-For information on modifying the options or to display the options and
-their current values, see the
-.QQ set
-command in the section entitled
-.QB "Ex Commands" .
-.KY altwerase
-.IP "altwerase [off]"
-.CO Vi
-only.
-Change how
-.CO vi
-does word erase during text input.
-When this option is set, text is broken up into three classes:
-alphabetic, numeric and underscore characters, other nonblank
-characters, and blank characters.
-Changing from one class to another marks the end of a word.
-In addition, the class of the first character erased is ignored
-(which is exactly what you want when erasing pathname components).
-.KY autoindent
-.IP "autoindent, ai [off]"
-If this option is set, whenever you create a new line (using the
-.CO vi
-.CO A ,
-.CO a ,
-.CO C ,
-.CO c ,
-.CO I ,
-.CO i ,
-.CO O ,
-.CO o ,
-.CO R ,
-.CO r ,
-.CO S ,
-and
-.CO s
-commands, or the
-.CO ex
-.CO append ,
-.CO change ,
-and
-.CO insert
-commands) the new line is automatically indented to align the cursor with
-the first nonblank character of the line from which you created it.
-Lines are indented using tab characters to the extent possible (based on
-the value of the
-.OP tabstop
-option) and then using space characters as necessary.
-For commands inserting text into the middle of a line, any blank characters
-to the right of the cursor are discarded, and the first nonblank character
-to the right of the cursor is aligned as described above.
-.sp
-The indent characters are themselves somewhat special.
-If you do not enter more characters on the new line before moving to
-another line, or entering
-.LI <escape> ,
-the indent character will be deleted and the line will be empty.
-For example, if you enter
-.LI <carriage-return>
-twice in succession,
-the line created by the first
-.LI <carriage-return>
-will not have any characters in it,
-regardless of the indentation of the previous or subsequent line.
-.sp
-Indent characters also require that you enter additional erase characters
-to delete them.
-For example,
-if you have an indented line, containing only blanks, the first
-.LI <word-erase>
-character you enter will erase up to end of the indent characters,
-and the second will erase back to the beginning of the line.
-(Historically, only the
-.CO <control-D>
-key would erase the indent characters.
-Both the
-.CO <control-D>
-key and the usual erase keys work in
-.CO nvi .)
-In addition, if the cursor is positioned at the end of the indent
-characters, the keys
-.QT 0<control-D>
-will erase all of the indent characters for the current line,
-resetting the indentation level to 0.
-Similarly, the keys
-.QT ^<control-D>
-will erase all of the indent characters for the current line,
-leaving the indentation level for future created lines unaffected.
-.sp
-Finally, if the
-.OP autoindent
-option is set, the
-.CO S
-and
-.CO cc
-commands change from the first nonblank of the line to the end of the
-line, instead of from the beginning of the line to the end of the line.
-.KY autoprint
-.IP "autoprint, ap [off]"
-.CO Ex
-only.
-Cause the current line to be automatically displayed after the
-.CO ex
-commands
-.CO < ,
-.CO > ,
-.CO copy ,
-.CO delete ,
-.CO join ,
-.CO move ,
-.CO put ,
-.CO t ,
-.CO Undo ,
-and
-.CO undo .
-This automatic display is suppressed during
-.CO global
-and
-.CO vglobal
-commands, and for any command where optional flags are used to explicitly
-display the line.
-.KY autowrite
-.IP "autowrite, aw [off]"
-If this option is set, the
-.CO vi
-.CO ! ,
-.CO ^^ ,
-.CO ^]
-and
-.CO <control-Z>
-commands, and the
-.CO ex
-.CO edit ,
-.CO next ,
-.CO rewind ,
-.CO stop ,
-.CO suspend ,
-.CO tag ,
-.CO tagpop ,
-and
-.CO tagtop
-commands automatically write the current file back to the current file name
-if it has been modified since it was last written.
-If the write fails, the command fails and goes no further.
-.sp
-Appending the optional force flag character
-.QT !
-to the
-.CO ex
-commands
-.CO next ,
-.CO rewind ,
-.CO stop ,
-.CO suspend ,
-.CO tag ,
-.CO tagpop ,
-and
-.CO tagtop
-stops the automatic write from being attempted.
-.sp
-(Historically, the
-.CO next
-command ignored the optional force flag.)
-Note, the
-.CO ex
-commands
-.CO edit ,
-.CO quit ,
-.CO shell ,
-and
-.CO xit
-are
-.i not
-affected by the
-.OP autowrite
-option.
-.KY beautify
-.IP "beautify, bf [off]"
-If this option is set, all control characters that are not currently being
-specially interpreted, other than
-.LI <tab> ,
-.LI <newline> ,
-and
-.LI <form-feed> ,
-are
-discarded from commands read in by
-.CO ex
-from command files, and from input text entered to
-.CO vi
-(either into the file or to the colon command line).
-Text files read by
-.EV ex vi
-are
-.i not
-affected by the
-.OP beautify
-option.
-.KY cdpath
-.IP "cdpath [environment variable CDPATH, or current directory]"
-This option is used to specify a colon separated list of directories
-which are used as path prefixes for any relative path names used as
-arguments for the
-.CO cd
-command.
-The value of this option defaults to the value of the environmental
-variable
-.LI CDPATH
-if it is set, otherwise to the current directory.
-For compatibility with the POSIX 1003.2 shell, the
-.CO cd
-command does
-.i not
-check the current directory as a path prefix for relative path names
-unless it is explicitly specified.
-It may be so specified by entering an empty string or a
-.QT \&.
-character into the
-.LI CDPATH
-variable or the option value.
-.KY columns
-.IP "columns, co [80]"
-The number of columns in the screen.
-Setting this option causes
-.EV ex vi
-to set (or reset) the environmental variable
-.LI COLUMNS .
-See the section entitled
-.QB "Sizing the Screen"
-more information.
-.KY comment
-.IP "comment [off]"
-.CO Vi
-only.
-If the first non-empty line of the file begins with the string
-.QT /\&* ,
-this option causes
-.CO vi
-to skip to the end of that C-language comment (probably a terribly boring
-legal notice) before displaying the file.
-.KY directory
-.IP "directory, dir [environment variable TMPDIR, or /tmp]"
-The directory where temporary files are created.
-The environmental variable
-.LI TMPDIR
-is used as the default value if it exists, otherwise
-.LI /tmp
-is used.
-.KY edcompatible
-.IP "edcompatible, ed [off]"
-Remember the values of the
-.QQ c
-and
-.QQ g
-suffices to the
-.CO substitute
-commands, instead of initializing them as unset for each new
-command.
-Specifying pattern and replacement strings to the
-.CO substitute
-command unsets the
-.QQ c
-and
-.QQ g
-suffices as well.
-.KY errorbells
-.IP "errorbells, eb [off]"
-.CO Ex
-only.
-.CO Ex
-error messages are normally presented in inverse video.
-If that is not possible for the terminal, setting this option causes
-error messages to be announced by ringing the terminal bell.
-.KY exrc
-.IP "exrc, ex [off]"
-If this option is turned off in the system or $HOME startup files,
-the local startup files are never read (unless they are the same
-as the system or $HOME startup files).
-Turning it on has no effect, i.e. the normal checks for local startup
-files are performed, regardless.
-See the section entitled
-.QB "Startup Information"
-for more information.
-.KY extended
-.IP "extended [off]"
-This option causes all regular expressions to be treated as POSIX
-1003.2 Extended Regular Expressions (which are similar to historic
-.XR egrep 1
-style expressions).
-.KY flash
-.IP "flash [on]"
-This option causes the screen to flash instead of beeping the keyboard,
-on error, if the terminal has the capability.
-.KY hardtabs
-.IP "hardtabs, ht [8]"
-This option defines the spacing between hardware tab settings, i.e.
-the tab expansion done by the operating system and/or the terminal
-itself.
-As
-.EV nex nvi
-never writes
-.LI <tab>
-characters to the terminal, unlike historic versions of
-.EV ex vi ,
-this option does not currently have any affect.
-.KY ignorecase
-.IP "ignorecase, ic [off]"
-This option causes regular expressions, both in
-.CO ex
-commands and in searches,
-to be evaluated in a case-insensitive manner.
-.KY keytime
-.IP "keytime [6]"
-The 10th's of a second
-.EV ex vi
-waits for a subsequent key to complete a key mapping.
-.KY leftright
-.IP "leftright [off]"
-.CO Vi
-only.
-This option causes the screen to be scrolled left-right to view
-lines longer than the screen, instead of the traditional
-.CO vi
-screen interface which folds long lines at the right-hand margin
-of the terminal.
-.KY lines
-.IP "lines, li [24]"
-.CO Vi
-only.
-The number of lines in the screen.
-Setting this option causes
-.EV ex vi
-to set (or reset) the environmental variable
-.LI LINES .
-See the section entitled
-.QB "Sizing the Screen"
-for more information.
-.KY lisp
-.IP "lisp [off]"
-.CO Vi
-only.
-This option changes the behavior of the
-.CO vi
-.CO ( ,
-.CO ) ,
-.CO { ,
-.CO } ,
-.CO [[
-and
-.CO ]]
-commands to match the Lisp language.
-Also, the
-.OP autoindent
-option's behavior is changed to be appropriate for Lisp.
-.sp
-.i "This option is not yet implemented."
-.KY list
-.IP "list [off]"
-This option causes lines to be displayed in an unambiguous fashion.
-Specifically, tabs are displayed as control characters, i.e.
-.QT ^I ,
-and the ends of lines are marked with a
-.QT $
-character.
-.KY magic
-.IP "magic [on]"
-This option is on by default.
-Turning the
-.OP magic
-option off causes all regular expression characters except for
-.QT ^
-and
-.QT $ ,
-to be treated as ordinary characters.
-To re-enable characters individually, when the
-.OP magic
-option is off,
-precede them with a backslash
-.QT \e
-character.
-See the section entitled
-.QB "Regular Expressions and Replacement Strings"
-for more information.
-.KY matchtime
-.IP "matchtime [7]"
-.CO Vi
-only.
-The 10th's of a second
-.EV ex vi
-pauses on the matching character when the
-.OP showmatch
-option is set.
-.KY mesg
-.IP "mesg [on]"
-This option allows other users to contact you using the
-.XR talk 1
-and
-.XR write 1
-utilities, while you are editing.
-.EV Ex vi
-does not turn message on, i.e. if messages were turned off when the
-editor was invoked, they will stay turned off.
-This option only permits you to disallow messages for the edit session.
-See the
-.XR mesg 1
-utility for more information.
-.KY modelines
-.IP "modelines, modeline [off]"
-If the
-.OP modelines
-option is set,
-.EV ex vi
-has historically scanned the first and last five lines of each file as
-it is read for editing, looking for any
-.CO ex
-commands that have been placed in those lines.
-After the startup information has been processed, and before the user
-starts editing the file, any commands embedded in the file are executed.
-.sp
-Commands were recognized by the letters
-.QQ e
-or
-.QQ v
-followed by
-.QQ x
-or
-.QQ i ,
-at the beginning of a line or following a tab or space character,
-and followed by a
-.QQ : ,
-an
-.CO ex
-command, and another
-.QQ : .
-.sp
-This option is a security problem of immense proportions,
-and should not be used under any circumstances.
-.sp
-.i "This option will never be implemented."
-.KY number
-.IP "number, nu [off]"
-Precede each line displayed with its current line number.
-.KY octal
-.IP "octal [off]"
-Display unknown characters as octal numbers, instead of the default
-hexadecimal.
-.KY open
-.IP "open [on]"
-.CO Ex
-only.
-If this option is not set, the
-.CO open
-and
-.CO visual
-commands are disallowed.
-.KY optimize
-.IP "optimize, opt [on]"
-.CO Vi
-only.
-Throughput of text is expedited by setting the terminal not to do automatic
-carriage returns when printing more than one (logical) line of output,
-greatly speeding output on terminals without addressable cursors when text
-with leading white space is printed.
-.sp
-.i "This option is not yet implemented."
-.KY paragraphs
-.IP "paragraphs, para [IPLPPPQPP LIpplpipbp]"
-.CO Vi
-only.
-Define additional paragraph boundaries for the
-.CO {
-and
-.CO }
-commands.
-The value of this option must be a character string consisting
-of zero or more character pairs.
-.sp
-In the text to be edited, the character string
-.LI "<newline>.<char-pair>" ,
-(where
-.LI <char-pair>
-is one of the character pairs in the option's value)
-defines a paragraph boundary.
-For example, if the option were set to
-.LI "LaA<space>##" ,
-then all of the following additional paragraph boundaries would be
-recognized:
-.sp
-.(l
-<newline>.La
-<newline>.A<space>
-<newline>.##
-.)l
-.KY prompt
-.IP "prompt [on]"
-.CO Ex
-only.
-This option causes
-.CO ex
-to prompt for command input with a
-.QT :
-character; when it is not set, no prompt is displayed.
-.KY readonly
-.IP "readonly, ro [off]"
-This option causes a force flag to be required to attempt to write
-the file back to the original file name.
-Setting this option is equivalent to using the
-.b \-R
-command line option, or editing a file which lacks write permission.
-.KY recdir
-.IP "recdir [/var/tmp/vi.recover]"
-The directory where recovery files are stored.
-.sp
-If you change the value of
-.CO recdir ,
-be careful to choose a directory whose contents are not regularly
-deleted.
-Bad choices include directories in memory based filesystems,
-or
-.LI /tmp ,
-on most systems,
-as their contents are removed when the machine is rebooted.
-.sp
-Public directories like
-.LI /usr/tmp
-and
-.LI /var/tmp
-are usually safe, although some sites periodically prune old files
-from them.
-There is no requirement that you use a public directory,
-e.g. a sub-directory of your home directory will work fine.
-.sp
-Finally, if you change the value of
-.CO recdir ,
-you must modify the recovery script to operate in your chosen recovery
-area.
-.sp
-See the section entitled
-.QB "Recovery"
-for further information.
-.KY redraw
-.IP "redraw, re [off]"
-.CO Vi
-only.
-The editor simulates (using great amounts of output), an intelligent
-terminal on a dumb terminal (e.g. during insertions in
-.CO vi
-the characters to the right of the cursor are refreshed as each input
-character is typed).
-.sp
-.i "This option is not yet implemented."
-.KY remap
-.IP "remap [on]"
-If this option is set,
-it is possible to define macros in terms of other macros.
-Otherwise, each key is only remapped up to one time.
-For example, if
-.QT A
-is mapped to
-.QT B ,
-and
-.QT B
-is mapped to
-.QT C ,
-The keystroke
-.QT A
-will be mapped to
-.QT C
-if the
-.OP remap
-option is set, and to
-.QT B
-if it is not set.
-.KY report
-.IP "report [5]"
-Set the threshold of the number of lines that need to be changed or
-yanked before a message will be displayed to the user.
-For everything but the yank command, the value is the largest value
-about which the editor is silent, i.e. by default, 6 lines must be
-deleted before the user is notified.
-However, if the number of lines yanked is greater than
-.i "or equal to"
-the set value, it is reported to the user.
-.KY ruler
-.IP "ruler [off]"
-.CO Vi
-only.
-Display a row/column ruler on the colon command line.
-.KY scroll
-.IP "scroll, scr [window / 2]"
-Set the number of lines scrolled by the
-.CO vi
-.CO <control-D>
-and
-.CO <control-U>
-commands.
-.sp
-Historically, the
-.CO ex
-.CO z
-command, when specified without a count, used two times the size of the
-scroll value; the POSIX 1003.2 standard specified the window size, which
-is a better choice.
-.KY sections
-.IP "sections, sect [NHSHH HUnhsh]"
-.CO Vi
-only.
-Define additional section boundaries for the
-.CO [[
-and
-.CO ]]
-commands.
-The
-.OP sections
-option should be set to a character string consisting of zero or
-more character pairs.
-In the text to be edited, the character string
-.LI "<newline>.<char-pair>" ,
-(where
-.LI <char-pair>
-is one of the character pairs in the option's value),
-defines a section boundary in the same manner that
-.OP paragraph
-option boundaries are defined.
-.KY shell
-.IP "shell, sh [environment variable SHELL, or /bin/sh]"
-Select the shell used by the editor.
-The specified path is the pathname of the shell invoked by the
-.CO vi
-.CO !
-shell escape command and by the
-.CO ex
-.CO shell
-command.
-This program is also used to resolve any shell meta-characters in
-.CO ex
-commands.
-.KY shiftwidth
-.IP "shiftwidth, sw [8]"
-Set the autoindent and shift command indentation width.
-This width is used by the
-.OP autoindent
-option and by the
-.CO < ,
-.CO > ,
-and
-.CO shift
-commands.
-.KY showdirty
-.IP "showdirty [off]"
-.CO Vi
-only.
-Display an asterisk on the colon command line if the file has been modified.
-.KY showmatch
-.IP "showmatch, sm [off]"
-.CO Vi
-only.
-This option causes
-.CO vi ,
-when a
-.QT }
-or
-.QT )
-is entered, to briefly move the cursor the matching
-.QT {
-or
-.QT ( .
-See the
-.OP matchtime
-option for more information.
-.KY showmode
-.IP "showmode [off]"
-.CO Vi
-only.
-This option causes
-.CO vi
-to display a string identifying the current editor mode on the
-colon command line.
-.KY sidescroll
-.IP "sidescroll [16]"
-.CO Vi
-only.
-Sets the number of columns that are shifted to the left or right,
-when
-.CO vi
-is doing left-right scrolling and the left or right margin is
-crossed.
-See the
-.OP leftright
-option for more information.
-.KY slowopen
-.IP "slowopen, slow [off]"
-This option affects the display algorithm used by
-.CO vi ,
-holding off display updating during input of new text to improve
-throughput when the terminal in use is slow and unintelligent.
-.sp
-.i "This option is not yet implemented."
-.KY sourceany
-.IP "sourceany [off]"
-If this option is turned on,
-.CO vi
-historically read startup files that were owned by someone other than
-the editor user.
-See the section entitled
-.QB "Startup Information"
-for more information.
-This option is a security problem of immense proportions,
-and should not be used under any circumstances.
-.sp
-.i "This option will never be implemented."
-.KY tabstop
-.IP "tabstop, ts [8]"
-This option sets tab widths for the editor display.
-.KY taglength
-.IP "taglength, tl [0]"
-This option sets the maximum number of characters that are considered
-significant in a tag name.
-Setting the value to 0 makes all of the characters in the tag name
-significant.
-.KY tags
-.IP "tags, tag [tags /var/db/libc.tags /sys/kern/tags]"
-Sets the list of tags files, in search order,
-which are used when the editor searches for a tag.
-.KY term
-.IP "term, ttytype, tty [environment variable TERM]"
-Set the terminal type.
-Setting this option causes
-.EV ex vi
-to set (or reset) the environmental variable
-.LI TERM .
-.KY terse
-.IP "terse [off]"
-This option has historically made editor messages less verbose.
-It has no effect in this implementation.
-See the
-.OP verbose
-option for more information.
-.KY tildeop
-.IP "tildeop"
-Modify the
-.CO ~
-command to take an associated motion.
-.KY timeout
-.IP "timeout, to [on]"
-If this option is set,
-.EV ex vi
-waits for a specific period for a subsequent key to complete a key
-mapping (see the
-.OP keytime
-option).
-If the option is not set, the editor waits until enough keys are
-entered to resolve the ambiguity, regardless of how long it takes.
-.KY ttywerase
-.IP "ttywerase [off]"
-.CO Vi
-only.
-This option changes how
-.CO vi
-does word erase during text input.
-If this option is set, text is broken up into two classes,
-blank characters and nonblank characters.
-Changing from one class to another marks the end of a word.
-.KY verbose
-.IP "verbose [off]"
-.CO Vi
-only.
-.CO Vi
-historically bells the terminal for many obvious mistakes, e.g. trying
-to move past the left-hand margin, or past the end of the file.
-If this option is set, an error message is displayed for all errors.
-.KY w300
-.IP "w300 [no default]"
-.CO Vi
-only.
-Set the window size if the baud rate is less than 1200 baud.
-See the
-.OP window
-option for more information.
-.KY w1200
-.IP "w1200 [no default]"
-.CO Vi
-only.
-Set the window size if the baud rate is equal to 1200 baud.
-See the
-.OP window
-option for more information.
-.KY w9600
-.IP "w9600 [no default]"
-.CO Vi
-only.
-Set the window size if the baud rate is greater than 1200 baud.
-See the
-.OP window
-option for more information.
-.KY warn
-.IP "warn [on]"
-.CO Ex
-only.
-This option causes a warning message to the terminal if the file has
-been modified, since it was last written, before a
-.CO !
-command.
-.KY window
-.IP "window, w, wi [environment variable LINES]"
-This option determines the default number of lines in a screenful,
-as written by the
-.CO z
-command.
-It also determines the number of lines scrolled by the
-.CO vi
-commands
-.CO <control-F>
-and
-.CO <control-B> .
-The value of window can be unrelated to the real screen size,
-although it starts out as the number of lines on the screen (see
-the section entitled
-.QB "Sizing the Screen"
-for more information).
-Setting the value of the
-.OP window
-option is the same as using the
-.b \-w
-command line option.
-.sp
-If the value of the
-.OP window
-option (as set by the
-.OP window ,
-.OP w300 ,
-.OP w1200
-or
-.OP w9600
-options) is smaller than the actual size of the screen, large screen
-movements will result in displaying only that smaller number of lines
-on the screen.
-(Further movements in that same area will result in the screen being
-filled.)
-This can provide a performance improvement when viewing different
-places in one or more files over a slow link.
-.KY wrapmargin
-.IP "wrapmargin, wm [0]"
-.CO Vi
-only.
-If the value of the
-.OP wrapmargin
-option is non-zero,
-.CO vi
-will split lines so that they end at least that number of characters
-before the right-hand margin of the screen.
-(Note, the value of
-.OP wrapmargin
-is
-.i not
-a text length.
-In a screen that is 80 columns wide, the command
-.QT ":set wrapmargin=8"
-attempts to keep the lines less than or equal to 72 columns wide.)
-.sp
-Lines are split at the previous whitespace character closest to the
-number.
-Any trailing whitespace characters before that character are deleted.
-If the line is split because of an inserted
-.LI <space>
-or
-.LI <tab>
-character, and you then enter another
-.LI <space>
-character, it is discarded.
-.sp
-If wrapmargin is set to 0,
-or if there is no blank character upon which to split the line,
-the line is not broken.
-.KY wrapscan
-.IP "wrapscan, ws [on]"
-This option causes searches to wrap around the end or the beginning
-of the file, and back to the starting point.
-Otherwise, the end or beginning of the file terminates the search.
-.KY writeany
-.IP "writeany, wa [off]"
-If this option is set, file-overwriting checks that would usually be
-made before the
-.CO write
-and
-.CO xit
-commands, or before an automatic write (see the
-.OP autowrite
-option), are not made.
-This allows a write to any file, provided the file permissions allow it.
diff --git a/usr.bin/vi/USD.doc/vi.ref/spell.ok b/usr.bin/vi/USD.doc/vi.ref/spell.ok
deleted file mode 100644
index 60084e3..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/spell.ok
+++ /dev/null
@@ -1,270 +0,0 @@
-Amir
-Autoprint
-BRE's
-Bostic
-Bourne
-DOUBLEQUOTE
-Dq
-Ds
-ERE's
-EXINIT
-Englar
-Ev
-FF
-Fa
-Fl
-HUnhsh
-IPLPPPQPP
-Kirkendall
-Korn
-LIpplpipbp
-LaA
-Li
-Lowercase
-MINUSSIGN
-Makefiles
-NEX
-NEXINIT
-NHSHH
-NVI
-Nex
-Nvi
-OS
-POSIX
-PostScript
-RE's
-README
-RECDIR
-Reference''USD:13
-SIGHUP
-SIGWINCH
-SQUOTE
-Se
-Std
-Std1003.2
-Sy
-TANDARDS
-TIOCGWINSZ
-TMPDIR
-Todo
-USD.doc
-USD:13
-UUNET
-Vx
-Whitespace
-XOFF
-XON
-XOptions
-XXCOLUMNS
-XXXX
-XXXXXX
-XXb
-ZZ
-ab
-abbrev
-ags
-ai
-al
-altwerase
-arg
-args
-autoindent
-autoprint
-autowrite
-aw
-bbrev
-bf
-bigword
-bigwords
-bostic
-brev
-bugs.current
-c2w
-carat
-cdy
-changelog
-chd
-cmd
-count1
-count2
-creens
-cs.berkeley.edu
-db
-dbopen
-def
-di
-dir
-dit
-docs
-eFlRsv
-eFlRv
-ead
-eb
-edcompatible
-elete
-elvis
-email
-enum
-eof
-errorbells
-esc
-ex.cmd.roff
-exrc
-ext
-exu
-exusage
-fi
-filesystem
-filesystems
-ftp.cs.berkeley.edu
-ftp.uu.net
-gdb
-gdb.script
-gs
-gzip'd
-halfbyte
-hange
-hangup
-hardtabs
-ht
-ic
-ifdef
-ignorecase
-ile
-ind
-ious
-ir
-ist
-ize
-keystroke
-keystrokes
-keytime
-leftright
-lhs
-li
-lib
-libc.tags
-lobal
-lowercase
-lp
-matchtime
-mber
-meta
-mk
-mkexrc
-modeful
-modeline
-modelines
-ndo
-nex
-nexrc
-nk
-nomagic
-nooption
-nsert
-nul
-nvi
-nvi.tar.Z
-nvi.tar.z
-nz
-oin
-op
-ove
-para
-pathname
-pathnames
-ppend
-pu
-py
-rc.local
-readonly
-rec
-recdir
-recfile
-recover.XXXX
-recover.XXXXXX
-recover.c
-recover.script
-remapmax
-res
-rew
-rhs
-ript
-rk
-ro
-roff
-rsion
-sc
-scr
-screeen
-se
-set.opt.roff
-shiftwidth
-showmatch
-showmode
-sidescroll
-slowopen
-sm
-sourceany
-sp
-spell.ok
-st
-sual
-svi
-sw
-ta
-tabstop
-taglength
-tagp
-tagpop
-tagstring
-tagt
-tagtop
-terminfo
-th
-tildeop
-tl
-tmp
-ts
-ttytype
-ttywerase
-uR
-ubstitute
-ucb
-uffers
-uit
-una
-unabbrev
-unm
-uppercase
-urce
-uunet
-var
-ve
-vglobal
-vi.0.ps
-vi.0.txt
-vi.1
-vi.XXXX
-vi.XXXXXX
-vi.cmd.roff
-vi.exrc
-vi.recover
-vibackup
-virecovery
-viu
-viusage
-wa
-whitespace
-wi
-wm
-wn
-wq
-wrapmargin
-wrapscan
-writeany
-ws
-xaw
-xit
-ya
-yy
diff --git a/usr.bin/vi/USD.doc/vi.ref/vi.cmd.roff b/usr.bin/vi/USD.doc/vi.ref/vi.cmd.roff
deleted file mode 100644
index 57c0d37..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/vi.cmd.roff
+++ /dev/null
@@ -1,2984 +0,0 @@
-.\" Copyright (c) 1994
-.\" 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.
-.\"
-.\" @(#)vi.cmd.roff 8.28 (Berkeley) 7/17/94
-.\"
-.SH 1 "Vi Description"
-.pp
-.CO Vi
-takes up the entire screen to display the edited file,
-except for the bottom line of the screen.
-The bottom line of the screen is used to enter
-.CO ex
-commands, and for
-.CO vi
-error and informational messages.
-If no other information is being displayed,
-the default display can show the current cursor row and cursor column,
-an indication of whether the file has been modified,
-and the current mode of the editor.
-See the
-.OP ruler ,
-.OP showdirty
-and
-.OP showmode
-options for more information.
-.pp
-Empty lines do not have any special representation on the screen,
-but lines on the screen that would logically come after the end of
-the file are displayed as a single tilde
-.PQ ~
-character.
-To differentiate between empty lines and lines consisting of only
-whitespace characters, use the
-.OP list
-option.
-Historically, implementations of
-.CO vi
-have also displayed some lines as single asterisk
-.PQ @
-characters.
-These were lines that were not correctly displayed, i.e. lines on the
-screen that did not correspond to lines in the file, or lines that did
-not fit on the current screen.
-.CO Nvi
-never displays lines in this fashion.
-.pp
-.CO Vi
-is a modeful editor, i.e. it has two modes,
-.QQ command
-mode and
-.QQ "text input"
-mode.
-When
-.CO vi
-first starts, it is in command mode.
-There are several commands that change
-.CO vi
-into text input mode.
-The
-.LI <escape>
-character is used to resolve the text input into the file,
-and exit back into command mode.
-In
-.CO vi
-command mode, the cursor is always positioned on the last column of
-characters which take up more than one column on the screen.
-In
-.CO vi
-text insert mode, the cursor is positioned on the first column of
-characters which take up more than one column on the screen.
-.pp
-Generally, if the cursor line and cursor column are not on the screen,
-then the screen is scrolled (if the target cursor is close) or repainted
-(if the target cursor is far away) so that the cursor is on the screen.
-If the screen is scrolled, it is moved a minimal amount, and the cursor
-line will usually appear at the top or bottom of the screen.
-In the screen is repainted, the cursor line will appear in the center of
-the screen, unless the cursor is sufficiently close to the beginning or
-end of the file that this is not possible.
-If the
-.OP leftright
-option is set, the screen may be scrolled or repainted in a horizontal
-direction as well as in a vertical one.
-.pp
-A major difference between the historical
-.CO vi
-presentation and
-.CO nvi
-is in the scrolling and screen oriented position commands,
-.CO <control-B> ,
-.CO <control-D> ,
-.CO <control-E> ,
-.CO <control-F> ,
-.CO <control-U> ,
-.CO <control-Y> ,
-.CO H ,
-.CO L
-and
-.CO M .
-In historical implementations of
-.CO vi ,
-these commands acted on physical (as opposed to logical, or screen)
-lines.
-For lines that were sufficiently long in relation to the size of the
-screen, this meant that single line scroll commands might repaint the
-entire screen, scrolling or screen positioning command might not change
-the screen or move the cursor at all, and some lines simply could not
-be displayed, even though
-.CO vi
-would edit the file that contained them.
-In
-.CO nvi ,
-these commands act on logical, i.e. screen lines.
-You are unlikely to notice any difference unless you are editing files
-with lines significantly longer than a screen width.
-.pp
-.CO Vi
-keeps track of the currently
-.QQ "most attractive"
-cursor position.
-Each command description (for commands that can change the current
-cursor position),
-specifies if the cursor is set to a specific location in the line,
-or if it is moved to the
-.QQ "most attractive cursor position" .
-The latter means that the cursor is moved to the cursor position
-that is vertically as close as possible to the current cursor
-position.
-If the current line is shorter than the cursor position
-.CO vi
-would select, the cursor is positioned on the last character in the line.
-(If the line is empty, the cursor is positioned on the first column
-of the line.)
-If a command moves the cursor to the most attractive position,
-it does not alter the current cursor position, and a subsequent
-movement will again attempt to move the cursor to that position.
-Therefore, although a movement to a line shorter than the currently
-most attractive position will cause the cursor to move to the end of
-that line, a subsequent movement to a longer line will cause the
-cursor to move back to the most attractive position.
-.pp
-In addition, the
-.CO $
-command makes the end of each line the most attractive cursor position
-rather than a specific column.
-.pp
-Each
-.CO vi
-command described below notes where the cursor ends up after it is
-executed.
-This position is described in terms of characters on the line, i.e.
-.QQ "the previous character" ,
-or,
-.QQ "the last character in the line" .
-This is to avoid needing to continually refer to on what part of the
-character the cursor rests.
-.pp
-The following words have special meaning for
-.CO vi
-commands.
-.KY "previous context"
-.IP "previous context"
-The position of the cursor before the command which caused the
-last absolute movement was executed.
-Each
-.CO vi
-command described in the next section that is considered an
-absolute movement is so noted.
-In addition, specifying
-.i any
-address to an
-.CO ex
-command is considered an absolute movement.
-.KY "motion"
-.IP "motion"
-A second
-.CO vi
-command can be used as an optional trailing argument to the
-.CO vi
-.CO \&! ,
-.CO \&< ,
-.CO \&> ,
-.CO \&c ,
-.CO \&d ,
-.CO \&y ,
-and (depending on the
-.OP tildeop
-option)
-.CO \&~
-commands.
-This command indicates the end of the region of text that's affected by
-the command.
-The motion command may be either the command character repeated (in
-which case it means the current line) or a cursor movement command.
-In the latter case, the region affected by the command is from the
-starting or stopping cursor position which comes first in the file,
-to immediately before the starting or stopping cursor position which
-comes later in the file.
-Commands that operate on lines instead of using beginning and ending
-cursor positions operate on all of the lines that are wholly or
-partially in the region.
-In addition, some other commands become line oriented depending on
-where in the text they are used.
-The command descriptions below note these special cases.
-.sp
-The following commands may all be used as motion components for
-.CO vi
-commands:
-.sp
-.ne 12v
-.ft C
-.TS
-r r r r.
-<control-A> <control-H> <control-J> <control-M>
-<control-N> <control-P> <space> $
-% '<character> ( )
-+ , - /
-0 ; ? B
-E F G H
-L M N T
-W [[ ]] ^
-\&_ `<character> b e
-f h j k
-l n t w
-{ | }
-.TE
-.ft R
-.sp
-The optional count prefix available for some of the
-.CO vi
-commands that take motion commands, or the count prefix available
-for the
-.CO vi
-commands that are used as motion components,
-may be included and is
-.i always
-considered part of the motion argument.
-For example, the commands
-.QT c2w
-and
-.QT 2cw
-are equivalent, and the region affected by the
-.CO c
-command is two words of text.
-In addition, if the optional count prefix is specified for both the
-.CO vi
-command and its motion component, the effect is multiplicative and
-is considered part of the motion argument.
-For example, the commands
-.QT 4cw
-and
-.QT 2c2w
-are equivalent, and the region affected by the
-.CO c
-command is four words of text.
-.KY "count"
-.IP "count"
-A positive number used as an optional argument to most commands,
-either to give a size or a position (for display or movement commands),
-or as a repeat count (for commands that modify text).
-The count argument is always optional and defaults to 1 unless otherwise
-noted in the command description.
-.sp
-When a
-.CO vi
-command synopsis shows both a
-.LI [buffer]
-and
-.LI [count] ,
-they may be presented in any order.
-.KY "bigword"
-.IP "bigword"
-A set of non-whitespace characters preceded and followed by whitespace
-characters or the beginning or end of the file or line.
-.sp
-Groups of empty lines (or lines containing only whitespace characters)
-are treated as a single bigword.
-.KY word
-.IP word
-Generally, in languages where it is applicable,
-.CO vi
-recognizes two kinds of words.
-First, a sequence of letters, digits and underscores, delimited at both
-ends by: characters other than letters, digits, or underscores; the
-beginning or end of a line; the beginning or end of the file.
-Second, a sequence of characters other than letters, digits, underscores,
-or whitespace characters, delimited at both ends by: a letter, digit,
-underscore, or whitespace character;
-the beginning or end of a line; the beginning or end of the file.
-.sp
-Groups of empty lines (or lines containing only whitespace characters)
-are treated as a single word.
-.KY "paragraph"
-.IP "paragraph"
-An area of text that begins with either the beginning of a file,
-an empty line, or a section boundary, and continues until either
-an empty line, section boundary, or the end of the file.
-.sp
-Groups of empty lines (or lines containing only whitespace characters)
-are treated as a single paragraph.
-.sp
-Additional paragraph boundaries can be defined using the
-.OP paragraph
-option.
-.KY "section"
-.IP "section"
-An area of text that starts with the beginning of the file or a line
-whose first character is an open brace
-.PQ {
-and continues until the next section or the end of the file.
-.sp
-Additional section boundaries can be defined using the
-.OP sections
-option.
-.KY "sentence"
-.IP "sentence"
-An area of text that begins with either the beginning of the file or the
-first nonblank character following the previous sentence, paragraph, or
-section boundary and continues until the end of the file or a or a period
-.PQ \&.
-exclamation point
-.PQ !
-or question mark
-.PQ ?
-character,
-followed by either an end-of-line or two whitespace characters.
-Any number of closing parentheses
-.PQ ) ,
-brackets
-.PQ ]
-or double-quote
-.PQ """"
-characters can appear between the period, exclamation point,
-or question mark and the whitespace characters or end-of-line.
-.sp
-Groups of empty lines (or lines containing only whitespace characters)
-are treated as a single sentence.
-.SH 1 "Vi Commands"
-.pp
-The following section describes the commands available in the command
-mode of the
-.CO vi
-editor.
-In each entry below, the tag line is a usage synopsis for the command
-character.
-In addition, the final line and column the cursor rests upon,
-and any options which affect the command are noted.
-.KY <control-A>
-.IP "[count] <control-A>"
-Search forward
-.LI count
-times for the current word.
-The current word begins at the first non-whitespace character on or
-after the current cursor position,
-and extends up to the next non-word character or the end of the line.
-The search is literal, i.e. no characters in the word have any special
-meaning in terms of Regular Expressions.
-It is an error if no matching pattern is found between the starting position
-and the end of the file.
-.sp
-The
-.CO <control-A>
-command is an absolute movement.
-The
-.CO <control-A>
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Set to the line where the word is found.
-.SP Column:
-Set to the first character of the word.
-.SP Options:
-Affected by the
-.OP extended ,
-.OP ignorecase
-and
-.OP wrapscan
-options.
-.SE
-.KY <control-B>
-.IP "[count] <control-B>"
-Page backward
-.LI count
-screens.
-Two lines of overlap are maintained by displaying the window
-starting at line
-.LI "(top_line - count * window_size) + 2" ,
-where
-.LI window_size
-is the value of the
-.OP window
-option.
-(In the case of split screens, this size is corrected to the
-current screen size.)
-This is an error if the movement is past the beginning of the file.
-.sp
-The
-.CO <control-B>
-command is an absolute movement.
-.SS
-.SP Line:
-Set to the last line of text displayed on the screen.
-.SP Column:
-Set to the first nonblank character of the line.
-.SP Options:
-None.
-.SE
-.KY <control-D>
-.IP "[count] <control-D>"
-Scroll forward
-.LI count
-lines.
-If
-.LI count
-is not specified, scroll forward the number of lines specified by the last
-.CO <control-D>
-or
-.CO <control-U>
-command.
-If this is the first
-.CO <control-D>
-or
-.CO <control-U>
-command,
-scroll forward half the number of lines in the screen.
-(In the case of split screens, the default scrolling distance is
-corrected to half the current screen size.)
-This is an error if the movement is past the end of the file.
-.sp
-The
-.CO <control-D>
-command is an absolute movement.
-.SS
-.SP Line:
-Set to the current line plus the number of lines scrolled.
-.SP Column:
-Set to the first nonblank character of the line.
-.SP Options:
-None.
-.SE
-.KY <control-E>
-.IP "[count] <control-E>"
-Scroll forward
-.LI count
-lines, leaving the cursor on the current line and column, if possible.
-This is an error if the movement is past the end of the file.
-.SS
-.SP Line:
-Unchanged unless the current line scrolls off the screen,
-in which case it is set to the first line on the screen.
-.SP Column:
-Unchanged unless the current line scrolls off the screen,
-in which case it is set to the most attractive cursor position.
-.SP Options:
-None.
-.SE
-.KY <control-F>
-.IP "[count] <control-F>"
-Page forward
-.LI count
-screens.
-Two lines of overlap are maintained by displaying the window
-starting at line
-.LI "top_line + count * window_size - 2" ,
-where
-.LI window_size
-is the value of the
-.OP window
-option.
-(In the case of split screens, this size is corrected to the
-current screen size.)
-This is an error if the movement is past the end of the file.
-.sp
-The
-.CO <control-F>
-command is an absolute movement.
-.SS
-.SP Line:
-Set to the first line on the screen.
-.SP Column:
-Set to the first nonblank character of the current line.
-.SP Options:
-None.
-.SE
-.KY <control-G>
-.IP "<control-G>"
-Display the file information.
-The information includes the current pathname, the current line,
-the number of total lines in the file, the current line as a percentage
-of the total lines in the file, if the file has been modified,
-was able to be locked, if the file's name has been changed,
-and if the edit session is read-only.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY <control-H>
-.IP "<control-H>"
-.Ip "[count] h"
-Move the cursor back
-.LI count
-characters in the current line.
-This is an error if the cursor is on the first character in the line.
-.sp
-The
-.CO <control-H>
-and
-.CO h
-commands may be used as the motion component of other
-.CO vi
-commands,
-in which case any text copied into a buffer is character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the
-.LI "current - count"
-character, or, the first character in the line if
-.LI count
-is greater than or equal to the number of characters in the line
-before the cursor.
-.SP Options:
-None.
-.SE
-.KY <control-J>
-.IP "[count] <control-J>"
-.KY <control-N>
-.Ip "[count] <control-N>"
-.KY j
-.Ip "[count] j"
-Move the cursor down
-.LI count
-lines without changing the current column.
-This is an error if the movement is past the end of the file.
-.sp
-The
-.CO <control-J> ,
-.CO <control-N>
-and
-.CO j
-commands may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to the current line plus
-.LI count .
-.SP Column:
-The most attractive cursor position.
-.SP Options:
-None.
-.SE
-.KY <control-L>
-.IP "<control-L>"
-.KY <control-R>
-.Ip "<control-R>"
-Repaint the screen.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY <control-M>
-.IP "[count] <control-M>"
-.KY +
-.Ip "[count] +"
-Move the cursor down
-.LI count
-lines to the first nonblank character of that line.
-This is an error if the movement is past the end of the file.
-.sp
-The
-.CO <control-M>
-and
-.CO +
-commands may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to the current line plus
-.LI count .
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-None.
-.SE
-.KY <control-P>
-.IP "[count] <control-P>"
-.KY k
-.Ip "[count] k"
-Move the cursor up
-.LI count
-lines, without changing the current column.
-This is an error if the movement is past the beginning of the file.
-.sp
-The
-.CO <control-P>
-and
-.CO k
-commands may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to the current line minus count.
-.SP Column:
-The most attractive cursor position.
-.SP Options:
-None.
-.SE
-.KY <control-T>
-.IP "<control-T>"
-Return to the most recent tag context.
-The
-.CO <control-T>
-command is an absolute movement.
-.SS
-.SP Line:
-Set to the context of the previous tag command.
-.SP Column:
-Set to the context of the previous tag command.
-.SP Options:
-None.
-.SE
-.KY <control-U>
-.IP "<control-U>"
-Scroll backward
-.LI count
-lines.
-If
-.LI count
-is not specified, scroll backward the number of lines specified by the
-last
-.CO <control-D>
-or
-.CO <control-U>
-command.
-If this is the first
-.CO <control-D>
-or
-.CO <control-U>
-command,
-scroll backward half the number of lines in the screen.
-(In the case of split screens, the default scrolling distance is
-corrected to half the current screen size.)
-This is an error if the movement is past the beginning of the file.
-.sp
-The
-.CO <control-U>
-command is an absolute movement.
-.SS
-.SP Line:
-Set to the current line minus the amount scrolled.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-None.
-.SE
-.KY <control-W>
-.IP "<control-W>"
-Switch to the next lower screen in the window, or, to the first
-screen if there are no lower screens in the window.
-.SS
-.SP Line:
-Set to the previous cursor position in the window.
-.SP Column:
-Set to the previous cursor position in the window.
-.SP Options:
-None.
-.SE
-.KY <control-Y>
-.IP "<control-Y>"
-Scroll backward
-.LI count
-lines, leaving the current line and column as is, if possible.
-This is an error if the movement is past the beginning of the file.
-.SS
-.SP Line:
-Unchanged unless the current line scrolls off the screen,
-in which case it is set to the last line of text displayed
-on the screen.
-.SP Column:
-Unchanged unless the current line scrolls off the screen,
-in which case it is the most attractive cursor position.
-.SP Options:
-None.
-.SE
-.KY <control-Z>
-.IP "<control-Z>"
-Suspend the current editor session.
-If the file has been modified since it was last completely written,
-and the
-.OP autowrite
-option is set, the file is written before the editor session is
-suspended.
-If this write fails, the editor session is not suspended.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged.
-.SP Options:
-Affected by the
-.OP autowrite
-option.
-.SE
-.KY <escape>
-.IP "<escape>"
-Execute
-.CO ex
-commands or cancel partial commands.
-If an
-.CO ex
-command is being entered (e.g.
-.CO / ,
-.CO ? ,
-.CO :
-or
-.CO ! ),
-the command is executed.
-If a partial command has been entered, e.g.
-.QL "[0-9]*" ,
-or
-.QL "[0-9]*[!<>cdy]" ,
-the command is cancelled.
-Otherwise, it is an error.
-.SS
-.SP Line:
-When an
-.CO ex
-command is being executed, the current line is set as described for
-that command.
-Otherwise, unchanged.
-.SP Column:
-When an
-.CO ex
-command is being executed, the current column is set as described for
-that command.
-Otherwise, unchanged.
-.SP Options:
-None.
-.SE
-.KY <control-]>
-.IP "<control-]>"
-Push a tag reference onto the tag stack.
-The tags files (see the
-.OP tags
-option for more information) are searched for a tag matching the
-current word.
-The current word begins at the first non-whitespace character on or
-after the current cursor position,
-and extends up to the next non-word character or the end of the line.
-If a matching tag is found, the current file is discarded and the
-file containing the tag reference is edited.
-.sp
-If the current file has been modified since it was last completely
-written, the command will fail.
-The
-.CO <control-]>
-command is an absolute movement.
-.SS
-.SP Line:
-Set to the line containing the matching tag string.
-.SP Column:
-Set to the start of the matching tag string.
-.SP Options:
-Affected by the
-.OP tags
-and
-.OP taglength
-options.
-.SE
-.KY <control-^>
-.IP "<control-^>"
-Switch to the most recently edited file.
-.sp
-If the file has been modified since it was last completely written,
-and the
-.OP autowrite
-option is set, the file is written out.
-If this write fails, the command will fail.
-Otherwise, if the current file has been modified since it was last
-completely written, the command will fail.
-.SS
-.SP Line:
-Set to the line the cursor was on when the file was last edited.
-.SP Column:
-Set to the column the cursor was on when the file was last edited.
-.SP Options:
-Affected by the
-.OP autowrite
-option.
-.SE
-.KY <space>
-.IP "[count] <space>"
-.KY l
-.Ip "[count] l"
-Move the cursor forward
-.LI count
-characters without changing the current line.
-This is an error if the cursor is on the last character in the line.
-.sp
-The
-.CO <space>
-and
-.CO \&l
-commands may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-In addition, these commands may be used as the motion components
-of other commands when the cursor is on the last character in the
-line, without error.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the current character plus the next
-.LI count
-characters, or to the last character on the line if
-.LI count
-is greater than the number of characters in the line after the
-current character.
-.SP Options:
-None.
-.SE
-.KY !
-.IP "[count] ! motion shell-argument(s)"
-Replace text with results from a shell command.
-Pass the lines specified by the
-.LI count
-and
-.LI motion
-arguments as standard input to the program named by the
-.OP shell
-option, and replace those lines with the output (both
-standard error and standard output) of that command.
-.sp
-After the motion is entered,
-.CO vi
-prompts for arguments to the shell command.
-.sp
-Within those arguments,
-.QT %
-and
-.QT #
-characters are expanded to the current and alternate pathnames,
-respectively.
-The
-.QT !
-character is expanded with the command text of the previous
-.CO !
-or
-.CO :!
-commands.
-(Therefore, the command
-.CO !!
-repeats the previous
-.CO !
-command.)
-The special meanings of
-.QT % ,
-.QT #
-and
-.QT !
-can be overridden by escaping them with a backslash.
-If no
-.CO !
-or
-.CO :!
-command has yet been executed, it is an error to use an unescaped
-.QT !
-character.
-The
-.CO !
-command does
-.i not
-do shell expansion on the strings provided as arguments.
-If any of the above expansions change the arguments the user entered,
-the command is redisplayed at the bottom of the screen.
-.sp
-.CO Vi
-then executes the program named by the
-.OP shell
-option, with a
-.b \-c
-flag followed by the arguments (which are bundled into a single argument).
-.sp
-The
-.CO !
-command is permitted in an empty file.
-.sp
-If the file has been modified since it was last completely written,
-the
-.CO !
-command will warn you.
-.SS
-.SP Line:
-The first line of the replaced text.
-.SP Column:
-The first column of the replaced text.
-.SP Options:
-Affected by the
-.OP shell
-option.
-.SE
-.KY #
-.IP "[count] # +|-|#"
-Increment or decrement the current number.
-The current number begins at the first non-number character on or
-before the current cursor position, or the beginning of the line,
-and extends up to the first non-number character on or after the
-current cursor position or the end of the line.
-If the trailing character is a
-.LI \&+ ,
-the number is incremented by
-.LI count .
-If the trailing character is a
-.LI \&- ,
-the number is decremented by
-.LI count .
-If the trailing character is a
-.LI \&# ,
-the previous increment or decrement is repeated.
-.sp
-The format of the number (decimal, hexadecimal, and octal,
-and leading 0's) is retained unless the new value cannot be
-represented in the previous format.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the first character in the cursor word.
-.SP Options:
-None.
-.SE
-.KY $
-.IP "[count] $"
-Move the cursor to the end of a line.
-If
-.LI count
-is specified, the cursor moves down
-.LI "count - 1"
-lines.
-.sp
-It is not an error to use the
-.CO $
-command when the cursor is on the last character in the line or
-when the line is empty.
-.sp
-The
-.CO $
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the cursor is at, or before the first
-nonblank character in the line, in which case it is line oriented.
-It is not an error to use the
-.CO $
-command as a motion component when the cursor is on the last character
-in the line, although it is an error when the line is empty.
-.SS
-.SP Line:
-Set to the current line plus
-.LI count
-minus 1.
-.SP Column:
-Set to the last character in the line.
-.SP Options:
-None.
-.SE
-.KY %
-.IP %
-Move to the matching character.
-The cursor moves to the parenthesis or curly brace which
-.i matches
-the parenthesis or curly brace found at the current cursor position
-or which is the closest one to the right of the cursor on the line.
-It is an error to execute the
-.CO %
-command on a line without a parenthesis or curly brace.
-Historically, any
-.LI count
-specified to the
-.CO %
-command was ignored.
-.sp
-The
-.CO %
-command is an absolute movement.
-The
-.CO %
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting point of the region is at
-or before the first nonblank character on its line, and the ending
-point is at or after the last nonblank character on its line, in
-which case it is line oriented.
-.SS
-.SP Line:
-Set to the line containing the matching character.
-.SP Column:
-Set to the matching character.
-.SP Options:
-None.
-.SE
-.KY &
-.IP "&"
-Repeat the previous substitution command on the current line.
-.sp
-Historically, any
-.LI count
-specified to the
-.CO &
-command was ignored.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged if the cursor was on the last character in the line,
-otherwise, set to the first nonblank character in the line.
-.SP Options:
-Affected by the
-.OP edcompatible ,
-.OP extended ,
-.OP ignorecase
-and
-.OP magic
-options.
-.SE
-.KY SQUOTE<character>
-.IP \'<character>
-.KY `<character>
-.Ip `<character>
-Return to a context marked by the character
-.LI <character> .
-If
-.LI <character>
-is the
-.QT '
-or
-.QT `
-character, return to the previous context.
-If
-.LI <character>
-is any other character,
-return to the context marked by that character (see the
-.CO m
-command for more information).
-If the command is the
-.CO \'
-command, only the line value is restored,
-and the cursor is placed on the first nonblank character of that line.
-If the command is the
-.CO `
-command, both the line and column values are restored.
-.sp
-It is an error if the context no longer exists because of
-line deletion.
-(Contexts follow lines that are moved, or which are deleted
-and then restored.)
-.sp
-The
-.CO \'
-and
-.CO `
-commands are both absolute movements.
-They may be used as a motion component for other
-.CO vi
-commands.
-For the
-.CO \'
-command, any text copied into a buffer is line oriented.
-For the
-.CO `
-command, any text copied into a buffer is character oriented, unless
-it both starts and stops at the first character in the line, in which
-case it is line oriented.
-In addition, when using the
-.CO `
-command as a motion component,
-commands which move backward and started at the first character in the
-line, or move forward and ended at the first character in the line,
-are corrected to the last character of the starting and ending lines,
-respectively.
-.SS
-.SP Line:
-Set to the line from the context.
-.SP Column:
-Set to the first nonblank character in the line, for the
-.CO \'
-command, and set to the context's column for the
-.CO `
-command.
-.SP Options:
-None.
-.SE
-.KY (
-.IP "[count] ("
-Back up
-.LI count
-sentences.
-.sp
-The
-.CO (
-command is an absolute movement.
-The
-.CO (
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting and stopping points of the
-region are the first character in the line, in which case it is
-line oriented.
-In the latter case, the stopping point of the region is adjusted
-to be the end of the line immediately before it, and not the original
-cursor position.
-.SS
-.SP Line:
-Set to the line containing the beginning of the sentence.
-.SP Column:
-Set to the first nonblank character of the sentence.
-.SP Options:
-None.
-.SE
-.KY )
-.IP "[count] )"
-Move forward
-.LI count
-sentences.
-.sp
-The
-.CO )
-command is an absolute movement.
-The
-.CO )
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting point of the region is the
-first character in the line, in which case it is line oriented.
-In the latter case, if the stopping point of the region is also
-the first character in the line, it is adjusted to be the end of the
-line immediately before it.
-.SS
-.SP Line:
-Set to the line containing the beginning of the sentence.
-.SP Column:
-Set to the first nonblank character of the sentence.
-.SP Options:
-None.
-.SE
-.KY ,
-.IP "[count] ,"
-Reverse find character
-.LI count
-times.
-Reverse the last
-.CO F ,
-.CO f ,
-.CO T
-or
-.CO t
-command, searching the other way in the line,
-.LI count
-times.
-.sp
-The
-.CO ,
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the searched-for character.
-.SP Options:
-None.
-.SE
-.KY MINUSSIGN
-.IP "[count] \-"
-Move to first nonblank of the previous line,
-.LI count
-times.
-.sp
-This is an error if the movement is past the beginning of the file.
-.sp
-The
-.CO -
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to the current line minus
-.LI count .
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-None.
-.SE
-.KY \&.
-.IP "[count] \&."
-Repeat the last
-.CO vi
-command that modified text.
-The repeated command may be a command and motion component combination.
-If
-.LI count
-is specified, it replaces
-.i both
-the count specified for the repeated command, and, if applicable, for
-the repeated motion component.
-If
-.LI count
-is not specified, the counts originally specified to the command being
-repeated are used again.
-.sp
-As a special case, if the
-.CO \.
-command is executed immediately after the
-.CO u
-command, the change log is rolled forward or backward, depending on
-the action of the
-.CO u
-command.
-.SS
-.SP Line:
-Set as described for the repeated command.
-.SP Column:
-Set as described for the repeated command.
-.SP Options:
-None.
-.SE
-.KY /RE/
-.IP "/RE<carriage-return>"
-.Ip "/RE/ [offset]<carriage-return>"
-.KY ?RE?
-.Ip "?RE<carriage-return>"
-.Ip "?RE? [offset]<carriage-return>"
-.KY N
-.Ip "N"
-.KY n
-.Ip "n"
-Search forward or backward for a regular expression.
-The commands beginning with a slash
-.PQ /
-character are forward searches, the commands beginning with a
-question mark
-.PQ ?
-are backward searches.
-.CO Vi
-prompts with the leading character on the last line of the screen
-for a string.
-It then searches forward or backward in the file for the next
-occurrence of the string, which is interpreted as a Basic Regular
-Expression.
-.sp
-The
-.CO /
-and
-.CO ?
-commands are absolute movements.
-They may be used as the motion components of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the search started and ended on
-the first column of a line, in which case it is line oriented.
-In addition, forward searches ending at the first character of a line,
-and backward searches beginning at the first character in the line,
-are corrected to begin or end at the last character of the previous line.
-(Note, forward and backward searches can occur for both
-.CO /
-and
-.CO ?
-commands, if the
-.OP wrapscan
-option is set.)
-.sp
-If an offset from the matched line is specified (i.e. a trailing
-.QT /
-or
-.QT ?
-character is followed by a signed offset), the buffer will always
-be line oriented (e.g.
-.QT /string/+0
-will always guarantee a line orientation).
-.sp
-The
-.CO n
-command repeats the previous search.
-.sp
-The
-.CO N
-command repeats the previous search, but in the reverse direction.
-.sp
-Missing RE's (e.g.
-.QT //<carriage-return> ,
-.QT /<carriage-return> ,
-.QT ??<carriage-return> ,
-or
-.QT ?<carriage-return>
-search for the last search RE, in the indicated direction.
-.sp
-Searches may be interrupted using the
-.LI <interrupt>
-character.
-.SS
-.SP Line:
-Set to the line in which the match occurred.
-.SP Column:
-Set to the first character of the matched string.
-.SP Options:
-Affected by the
-.OP edcompatible ,
-.OP extended ,
-.OP ignorecase ,
-.OP magic ,
-and
-.OP wrapscan
-options.
-.SE
-.KY 0
-.IP "0"
-Move to the first character in the current line.
-It is not an error to use the
-.CO 0
-command when the cursor is on the first character in the line,
-.sp
-The
-.CO 0
-command may be used as the motion component of other
-.CO vi
-commands, in which case it is an error if the cursor is on the
-first character in the line.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the first character in the line.
-.SP Options:
-None.
-.SE
-.KY :
-.IP ":"
-Execute an ex command.
-.CO Vi
-prompts for an
-.CO ex
-command on the last line of the screen, using a colon
-.PQ :
-character.
-The command is terminated by a
-.LI <carriage-return> ,
-.LI <newline>
-or
-.LI <escape>
-character; all of these characters may be escaped by using a
-.LI "<literal next>"
-character.
-The command is then executed.
-.sp
-If the
-.CO ex
-command writes to the screen,
-.CO vi
-will prompt the user for a
-.LI <carriage-return>
-before continuing
-when the
-.CO ex
-command finishes.
-Large amounts of output from the
-.CO ex
-command will be paged for the user, and the user prompted for a
-.LI <carriage-return>
-or
-.LI <space>
-key to continue.
-In some cases, a quit (normally a
-.QQ q
-character) or
-.LI <interrupt>
-may be entered to interrupt the
-.CO ex
-command.
-.sp
-When the
-.CO ex
-command finishes, and the user is prompted to resume visual mode,
-it is also possible to enter another
-.QT :
-character followed by another
-.CO ex
-command.
-.SS
-.SP Line:
-The current line is set as described for the
-.CO ex
-command.
-.SP Column:
-The current column is set as described for the
-.CO ex
-command.
-.SP Options:
-None.
-.SE
-.KY ;
-.IP "[count] ;"
-Repeat the last character find
-.LI count
-times.
-The last character find is one of the
-.CO F ,
-.CO f ,
-.CO T
-or
-.CO t
-commands.
-.sp
-The
-.CO ;
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the searched-for character.
-.SP Options:
-None.
-.SE
-.KY <
-.IP "[count] < motion"
-.KY >
-.Ip "[count] > motion"
-Shift lines left or right.
-Shift the number of lines in the region specified by the motion component,
-times
-.LI count ,
-left (for the
-.CO <
-command) or right (for the
-.CO >
-command) by the number of columns specified by the
-.OP shiftwidth
-option.
-Only whitespace characters are deleted when shifting left;
-once the first character in the line contains a nonblank character,
-the
-.CO shift
-will succeed, but the line will not be modified.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-Affected by the
-.OP shiftwidth
-option.
-.SE
-.KY @
-.IP "@ buffer"
-Execute a named buffer.
-Execute the named buffer as
-.CO vi
-commands.
-The buffer may include
-.CO ex
-commands, too, but they must be expressed as a
-.CO :
-command.
-If the buffer is line oriented,
-.LI <newline>
-characters are logically appended to each line of the buffer.
-If the buffer is character oriented,
-.LI <newline>
-characters are logically appended to all but the last line in the buffer.
-.sp
-If the buffer name is
-.QT @ ,
-or
-.QT * ,
-then the last buffer executed shall be used.
-It is an error to specify
-.QT @@
-or
-.QT **
-if there were no buffer previous executions.
-The text of a macro may contain an
-.CO @
-command,
-and it is possible to create infinite loops in this manner.
-(The
-.LI <interrupt>
-character may be used to interrupt the loop.)
-.SS
-.SP Line:
-The current line is set as described for the command(s).
-.SP Column:
-The current column is set as described for the command(s).
-.SP Options:
-None.
-.SE
-.KY A
-.IP "[count] A"
-Enter input mode, appending the text after the end of the line.
-If
-.LI count
-is specified, the text is repeatedly input
-.LI "count - 1"
-more times after input mode is exited.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY B
-.IP "[count] B"
-Move backward
-.LI count
-bigwords.
-Move the cursor backward to the beginning of a bigword by repeating the
-following algorithm: if the current position is at the beginning of a
-bigword or the character at the current position cannot be part of a bigword,
-move to the first character of the preceding bigword.
-Otherwise, move to the first character of the bigword at the current position.
-If no preceding bigword exists on the current line, move to the first
-character of the last bigword on the first preceding line that contains a
-bigword.
-.sp
-The
-.CO B
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Set to the line containing the word selected.
-.SP Column:
-Set to the first character of the word selected.
-.SP Options:
-None.
-.SE
-.KY C
-.IP "[buffer] [count] C"
-Change text from the current position to the end-of-line.
-If
-.LI count
-is specified, the input text replaces from the current position to
-the end-of-line, plus
-.LI "count - 1"
-subsequent lines.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY D
-.IP "[buffer] D"
-Delete text from the current position to the end-of-line.
-.sp
-It is not an error to execute the
-.CO D
-command on an empty line.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the character before the current character, or, column 1 if
-the cursor was on column 1.
-.SP Options:
-None.
-.SE
-.KY E
-.IP "[count] E"
-Move forward
-.LI count
-end-of-bigwords.
-Move the cursor forward to the end of a bigword by repeating the
-following algorithm: if the current position is the end of a
-bigword or the character at that position cannot be part of a bigword,
-move to the last character of the following bigword.
-Otherwise, move to the last character of the bigword at the current
-position.
-If no succeeding bigword exists on the current line,
-move to the last character of the first bigword on the next following
-line that contains a bigword.
-.sp
-The
-.CO E
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Set to the line containing the word selected.
-.SP Column:
-Set to the last character of the word selected.
-.SP Options:
-None.
-.SE
-.KY F
-.IP "[count] F <character>"
-Search
-.LI count
-times backward through the current line for
-.LI <character> .
-.sp
-The
-.CO F
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the searched-for character.
-.SP Options:
-None.
-.SE
-.KY G
-.IP "[count] G"
-Move to line
-.LI count ,
-or the last line of the file if
-.LI count
-not specified.
-.sp
-The
-.CO G
-command is an absolute movement.
-The
-.CO \&G
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to
-.LI count ,
-if specified, otherwise, the last line.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-None.
-.SE
-.KY H
-.IP "[count] H"
-Move to the screen line
-.LI "count - 1"
-lines below the top of the screen.
-.sp
-The
-.CO H
-command is an absolute movement.
-The
-.CO H
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to the line
-.LI "count - 1"
-lines below the top of the screen.
-.SP Column:
-Set to the first nonblank character of the
-.i screen
-line.
-.SP Options:
-None.
-.SE
-.KY I
-.IP "[count] I"
-Enter input mode, inserting the text at the beginning of the line.
-If
-.LI count
-is specified, the text input is repeatedly input
-.LI "count - 1"
-more times.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-None.
-.SE
-.KY J
-.IP "[count] J"
-Join lines.
-If
-.LI count
-is specified,
-.LI count
-lines are joined; a minimum of two lines are always joined,
-regardless of the value of
-.LI count .
-.sp
-If the current line ends with a whitespace character, all whitespace
-is stripped from the next line.
-Otherwise, if the next line starts with a open parenthesis
-.PQ (
-do nothing.
-Otherwise, if the current line ends with a question mark
-.PQ ? ,
-period
-.PQ \&.
-or exclamation point
-.PQ ! ,
-insert two spaces.
-Otherwise, insert a single space.
-.sp
-It is not an error to join lines past the end of the file,
-i.e. lines that do not exist.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the character after the last character of the next-to-last
-joined line.
-.SP Options:
-None.
-.SE
-.KY L
-.IP "[count] L"
-Move to the screen line
-.LI "count - 1"
-lines above the bottom of the screen.
-.sp
-The
-.CO L
-command is an absolute movement.
-The
-.CO L
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.SS
-.SP Line:
-Set to the line
-.LI "count - 1"
-lines above the bottom of the screen.
-.SP Column:
-Set to the first nonblank character of the
-.i screen
-line.
-.SP Options:
-None.
-.SE
-.KY M
-.IP " M"
-Move to the screen line in the middle of the screen.
-.sp
-The
-.CO M
-command is an absolute movement.
-The
-.CO M
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.sp
-Historically, any
-.LI count
-specified to the
-.CO M
-command was ignored.
-.SS
-.SP Line:
-Set to the line in the middle of the screen.
-.SP Column:
-Set to the first nonblank character of the
-.i screen
-line.
-.SP Options:
-None.
-.SE
-.KY O
-.IP "[count] O"
-Enter input mode, appending text in a new line above the current line.
-If
-.LI count
-is specified, the text input is repeatedly input
-.LI "count - 1"
-more times.
-.sp
-Historically, any
-.LI count
-specified to the
-.CO O
-command was ignored.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY P
-.IP "[buffer] P"
-Insert text from a buffer.
-Text from the buffer (the unnamed buffer by default) is inserted
-before the current column or, if the buffer is line oriented,
-before the current line.
-.SS
-.SP Line:
-Set to the lowest numbered line insert,
-if the buffer is line oriented, otherwise unchanged.
-.SP Column:
-Set to the first nonblank character of the appended text,
-if the buffer is line oriented, otherwise, the last character
-of the appended text.
-.SP Options:
-None.
-.SE
-.KY Q
-.IP "Q"
-Exit
-.CO vi
-(or visual) mode and switch to
-.CO ex
-mode.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-No longer relevant.
-.SP Options:
-None.
-.SE
-.KY R
-.IP "[count] R"
-Enter input mode, replacing the characters in the current line.
-If
-.LI count
-is specified, the text input is repeatedly input
-.LI "count - 1"
-more times.
-.sp
-If the end of the current line is reached, no more characters are
-replaced and any further characters input are appended to the line.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY S
-.IP "[buffer] [count] S"
-Substitute
-.LI count
-lines.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY T
-.IP "[count] T <character>"
-Search backward,
-.LI count
-times,
-through the current line for the character
-.i after
-the specified
-.LI <character> .
-.sp
-The
-.CO T
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the character
-.i after
-the searched-for character.
-.SP Options:
-None.
-.SE
-.KY U
-.IP "U"
-Restore the current line to its state before the cursor last
-moved to it.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-The first character in the line.
-.SP Options:
-None.
-.SE
-.KY W
-.IP "[count] W"
-Move forward
-.LI count
-bigwords.
-Move the cursor forward to the beginning of a bigword by repeating the
-following algorithm: if the current position is within a bigword or the
-character at that position cannot be part of a bigword, move to the first
-character of the next bigword.
-If no subsequent bigword exists on the current line,
-move to the first character of the first bigword on the first following
-line that contains a bigword.
-.sp
-The
-.CO W
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-The line containing the word selected.
-.SP Column:
-The first character of the word selected.
-.SP Options:
-None.
-.SE
-.KY X
-.IP "[buffer] [count] X"
-Delete
-.LI count
-characters before the cursor.
-If the number of characters to be deleted is greater than or equal to
-the number of characters to the beginning of the line, all of the
-characters before the current cursor position, to the beginning of the
-line, are deleted.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the current character minus
-.LI count ,
-or the first character if count is greater than the number of
-characters in the line before the cursor.
-.SP Options:
-None.
-.SE
-.KY Y
-.IP "[buffer] [count] Y"
-Copy (or
-.QQ yank )
-.LI count
-lines into the specified buffer.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY ZZ
-.IP "ZZ"
-Write the file and exit
-.CO vi .
-The file is only written if it has been modified since the last
-complete write of the file to any file.
-.sp
-The
-.CO ZZ
-command will exit the editor after writing the file,
-if there are no further files to edit.
-Entering two
-.QQ quit
-commands (i.e.
-.CO wq ,
-.CO quit ,
-.CO xit
-or
-.CO ZZ )
-in a row will override this check and the editor will exit,
-ignoring any files that have not yet been edited.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY [[
-.IP "[count] [["
-Back up
-.LI count
-section boundaries.
-.sp
-The
-.CO [[
-command is an absolute movement.
-The
-.CO [[
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting position is column 0,
-in which case it is line oriented.
-.sp
-This is an error if the movement is past the beginning of the file.
-.SS
-.SP Line:
-Set to the previous line that is
-.LI count
-section boundaries back,
-or the first line of the file if no more section boundaries exist
-preceding the current line.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-Affected by the
-.OP sections
-option.
-.SE
-.KY ]]
-.IP "[count] ]]"
-Move forward
-.LI count
-section boundaries.
-.sp
-The
-.CO ]]
-command is an absolute movement.
-The
-.CO ]]
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting position is column 0,
-in which case it is line oriented.
-.sp
-This is an error if the movement is past the end of the file.
-.SS
-.SP Line:
-Set to the line that is
-.LI count
-section boundaries forward,
-or to the last line of the file if no more section
-boundaries exist following the current line.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-Affected by the
-.OP sections
-option.
-.SE
-.KY ^
-.IP "\&^"
-Move to first nonblank character on the current line.
-.sp
-The
-.CO ^
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the first nonblank character of the current line.
-.SP Options:
-None.
-.SE
-.KY _
-.IP "[count] _"
-Move down
-.LI "count - 1"
-lines, to the first nonblank character.
-The
-.CO _
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-line oriented.
-.sp
-It is not an error to execute the
-.CO _
-command when the cursor is on the first character in the line.
-.SS
-.SP Line:
-The current line plus
-.LI "count - 1" .
-.SP Column:
-The first nonblank character in the line.
-.SP Options:
-None.
-.SE
-.KY a
-.IP "[count] a"
-Enter input mode, appending the text after the cursor.
-If
-.LI count
-is specified, the text input is repeatedly input
-.LI "count - 1"
-more times.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY b
-.IP "[count] b"
-Move backward
-.LI count
-words.
-Move the cursor backward to the beginning of a word by repeating the
-following algorithm: if the current position is at the beginning of a word,
-move to the first character of the preceding word.
-Otherwise, the current position moves to the first character of the word
-at the current position.
-If no preceding word exists on the current line, move to the first
-character of the last word on the first preceding line that contains
-a word.
-.sp
-The
-.CO b
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Set to the line containing the word selected.
-.SP Column:
-Set to the first character of the word selected.
-.SP Options:
-None.
-.SE
-.KY c
-.IP "[buffer] [count] c motion"
-Change a region of text.
-If only part of a single line is affected, then the last character
-being changed is marked with a
-.QT $ .
-Otherwise, the region of text is deleted, and input mode is entered.
-.sp
-If
-.LI count
-is specified, it is applied to the
-.LI motion .
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY d
-.IP "[buffer] [count] d motion"
-Delete a region of text.
-If
-.LI count
-is specified, it is applied to the
-.LI motion .
-.SS
-.SP Line:
-Set to the line where the region starts.
-.SP Column:
-Set to the first character in the line after the last character in the
-region.
-If no such character exists, set to the last character before the region.
-.SP Options:
-None.
-.SE
-.KY e
-.IP "[count] e"
-Move forward
-.LI count
-end-of-words.
-Move the cursor forward to the end of a word by repeating the following
-algorithm: if the current position is the end of a word,
-move to the last character of the following word.
-Otherwise, move to the last character of the word at the current position.
-If no succeeding word exists on the current line, move to the last character
-of the first word on the next following line that contains a word.
-.sp
-The
-.CO e
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Set to the line containing the word selected.
-.SP Column:
-Set to the last character of the word selected.
-.SP Options:
-None.
-.SE
-.KY f
-.IP "[count] f <character>"
-Search forward,
-.LI count
-times, through the rest of the current line for
-.LI <character> .
-.sp
-The
-.CO f
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the searched-for character.
-.SP Options:
-None.
-.SE
-.KY i
-.IP "[count] i"
-Enter input mode, inserting the text before the cursor.
-If
-.LI count
-is specified, the text input is repeatedly input
-.LI "count - 1"
-more times.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY m
-.IP "m <character>"
-Save the current context (line and column) as
-.LI <character> .
-The exact position is referred to by
-.QT `<character> .
-The line is referred to by
-.QT '<character> .
-.sp
-Historically,
-.LI <character>
-was restricted to lower-case letters only,
-.CO nvi
-permits the use of any character.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged.
-.SP Options:
-None.
-.SE
-.KY o
-.IP "[count] o"
-Enter input mode, appending text in a new line under the current line.
-If
-.LI count
-is specified, the text input is repeatedly input
-.LI "count - 1"
-more times.
-.sp
-Historically, any
-.LI count
-specified to the
-.CO o
-command was ignored.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY p
-.IP "[buffer] p"
-Append text from a buffer.
-Text from the buffer (the unnamed buffer by default) is appended
-after the current column or, if the buffer is line oriented,
-after the current line.
-.SS
-.SP Line:
-Set to the first line appended, if the buffer is line oriented,
-otherwise unchanged.
-.SP Column:
-Set to the first nonblank character of the appended text if the buffer
-is line oriented, otherwise, the last character of the appended text.
-.SP Options:
-None.
-.SE
-.KY r
-.IP "[count] r <character>"
-Replace characters.
-The next
-.LI count
-characters in the line are replaced with
-.LI <character> .
-Replacing characters with
-.LI <newline>
-characters results in creating new, empty lines into the file.
-.sp
-If
-.LI <character>
-is
-.LI <escape> ,
-the command is cancelled.
-.SS
-.SP Line:
-Unchanged unless the replacement character is a
-.LI <newline> ,
-in which case it is set to the current line plus
-.LI "count - 1" .
-.SP Column:
-Set to the last character replaced,
-unless the replacement character is a
-.LI <newline> ,
-in which case the cursor is in column 1 of the last line inserted.
-.SP Options:
-None.
-.SE
-.KY s
-.IP "[buffer] [count] s"
-Substitute
-.LI count
-characters in the current line starting with the current character.
-.SS
-.SP Line:
-Set to the last line upon which characters were entered.
-.SP Column:
-Set to the last character entered.
-.SP Options:
-Affected by the
-.OP altwerase ,
-.OP autoindent ,
-.OP beautify ,
-.OP showmatch ,
-.OP ttywerase
-and
-.OP wrapmargin
-options.
-.SE
-.KY t
-.IP "[count] t <character>"
-Search forward,
-.LI count
-times, through the current line for the character immediately
-.i before
-.LI <character> .
-.sp
-The
-.CO t
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the character
-.i before
-the searched-for character.
-.SP Options:
-None.
-.SE
-.KY u
-.IP "u"
-Undo the last change made to the file.
-If repeated, the
-.CO u
-command alternates between these two states, and is its own inverse.
-When used after an insert that inserted text on more than one line,
-the lines are saved in the numeric buffers.
-.sp
-The
-.CO \&.
-command, when used immediately after the
-.CO u
-command, causes the change log to be rolled forward or backward,
-depending on the action of the
-.CO u
-command.
-.SS
-.SP Line:
-Set to the position of the first line changed, if the reversal affects
-only one line or represents an addition or change; otherwise, the line
-preceding the deleted text.
-.SP Column:
-Set to the cursor position before the change was made.
-.SP Options:
-None.
-.SE
-.KY w
-.IP "[count] w"
-Move forward
-.LI count
-words.
-Move the cursor forward to the beginning of a word by repeating the
-following algorithm: if the current position is at the
-beginning of a word, move to the first character of the next word.
-If no subsequent word exists on the current line, move to the first
-character of the first word on the first following line that contains
-a word.
-.sp
-The
-.CO w
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-.SS
-.SP Line:
-Set to the line containing the word selected.
-.SP Column:
-Set to the first character of the word selected.
-.SP Options:
-None.
-.SE
-.KY x
-.IP "[buffer] [count] x"
-Delete
-.LI count
-characters.
-The deletion is at the current character position.
-If the number of characters to be deleted is greater than or equal to
-the number of characters to the end of the line, all of the characters
-from the current cursor position to the end of the line are deleted.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Unchanged unless the last character in the line is deleted and the cursor
-is not already on the first character in the line, in which case it is
-set to the previous character.
-.SP Options:
-None.
-.SE
-.KY y
-.IP "[buffer] [count] y motion"
-Copy (or
-.QQ yank )
-a text region specified by the
-.LI count
-and motion into a buffer.
-If
-.LI count
-is specified, it is applied to the
-.LI motion .
-.SS
-.SP Line:
-Unchanged, unless the region covers more than a single line,
-in which case it is set to the line where the region starts.
-.SP Column:
-Unchanged, unless the region covers more than a single line,
-in which case it is set to the character were the region starts.
-.SP Options:
-None.
-.SE
-.KY z
-.IP "[count1] z [count2] type"
-Redraw the screen with a window
-.LI count2
-lines long, with line
-.LI count1
-placed as specified by the
-.LI type
-character.
-If
-.LI count1
-is not specified, it defaults to the current line.
-If
-.LI count2
-is not specified, it defaults to the current window size.
-.sp
-The following
-.LI type
-characters may be used:
-.SS
-.SP +
-If
-.LI count1
-is specified, place the line
-.LI count1
-at the top of the screen.
-Otherwise, display the screen after the current screen, similarly to the
-.CO <control-F>
-command.
-.SP <carriage-return>
-Place the line
-.LI count1
-at the top of the screen.
-.SP \&.
-Place the line
-.LI count1
-in the center of the screen.
-.SP \-
-Place the line
-.LI count1
-at the bottom of the screen.
-.SP ^
-If
-.LI count1
-is specified, place the line that is at the top of the screen
-when
-.LI count1
-is at the bottom of the screen, at the bottom of the screen,
-i.e. display the screen before the screen before
-.LI count1 .
-Otherwise, display the screen before the current screen, similarly to the
-.CO <control-B>
-command.
-.SE
-.SS
-.SP Line:
-Set to
-.LI count1
-unless
-.LI count1
-is not specified and the
-.LI type
-character was either
-.QT ^
-or
-.QT + ,
-in which case it is set to the line before the first line on the
-previous screen or the line after the last line on the previous
-screen, respectively.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-None.
-.SE
-.KY {
-.IP "[count] {"
-Move backward
-.LI count
-paragraphs.
-.sp
-The
-.CO {
-command is an absolute movement.
-The
-.CO {
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting character is the first
-character on its line, in which case it is line oriented.
-.SS
-.SP Line:
-Set to the line containing the beginning of the previous paragraph.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-Affected by the
-.OP paragraph
-option.
-.SE
-.KY |
-.IP "[count] |"
-Move to a specific
-.i column
-position on the current line.
-.sp
-The
-.CO |
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented.
-It is an error to use the
-.CO |
-command as a motion component and for the cursor not to move.
-.SS
-.SP Line:
-Unchanged.
-.SP Column:
-Set to the character occupying the column position identified by
-.LI count ,
-if the position exists in the line.
-If the column length of the current line is less than
-.LI count ,
-the cursor is moved to the last character in the line.
-.SP Options:
-None.
-.SE
-.KY }
-.IP "[count] }"
-Move forward
-.LI count
-paragraphs.
-.sp
-The
-.CO }
-command is an absolute movement.
-The
-.CO }
-command may be used as the motion component of other
-.CO vi
-commands, in which case any text copied into a buffer is
-character oriented, unless the starting character is at or
-before any nonblank characters in its line,
-in which case it is line oriented.
-.SS
-.SP Line:
-Set to the line containing the beginning of the next paragraph.
-.SP Column:
-Set to the first nonblank character in the line.
-.SP Options:
-Affected by the
-.OP paragraph
-option.
-.SE
-.KY ~
-.IP "[count] ~"
-Reverse the case of the next
-.LI count
-character(s).
-This is the historic semantic for the
-.CO ~
-command and it is only in effect if the
-.OP tildeop
-option is not set.
-.sp
-Lowercase alphabetic characters are changed to uppercase,
-and uppercase characters are changed to lowercase.
-No other characters are affected.
-.sp
-Historically, the
-.CO ~
-command did not take an associated count, nor did it move past the
-end of the current line.
-As it had no associated motion it was difficult to change the case
-of large blocks of text.
-In
-.CO nvi ,
-if the cursor is on the last character of a line, and there are
-more lines in the file, the cursor moves to the next line.
-.sp
-It is not an error to specify a count larger than the number of
-characters between the cursor and the end of the file.
-.SS
-.SP Line:
-Set to the line of the character after
-.LI count
-characters, or, end of file.
-.SP Column:
-Set to the character after
-.LI count
-characters, or, end-of-file.
-.SP Options:
-Affected by the
-.OP tildeop
-option.
-.SE
-.KY ~
-.IP "[count] ~ motion"
-Reverse the case of the characters in a text region specified by the
-.LI count
-and
-.LI motion .
-Only in effect if the
-.OP tildeop
-option is set.
-.sp
-Lowercase characters are changed to uppercase,
-and uppercase characters are changed to lowercase.
-No other characters are affected.
-.SS
-.SP Line:
-Set to the line of the character after the last character in the region.
-.SP Column:
-Set to the character after the last character in the region.
-.SP Options:
-Affected by the
-.OP tildeop
-option.
-.SE
-.KY <interrupt>
-.IP "<interrupt>"
-Interrupt the current operation.
-Many of the potentially long-running
-.CO vi
-commands may be interrupted using the terminal interrupt character.
-These operations include searches, file reading and writing, filter
-operations and map character expansion.
-Interrupts are also enabled when running commands outside of
-.CO vi .
-.sp
-If the
-.LI <interrupt>
-character is used to interrupt while entering an
-.CO ex
-command, the command is aborted, the cursor returns to its previous
-position, and
-.CO vi
-remains in command mode.
-.sp
-Generally, if the
-.LI <interrupt>
-character is used to interrupt any
-operation, any changes made before the interrupt are left in place.
-.SS
-.SP Line:
-Dependent on the operation being interrupted.
-.SP Column:
-Dependent on the operation being interrupted.
-.SP Options:
-None.
-.SH 1 "Vi Text Input Commands"
-.pp
-The following section describes the commands available in the text
-input mode of the
-.CO vi
-editor.
-.pp
-Historically,
-.CO vi
-implementations only permitted the characters inserted on the current
-line to be erased.
-In addition, only the
-.LI <control-D>
-erase character and the
-.QT 0<control-D>
-and
-.QT ^<control-D>
-erase strings could erase autoindent characters.
-This implementation permits erasure to continue past the beginning
-of the current line, and back to where text input mode was entered.
-In addition, autoindent characters may be erased using the standard
-erase characters.
-For the line and word erase characters, reaching the autoindent
-characters forms a
-.QQ soft
-boundary, denoting the end of the current word or line erase.
-Repeating the word or line erase key will erase the autoindent characters.
-.pp
-Historically,
-.CO vi
-always used
-.LI <control-H>
-and
-.LI <control-W>
-as character and word erase characters, respectively, regardless of
-the current terminal settings.
-This implementation accepts, in addition to these two characters,
-the current terminal characters for those operations.
-.KY <nul>
-.IP "<nul>"
-If the first character of the input is a
-.LI <nul> ,
-the previous input is replayed, as if just entered.
-.KY <control-D>
-.IP "<control-D>"
-If the previous character on the line was an autoindent character,
-erase it.
-Otherwise, if the user is entering the first character in the line,
-.LI <control-D>
-is ignored.
-Otherwise, a literal
-.LI <control-D>
-character is entered.
-.KY ^<control-D>
-.IP "^<control-D>"
-If the previous character on the line was an autoindent character,
-erase all of the autoindent characters on the line.
-In addition, the autoindent level is reset to 0.
-.KY 0<control-D>
-.IP "0<control-D>"
-If the previous character on the line was an autoindent character,
-erase all of the autoindent characters on the line.
-.KY <control-T>
-.IP "<control-T>"
-Insert sufficient
-.LI <tab>
-and
-.LI <space>
-characters to move the cursor forward to a column immediately
-after the next column which is an even multiple of the
-.OP shiftwidth
-option.
-.sp
-Historically,
-.CO vi
-did not permit the
-.LI <control-T>
-command to be used unless the cursor was at the first column of a new
-line or it was preceded only by autoindent characters.
-.CO Nvi
-permits it to be used at any time during insert mode.
-.KY <erase>
-.IP <erase>
-.KY <control-H>
-.Ip <control-H>
-Erase the last character.
-.KY "<literal next>"
-.IP "<literal next>"
-Quote the next character.
-The next character will not be mapped (see the
-.CO map
-command for more information)
-or interpreted specially.
-A carat
-.PQ ^
-character will be displayed immediately as a placeholder,
-but will be replaced by the next character.
-.KY <escape>
-.IP <escape>
-Resolve all text input into the file, and return to command mode.
-.KY "<line erase>"
-.IP "<line erase>"
-Erase the current line.
-.KY "<control-W>"
-.IP "<control-W>"
-.KY "<word erase>"
-.Ip "<word erase>"
-Erase the last word.
-The definition of word is dependent on the
-.OP altwerase
-and
-.OP ttywerase
-options.
-.KY "<control-X>"
-.IP "<control-X>[0-9A-Fa-f]*"
-Insert a character with the specified hexadecimal value into the text.
-.KY <interrupt>
-.IP "<interrupt>"
-Interrupt text input mode, returning to command mode.
-If the
-.LI <interrupt>
-character is used to interrupt inserting text into the file,
-it is as if the
-.LI <escape>
-character was used; all text input up to the interruption is
-resolved into the file.
diff --git a/usr.bin/vi/USD.doc/vi.ref/vi.ref b/usr.bin/vi/USD.doc/vi.ref/vi.ref
deleted file mode 100644
index 5058cc7..0000000
--- a/usr.bin/vi/USD.doc/vi.ref/vi.ref
+++ /dev/null
@@ -1,1270 +0,0 @@
-.\" Copyright (c) 1994
-.\" 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.
-.\"
-.\" @(#)vi.ref 8.52 (Berkeley) 8/13/94
-.\"
-.\"
-.so ref.so
-.tp
-.(l C
-.ps 12
-.ft B
-Ex/Vi Reference Manual
-.ft
-.ps
-.sp
-.i "Keith Bostic"
-.sp
-Computer Science Division
-Department of Electrical Engineering and Computer Science
-University of California, Berkeley
-Berkeley, California 94720
-.sp 1
-\*(td
-.sp 3
-.i Abstract
-.sp
-.)l
-.(q
-.pp
-This document is the reference guide for the 4.4BSD
-implementations of
-.EV nex nvi ,
-which are reimplementations of the historic Berkeley
-.EV ex vi
-editors.
-.)q
-.sp 3
-.(l C
-.i Acknowledgements
-.)l
-.sp
-.(q
-.pp
-Bruce Englar encouraged the early development of the historic
-.EV ex vi
-editor.
-Peter Kessler helped bring sanity to version 2's command layout.
-Bill Joy wrote versions 1 and 2.0 through 2.7,
-and created the framework that users see in the present editor.
-Mark Horton added macros and other features and made
-.EV ex vi
-work on a large number of terminals and Unix systems.
-.pp
-.CO Nvi
-is originally derived from software contributed to the University of
-California, Berkeley by Steve Kirkendall, the author of the
-.CO vi
-clone
-.CO elvis .
-.pp
-IEEE Standard Portable Operating System Interface for Computer
-Environments (POSIX) 1003.2 style Regular Expression support was
-done by Henry Spencer.
-.pp
-The curses library was originally done by Ken Arnold.
-Scrolling and reworking for
-.CO nvi
-was done by Elan Amir.
-.pp
-The Institute of Electrical and Electronics Engineers has
-given us permission to reprint portions of their documentation.
-Portions of this document are reprinted and reproduced from
-IEEE Std 1003.2-1992, IEEE Standard Portable Operating
-System Interface for Computer Environments (POSIX),
-copyright 1992 by the Institute of Electrical and Electronics
-Engineers, Inc.
-.pp
-The financial support of UUNET Communications Services is gratefully
-acknowledged.
-.)q
-.sy echo -n >index
-.oh 'Nvi/Nex Reference''USD:13-%'
-.eh 'USD:13-%''Nvi/Nex Reference'
-.bp 3
-.SH 1 Description
-.pp
-.CO Vi
-is a screen oriented text editor.
-.CO Ex
-is a line-oriented text editor.
-.CO Ex
-and
-.CO vi
-are different interfaces to the same program,
-and it is possible to switch back and forth during an edit session.
-.CO View
-is the equivalent of using the
-.b \-R
-(read-only) option of
-.CO vi .
-.pp
-This reference manual is the one provided with the
-.EV nex nvi
-versions of the
-.EV ex vi
-text editors.
-.EV Nex nvi
-are intended as bug-for-bug compatible replacements for the original
-Fourth Berkeley Software Distribution (4BSD)
-.EV ex vi
-programs.
-This reference manual is accompanied by a traditional-style manual page.
-That manual page describes the functionality found in
-.EV ex vi
-in far less detail than the description here.
-In addition, it describes the system interface to
-.EV ex vi ,
-e.g. command line options, session recovery, signals,
-environmental variables, and similar things.
-.pp
-This reference is intended for users already familiar with
-.EV ex vi .
-Anyone else should almost certainly read a good tutorial on the
-editor first.
-If you are in an unfamiliar environment,
-and you absolutely have to get work done immediately,
-see the section entitled
-.QB "Fast Startup"
-in the manual page.
-It is probably enough to get you started.
-.pp
-There are a few features in
-.EV nex nvi
-that are not found in historic versions of
-.EV ex vi .
-Some of the more interesting of those features are briefly described
-in the section entitled
-.QB "Additional Features"
-near the end of this document.
-For the rest of this document,
-.EV nex nvi
-is used only when it is necessary to distinguish it from the historic
-implementations of
-.EV ex vi .
-.pp
-Future versions of this software will be periodically made available
-by anonymous ftp, and can be retrieved from
-.LI ftp.cs.berkeley.edu ,
-in the directory
-.LI ucb/4bsd .
-.SH 1 "Startup Information"
-.pp
-.EV Ex vi
-interprets one of two possible environmental variables and reads up to
-three of five possible files during startup.
-The variables and files are expected to contain
-.CO ex
-commands, not
-.CO vi
-commands.
-In addition, they are interpreted
-.i before
-the file to be edited is read, and therefore many
-.CO ex
-commands may not be used.
-Generally, any command that requires output to the screen or that
-needs a file upon which to operate, will cause an error if included
-in a startup file or environmental variable.
-.pp
-Because the
-.CO ex
-command set supported by
-.EV nex nvi
-is a superset of the command set supported by most historical
-implementations of
-.CO ex ,
-.EV nex nvi
-can use the startup files created for the historical implementations,
-but the converse may not be true.
-.pp
-If the
-.b \-s
-(the historic \- option)
-is specified, or if standard input is redirected from a file,
-all environmental variables and startup files are ignored.
-.pp
-Otherwise, startup files and environmental variables are handled
-in the following order:
-.np
-The file
-.LI /etc/vi.exrc
-is read,
-as long as it is owned by root or the effective user ID of the user.
-.np
-The environmental variable
-.LI NEXINIT
-(or the variable
-.LI EXINIT ,
-if
-.LI NEXINIT
-is not set) is interpreted.
-.np
-If neither
-.LI NEXINIT
-or
-.LI EXINIT
-was set, and the
-.LI HOME
-environmental variable is set, the file
-.LI $HOME/.nexrc
-(or the file
-.LI $HOME/.exrc ,
-if
-.LI $HOME/.nexrc
-does not exist) is read,
-as long as the effective user ID of the user is root or is the same as
-the owner of the file.
-.np
-If the
-.OP exrc
-option was turned on by one of the previous startup information
-sources, the file
-.LI \&.nexrc
-(or the file
-.LI \&.exrc ,
-if
-.LI \&.nexrc
-does not exist) is read, as long as the effective user ID of the user
-is the same as the owner of the file.
-.pp
-No startup file is read if it is writable by anyone other than its owner.
-.pp
-It is not an error for any of the startup environmental variables or files
-not to exist.
-.pp
-Once all environmental variables are interpreted,
-and all startup files are read,
-the first file to be edited is read in (or a temporary file is created).
-Then, any commands specified using the
-.b \-c
-option are executed, in the context of that file.
-.SH 1 Recovery
-.pp
-There is no recovery program for
-.EV nex nvi ,
-nor does
-.EV nex nvi
-run setuid.
-Recovery files are created readable and writable by the owner only.
-Users may recover any file which they can read,
-and the superuser may recover any edit session.
-.pp
-Edit sessions are backed by files in the directory named by the
-.OP recdir
-option (the directory
-.LI /var/tmp/vi.recover
-by default), and are named
-.QC vi.XXXXXX ,
-where
-.QC XXXXXX
-is a number related to the process ID.
-When a file is first modified,
-a second recovery file containing an email message for the user is created,
-and is named
-.QC recover.XXXXXX ,
-where, again,
-.QC XXXXXX
-is associated with the process ID.
-Both files are removed at the end of a normal edit session,
-but will remain if the edit session is abnormally terminated
-or the user runs the
-.CO ex
-.CO preserve
-command.
-.pp
-The
-.OP recdir
-option may be set in either the user's or system's startup information,
-changing the recovery directory.
-(Note, however, that if a memory based file system is used as the backup
-directory, each system reboot will delete all of the recovery files!
-The same caution applies to directories such as
-.LI /tmp
-which are cleared of their contents by a system reboot, or
-.LI /usr/tmp
-which is periodically cleared of old files on many systems.)
-.pp
-The recovery directory should be owned by root, or at least by a pseudo-user.
-In addition, if directory
-.QQ sticky-bit
-semantics are available, the directory should have the sticky-bit
-set so that files may only be removed by their owners.
-The recovery directory must be read, write, and executable by any user,
-i.e. mode 1777.
-.pp
-If the recovery directory does not exist,
-.EV ex vi
-will attempt to create it.
-This can result in the recovery directory being owned by a normal user,
-which means that that user will be able to remove other user's recovery
-and backup files.
-This is annoying, but is not a security issue as the user cannot
-otherwise access or modify the files.
-.pp
-The recovery file has all of the necessary information in it to enable the
-user to recover the edit session.
-In addition, it has all of the necessary email headers for
-.XR sendmail 8 .
-When the system is rebooted, all of the files in
-.LI /var/tmp/vi.recover
-named
-.QC recover.XXXXXX
-should be sent to their owners, by email, using the
-.b \-t
-option of
-.CO sendmail
-(or a similar mechanism in other mailers).
-If
-.EV ex vi
-receives a hangup (SIGHUP) signal, or the user executes the
-.CO ex
-.CO preserve
-command,
-.EV ex vi
-will automatically email the recovery information to the user.
-.pp
-If your system does not have the
-.CO sendmail
-utility (or a mailer program which supports its interface)
-the source file
-.LI nvi/common/recover.c
-will have to be modified to use your local mail delivery programs.
-Note, if
-.EV nex nvi
-is changed to use another mailer,
-it is important to remember that the owner of the file given to
-the mailer is the
-.EV nex nvi
-user, so nothing in the file should be trusted as it may have been
-modified in an effort to compromise the system.
-.pp
-Finally, the owner execute bit is set on backup files when they are
-created, and unset when they are first modified, e.g. backup files
-that have no associated email recovery file will have this bit set.
-(There is also a small window where empty files can be created and
-not yet have this bit set.
-This is due to the method in which the files are created.)
-Such files should be deleted when the system reboots.
-.pp
-A simple way to do this cleanup is to insert the following Bourne
-shell script into your
-.LI /etc/rc.local
-(or other startup) file.
-The script should work with the historic Bourne shell,
-a POSIX 1003.2 shell or the Korn shell.
-(A copy of this script is included as
-.LI nvi/install/recover.script
-in the
-.EV nex nvi
-distribution.)
-.sp
-.(b
-.ft C
-.so ../../install/recover.script
-.ft R
-.)b
-.sp
-.pp
-If you are not using the default value for the
-.OP recdir
-option, be sure to substitute the value you're using for the
-.LI RECDIR
-value in the recovery script.
-.pp
-If the path of your system's
-.CO sendmail
-program (or whatever mailer you're using) is not
-.LI /usr/lib/sendmail ,
-be sure to substitute the correct pathname for the
-.LI SENDMAIL
-value in the recovery script.
-Consult the manual page for details on recovering preserved or
-aborted editing sessions.
-.SH 1 "Sizing the Screen"
-.pp
-The size of the screen can be set in a number of ways.
-.EV Ex vi
-takes the following steps until values are obtained for both the
-number of rows and number of columns in the screen.
-.np
-If the environmental variable
-.LI LINES
-exists,
-it is used to specify the number of rows in the screen.
-.np
-If the environmental variable
-.LI COLUMNS
-exists,
-it is used to specify the number of columns in the screen.
-.np
-The TIOCGWINSZ
-.XR ioctl 2
-is attempted on the standard error file descriptor.
-.np
-The termcap entry (or terminfo entry on System V machines)
-is checked for the
-.QQ li
-entry (rows) and the
-.QQ co
-entry (columns).
-.np
-The number of rows is set to 24, and the number of columns is set to 80.
-.pp
-If a window change size signal (SIGWINCH) is received,
-the new window size is retrieved using the TIOCGWINSZ
-.XR ioctl 2
-call, and all other information is ignored.
-.SH 1 "Character Display"
-.pp
-In both
-.CO ex
-and
-.CO vi
-printable characters as defined by
-.XR isprint 3
-are displayed using the local character set.
-.pp
-Non-printable characters, for which
-.XR iscntrl 3
-returns true, and which are less than octal \e076,
-are displayed as the string
-.QT ^<character> ,
-where
-.LI <character>
-is the character that is the original character's value offset from the
-.QT @
-character.
-For example, the octal character \e001 is displayed as
-.QT ^A .
-If
-.XR iscntrl 3
-returns true for the octal character \e177,
-it is displayed as the string
-.QT ^? .
-All other characters are displayed as either hexadecimal values,
-in the form
-.QT "0x<high-halfbyte> ... 0x<low-halfbyte>" ,
-or as octal values, in the form
-.QT "\e<high-one-or-two-bits> ... \e<low-three-bits>" .
-The display of unknown characters is based on the value of the
-.OP octal
-option.
-.pp
-In
-.CO vi
-command mode, the cursor is always positioned on the last column of
-characters which take up more than one column on the screen.
-In
-.CO vi
-text input mode, the cursor is positioned on the first column of
-characters which take up more than one column on the screen.
-.SH 1 "Multiple Screens"
-.pp
-.CO Nvi
-supports multiple screens by dividing the window into regions.
-It also supports stacks of screens by permitting the user to change
-the set of screens that are currently displayed.
-.pp
-The command
-.CO split
-divides the current screen into two regions of approximately equal
-size.
-If a list of files are specified as arguments to the
-.CO split
-command, the list of files to be edited is initialized as if the
-.CO next
-command had been used.
-If no files are specified, the new screen will begin by editing the same
-file as the previous screen.
-.pp
-When more than one screen is editing a file, changes in any screen are
-reflected in all other screens editing the same file.
-Exiting any screen without saving any changes (or explicitly discarding
-them) is permitted until the last screen editing the file is exited.
-.pp
-The
-.CO resize
-command permits resizing of individual screens.
-Screens may be grown, shrunk or set to an absolute number of rows.
-.pp
-The
-.CO ^W
-command is used to switch between screens.
-Each
-.CO ^W
-moves to the next lower screen in the window, or to the first screen
-in the window if there are no lower screens.
-.pp
-The
-.CO bg
-command
-.QQ backgrounds
-the current screen.
-The screen disappears from the window,
-and the rows it occupied are taken over by a neighboring screen.
-It is an error to attempt to background the only screen in the window.
-.pp
-The
-.CO "display screens"
-command displays the names of the files associated with the current
-backgrounded screens in the window.
-.pp
-The
-.CO "fg [file]"
-command
-.QQ foregrounds
-the first screen in the list of backgrounded screens that is
-associated with its argument.
-If no file argument is specified, the first screen on the list is
-foregrounded.
-Foregrounding consists of backgrounding the current screen,
-and replacing its space in the window with the foregrounded screen.
-.pp
-If the last screen in the window is exited, and there are backgrounded
-screens, the first screen on the list of backgrounded screens takes over
-the window.
-.SH 1 "Regular Expressions and Replacement Strings"
-.pp
-Regular expressions are used in line addresses,
-as the first part of the
-.CO ex
-.CO substitute ,
-.CO global ,
-and
-.CO vglobal
-commands, and in search patterns.
-.pp
-The regular expressions supported by
-.EV ex vi
-are, by default, the Basic Regular Expressions (BRE's) described in the
-IEEE POSIX Standard 1003.2.
-The
-.OP extended
-option causes all regular expressions to be interpreted as the Extended
-Regular Expressions (ERE's) described by the same standard.
-(See
-.XR re_format 7
-for more information.)
-Generally speaking, BRE's are the Regular Expressions found in
-.XR ed 1
-and
-.XR grep 1 ,
-and ERE's are the Regular Expressions found in
-.XR egrep 1 .
-.pp
-The following is not intended to provide a description of Regular
-Expressions.
-The information here only describes strings and characters which
-have special meanings in the
-.EV ex vi
-version of RE's,
-or options which change the meanings of characters that normally
-have special meanings in RE's.
-.np
-An empty RE (e.g.
-.QT //
-or
-.QT ??
-is equivalent to the last RE used.
-.np
-The construct
-.QT \e<
-matches the beginning of a word.
-.np
-The construct
-.QT \e>
-matches the end of a word.
-.np
-The character
-.QT ~
-matches the replacement part of the last
-.CO substitute
-command.
-.pp
-When the
-.OP magic
-option is
-.i not
-set, the only characters with special meanings are a
-.QT ^
-character at the beginning of an RE, a
-.QT $
-character at the end of an RE, and the escaping character
-.QT \e .
-The characters
-.QT \&. ,
-.QT * ,
-.QT [
-and
-.QT ~
-are treated as ordinary characters unless preceded by a
-.QT \e ;
-when preceded by a
-.QT \e
-they regain their special meaning.
-.pp
-Replacement strings are the second part of a
-.CO substitute
-command.
-.pp
-The character
-.QT &
-(or
-.QT \e&
-if the
-.OP magic
-option is
-.i not
-set) in the replacement string stands for the text matched by the RE
-that is being replaced.
-The character
-.QT ~
-(or
-.QT \e~
-if the
-.OP magic
-option is
-.i not
-set) stands for the replacement part of the previous
-.CO substitute
-command.
-It is only valid after a
-.CO substitute
-command has been performed.
-.pp
-The string
-.QT \e# ,
-where
-.QT #
-is an integer value from 1 to 9, stands for the text matched by
-the portion of the RE enclosed in the
-.QT # 'th
-set of escaped parentheses, e.g.
-.QT \e(
-and
-.QT \e) .
-For example,
-.QT "s/abc\e(.*\e)def/\e1/"
-deletes the strings
-.QT abc
-and
-.QT def
-from the matched pattern.
-.pp
-The strings
-.QT \el ,
-.QT \eu ,
-.QT \eL
-and
-.QT \eU
-can be used to modify the case of elements in the replacement string.
-The string
-.QT \el
-causes the next character to be converted to lowercase;
-the string
-.QT \eu
-behaves similarly, but converts to uppercase
-(e.g.
-.LI s/abc/\eU&/
-replaces the string
-.LI abc
-with
-.LI ABC ).
-The strings
-.QT \eL
-causes characters up to the end of the string or the next occurrence
-of the strings
-.QT \ee
-or
-.QT \eE
-to be converted to lowercase;
-the string
-.QT \eU
-behaves similarly, but converts to uppercase.
-.pp
-If the entire replacement pattern is
-.QT % ,
-then the last replacement pattern is used again.
-.pp
-In
-.CO vi ,
-inserting a
-.LI <control-M>
-into the replacement string will cause
-the matched line to be split into two lines at that point.
-(The
-.LI <control-M>
-will be discarded.)
-.SH 1 "General Editor Description"
-.pp
-When
-.CO ex
-or
-.CO vi
-are executed,
-the text of a file is read (or a temporary file is created),
-and then all editing changes happen within the context of the
-copy of the file.
-.i "No changes affect the actual file until the file is written out" ,
-either using a write command or another command which is affected by the
-.OP autowrite
-option.
-.pp
-All files are locked (using the
-.XR flock 2
-or
-.XR fcntl 2
-interfaces) during the edit session,
-to avoid inadvertently making modifications to multiple copies of the file.
-If a lock cannot be obtained for a file because it is locked by another
-process, the edit session is read-only (as if the
-.OP readonly
-option or the
-.b \-R
-flag had been specified).
-If a lock cannot be obtained for other reasons, the edit session will
-continue, but the file status information
-(see the
-.CO <control-G>
-command) will reflect this fact.
-.pp
-Both
-.CO ex
-and
-.CO vi
-are modeful editors, i.e. they have two modes,
-.QQ command
-mode and
-.QQ "text input"
-mode.
-The former is intended to permit you to enter commands which modifies
-already existing text.
-The latter is intended to permit you to enter new text.
-When
-.CO ex
-first starts running, it is in command mode, and usually displays a prompt
-(see the
-.OP prompt
-option for more information).
-The prompt is a single colon
-.PQ :
-character.
-There are three commands that switch
-.CO ex
-into text input mode:
-.CO append ,
-.CO change
-and
-.CO insert .
-Once in input mode, entering a line containing only a single period
-.PQ \&.
-terminates text input mode and returns to command mode,
-where the prompt is redisplayed.
-.pp
-When
-.CO vi
-first starts running, it is in command mode as well.
-There are eleven commands that switch
-.CO vi
-into text input mode:
-.CO A ,
-.CO a ,
-.CO C ,
-.CO c ,
-.CO I ,
-.CO i ,
-.CO O ,
-.CO o ,
-.CO R ,
-.CO S
-and
-.CO s .
-Once in input mode, entering an
-.LI <escape>
-character terminates text input mode and returns to command mode.
-.pp
-The following words have special meanings in both the
-.CO ex
-and
-.CO vi
-command descriptions:
-.KY <interrupt>
-.IP <interrupt>
-The interrupt character is used to interrupt the current operation.
-Normally
-.LI <control-C> ,
-whatever character is set for the current terminal is used.
-.KY "<literal next>"
-.IP "<literal next>"
-The literal next character is used to escape the subsequent character
-from any special meaning.
-This character is always
-.LI <control-V> .
-If the terminal is not set up to do XON/XOFF flow control,
-then
-.LI <control-Q>
-is used to mean literal next as well.
-.KY "current pathname"
-.IP "current pathname"
-The pathname of the file currently being edited by vi.
-When the percent character
-.PQ %
-appears in a file name entered as part of an
-.CO ex
-command argument, it is replaced by the current pathname.
-(The
-.QT %
-character can be escaped by preceding it with a backslash.)
-.KY "alternate pathname"
-.IP "alternate pathname"
-The name of the last file name mentioned in an
-.CO ex
-command, or,
-the previous current pathname if the last file mentioned
-becomes the current file.
-When the hash mark character
-.PQ #
-appears in a file name entered as part of an
-.CO ex
-command argument, it is replaced by the alternate pathname.
-(The
-.QT #
-character can be escaped by preceding it with a backslash.)
-.KY buffer
-.IP buffer
-One of a number of named areas for saving copies of text.
-Commands that change or delete text can save the changed or deleted
-text into a specific buffer, for later use, if the command allows
-it (i.e. the
-.CO ex
-.CO change
-command cannot save the changed text in a named buffer).
-Buffers are named with a single character, preceded by a double quote,
-e.g.
-.LI """<character>" .
-Historic implementations of
-.EV ex vi
-limited
-.LI <character>
-to the alphanumeric characters;
-.EV nex nvi
-permits the use of any character.
-.sp
-Buffers named by uppercase characters are the same as buffers
-named by lowercase characters, e.g. the buffer named by the
-English character
-.QT A
-is the same as the buffer named by the character
-.QT a ,
-with the exception that, if the buffer contents are being changed (as
-with a text deletion or
-.CO vi
-.CO change
-command), the text is
-.i appended
-to the buffer, instead of replacing the current contents.
-.sp
-The buffers named by the numeric characters (in English,
-.QT 1
-through
-.QT 9 ),
-are special, in that if at least one line is changed or deleted in
-the file,
-(or a command changes or deletes a region that crosses a line boundary)
-a copy of the text is placed into the numeric buffer
-.QT 1 ,
-regardless of the user specifying another buffer in which to save it.
-Before this copy is done, the previous contents of buffer
-.QT 1
-are moved into buffer
-.QT 2 ,
-.QT 2
-into buffer
-.QT 3 ,
-and so on.
-The contents of buffer
-.QT 9
-are discarded.
-In
-.CO vi ,
-text may be explicitly stored into the numeric buffers.
-In this case, the buffer rotation described above occurs before the
-replacement of the buffer's contents.
-(Text cannot be explicitly stored into the numeric buffers in
-.CO ex
-because of ambiguities that this would cause in the
-.CO ex
-command syntax.)
-.sp
-When a
-.CO vi
-command synopsis shows both a
-.LI [buffer]
-and a
-.LI [count] ,
-they may be presented in any order.
-.sp
-Finally, all buffers are either
-.QQ line
-or
-.QQ character
-oriented.
-All
-.CO ex
-commands which store text into buffers are line oriented.
-Some
-.CO vi
-commands which store text into buffers are line oriented,
-and some are character oriented; the description for each applicable
-.CO vi
-command notes whether text copied into buffers using the command
-is line or character oriented.
-In addition, the
-.CO vi
-command
-.CO "display buffers"
-displays the current orientation for each buffer.
-Generally, the only importance attached to this orientation is that
-if the buffer is subsequently inserted into the text, line oriented
-buffers create new lines for each of the lines they contain, and
-character oriented buffers create new lines for any lines
-.i other
-than the first and last lines they contain.
-The first and last lines are inserted into the text at the current
-cursor position, becoming part of the current line.
-If there is more than one line in the buffer, however, the current
-line itself will be split.
-.KY "unnamed buffer"
-.IP "unnamed buffer"
-The unnamed buffer is a text storage area which is used by commands
-that take a buffer as an argument, when no buffer is specified by
-the user.
-There is no way to explicitly reference this buffer.
-.oh 'Nvi/Nex Reference (Vi Commands)''USD:13-%'
-.eh 'USD:13-%''Nvi/Nex Reference (Vi Commands)'
-.so vi.cmd.roff
-.oh 'Nvi/Nex Reference''USD:13-%'
-.eh 'USD:13-%''Nvi/Nex Reference'
-.SH 1 "Ex Addressing"
-.pp
-Addressing in
-.CO ex
-(and when
-.CO ex
-commands are executed from
-.CO vi )
-relates to the current line.
-In general, the current line is the last line affected by a command.
-The exact effect on the current line is discussed under the description
-of each command.
-When the file contains no lines, the current line is zero.
-.pp
-Addresses are constructed by one or more of the following methods:
-.np
-The address
-.QT \&.
-refers to the current line.
-.np
-The address
-.QT $
-refers to the last line of the file.
-.np
-The address
-.QT N ,
-where
-.LI N
-is a positive number, refers to the N-th line of the file.
-.np
-The address
-.QT '<character>
-or
-.QT `<character>
-refers to the line marked with the name
-.LI <character> .
-(See the
-.CO k
-or
-.CO m
-commands for more information on how to mark lines.)
-.np
-A regular expression (RE) enclosed by slashes
-.PQ /
-is an address,
-and it refers to the first line found by searching forward from the line
-.i after
-the current line toward the end of the file, and stopping at the
-first line containing a string matching the RE.
-(The trailing slash can be omitted at the end of the command line.)
-.sp
-If no RE is specified, i.e. the pattern is
-.QT // ,
-the last RE used in any command is used in the search.
-.sp
-If the
-.OP extended
-option is set, the RE is handled as an extended RE, not a basic RE.
-If the
-.OP wrapscan
-option is set, the search wraps around to the beginning of the file
-and continues up to and including the current line, so that the entire
-file is searched.
-.sp
-The form
-.QT \e/
-is accepted for historic reasons,
-and is identical to
-.QT // .
-.np
-An RE enclosed in question marks
-.PQ ?
-addresses the first line found by searching backward from the line
-.i preceding
-the current line, toward the beginning of the file and stopping at the
-first line containing a string matching the RE.
-(The trailing question mark can be omitted at the end of a command line.)
-.sp
-If no RE is specified, i.e. the pattern is
-.QT ?? ,
-the last RE used in any command is used in the search.
-.sp
-If the
-.OP extended
-option is set, the RE is handled as an extended RE, not a basic RE.
-If the
-.OP wrapscan
-option is set, the search wraps around from the beginning of the file to
-the end of the file and continues up to and including the current line,
-so that the entire file is searched.
-.sp
-The form
-.QT \e?
-is accepted for historic reasons, and is identical to
-.QT ?? .
-.np
-An address followed by a plus sign
-.PQ +
-or a minus sign
-.PQ -
-followed by a number is an offset address and refers to the address
-plus (or minus) the indicated number of lines.
-If the address is omitted, the addition or subtraction is done with
-respect to the current line.
-.np
-An address of
-.QT +
-or
-.QT \-
-followed by a number is an offset from the current line.
-For example,
-.QT \-5
-is the same as
-.QT \&.\-5 .
-.np
-An address ending with
-.QT +
-or
-.QT -
-has 1 added to or subtracted from the address, respectively.
-As a consequence of this rule and of the previous rule, the address
-.QT \-
-refers to the line preceding the current line.
-Moreover, trailing
-.QT +
-and
-.QT \-
-characters have a cumulative effect.
-For example,
-.QT ++\-++
-refers to the current line plus 3.
-.np
-A percent sign
-.PQ %
-is equivalent to the address range
-.QT 1,$ .
-.pp
-.CO Ex
-commands require zero, one, or two addresses.
-It is an error to specify an address to a command which requires zero
-addresses.
-.pp
-If the user provides more than the expected number of addresses to any
-.CO ex
-command, the first addresses specified are discarded.
-For example,
-.QT 1,2,3,5 print
-prints lines 3 through 5, because the
-.CO print
-command only takes two addresses.
-.pp
-The addresses in a range are separated from each other by a comma
-.PQ ,
-or a semicolon
-.PQ ; .
-In the latter case, the current line
-.PQ \&.
-is set to the first address, and only then is the second address calculated.
-This feature can be used to determine the starting line for forward and
-backward searches (see rules (5) and (6) above).
-The second address of any two-address sequence corresponds to a line that
-follows, in the file, the line corresponding to the first address.
-The first address must be less than or equal to the second address.
-The first address must be greater than or equal to the first line of the
-file, and the last address must be less than or equal to the last line
-of the file.
-.oh 'Nvi/Nex Reference (Ex Commands)''USD:13-%'
-.eh 'USD:13-%''Nvi/Nex Reference (Ex Commands)'
-.so ex.cmd.roff
-.oh 'Nvi/Nex Reference''USD:13-%'
-.eh 'USD:13-%''Nvi/Nex Reference'
-.so set.opt.roff
-.SH 1 "Additional Features in Nex/Nvi"
-.pp
-There are a few features in
-.EV nex nvi
-that are not found in historic versions of
-.EV ex vi .
-Some of the more interesting of those features are as follows:
-.IP "8-bit clean data, large lines, files"
-.EV Nex nvi
-will edit any format file.
-Line lengths are limited by available memory,
-and file sizes are limited by available disk space.
-The
-.CO vi
-text input mode command
-.CO <control-X>
-can insert any possible character value into the text.
-.IP "Split screens"
-The
-.CO split
-command divides the screen into multiple editing regions.
-The
-.CO <control-W>
-command rotates between the foreground screens.
-The
-.CO resize
-command can be used to grow or shrink a particular screen.
-.IP "Background and foreground screens"
-The
-.CO bg
-command backgrounds the current screen, and the
-.CO fg
-command foregrounds backgrounded screens.
-The
-.CO display
-command can be used to list the background screens.
-.\".IP "Shell screens"
-.\"The
-.\".CO ":sc[ript] [file ...]"
-.\"command runs a shell in the screen.
-.\"Editing is unchanged, with the exception that a \fC<carriage-return>\fP
-.\"enters the current line (stripped of any prompt) as input to the
-.\"shell.
-.IP "Tag stacks"
-Tags are now maintained in a stack.
-The
-.CO <control-T>
-command returns to the previous tag location.
-The
-.CO tagpop
-command returns to the most recent tag location by default, or,
-optionally to a specific tag number in the tag stack,
-or the most recent tag from a specified file.
-The
-.CO display
-command can be used to list the tags stack.
-The
-.CO tagtop
-command returns to the top of the tag stack.
-.IP "New displays"
-The
-.CO display
-command can be used to display the current buffers, the backgrounded
-screens, and the tags stack.
-.IP "Infinite undo"
-Changes made during an edit session may be rolled backward and forward.
-A
-.CO \&.
-command immediately after a
-.CO u
-command continues either forward or backward depending on whether the
-.CO u
-command was an undo or a redo.
-.IP "Usage information"
-The
-.CO exusage
-and
-.CO viusage
-commands provide usage information for all of the
-.CO ex
-and
-.CO vi
-commands by default, or, optionally, for a specific command or key.
-.IP "Extended Regular Expressions"
-The
-.CO extended
-option causes Regular Expressions to be interpreted as as Extended
-Regular Expressions, (i.e. \fIegrep\fP(1) style Regular Expressions).
-.IP "Word search"
-The
-.CO <control-A>
-command searches for the word referenced by the cursor.
-.IP "Number increment"
-The
-.CO \&#
-command increments or decrements the number referenced by the cursor.
-.IP "Previous file"
-The
-.CO previous
-command edits the previous file from the argument list.
-.IP "Left-right scrolling"
-The
-.CO leftright
-option causes
-.CO nvi
-to do left-right screen scrolling, instead of the traditional
-.CO vi
-line wrapping.
-.bp
-.SH 1 Index
-.lp
-.2c +0.5i 3
-.ta \n($luR
-.nf
-.so index.so
-.fi
-.bp 2
-.1c
-.ce 1
-\fB\s+2Table of Contents\s0\fP
-.sp
-.xp
diff --git a/usr.bin/vi/USD.doc/vitut/Makefile b/usr.bin/vi/USD.doc/vitut/Makefile
deleted file mode 100644
index bfb29bf..0000000
--- a/usr.bin/vi/USD.doc/vitut/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# @(#)Makefile 8.1 (Berkeley) 8/14/93
-
-DIR= usd/12.vi
-SRCS= vi.in vi.chars
-MACROS= -msU
-CLEANFILES+=summary.* viapwh.*
-
-paper.ps: ${SRCS} summary.ps viapwh.ps
- ${TBL} ${SRCS} | ${ROFF} > ${.TARGET}
-
-summary.ps: vi.summary
- ${TBL} vi.summary | ${ROFF} > ${.TARGET}
-
-viapwh.ps: vi.apwh.ms
- ${ROFF} vi.apwh.ms > ${.TARGET}
-
-.include <bsd.doc.mk>
diff --git a/usr.bin/vi/USD.doc/vitut/vi.apwh.ms b/usr.bin/vi/USD.doc/vitut/vi.apwh.ms
deleted file mode 100644
index d0b6261..0000000
--- a/usr.bin/vi/USD.doc/vitut/vi.apwh.ms
+++ /dev/null
@@ -1,1079 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)vi.apwh.ms 8.1 (Berkeley) 6/8/93
-.\"
-.TL
-Vi Command & Function Reference
-.AU CB 2675
-Alan P.W. Hewett
-.sp
-Revised for version 2.12 by Mark Horton
-.CB
-.NH 1
-Author's Disclaimer
-.LP
-This document does not claim to be 100% complete. There are a
-few commands listed in the original document that I was unable
-to test either because I do not speak \fBlisp\fR, because they
-required programs we don't have, or because I wasn't able to make
-them work. In these cases I left the command out. The commands
-listed in this document have been tried and are known to work.
-It is expected that prospective users of this document will read
-it once to get the flavor of everything that \fBvi\fR can do
-and then use it as a reference document. Experimentation is
-recommended. If you don't understand a command, try it and
-see what happens.
-.LP
-[Note: In revising this document, I have attempted to make it
-completely reflect version 2.12 of
-.B vi .
-It does not attempt to document the VAX version (version 3),
-but with one or two exceptions (wrapmargin, arrow keys)
-everything said about 2.12 should apply to 3.1.
-.I "Mark Horton" ]
-.NH 1
-Notation
-.LP
-\fB[option]\fR is used to denote optional parts of a command.
-Many \fBvi\fR commands have an optional count. \fB[cnt]\fR
-means that an optional number may precede the command to
-multiply or iterate the command.
-\fB{variable item}\fR is used to denote parts of the command
-which must appear, but can take a number of different values.
-\fB<character [-character]>\fR means that the character or
-one of the characters in the range described between the
-two angle brackets is to be typed.
-For example \fB<esc>\fR means
-the \fBescape\fR key is to be typed. \fB<a-z>\fR means that a
-lower case letter is to be typed. \fB^<character>\fR means that
-the character is to be typed as a \fBcontrol\fR character, that is,
-with the \fB<cntl>\fR key held down while simultaneously typing
-the specified character. In this document control characters will
-be denoted using the \fIupper case\fR character, but
-^<uppercase chr> and ^<lowercase chr> are equivalent. That is, for
-example, \fB<^D>\fR is equal to \fB<^d>\fR.
-The most common character abbreviations
-used in this list are as follows:
-.VL 8
-.IP <esc> 8
-escape, octal 033
-.IP <cr> 8
-carriage return, ^M, octal 015
-.IP <lf> 8
-linefeed ^J, octal 012
-.IP <nl> 8
-newline, ^J, octal 012 (same as linefeed)
-.IP <bs> 8
-backspace, ^H, octal 010
-.IP <tab> 8
-tab, ^I, octal 011
-.IP <bell> 8
-bell, ^G, octal 07
-.IP <ff> 8
-formfeed, ^L, octal 014
-.IP <sp> 8
-space, octal 040
-.IP <del> 8
-delete, octal 0177
-.LE
-.sp 1
-.NH 1
-Basics
-.LP
-To run \fBvi\fR the shell variable \fBTERM\fR must be defined and
-exported to your environment.
-How you do this depends on which shell you are using.
-You can tell which shell you have by the character it
-prompts you for commands with.
-The Bourne shell prompts with `$', and the C shell prompts with `%'.
-For these examples, we will suppose
-that you are using an HP 2621 terminal, whose termcap name is ``2621''.
-.NH 2
-Bourne Shell
-.LP
-To manually set your terminal type to 2621 you would type:
-.DS
-TERM=2621
-export TERM
-.DE
-.PP
-There are various ways of having this automatically or
-semi-automatically done when you log in.
-Suppose you usually dial in on a 2621.
-You want to tell this to the machine, but still have it
-work when you use a hardwired terminal.
-The recommended way, if you have the
-.B tset
-program, is to use the sequence
-.DS
-tset \-s \-d 2621 > tset$$
-\&. tset$$
-rm tset$$
-.DE
-in your .login (for csh) or the same thing using `.' instead of `source'
-in your .profile (for sh).
-The above line says that if you are dialing in you are on a 2621,
-but if you are on a hardwired terminal it figures out your terminal
-type from an on-line list.
-.NH 2
-The C Shell
-.LP
-To manually set your terminal type to 2621 you would type:
-.DS
-setenv TERM 2621
-.DE
-.PP
-There are various ways of having this automatically or
-semi-automatically done when you log in.
-Suppose you usually dial in on a 2621.
-You want to tell this to the machine, but still have it
-work when you use a hardwired terminal.
-The recommended way, if you have the
-.B tset
-program, is to use the sequence
-.DS
-tset \-s \-d 2621 > tset$$
-source tset$$
-rm tset$$
-.DE
-in your .login.*
-.FS
-* On a version 6 system
-without environments, the invocation of tset
-is simpler, just add the line ``tset \-d 2621''
-to your .login or .profile.
-.FE
-The above line says that if you are dialing in you are on a 2621,
-but if you are on a hardwired terminal it figures out your terminal
-type from an on-line list.
-.NH 1
-Normal Commands
-.LP
-\fBVi\fR is a visual editor with a window on the file. What
-you see on the screen is \fBvi\fR's current notion of
-what your file will contain,
-(at this point in the file),
-when it is written out.
-Most commands do not cause any change in the screen until the
-complete command is typed. Should you get confused while
-typing a command, you can abort the command by typing an
-<del> character. You will know you are back to command level
-when you hear a <bell>. Usually typing an <esc> will produce the
-same result. When \fBvi\fR gets an improperly formatted command
-it rings the <bell>.
-Following are the \fBvi\fR commands broken down by function.
-.NH 2
-Entry and Exit
-.LP
-To enter
-.B vi
-on a particular
-.I file ,
-type
-.DS
-\fBvi\fP \fIfile\fP
-.DE
-The file will be read in and the cursor will be placed at the beginning
-of the first line.
-The first screenfull of the file will be displayed on the terminal.
-.PP
-To get out of the editor, type
-.DS
-ZZ
-.DE
-If you are in some special mode, such as input mode
-or the middle of a multi-keystroke command, it may
-be necessary to type <esc> first.
-.NH 2
-Cursor and Page Motion
-.LP
-.VL 16
-.B NOTE:
-The arrow keys (see the next four commands)
-on certain kinds of terminals will not work with the
-PDP-11 version of vi. The control versions or the hjkl versions will
-work on any terminal. Experienced users prefer the hjkl keys because
-they are always right under their fingers. Beginners often prefer
-the arrow keys, since they do not require memorization of which hjkl
-key is which.
-The mnemonic value of hjkl is clear from looking at the keyboard of an adm3a.
-.sp
-.IP "[cnt]<bs> or [cnt]h or [cnt]\(<-" 16
-.br
-Move the cursor to the left one character. Cursor stops at the left
-margin of the page.
-If cnt is given, these commands move that many spaces.
-.IP "[cnt]^N or [cnt]j or [cnt]\(da or [cnt]<lf>" 16
-.br
-Move down one line.
-Moving off the screen scrolls the window to force a new line
-onto the screen.
-Mnemonic: \fBN\fRext
-.IP "[cnt]^P or [cnt]k or [cnt]\(ua" 16
-.br
-Move up one line.
-Moving off the top of the screen forces new text onto the screen.
-Mnemonic: \fBP\fRrevious
-.IP "[cnt]<sp> or [cnt]l or [cnt]\(->" 16
-.br
-Move to the right one character.
-Cursor will not go beyond the end of the line.
-.IP [cnt]- 16
-Move the cursor up the screen to the beginning of the next line.
-Scroll if necessary.
-.IP "[cnt]+ or [cnt]<cr>" 16
-.sp 1
-Move the cursor down the screen to the beginning of the next line.
-Scroll up if necessary.
-.IP "[cnt]$" 16
-Move the cursor to the end of the line.
-If there is a count, move to the end of the line "cnt" lines
-forward in the file.
-.IP "^" 16
-Move the cursor to the beginning of the first word on the line.
-.IP "0" 16
-Move the cursor to the left margin of the current line.
-.IP "[cnt]|" 16
-Move the cursor to the column specified by the count. The default is
-column zero.
-.IP "[cnt]w" 16
-Move the cursor to the beginning of the next word. If there
-is a count, then move forward that many words and
-position the cursor at the beginning of the word.
-Mnemonic: next-\fBw\fRord
-.IP "[cnt]W" 16
-Move the cursor to the beginning of the next word which follows
-a "white space" (<sp>,<tab>, or <nl>). Ignore other punctuation.
-.IP "[cnt]b" 16
-Move the cursor to the preceding word. Mnemonic: \fBb\fRackup-word
-.IP "[cnt]B" 16
-Move the cursor to the preceding word that is separated from the
-current word by a "white space" (<sp>,<tab>, or <nl>).
-.IP "[cnt]e" 16
-Move the cursor to the end of the current word or the end of the
-"cnt"'th word hence. Mnemonic: \fBe\fRnd-of-word
-.IP "[cnt]E" 16
-Move the cursor to the end of the current word which is delimited by
-"white space" (<sp>,<tab>, or <nl>).
-.IP "[line number]G" 16
-.br
-Move the cursor to the line specified. Of particular use are the
-sequences "1G" and "G", which move the cursor to the beginning and
-the end of the file respectively. Mnemonic: \fBG\fRo-to
-.LP
-.B NOTE:
-The next four commands (^D, ^U, ^F, ^B)
-are not true motion commands, in that they
-cannot be used as the object of commands such as delete or change.
-.IP "[cnt]^D" 16
-Move the cursor down in the file by "cnt" lines (or the last "cnt"
-if a new count isn't given. The initial default is half a page.) The
-screen is simultaneously scrolled up. Mnemonic: \fBD\fRown
-.IP "[cnt]^U" 16
-Move the cursor up in the file by "cnt" lines. The screen is simultaneously
-scrolled down. Mnemonic: \fBU\fRp
-.IP "[cnt]^F" 16
-Move the cursor to the next page. A count moves that many pages.
-Two lines of the previous page are kept on the screen for continuity if
-possible. Mnemonic: \fBF\fRorward-a-page
-.IP "[cnt]^B" 16
-Move the cursor to the previous page. Two lines of the current page
-are kept if possible. Mnemonic: \fBB\fRackup-a-page
-.IP "[cnt](" 16
-Move the cursor to the beginning of the next sentence.
-A sentence is defined as ending with a ".", "!", or "?"
-followed by two spaces or a <nl>.
-.IP "[cnt])" 16
-Move the cursor backwards to the beginning of a sentence.
-.IP "[cnt]}" 16
-Move the cursor to the beginning of the next paragraph. This command
-works best inside \fBnroff\fR documents. It understands two sets of
-\fBnroff\fR macros, \fB\-ms\fR and \fB\-mm\fR, for which the
-commands ".IP", ".LP", ".PP", ".QP", "P", as well as the nroff command ".bp"
-are considered to be paragraph delimiters.
-A blank line also delimits a paragraph.
-The \fBnroff\fR macros that it accepts as paragraph delimiters is
-adjustable. See \fBparagraphs\fR under the \fBSet Commands\fR section.
-.IP "[cnt]{" 16
-Move the cursor backwards to the beginning of a paragraph.
-.IP "]]" 16
-Move the cursor to the next "section", where a section is defined by
-two sets of \fBnroff\fR macros, \fB\-ms\fR and \fB\-mm\fR, in which
-".NH", ".SH", and ".H" delimit a section. A line beginning with a <ff><nl>
-sequence, or a line beginning with a "{" are also considered to
-be section delimiters. The last option makes it
-useful for finding the beginnings of C functions.
-The \fBnroff\fR macros that are used for section delimiters can be adjusted.
-See \fBsections\fR under the \fBSet Commands\fR section.
-.IP "[[" 16
-Move the cursor backwards to the beginning of a section.
-.IP "%" 16
-Move the cursor to the matching parenthesis
-or brace. This is very useful in C or lisp code. If the
-cursor is sitting on a \fB( ) {\fR or \fB}\fR the cursor
-is moved to the matching character at the other end of the
-section. If the cursor is not sitting on a brace or a
-parenthesis, \fBvi\fR searches forward until it finds one
-and then jumps to the match mate.
-.IP "[cnt]H" 16
-If there is no count move the cursor to the top left position on the screen.
-If there is a count, then move the cursor to the beginning of the line
-"cnt" lines from the top of the screen. Mnemonic: \fBH\fRome
-.IP "[cnt]L" 16
-If there is no count move the cursor to the beginning
-of the last line on the screen.
-If there is a count, then move the cursor to the beginning of the line
-"cnt" lines from the bottom of the screen. Mnemonic: \fBL\fRast
-.IP "M" 16
-Move the cursor to the beginning of the middle line on the screen.
-Mnemonic: \fBM\fRiddle
-.IP "m<a-z>" 16
-This command does not move the cursor, but it \fBmarks\fR the place
-in the file and the character "<a-z>" becomes the label for referring
-to this location in the file. See the next two commands. Mnemonic:
-\fBm\fRark
-.B NOTE:
-The mark command is not a motion, and cannot be used as the target
-of commands such as delete.
-.IP "\(aa<a-z>" 16
-Move the cursor to the beginning of the line that is marked with the label
-"<a-z>".
-.IP "\(ga<a-z>" 16
-Move the cursor to the exact position on the line that was marked with
-with the label "<a-z>".
-.IP "\(aa\(aa" 16
-Move the cursor back to the beginning of the line where it was before the
-last "non-relative" move. A "non-relative" move is something such as a
-search or a jump to a specific line in the file, rather than moving the
-cursor or scrolling the screen.
-.IP "\(ga\(ga" 16
-Move the cursor back to the exact spot on the line where it was located
-before the last "non-relative" move.
-.LE
-.NH 2
-Searches
-.LP
-The following commands allow you to search for items in a file.
-.VL 16
-.IP [cnt]f{chr} 16
-.sp 1
-Search forward on the line for the next or "cnt"'th occurrence of
-the character "chr". The cursor is placed \fBat\fR the character
-of interest. Mnemonic: \fBf\fRind character
-.IP [cnt]F{chr} 16
-.sp 1
-Search backwards on the line for the next or "cnt"'th occurrence of
-the character "chr". The cursor is placed \fBat\fR the character
-of interest.
-.IP [cnt]t{chr} 16
-.sp 1
-Search forward on the line for the next or "cnt"'th occurrence of
-the character "chr". The cursor is placed \fBjust preceding\fR
-the character of interest. Mnemonic: move cursor up \fBt\fRo character
-.IP [cnt]T{chr} 16
-.sp 1
-Search backwards on the line for the next or "cnt"'th occurrence of
-the character "chr". The cursor is placed \fBjust preceding\fR
-the character of interest.
-.IP "[cnt];" 16
-Repeat the last "f", "F", "t" or "T" command.
-.IP "[cnt]," 16
-Repeat the last "f", "F", "t" or "T" command, but in the opposite
-search direction. This is useful if you overshoot.
-.IP "[cnt]/[string]/<nl>" 16
-.br
-Search forward for the next occurrence of "string".
-Wrap around at the end of the file
-does occur.
-The final \fB</>\fR is not required.
-.IP "[cnt]?[string]?<nl>" 16
-.br
-Search backwards for the next occurrence of "string". If a count is
-specified, the count becomes the new window size. Wrap around at the beginning
-of the file does occur.
-The final \fB<?>\fR is not required.
-.IP n 16
-Repeat the last /[string]/ or ?[string]? search. Mnemonic: \fBn\fRext
-occurrence.
-.IP N 16
-Repeat the last /[string]/ or ?[string]? search, but in the reverse
-direction.
-.IP ":g/[string]/[editor command]<nl>" 16
-.sp 1
-Using the \fB:\fR syntax it is possible to do global searches ala the
-standard UNIX "ed" editor.
-.LE
-.NH 2
-Text Insertion
-.LP
-The following commands allow for the insertion of text. All multicharacter
-text insertions are terminated with an <esc> character.
-The last change
-can always be \fBundone\fR by typing a \fBu\fR.
-The text insert in insertion mode can contain newlines.
-.VL 16
-.IP a{text}<esc> 16
-Insert text immediately following the cursor position.
-Mnemonic: \fBa\fRppend
-.IP A{text}<esc> 16
-Insert text at the end of the current line.
-Mnemonic: \fBA\fRppend
-.IP i{text}<esc> 16
-Insert text immediately preceding the cursor position.
-Mnemonic: \fBi\fRnsert
-.IP I{text}<esc> 16
-Insert text at the beginning of the current line.
-.IP o{text}<esc> 16
-Insert a new line after the line on which the cursor appears and
-insert text there. Mnemonic: \fBo\fRpen new line
-.IP O{text}<esc> 16
-Insert a new line preceding the line on which the cursor appears
-and insert text there.
-.LE
-.NH 2
-Text Deletion
-.LP
-The following commands allow the user to delete text in various ways.
-All changes can always be \fBundone\fR by typing the \fBu\fR command.
-.VL 16
-.IP "[cnt]x" 16
-Delete the character or characters starting at the cursor position.
-.IP "[cnt]X" 16
-Delete the character or characters starting at the character preceding
-the cursor position.
-.IP "D" 16
-Deletes the remainder of the line starting at the cursor.
-Mnemonic: \fBD\fRelete the rest of line
-.IP "[cnt]d{motion}" 16
-.br
-Deletes one or more occurrences of the specified motion.
-Any motion from sections 4.1 and 4.2 can be used here.
-The d can be stuttered (e.g. [cnt]dd) to delete cnt lines.
-.LE
-.NH 2
-Text Replacement
-.LP
-The following commands allow the user to simultaneously delete and
-insert new text. All such actions can be \fBundone\fR by typing
-\fBu\fR following the command.
-.VL 16
-.IP "r<chr>" 16
-Replaces the character at the current cursor position with <chr>. This
-is a one character replacement. No <esc> is required for termination.
-Mnemonic: \fBr\fReplace character
-.IP "R{text}<esc>" 16
-Starts overlaying the characters on the screen with whatever you type.
-It does not stop until an <esc> is typed.
-.IP "[cnt]s{text}<esc>" 16
-Substitute for "cnt" characters beginning at the current cursor
-position. A "$" will appear at the position in the text where the
-"cnt"'th character appears so you will know how much you are erasing.
-Mnemonic: \fBs\fRubstitute
-.IP "[cnt]S{text}<esc>" 16
-Substitute for the entire current line (or lines). If no count is given,
-a "$" appears at the end of the current line. If a count of more than
-1 is given, all the lines to be replaced are deleted before the insertion
-begins.
-.IP "[cnt]c{motion}{text}<esc>" 16
-.br
-Change the specified "motion" by replacing it with the
-insertion text. A "$" will appear at the end of the last item
-that is being deleted unless the deletion involves whole lines.
-Motion's can be any motion from sections 4.1 or 4.2.
-Stuttering the c (e.g. [cnt]cc) changes cnt lines.
-.LE
-.NH 2
-Moving Text
-.LP
-\fBVi\fR provides a number of ways of moving chunks of text around.
-There are nine buffers into which each piece of text which is deleted
-or "yanked" is put in addition to the "undo" buffer.
-The most recent deletion or yank is in the "undo" buffer and also
-usually in buffer
-1, the next most recent in buffer 2, and so forth. Each new deletion
-pushes down all the older deletions. Deletions older than 9
-disappear. There is also
-a set of named registers, a-z, into which text can optionally
-be placed. If any delete or replacement type command is preceded
-by \fB"<a-z>\fR, that named buffer will contain the text deleted
-after the command is executed. For example, \fB"a3dd\fR will delete
-three lines starting at the current line and put them in buffer \fB"a\fR.*
-.FS
-* Referring to an upper case letter as a buffer name (A-Z) is the
-same as referring to the lower case letter, except that text placed
-in such a buffer is appended to it instead of replacing it.
-.FE
-There are two more basic commands and
-some variations useful in getting and putting text into a file.
-.VL 16
-.IP ["<a-z>][cnt]y{motion} 16
-.sp 1
-Yank the specified item or "cnt" items and put in the "undo" buffer or
-the specified buffer. The variety of "items" that can be yanked
-is the same as those that can be deleted with the "d" command or
-changed with the "c" command. In the same way that "dd" means
-delete the current line and "cc" means replace the current line,
-"yy" means yank the current line.
-.IP ["<a-z>][cnt]Y 16
-Yank the current line or the "cnt" lines starting from the current
-line. If no buffer is specified, they will go into the "undo" buffer,
-like any delete would. It is equivalent to "yy".
-Mnemonic: \fBY\fRank
-.IP ["<a-z>]p 16
-Put "undo" buffer or the specified buffer down \fBafter\fR the cursor.
-If whole lines were yanked or deleted into the buffer, then they will be
-put down on the line following the line the cursor is on. If
-something else was deleted, like a word or sentence, then it will
-be inserted immediately following the cursor.
-Mnemonic: \fBp\fRut buffer
-.IP
-It should be noted that text in the named buffers remains there when you
-start editing a new file with the \fB:e file<esc>\fR command. Since
-this is so, it is possible to copy or delete text from one file and
-carry it over to another file in the buffers.
-However, the undo buffer and the ability to undo are lost when
-changing files.
-.IP ["<a-z>]P 16
-Put "undo" buffer or the specified buffer down \fBbefore\fR the cursor.
-If whole lines where yanked or deleted into the buffer, then they will be
-put down on the line preceding the line the cursor is on. If
-something else was deleted, like a word or sentence, then it will
-be inserted immediately preceding the cursor.
-.IP [cnt]>{motion} 16
-The shift operator will right shift all the text from the line on which
-the cursor is located to the line where the \fBmotion\fR is located.
-The text is shifted by one \fBshiftwidth\fR. (See section 6.)
-\fB>>\fR means right shift the current line or lines.
-.IP [cnt]<{motion} 16
-The shift operator will left shift all the text from the line on which
-the cursor is located to the line where the \fBitem\fR is located.
-The text is shifted by one \fBshiftwidth\fR. (See section 6.)
-\fB<<\fR means left shift the current line or lines.
-Once the line has reached the left margin it is not further affected.
-.IP [cnt]={motion} 16
-Prettyprints the indicated area according to
-.B lisp
-conventions.
-The area should be a lisp s-expression.
-.LE
-.NH 2
-Miscellaneous Commands
-.LP
-\fBVi\fR has a number of miscellaneous commands that are very
-useful. They are:
-.VL 16
-.IP ZZ 16
-This is the normal way to exit from vi.
-If any changes have been made, the file is written out.
-Then you are returned to the shell.
-.IP ^L 16
-Redraw the current screen. This is useful if someone "write"s you
-while you are in "vi" or if for any reason garbage gets onto the
-screen.
-.IP ^R 16
-On dumb terminals, those not having the "delete line" function
-(the vt100 is such a terminal), \fBvi\fR saves redrawing the
-screen when you delete a line by just marking the line with an
-"@" at the beginning and blanking the line. If you want to
-actually get rid of the lines marked with "@" and see what the
-page looks like, typing a ^R will do this.
-.IP \s+4.\s0 16
-"Dot" is a particularly useful command. It repeats the last
-text modifying command. Therefore you can type a command once and
-then to another place and repeat it by just typing ".".
-.IP u 16
-Perhaps the most important command in the editor,
-u undoes the last command that changed the buffer.
-Mnemonic: \fBu\fRndo
-.IP U 16
-Undo all the text modifying commands performed on the current line
-since the last time you moved onto it.
-.IP [cnt]J 16
-Join the current line and the following line. The <nl> is deleted
-and the two lines joined, usually with a space between the
-end of the first line and the beginning of what was the second
-line. If the first line ended with a "period", then two spaces
-are inserted.
-A count joins the next cnt lines.
-Mnemonic: \fBJ\fRoin lines
-.IP Q 16
-Switch to \fBex\fR editing mode.
-In this mode \fBvi\fR will behave very much like \fBed\fR.
-The editor in this mode will operate on single lines normally and
-will not attempt to keep the "window" up to date.
-Once in this mode it is also possible to switch to the \fBopen\fR
-mode of editing. By entering the command \fB[line number]open<nl>\fR
-you enter this mode. It is similar to the normal visual mode
-except the window is only \fBone\fR line long.
-Mnemonic: \fBQ\fRuit visual mode
-.IP ^] 16
-An abbreviation for a tag command.
-The cursor should be positioned at the beginning of a word.
-That word is taken as a tag name, and the tag with that
-name is found as if it had been typed in a :tag command.
-.IP [cnt]!{motion}{UNIX\ cmd}<nl> 16
-.br
-Any UNIX filter
-(e.g. command that reads the standard input and outputs something
-to the standard output) can be sent a section of the current file and
-have the output of the command replace the original text. Useful
-examples are programs like \fBcb\fR, \fBsort\fR, and
-\fBnroff\fR. For instance, using \fBsort\fR it would be possible to
-sort a section of the current file into a new list.
-Using \fB!!\fR means take a line or lines starting at the line the
-cursor is currently on and pass them to the UNIX command.
-.B NOTE:
-To just escape to the shell for one command,
-use :!{cmd}<nl>, see section 5.
-.IP z{cnt}<nl> 16
-This resets the current window size to "cnt" lines and redraws the screen.
-.LE
-.NH 2
-Special Insert Characters
-.LP
-There are some characters that have special meanings during
-insert modes. They are:
-.VL 16
-.IP ^V 16
-During inserts, typing a ^V allows you to quote control characters
-into the file. Any character typed after the ^V will be inserted
-into the file.
-.IP [^]^D\ or\ [0]^D 16
-<^D> without any argument backs up one \fBshiftwidth\fR. This is necessary
-to remove indentation that was inserted by the \fBautoindent\fR feature.
-^<^D> temporarily removes all the autoindentation, thus placing the cursor
-at the left margin. On the next line, the previous indent level will be
-restored. This is useful for putting "labels" at the left margin.
-0<^D> says remove all autoindents and stay that way. Thus the cursor
-moves to the left margin and stays there on successive lines until
-<tab>'s are typed. As with the <tab>, the <^D> is only effective before
-any other "non-autoindent" controlling characters are typed.
-Mnemonic: \fBD\fRelete a shiftwidth
-.IP ^W 16
-If the cursor is sitting on a word, <^W> moves the cursor back to the beginning
-of the word, thus erasing the word from the insert.
-Mnemonic: erase \fBW\fRord
-.IP <bs> 16
-The backspace always serves as an erase during insert modes in addition
-to your normal "erase" character. To insert a <bs> into your file, use
-the <^V> to quote it.
-.LE
-.NH 1
-\fB:\fR Commands
-.LP
-Typing a ":" during command mode causes \fBvi\fR to put the cursor at
-the bottom on the screen in preparation for a command. In the
-":" mode, \fBvi\fR can be given most \fBed\fR commands. It is
-also from this mode that you exit from \fBvi\fR or switch to different
-files. All commands of this variety are terminated by a <nl>, <cr>,
-or <esc>.
-.VL 16
-.IP ":w[!] [file]" 16
-Causes \fBvi\fR to write out the current text to the disk. It is
-written to the file you are editing unless "file" is supplied. If
-"file" is supplied, the write is directed to that file instead. If
-that file already exists, \fBvi\fR will not perform the write unless
-the "!" is supplied indicating you
-.I really
-want to destroy the older copy of the file.
-.IP :q[!] 16
-Causes \fBvi\fR to exit. If you have modified the file you are
-looking at currently and haven't written it out, \fBvi\fR will
-refuse to exit unless the "!" is supplied.
-.IP ":e[!] [+[cmd]] [file]" 16
-.sp 1
-Start editing a new file called "file" or start editing the current
-file over again. The command ":e!" says "ignore the changes I've made
-to this file and start over from the beginning". It is useful if
-you really mess up the file. The optional "+" says instead of starting
-at the beginning, start at the "end", or,
-if "cmd" is supplied, execute "cmd" first.
-Useful cases of this are where cmd is "n" (any integer) which starts
-at line number n,
-and "/text", which searches for "text" and starts at the line where
-it is found.
-.IP "^^" 16
-Switch back to the place you were before your last tag command.
-If your last tag command stayed within the file, ^^ returns to that tag.
-If you have no recent tag command, it will return to the
-same place in the previous file that it was showing when you switched
-to the current file.
-.IP ":n[!]" 16
-Start editing the next file in the argument list. Since \fBvi\fR
-can be called with multiple file names, the ":n" command tells it to
-stop work on the current file and switch to the next file. If the
-current file was modifies, it has to be written out before the ":n"
-will work or else the "!" must be supplied, which says discard the
-changes I made to the current file.
-.IP ":n[!] file [file file ...]" 16
-.sp
-Replace the current argument list with a new list of files and start
-editing the first file in this new list.
-.IP ":r file" 16
-Read in a copy of "file" on the line after the cursor.
-.IP ":r !cmd" 16
-Execute the "cmd" and take its output and put it into the file after
-the current line.
-.IP ":!cmd" 16
-Execute any UNIX shell command.
-.IP ":ta[!] tag" 16
-.B Vi
-looks in the file named
-.B tags
-in the current directory.
-.B Tags
-is a file of lines in the format:
-.sp 1
-.ti +8
-tag filename \fBvi\fR-search-command
-.sp 1
-If \fBvi\fR finds the tag you specified in the \fB:ta\fR command,
-it stops editing the current file if necessary and if the current file is
-up to date on the disk and switches to the file specified and uses the
-search pattern specified to find the "tagged" item of interest. This
-is particularly useful when editing multi-file C programs such as the
-operating system. There is a program called \fBctags\fR which will
-generate an appropriate \fBtags\fR file for C and f77
-programs so that by saying
-\fB:ta function<nl>\fR you will be switched to that function.
-It could also be useful when editing multi-file documents, though the
-\fBtags\fR file would have to be generated manually.
-.LE
-.NH 1
-Special Arrangements for Startup
-.PP
-\fBVi\fR takes the value of \fB$TERM\fR and looks up the characteristics
-of that terminal in the file \fB/etc/termcap\fR.
-If you don't know \fBvi\fR's name for the terminal you are working
-on, look in \fB/etc/termcap\fR.
-.PP
-When \fBvi\fR starts, it attempts to read the variable EXINIT
-from your environment.*
-If that exists, it takes the values in it as the default values
-for certain of its internal constants. See the section on "Set Values"
-for further details.
-If EXINIT doesn't exist you will get all the normal defaults.
-.FS
-* On version 6 systems
-Instead of EXINIT, put the startup commands in the file .exrc
-in your home directory.
-.FE
-.PP
-Should you inadvertently hang up the phone while inside
-.B vi ,
-or should the computer crash,
-all may not be lost.
-Upon returning to the system, type:
-.DS
-vi \-r file
-.DE
-This will normally recover the file. If there is more than one
-temporary file for a specific file name, \fBvi\fR recovers the
-newest one. You can get an older version by recovering the
-file more than once.
-The command "vi -r" without a file name gives you the list of files
-that were saved in the last system crash
-(but
-.I not
-the file just saved when the phone was hung up).
-.NH 1
-Set Commands
-.LP
-\fBVi\fR has a number of internal variables and switches which can be
-set to achieve special affects.
-These options come in three forms, those that are switches, which toggle
-from off to on and back, those that require a numeric value, and those
-that require an alphanumeric string value.
-The toggle options are set by a command of the form:
-.DS
-:set option<nl>
-.DE
-and turned off with the command:
-.DS
-:set nooption<nl>
-.DE
-Commands requiring a value are set with a command of the form:
-.DS
-:set option=value<nl>
-.DE
-To display the value of a specific option type:
-.DS
-:set option?<nl>
-.DE
-To display only those that you have changed type:
-.DS
-:set<nl>
-.DE
-and to display the long table of all the settable parameters and
-their current values type:
-.DS
-:set all<nl>
-.DE
-.PP
-Most of the options have a long form and an abbreviation. Both are
-listed in the following table as well as the normal default value.
-.PP
-To arrange to have values other than the default used every time you
-enter
-.B vi ,
-place the appropriate
-.B set
-command in EXINIT in your environment, e.g.
-.DS
-EXINIT='set ai aw terse sh=/bin/csh'
-export EXINIT
-.DE
-or
-.DS
-setenv EXINIT 'set ai aw terse sh=/bin/csh'
-.DE
-for
-.B sh
-and
-.B csh ,
-respectively.
-These are usually placed in your .profile or .login.
-If you are running a system without environments (such as version 6)
-you can place the set command in the file .exrc in your home
-directory.
-.VL 16
-.IP autoindent\ ai 16
-Default: noai Type: toggle
-.br
-When in autoindent mode, vi helps you indent code by starting each
-line in the same column as the preceding line.
-Tabbing to the right with <tab> or <^T> will move this boundary to
-the right, and it can be moved to the left with <^D>.
-.IP autoprint\ ap 16
-Default: ap Type: toggle
-.br
-Causes the current line to be printed after each ex text modifying command.
-This is not of much interest in the normal \fBvi\fR visual mode.
-.IP autowrite\ aw 16
-Default: noaw type: toggle
-.br
-Autowrite causes an automatic write to be done if there are unsaved
-changes before certain commands which change files or otherwise
-interact with the outside world.
-These commands are :!, :tag, :next, :rewind, ^^, and ^].
-.IP beautify\ bf 16
-Default: nobf Type: toggle
-.br
-Causes all control characters except <tab>, <nl>, and <ff> to be discarded.
-.IP directory\ dir 16
-Default: dir=/tmp Type: string
-.br
-This is the directory in which \fBvi\fR puts its temporary file.
-.IP errorbells\ eb 16
-Default: noeb Type: toggle
-.br
-Error messages are preceded by a <bell>.
-.IP hardtabs\ ht 16
-Default: hardtabs=8 Type: numeric
-.br
-This option contains the value of hardware tabs in your terminal, or
-of software tabs expanded by the Unix system.
-.IP ignorecase\ ic 16
-Default: noic Type: toggle
-.br
-All upper case characters are mapped to lower case in regular expression
-matching.
-.IP lisp 16
-Default: nolisp Type: toggle
-.br
-Autoindent for \fBlisp\fR code. The commands \fB( ) [[\fR and \fB]]\fR
-are modified appropriately to affect s-expressions and functions.
-.IP list 16
-Default: nolist Type: toggle
-.br
-All printed lines have the <tab> and <nl> characters displayed visually.
-.IP magic 16
-Default: magic Type: toggle
-.br
-Enable the metacharacters for matching. These include \fB. * < > [string]
-[^string]\fR and \fB[<chr>-<chr>]\fR.
-.IP number\ nu 16
-Default: nonu Type: toggle
-.br
-Each line is displayed with its line number.
-.IP open 16
-Default: open Type: toggle
-.br
-When set, prevents entering open or visual modes from ex or edit.
-Not of interest from vi.
-.IP optimize\ opt 16
-Default: opt Type: toggle
-.br
-Basically of use only when using the \fBex\fR capabilities. This
-option prevents automatic <cr>s from taking place,
-and speeds up output of indented lines,
-at the expense of losing typeahead on some versions of UNIX.
-.IP paragraphs\ para 16
-Default: para=IPLPPPQPP\ bp Type: string
-.br
-Each pair of characters in the string indicate \fBnroff\fR macros
-which are to be treated as the beginning of a paragraph for the
-\fB{\fR and \fB}\fR commands. The default string is for the \fB-ms\fR
-and \fB-mm\fR macros.
-To indicate one letter \fBnroff\fR macros, such as \fB.P\fR or \fB.H\fR,
-quote a space in for the second character position. For example:
-.sp 1
-.ti +8
-:set paragraphs=P\e bp<nl>
-.sp 1
-would cause \fBvi\fR to consider \fB.P\fR and \fB.bp\fR as paragraph
-delimiters.
-.IP prompt 16
-Default: prompt Type: toggle
-.br
-In
-.B ex
-command mode the prompt character \fB:\fR will be printed when
-\fBex\fR is waiting for a command. This is not of interest from vi.
-.IP redraw 16
-Default: noredraw Type: toggle
-.br
-On dumb terminals, force the screen to always be up to date,
-by sending great amounts of output. Useful only at high speeds.
-.IP report 16
-Default: report=5 Type: numeric
-.br
-This sets the threshold for the number of lines modified. When
-more than this number of lines are modified, removed, or yanked,
-\fBvi\fR will report the number of lines changed at the bottom of
-the screen.
-.IP scroll 16
-Default: scroll={1/2 window} Type: numeric
-.br
-This is the number of lines that the screen scrolls up or down when
-using the <^U> and <^D> commands.
-.IP sections 16
-Default: sections=SHNHH HU Type: string
-.br
-Each two character pair of this string specify \fBnroff\fR macro names
-which are to be treated as the beginning of a section by the
-\fB]]\fR and \fB[[\fR commands. The default string is for the \fB-ms\fR
-and \fB-mm\fR macros.
-To enter one letter \fBnroff\fR macros, use a quoted space as the
-second character.
-See \fBparagraphs\fR for a fuller explanation.
-.IP shell\ sh 16
-Default: sh=from environment SHELL or /bin/sh Type: string
-.br
-This is the name of the \fBsh\fR to be used for "escaped" commands.
-.IP shiftwidth\ sw 16
-Default: sw=8 Type: numeric
-.br
-This is the number of spaces that a <^T> or <^D> will move over for
-indenting, and the amount < and > shift by.
-.IP showmatch\ sm 16
-Default: nosm Type: toggle
-.br
-When a \fB)\fR or \fB}\fR is typed, show the matching \fB(\fR or \fB{\fR
-by moving the cursor to it for one second if it is on the current screen.
-.IP slowopen\ slow 16
-Default: terminal dependent Type: toggle
-.br
-On terminals that are slow and unintelligent, this option prevents the
-updating of the screen some of the time to improve speed.
-.IP tabstop\ ts 16
-Default: ts=8 Type: numeric
-.br
-<tab>s are expanded to boundaries that are multiples of this value.
-.IP taglength\ tl 16
-Default: tl=0 Type: numeric
-.br
-If nonzero, tag names are only significant to this many characters.
-.IP term 16
-Default: (from environment \fBTERM\fP, else dumb) Type: string
-.br
-This is the terminal and controls the visual displays. It cannot be
-changed when in "visual" mode,
-you have to Q to command mode, type a
-set term command, and do ``vi.'' to get back into visual.
-Or exit vi, fix $TERM, and reenter.
-The definitions that drive a particular
-terminal type are found in the file \fB/etc/termcap\fR.
-.IP terse 16
-Default: terse Type: toggle
-.br
-When set, the error diagnostics are short.
-.IP warn 16
-Default: warn Type: toggle
-.br
-The user is warned if she/he tries to escape to
-the shell without writing out the current changes.
-.IP window 16
-Default: window={8 at 600 baud or less, 16 at 1200 baud, and screen
-size \- 1 at 2400 baud or more} Type: numeric
-.br
-This is the number of lines in the window whenever \fBvi\fR must redraw
-an entire screen. It is useful to make this size smaller if you are
-on a slow line.
-.IP w300,\ w1200,\ w9600
-.br
-These set window, but only within the corresponding speed ranges.
-They are useful in an EXINIT to fine tune window sizes.
-For example,
-.DS
-set w300=4 w1200=12
-.DE
-causes a 4 lines window at speed up to 600 baud, a 12 line window at 1200
-baud, and a full screen (the default) at over 1200 baud.
-.IP wrapscan\ ws 16
-Default: ws Type: toggle
-.br
-Searches will wrap around the end of the file when is option is set. When
-it is off, the search will terminate when it reaches the end or the
-beginning of the file.
-.IP wrapmargin\ wm 16
-Default: wm=0 Type: numeric
-.br
-\fBVi\fR will automatically insert a <nl> when it finds a natural
-break point (usually a <sp> between words) that occurs within
-"wm" spaces of the right margin.
-Therefore with "wm=0" the option is off. Setting it to 10 would
-mean that any time you are within 10 spaces of the right margin
-\fBvi\fR would be looking for a <sp> or <tab> which it could
-replace with a <nl>. This is convenient for people who forget
-to look at the screen while they type.
-(In version 3, wrapmargin behaves more like nroff, in that the
-boundary specified by the distance from the right edge of the screen
-is taken as the rightmost edge of the area where a break is allowed,
-instead of the leftmost edge.)
-.IP writeany\ wa 16
-Default: nowa Type: toggle
-.br
-\fBVi\fR normally makes a number of checks before it writes out a file.
-This prevents the user from inadvertently destroying a file. When the
-"writeany" option is enabled, \fBvi\fR no longer makes these checks.
-.LE
diff --git a/usr.bin/vi/USD.doc/vitut/vi.chars b/usr.bin/vi/USD.doc/vitut/vi.chars
deleted file mode 100644
index 147c4ff..0000000
--- a/usr.bin/vi/USD.doc/vitut/vi.chars
+++ /dev/null
@@ -1,644 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)vi.chars 8.1 (Berkeley) 6/8/93
-.\"
-.bd S 3
-..pn 21
-.de iP
-.IP "\fB\\$1\fR" \\$2
-..
-.SH
-Appendix: character functions
-.PP
-This appendix gives the uses the editor makes of each character. The
-characters are presented in their order in the \s-2ASCII\s0 character
-set: Control characters come first, then most special characters, then
-the digits, upper and then lower case characters.
-.PP
-For each character we tell a meaning it has as a command and any meaning it
-has during an insert.
-If it has only meaning as a command, then only this is discussed.
-Section numbers in parentheses indicate where the character is discussed;
-a `f' after the section number means that the character is mentioned
-in a footnote.
-.iP "^@" 15
-Not a command character.
-If typed as the first character of an insertion it is replaced with the
-last text inserted, and the insert terminates. Only 128 characters are
-saved from the last insert; if more characters were inserted the mechanism
-is not available.
-A \fB^@\fR cannot be part of the file due to the editor implementation
-(7.5f).
-.iP "^A" 15
-Unused.
-.iP "^B" 15
-Backward window.
-A count specifies repetition.
-Two lines of continuity are kept if possible (2.1, 6.1, 7.2).
-.iP "^C" 15
-Unused.
-.iP "^D" 15
-As a command, scrolls down a half-window of text.
-A count gives the number of (logical) lines to scroll, and is remembered
-for future \fB^D\fR and \fB^U\fR commands (2.1, 7.2).
-During an insert, backtabs over \fIautoindent\fR white space at the beginning
-of a line (6.6, 7.5); this white space cannot be backspaced over.
-.iP "^E" 15
-Exposes one more line below the current screen in the file, leaving
-the cursor where it is if possible.
-(Version 3 only.)
-.iP "^F" 15
-Forward window. A count specifies repetition.
-Two lines of continuity are kept if possible (2.1, 6.1, 7.2).
-.iP "^G" 15
-Equivalent to \fB:f\fR\s-2CR\s0, printing the current file, whether
-it has been modified, the current line number and the number of lines
-in the file, and the percentage of the way through the file that you
-are.
-.iP "^H (\fR\s-2BS\s0\fP)" 15
-Same as
-.B "left arrow" .
-(See
-.B h ).
-During an insert, eliminates the last input character, backing over it
-but not erasing it; it remains so you can see what you typed if you
-wish to type something only slightly different (3.1, 7.5).
-.iP "^I\ (\fR\s-2TAB\s0\fP)" 15
-Not a command character.
-When inserted it prints as some
-number of spaces.
-When the cursor is at a tab character it rests at the last of the spaces
-which represent the tab.
-The spacing of tabstops is controlled by the \fItabstop\fR option (4.1, 6.6).
-.iP "^J\ (\fR\s-2LF\s0\fP)" 15
-Same as
-.B "down arrow"
-(see
-.B j ).
-.iP "^K" 15
-Unused.
-.iP "^L" 15
-The \s-2ASCII\s0 formfeed character, this causes the screen to be cleared
-and redrawn. This is useful after a transmission error, if characters
-typed by a program other than the editor scramble the screen,
-or after output is stopped by an interrupt (5.4, 7.2f).
-.iP "^M\ (\fR\s-2CR\s0\fP)" 15
-A carriage return advances to the next line, at the first non-white position
-in the line. Given a count, it advances that many lines (2.3).
-During an insert, a \s-2CR\s0 causes the insert to continue onto
-another line (3.1).
-.iP "^N" 15
-Same as
-.B "down arrow"
-(see
-.B j ).
-.iP "^O" 15
-Unused.
-.iP "^P" 15
-Same as
-.B "up arrow"
-(see
-.B k ).
-.iP "^Q" 15
-Not a command character.
-In input mode,
-.B ^Q
-quotes the next character, the same as
-.B ^V ,
-except that some teletype drivers will eat the
-.B ^Q
-so that the editor never sees it.
-.iP "^R" 15
-Redraws the current screen, eliminating logical lines not corresponding
-to physical lines (lines with only a single @ character on them).
-On hardcopy terminals in \fIopen\fR mode, retypes the current line
-(5.4, 7.2, 7.8).
-.iP "^S" 15
-Unused. Some teletype drivers use
-.B ^S
-to suspend output until
-.B ^Q is pressed.
-.iP "^T" 15
-Not a command character.
-During an insert, with \fIautoindent\fR set and at the beginning of the
-line, inserts \fIshiftwidth\fR white space.
-.iP "^U" 15
-Scrolls the screen up, inverting \fB^D\fR which scrolls down. Counts work as
-they do for \fB^D\fR, and the previous scroll amount is common to both.
-On a dumb terminal, \fB^U\fR will often necessitate clearing and redrawing
-the screen further back in the file (2.1, 7.2).
-.iP "^V" 15
-Not a command character.
-In input mode, quotes the next character so that it is possible
-to insert non-printing and special characters into the file (4.2, 7.5).
-.iP "^W" 15
-Not a command character.
-During an insert, backs up as \fBb\fR would in command mode; the deleted
-characters remain on the display (see \fB^H\fR) (7.5).
-.iP "^X" 15
-Unused.
-.iP "^Y" 15
-Exposes one more line above the current screen, leaving the cursor where
-it is if possible. (No mnemonic value for this key; however, it is next
-to \fB^U\fR which scrolls up a bunch.)
-(Version 3 only.)
-.iP "^Z" 15
-If supported by the Unix system,
-stops the editor, exiting to the top level shell.
-Same as \fB:stop\fP\s-2CR\s0.
-Otherwise, unused.
-.iP "^[\ (\fR\s-2ESC\s0\fP)" 15
-Cancels a partially formed command, such as a \fBz\fR when no following
-character has yet been given; terminates inputs on the last line (read
-by commands such as \fB: /\fR and \fB?\fR); ends insertions of new text
-into the buffer.
-If an \s-2ESC\s0 is given when quiescent in command state, the editor
-rings the bell or flashes the screen. You can thus hit \s-2ESC\s0 if
-you don't know what is happening till the editor rings the bell.
-If you don't know if you are in insert mode you can type \s-2ESC\s0\fBa\fR,
-and then material to be input; the material will be inserted correctly
-whether or not you were in insert mode when you started (1.5, 3.1, 7.5).
-.iP "^\e" 15
-Unused.
-.iP "^]" 15
-Searches for the word which is after the cursor as a tag. Equivalent
-to typing \fB:ta\fR, this word, and then a \s-2CR\s0.
-Mnemonically, this command is ``go right to'' (7.3).
-.iP "^\(ua" 15
-Equivalent to \fB:e #\fR\s-2CR\s0, returning to the previous position
-in the last edited file, or editing a file which you specified if you
-got a `No write since last change diagnostic' and do not want to have
-to type the file name again (7.3).
-(You have to do a \fB:w\fR before \fB^\(ua\fR
-will work in this case. If you do not wish to write the file you should
-do \fB:e!\ #\fR\s-2CR\s0 instead.)
-.iP "^_" 15
-Unused.
-Reserved as the command character for the
-Tektronix 4025 and 4027 terminal.
-.iP "\fR\s-2SPACE\s0\fP" 15
-Same as
-.B "right arrow"
-(see
-.B l ).
-.iP "!" 15
-An operator, which processes lines from the buffer with reformatting commands.
-Follow \fB!\fR with the object to be processed, and then the command name
-terminated by \s-2CR\s0. Doubling \fB!\fR and preceding it by a count
-causes count lines to be filtered; otherwise the count
-is passed on to the object after the \fB!\fR. Thus \fB2!}\fR\fIfmt\fR\s-2CR\s0
-reformats the next two paragraphs by running them through the program
-\fIfmt\fR. If you are working on \s-2LISP\s0,
-the command \fB!%\fR\fIgrind\fR\s-2CR\s0,*
-.FS
-*Both
-.I fmt
-and
-.I grind
-are Berkeley programs and may not be present at all installations.
-.FE
-given at the beginning of a
-function, will run the text of the function through the \s-2LISP\s0 grinder
-(6.7, 7.3).
-To read a file or the output of a command into the buffer use \fB:r\fR (7.3).
-To simply execute a command use \fB:!\fR (7.3).
-.tr "
-.iP  15
-Precedes a named buffer specification. There are named buffers \fB1\-9\fR
-used for saving deleted text and named buffers \fBa\-z\fR into which you can
-place text (4.3, 6.3)
-.tr 
-.iP "#" 15
-The macro character which, when followed by a number, will substitute
-for a function key on terminals without function keys (6.9).
-In input mode,
-if this is your erase character, it will delete the last character
-you typed in input mode, and must be preceded with a \fB\e\fR to insert
-it, since it normally backs over the last input character you gave.
-.iP "$" 15
-Moves to the end of the current line. If you \fB:se list\fR\s-2CR\s0,
-then the end of each line will be shown by printing a \fB$\fR after the
-end of the displayed text in the line. Given a count, advances to the
-count'th following end of line; thus \fB2$\fR advances to the end of the
-following line.
-.iP "%" 15
-Moves to the parenthesis or brace \fB{ }\fR which balances the parenthesis
-or brace at the current cursor position.
-.iP "&" 15
-A synonym for \fB:&\fR\s-2CR\s0, by analogy with the
-.I ex
-.B &
-command.
-.iP "\(aa" 15
-When followed by a \fB\(aa\fR returns to the previous context at the
-beginning of a line. The previous context is set whenever the current
-line is moved in a non-relative way.
-When followed by a letter \fBa\fR\-\fBz\fR, returns to the line which
-was marked with this letter with a \fBm\fR command, at the first non-white
-character in the line. (2.2, 5.3).
-When used with an operator such as \fBd\fR, the operation takes place
-over complete lines; if you use \fB\(ga\fR, the operation takes place
-from the exact marked place to the current cursor position within the
-line.
-.iP "(" 15
-Retreats to the beginning of a
-sentence, or to the beginning of a \s-2LISP\s0 s-expression
-if the \fIlisp\fR option is set.
-A sentence ends at a \fB. !\fR or \fB?\fR which is followed by either
-the end of a line or by two spaces. Any number of closing \fB) ] "\fR
-and \fB\(aa\fR characters may appear after the \fB. !\fR or \fB?\fR,
-and before the spaces or end of line. Sentences also begin
-at paragraph and section boundaries
-(see \fB{\fR and \fB[[\fR below).
-A count advances that many sentences (4.2, 6.8).
-.iP ")" 15
-Advances to the beginning of a sentence.
-A count repeats the effect.
-See \fB(\fR above for the definition of a sentence (4.2, 6.8).
-.iP "*" 15
-Unused.
-.iP "+" 15
-Same as \s-2CR\s0 when used as a command.
-.iP "," 15
-Reverse of the last \fBf F t\fR or \fBT\fR command, looking the other way
-in the current line. Especially useful after hitting too many \fB;\fR
-characters. A count repeats the search.
-.iP "\-" 15
-Retreats to the previous line at the first non-white character.
-This is the inverse of \fB+\fR and \s-2RETURN\s0.
-If the line moved to is not on the screen, the screen is scrolled, or
-cleared and redrawn if this is not possible.
-If a large amount of scrolling would be required the screen is also cleared
-and redrawn, with the current line at the center (2.3).
-.iP "\&." 15
-Repeats the last command which changed the buffer. Especially useful
-when deleting words or lines; you can delete some words/lines and then
-hit \fB.\fR to delete more and more words/lines.
-Given a count, it passes it on to the command being repeated. Thus after
-a \fB2dw\fR, \fB3.\fR deletes three words (3.3, 6.3, 7.2, 7.4).
-.iP "/" 15
-Reads a string from the last line on the screen, and scans forward for
-the next occurrence of this string. The normal input editing sequences may
-be used during the input on the bottom line; an returns to command state
-without ever searching.
-The search begins when you hit \s-2CR\s0 to terminate the pattern;
-the cursor moves to the beginning of the last line to indicate that the search
-is in progress; the search may then
-be terminated with a \s-2DEL\s0 or \s-2RUB\s0, or by backspacing when
-at the beginning of the bottom line, returning the cursor to
-its initial position.
-Searches normally wrap end-around to find a string
-anywhere in the buffer.
-.IP
-When used with an operator the enclosed region is normally affected.
-By mentioning an
-offset from the line matched by the pattern you can force whole lines
-to be affected. To do this give a pattern with a closing
-a closing \fB/\fR and then an offset \fB+\fR\fIn\fR or \fB\-\fR\fIn\fR.
-.IP
-To include the character \fB/\fR in the search string, you must escape
-it with a preceding \fB\e\fR.
-A \fB\(ua\fR at the beginning of the pattern forces the match to occur
-at the beginning of a line only; this speeds the search. A \fB$\fR at
-the end of the pattern forces the match to occur at the end of a line
-only.
-More extended pattern matching is available, see section 7.4;
-unless you set \fBnomagic\fR in your \fI\&.exrc\fR file you will have
-to preceed the characters \fB. [ *\fR and \fB~\fR in the search pattern
-with a \fB\e\fR to get them to work as you would naively expect (1.5, 2,2,
-6.1, 7.2, 7.4).
-.iP "0" 15
-Moves to the first character on the current line.
-Also used, in forming numbers, after an initial \fB1\fR\-\fB9\fR.
-.iP "1\-9" 15
-Used to form numeric arguments to commands (2.3, 7.2).
-.iP ":" 15
-A prefix to a set of commands for file and option manipulation and escapes
-to the system. Input is given on the bottom line and terminated with
-an \s-2CR\s0, and the command then executed. You can return to where
-you were by hitting \s-2DEL\s0 or \s-2RUB\s0 if you hit \fB:\fR accidentally
-(see primarily 6.2 and 7.3).
-.iP ";" 15
-Repeats the last single character find which used \fBf F t\fR or \fBT\fR.
-A count iterates the basic scan (4.1).
-.iP "<" 15
-An operator which shifts lines left one \fIshiftwidth\fR, normally 8
-spaces. Like all operators, affects lines when repeated, as in
-\fB<<\fR. Counts are passed through to the basic object, thus \fB3<<\fR
-shifts three lines (6.6, 7.2).
-.iP "=" 15
-Reindents line for \s-2LISP\s0, as though they were typed in with \fIlisp\fR
-and \fIautoindent\fR set (6.8).
-.iP ">" 15
-An operator which shifts lines right one \fIshiftwidth\fR, normally 8
-spaces. Affects lines when repeated as in \fB>>\fR. Counts repeat the
-basic object (6.6, 7.2).
-.iP "?" 15
-Scans backwards, the opposite of \fB/\fR. See the \fB/\fR description
-above for details on scanning (2.2, 6.1, 7.4).
-.iP "@" 15
-A macro character (6.9). If this is your kill character, you must escape it with a \e
-to type it in during input mode, as it normally backs over the input you
-have given on the current line (3.1, 3.4, 7.5).
-.iP "A" 15
-Appends at the end of line, a synonym for \fB$a\fR (7.2).
-.iP "B" 15
-Backs up a word, where words are composed of non-blank sequences, placing
-the cursor at the beginning of the word. A count repeats the effect
-(2.4).
-.iP "C" 15
-Changes the rest of the text on the current line; a synonym for \fBc$\fR.
-.iP "D" 15
-Deletes the rest of the text on the current line; a synonym for \fBd$\fR.
-.iP "E" 15
-Moves forward to the end of a word, defined as blanks and non-blanks,
-like \fBB\fR and \fBW\fR. A count repeats the effect.
-.iP "F" 15
-Finds a single following character, backwards in the current line.
-A count repeats this search that many times (4.1).
-.iP "G" 15
-Goes to the line number given as preceding argument, or the end of the
-file if no preceding count is given. The screen is redrawn with the
-new current line in the center if necessary (7.2).
-.iP "H" 15
-.B "Home arrow" .
-Homes the cursor to the top line on the screen. If a count is given,
-then the cursor is moved to the count'th line on the screen.
-In any case the cursor is moved to the first non-white character on the
-line. If used as the target of an operator, full lines are affected
-(2.3, 3.2).
-.iP "I" 15
-Inserts at the beginning of a line; a synonym for \fB\(uai\fR.
-.iP "J" 15
-Joins together lines, supplying appropriate white space: one space between
-words, two spaces after a \fB.\fR, and no spaces at all if the first
-character of the joined on line is \fB)\fR. A count causes that many
-lines to be joined rather than the default two (6.5, 7.1f).
-.iP "K" 15
-Unused.
-.iP "L" 15
-Moves the cursor to the first non-white character of the last line on
-the screen. With a count, to the first non-white of the count'th line
-from the bottom. Operators affect whole lines when used with \fBL\fR
-(2.3).
-.iP "M" 15
-Moves the cursor to the middle line on the screen, at the first non-white
-position on the line (2.3).
-.iP "N" 15
-Scans for the next match of the last pattern given to
-\fB/\fR or \fB?\fR, but in the reverse direction; this is the reverse
-of \fBn\fR.
-.iP "O" 15
-Opens a new line above the current line and inputs text there up to an
-\s-2ESC\s0. A count can be used on dumb terminals to specify a number
-of lines to be opened; this is generally obsolete, as the \fIslowopen\fR
-option works better (3.1).
-.iP "P" 15
-Puts the last deleted text back before/above the cursor. The text goes
-back as whole lines above the cursor if it was deleted as whole lines.
-Otherwise the text is inserted between the characters before and at the
-cursor. May be preceded by a named buffer specification \fB"\fR\fIx\fR
-to retrieve the contents of the buffer; buffers \fB1\fR\-\fB9\fR contain
-deleted material, buffers \fBa\fR\-\fBz\fR are available for general
-use (6.3).
-.iP "Q" 15
-Quits from \fIvi\fR to \fIex\fR command mode. In this mode, whole lines
-form commands, ending with a \s-2RETURN\s0. You can give all the \fB:\fR
-commands; the editor supplies the \fB:\fR as a prompt (7.7).
-.iP "R" 15
-Replaces characters on the screen with characters you type (overlay fashion).
-Terminates with an \s-2ESC\s0.
-.iP "S" 15
-Changes whole lines, a synonym for \fBcc\fR. A count substitutes for
-that many lines. The lines are saved in the numeric buffers, and erased
-on the screen before the substitution begins.
-.iP "T" 15
-Takes a single following character, locates the character before the
-cursor in the current line, and places the cursor just after that character.
-A count repeats the effect. Most useful with operators such as \fBd\fR
-(4.1).
-.iP "U" 15
-Restores the current line to its state before you started changing it
-(3.5).
-.iP "V" 15
-Unused.
-.iP "W" 15
-Moves forward to the beginning of a word in the current line,
-where words are defined as sequences of blank/non-blank characters.
-A count repeats the effect (2.4).
-.iP "X" 15
-Deletes the character before the cursor. A count repeats the effect,
-but only characters on the current line are deleted.
-.iP "Y" 15
-Yanks a copy of the current line into the unnamed buffer, to be put back
-by a later \fBp\fR or \fBP\fR; a very useful synonym for \fByy\fR.
-A count yanks that many lines. May be preceded by a buffer name to put
-lines in that buffer (7.4).
-.iP "ZZ" 15
-Exits the editor.
-(Same as \fB:x\fP\s-2CR\s0.)
-If any changes have been made, the buffer is written out to the current file.
-Then the editor quits.
-.iP "[[" 15
-Backs up to the previous section boundary. A section begins at each
-macro in the \fIsections\fR option,
-normally a `.NH' or `.SH' and also at lines which which start
-with a formfeed \fB^L\fR. Lines beginning with \fB{\fR also stop \fB[[\fR;
-this makes it useful for looking backwards, a function at a time, in C
-programs. If the option \fIlisp\fR is set, stops at each \fB(\fR at the
-beginning of a line, and is thus useful for moving backwards at the top
-level \s-2LISP\s0 objects. (4.2, 6.1, 6.6, 7.2).
-.iP "\e" 15
-Unused.
-.iP "]]" 15
-Forward to a section boundary, see \fB[[\fR for a definition (4.2, 6.1,
-6.6, 7.2).
-.iP "\(ua" 15
-Moves to the first non-white position on the current line (4.4).
-.iP "_" 15
-Unused.
-.iP "\(ga" 15
-When followed by a \fB\(ga\fR returns to the previous context.
-The previous context is set whenever the current
-line is moved in a non-relative way.
-When followed by a letter \fBa\fR\-\fBz\fR, returns to the position which
-was marked with this letter with a \fBm\fR command.
-When used with an operator such as \fBd\fR, the operation takes place
-from the exact marked place to the current position within the line;
-if you use \fB\(aa\fR, the operation takes place over complete lines
-(2.2, 5.3).
-.iP "a" 15
-Appends arbitrary text after the current cursor position; the insert
-can continue onto multiple lines by using \s-2RETURN\s0 within the insert.
-A count causes the inserted text to be replicated, but only if the inserted
-text is all on one line.
-The insertion terminates with an \s-2ESC\s0 (3.1, 7.2).
-.iP "b" 15
-Backs up to the beginning of a word in the current line. A word is a
-sequence of alphanumerics, or a sequence of special characters.
-A count repeats the effect (2.4).
-.iP "c" 15
-An operator which changes the following object, replacing it with the
-following input text up to an \s-2ESC\s0. If more than part of a single
-line is affected, the text which is changed away is saved in the numeric named
-buffers. If only part of the current line is affected, then the last
-character to be changed away is marked with a \fB$\fR.
-A count causes that many objects to be affected, thus both
-\fB3c)\fR and \fBc3)\fR change the following three sentences (7.4).
-.iP "d" 15
-An operator which deletes the following object. If more than part of
-a line is affected, the text is saved in the numeric buffers.
-A count causes that many objects to be affected; thus \fB3dw\fR is the
-same as \fBd3w\fR (3.3, 3.4, 4.1, 7.4).
-.iP "e" 15
-Advances to the end of the next word, defined as for \fBb\fR and \fBw\fR.
-A count repeats the effect (2.4, 3.1).
-.iP "f" 15
-Finds the first instance of the next character following the cursor on
-the current line. A count repeats the find (4.1).
-.iP "g" 15
-Unused.
-.sp
-Arrow keys
-.B h ,
-.B j ,
-.B k ,
-.B l ,
-and
-.B H .
-.iP "h" 15
-.B "Left arrow" .
-Moves the cursor one character to the left.
-Like the other arrow keys, either
-.B h ,
-the
-.B "left arrow"
-key, or one of the synonyms (\fB^H\fP) has the same effect.
-On v2 editors, arrow keys on certain kinds of terminals
-(those which send escape sequences, such as vt52, c100, or hp)
-cannot be used.
-A count repeats the effect (3.1, 7.5).
-.iP "i" 15
-Inserts text before the cursor, otherwise like \fBa\fR (7.2).
-.iP "j" 15
-.B "Down arrow" .
-Moves the cursor one line down in the same column.
-If the position does not exist,
-.I vi
-comes as close as possible to the same column.
-Synonyms include
-.B ^J
-(linefeed) and
-.B ^N .
-.iP "k" 15
-.B "Up arrow" .
-Moves the cursor one line up.
-.B ^P
-is a synonym.
-.iP "l" 15
-.B "Right arrow" .
-Moves the cursor one character to the right.
-\s-2SPACE\s0 is a synonym.
-.iP "m" 15
-Marks the current position of the cursor in the mark register which is
-specified by the next character \fBa\fR\-\fBz\fR. Return to this position
-or use with an operator using \fB\(ga\fR or \fB\(aa\fR (5.3).
-.iP "n" 15
-Repeats the last \fB/\fR or \fB?\fR scanning commands (2.2).
-.iP "o" 15
-Opens new lines below the current line; otherwise like \fBO\fR (3.1).
-.iP "p" 15
-Puts text after/below the cursor; otherwise like \fBP\fR (6.3).
-.iP "q" 15
-Unused.
-.iP "r" 15
-Replaces the single character at the cursor with a single character you
-type. The new character may be a \s-2RETURN\s0; this is the easiest
-way to split lines. A count replaces each of the following count characters
-with the single character given; see \fBR\fR above which is the more
-usually useful iteration of \fBr\fR (3.2).
-.iP "s" 15
-Changes the single character under the cursor to the text which follows
-up to an \s-2ESC\s0; given a count, that many characters from the current
-line are changed. The last character to be changed is marked with \fB$\fR
-as in \fBc\fR (3.2).
-.iP "t" 15
-Advances the cursor upto the character before the next character typed.
-Most useful with operators such as \fBd\fR and \fBc\fR to delete the
-characters up to a following character. You can use \fB.\fR to delete
-more if this doesn't delete enough the first time (4.1).
-.iP "u" 15
-Undoes the last change made to the current buffer. If repeated, will
-alternate between these two states, thus is its own inverse. When used
-after an insert which inserted text on more than one line, the lines are
-saved in the numeric named buffers (3.5).
-.iP "v" 15
-Unused.
-.iP "w" 15
-Advances to the beginning of the next word, as defined by \fBb\fR (2.4).
-.iP "x" 15
-Deletes the single character under the cursor. With a count deletes
-deletes that many characters forward from the cursor position, but only
-on the current line (6.5).
-.iP "y" 15
-An operator, yanks the following object into the unnamed temporary buffer.
-If preceded by a named buffer specification, \fB"\fR\fIx\fR, the text
-is placed in that buffer also. Text can be recovered by a later \fBp\fR
-or \fBP\fR (7.4).
-.iP "z" 15
-Redraws the screen with the current line placed as specified by the following
-character: \s-2RETURN\s0 specifies the top of the screen, \fB.\fR the
-center of the screen, and \fB\-\fR at the bottom of the screen.
-A count may be given after the \fBz\fR and before the following character
-to specify the new screen size for the redraw.
-A count before the \fBz\fR gives the number of the line to place in the
-center of the screen instead of the default current line. (5.4)
-.iP "{" 15
-Retreats to the beginning of the beginning of the preceding paragraph.
-A paragraph begins at each macro in the \fIparagraphs\fR option, normally
-`.IP', `.LP', `.PP', `.QP' and `.bp'.
-A paragraph also begins after a completely
-empty line, and at each section boundary (see \fB[[\fR above) (4.2, 6.8,
-7.6).
-.iP "|" 15
-Places the cursor on the character in the column specified
-by the count (7.1, 7.2).
-.iP "}" 15
-Advances to the beginning of the next paragraph. See \fB{\fR for the
-definition of paragraph (4.2, 6.8, 7.6).
-.iP "~" 15
-Unused.
-.iP "^?\ (\s-2\fRDEL\fP\s0)" 15
-Interrupts the editor, returning it to command accepting state (1.5,
-7.5)
-.bp
-\&.
diff --git a/usr.bin/vi/USD.doc/vitut/vi.in b/usr.bin/vi/USD.doc/vitut/vi.in
deleted file mode 100644
index 3bdfeb9..0000000
--- a/usr.bin/vi/USD.doc/vitut/vi.in
+++ /dev/null
@@ -1,2064 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)vi.in 8.1 (Berkeley) 6/8/93
-.\"
-.EH 'USD:12-%''An Introduction to Display Editing with Vi'
-.OH 'An Introduction to Display Editing with Vi''USD:12-%'
-.bd S 3
-.if t .ds dg \(dg
-.if n .ds dg +
-.if t .ds dd \(dd
-.if n .ds dd ++
-.\".RP
-.TL
-An Introduction to Display Editing with Vi
-.AU
-William Joy
-.AU
-Mark Horton
-.AI
-Computer Science Division
-Department of Electrical Engineering and Computer Science
-University of California, Berkeley
-Berkeley, Ca. 94720
-.AB
-.PP
-.I Vi
-(visual) is a display oriented interactive text editor.
-When using
-.I vi
-the screen of your terminal acts as a window into the file which you
-are editing. Changes which you make to the file are reflected
-in what you see.
-.PP
-Using
-.I vi
-you can insert new text any place in the file quite easily.
-Most of the commands to
-.I vi
-move the cursor around in the file.
-There are commands to move the cursor
-forward and backward in units of characters, words,
-sentences and paragraphs.
-A small set of operators, like
-.B d
-for delete and
-.B c
-for change, are combined with the motion commands to form operations
-such as delete word or change paragraph, in a simple and natural way.
-This regularity and the mnemonic assignment of commands to keys makes the
-editor command set easy to remember and to use.
-.PP
-.I Vi
-will work on a large number of display terminals,
-and new terminals are easily driven after editing a terminal description file.
-While it is advantageous to have an intelligent terminal which can locally
-insert and delete lines and characters from the display, the editor will
-function quite well on dumb terminals over slow phone lines.
-The editor makes allowance for the low bandwidth in these situations
-and uses smaller window sizes and
-different display updating algorithms to make best use of the
-limited speed available.
-.PP
-It is also possible to use the command set of
-.I vi
-on hardcopy terminals, storage tubes and ``glass tty's'' using a one line
-editing window; thus
-.I vi's
-command set is available on all terminals.
-The full command set of the more traditional, line
-oriented editor
-.I ex
-is available within
-.I vi;
-it is quite simple to switch between the two modes of editing.
-.AE
-.NH 1
-Getting started
-.PP
-.FS
-The financial support of an \s-2IBM\s0 Graduate Fellowship and the
-National Science Foundation under grants MCS74-07644-A03 and MCS78-07291
-is gratefully acknowledged.
-.FE
-This document provides a quick introduction to
-.I vi.
-(Pronounced \fIvee-eye\fP.)
-You should be running
-.I vi
-on a file you are familiar with while you are reading this.
-The first part of this document (sections 1 through 5)
-describes the basics of using
-.I vi.
-Some topics of special interest are presented in section 6, and
-some nitty-gritty details of how the editor functions are saved for section
-7 to avoid cluttering the presentation here.
-.PP
-There is also a short appendix here, which gives for each character the
-special meanings which this character has in \fIvi\fR. Attached to
-this document should be a quick reference card.
-This card summarizes the commands of
-.I vi
-in a very compact format. You should have the card handy while you are
-learning
-.I vi.
-.NH 2
-Specifying terminal type
-.PP
-Before you can start
-.I vi
-you must tell the system what kind of terminal you are using.
-Here is a (necessarily incomplete) list of terminal type codes.
-If your terminal does not appear here, you should consult with one of
-the staff members on your system to find out the code for your terminal.
-If your terminal does not have a code, one can be assigned and a description
-for the terminal can be created.
-.LP
-.TS
-center;
-ab ab ab
-a a a.
-Code Full name Type
-_
-2621 Hewlett-Packard 2621A/P Intelligent
-2645 Hewlett-Packard 264x Intelligent
-act4 Microterm ACT-IV Dumb
-act5 Microterm ACT-V Dumb
-adm3a Lear Siegler ADM-3a Dumb
-adm31 Lear Siegler ADM-31 Intelligent
-c100 Human Design Concept 100 Intelligent
-dm1520 Datamedia 1520 Dumb
-dm2500 Datamedia 2500 Intelligent
-dm3025 Datamedia 3025 Intelligent
-fox Perkin-Elmer Fox Dumb
-h1500 Hazeltine 1500 Intelligent
-h19 Heathkit h19 Intelligent
-i100 Infoton 100 Intelligent
-mime Imitating a smart act4 Intelligent
-t1061 Teleray 1061 Intelligent
-vt52 Dec VT-52 Dumb
-.TE
-.PP
-Suppose for example that you have a Hewlett-Packard HP2621A
-terminal. The code used by the system for this terminal is `2621'.
-In this case you can use one of the following commands to tell the system
-the type of your terminal:
-.DS
-% \fBsetenv TERM\fP 2621
-.DE
-This command works with the
-.I csh
-shell.
-If you are using the standard Bourne shell
-.I sh
-then you should give the commands
-.DS
-$ \fBTERM=\fP2621
-$ \fBexport TERM\fP
-.DE
-.PP
-If you want to arrange to have your terminal type set up automatically
-when you log in, you can use the
-.I tset
-program.
-If you dial in on a
-.I mime ,
-but often use hardwired ports, a typical line for your
-.I .login
-file (if you use csh) would be
-.DS
-\fBsetenv TERM \(gatset\fP \- \-d mime\(ga
-.DE
-or for your
-.I .profile
-file (if you use sh)
-.DS
-\fBTERM=\(gatse\fPt \- \-d mime\(ga
-.DE
-.I Tset
-knows which terminals are hardwired to each port
-and needs only to be told that when you dial in you
-are probably on a
-.I mime .
-.I Tset
-is usually used to change the erase and kill characters, too.
-.NH 2
-Editing a file
-.PP
-After telling the system which kind of terminal you have, you should
-make a copy of a file you are familiar with, and run
-.I vi
-on this file, giving the command
-.DS
-% \fBvi\fR \fIname\fR
-.DE
-replacing \fIname\fR with the name of the copy file you just created.
-The screen should clear and the text of your file should appear on the
-screen. If something else happens refer to the footnote.\*(dd
-.FS
-\*(dd If you gave the system an incorrect terminal type code then the
-editor may have just made a mess out of your screen. This happens when
-it sends control codes for one kind of terminal to some other
-kind of terminal. In this case hit
-the keys \fB:q\fR (colon and the q key) and then hit the \s-2RETURN\s0 key.
-This should get you back to the command level interpreter.
-Figure out what you did wrong (ask someone else if necessary) and try again.
- Another thing which can go wrong is that you typed the wrong file name and
-the editor just printed an error diagnostic. In this case you should
-follow the above procedure for getting out of the editor, and try again
-this time spelling the file name correctly.
- If the editor doesn't seem to respond to the commands which you type
-here, try sending an interrupt to it by hitting the \s-2DEL\s0 or \s-2RUB\s0
-key on your terminal, and then hitting the \fB:q\fR command again followed
-by a carriage return.
-.sp
-.FE
-.NH 2
-The editor's copy: the buffer
-.PP
-The editor does not directly modify the file which you are editing.
-Rather, the editor makes a copy of this file, in a place called the
-.I buffer,
-and remembers the file's
-name. You do not affect the contents of the file unless and until you
-write the changes you make back into the original file.
-.NH 2
-Notational conventions
-.PP
-In our examples, input which must be typed as is will be presented in
-\fBbold face\fR. Text which should be replaced with appropriate input
-will be given in \fIitalics\fR. We will represent special characters
-in \s-2SMALL CAPITALS\s0.
-.NH 2
-Arrow keys
-.PP
-The editor command set is independent of the terminal
-you are using. On most terminals with cursor positioning keys, these keys
-will also work within the editor.
-If you don't have cursor positioning keys, or even if you do, you can use
-the \fBh j k\fR and \fBl\fR keys as cursor positioning
-keys (these are labelled with arrows on an
-.I adm3a).*
-.PP
-(Particular note for the HP2621: on this terminal the function keys
-must be \fIshifted\fR (ick) to send to the machine, otherwise they
-only act locally. Unshifted use will leave the cursor positioned
-incorrectly.)
-.FS
-* As we will see later,
-.I h
-moves back to the left (like control-h which is a backspace),
-.I j
-moves down (in the same column),
-.I k
-moves up (in the same column),
-and
-.I l
-moves to the right.
-.FE
-.NH 2
-Special characters: \s-2ESC\s0, \s-2CR\s0 and \s-2DEL\s0
-.PP
-Several of these special characters are very important, so be sure to
-find them right now. Look on your keyboard for a key labelled \s-2ESC\s0
-or \s-2ALT\s0. It should be near the upper left corner of your terminal.
-Try hitting this key a few times. The editor will ring the bell
-to indicate that it is in a quiescent state.\*(dd
-.FS
-\*(dd On smart terminals where it is possible, the editor will quietly
-flash the screen rather than ringing the bell.
-.FE
-Partially formed commands are cancelled by \s-2ESC\s0, and when you insert
-text in the file you end the text insertion
-with \s-2ESC\s0. This key is a fairly
-harmless one to hit, so you can just hit it if you don't know
-what is going on until the editor rings the bell.
-.PP
-The \s-2CR\s0 or \s-2RETURN\s0 key is important because it is used
-to terminate certain commands.
-It is usually at the right side of the keyboard,
-and is the same command used at the end of each shell command.
-.PP
-Another very useful key is the \s-2DEL\s0 or \s-2RUB\s0 key, which generates
-an interrupt, telling the editor to stop what it is doing.
-It is a forceful way of making the editor listen
-to you, or to return it to the quiescent state if you don't know or don't
-like what is going on. Try hitting the `/' key on your terminal. This
-key is used when you want to specify a string to be searched for. The
-cursor should now be positioned at the bottom line of the terminal after
-a `/' printed as a prompt. You can get the cursor back to the current
-position by hitting the \s-2DEL\s0 or \s-2RUB\s0 key; try this now.*
-.FS
-* Backspacing over the `/' will also cancel the search.
-.FE
-From now on we will simply refer to hitting the \s-2DEL\s0 or \s-2RUB\s0
-key as ``sending an interrupt.''**
-.FS
-** On some systems, this interruptibility comes at a price: you cannot type
-ahead when the editor is computing with the cursor on the bottom line.
-.FE
-.PP
-The editor often echoes your commands on the last line of the terminal.
-If the cursor is on the first position of this last line, then the editor
-is performing a computation, such as computing a new position in the
-file after a search or running a command to reformat part of the buffer.
-When this is happening you can stop the editor by
-sending an interrupt.
-.NH 2
-Getting out of the editor
-.PP
-After you have worked with this introduction for a while, and you wish
-to do something else, you can give the command \fBZZ\fP
-to the editor.
-This will write the contents of the editor's buffer back into
-the file you are editing, if you made any changes, and then quit from
-the editor. You can also end an editor
-session by giving the command \fB:q!\fR\s-2CR\s0;\*(dg
-.FS
-\*(dg All commands which read from the last display line can also be
-terminated with a \s-2ESC\s0 as well as an \s-2CR\s0.
-.FE
-this is a dangerous but occasionally essential
-command which ends the editor session and discards all your changes.
-You need to know about this command in case you change the editor's
-copy of a file you wish only to look at. Be very careful
-not to give this command when you really want to save
-the changes you have made.
-.NH 1
-Moving around in the file
-.NH 2
-Scrolling and paging
-.PP
-The editor has a number of commands for moving around in the file.
-The most useful of these is generated by hitting the control and D keys
-at the same time, a control-D or `^D'. We will use this two character
-notation for referring to these control keys from now on. You may have
-a key labelled `^' on your terminal. This key will be represented as `\(ua'
-in this document; `^' is exclusively used as part of the `^x' notation
-for control characters.\*(dd
-.FS
-\*(dd If you don't have a `^' key on your terminal
-then there is probably a key labelled `\(ua'; in any case these characters
-are one and the same.
-.FE
-.PP
-As you know now if you tried hitting \fB^D\fR, this command scrolls down in
-the file. The \fBD\fR thus stands for down. Many editor commands are mnemonic
-and this makes them much easier to remember. For instance the command
-to scroll up is \fB^U\fR. Many dumb terminals can't scroll up at all, in which
-case hitting \fB^U\fR clears the screen and refreshes it
-with a line which is farther back in the file at the top.
-.PP
-If you want to see more of the file below where you are, you can
-hit \fB^E\fR to expose one more line at the bottom of the screen,
-leaving the cursor where it is.
-The command \fB^Y\fR (which is hopelessly non-mnemonic, but next to \fB^U\fR
-on the keyboard) exposes one more line at the top of the screen.
-.PP
-There are other ways to move around in the file; the keys \fB^F\fR and \fB^B\fR
-move forward and backward a page,
-keeping a couple of lines of continuity between screens
-so that it is possible to read through a file using these rather than
-\fB^D\fR and \fB^U\fR if you wish.
-.PP
-Notice the difference between scrolling and paging. If you are trying
-to read the text in a file, hitting \fB^F\fR to move forward a page
-will leave you only a little context to look back at. Scrolling on the
-other hand leaves more context, and happens more smoothly. You can continue
-to read the text as scrolling is taking place.
-.NH 2
-Searching, goto, and previous context
-.PP
-Another way to position yourself in the file is by giving the editor a string
-to search for. Type the character \fB/\fR followed by a string of characters
-terminated by \s-2CR\s0. The editor will position the cursor
-at the next occurrence of this string.
-Try hitting \fBn\fR to then go to the next occurrence of this string.
-The character \fB?\fR will search backwards from where you are, and is
-otherwise like \fB/\fR.\*(dg
-.FS
-\*(dg These searches will normally wrap around the end of the file, and thus
-find the string even if it is not on a line in the direction you search
-provided it is anywhere else in the file. You can disable this wraparound
-in scans by giving the command \fB:se nowrapscan\fR\s-2CR\s0,
-or more briefly \fB:se nows\fR\s-2CR\s0.
-.FE
-.PP
-If the search string you give the editor is not present in the
-file the editor will print
-a diagnostic on the last line of the screen, and the cursor will be returned
-to its initial position.
-.PP
-If you wish the search to match only at the beginning of a line, begin
-the search string with an \fB\(ua\fR. To match only at the end of
-a line, end the search string with a \fB$\fR.
-Thus \fB/\(uasearch\fR\s-2CR\s0 will search for the word `search' at
-the beginning of a line, and \fB/last$\fR\s-2CR\s0 searches for the
-word `last' at the end of a line.*
-.FS
-*Actually, the string you give to search for here can be a
-.I "regular expression"
-in the sense of the editors
-.I ex (1)
-and
-.I ed (1).
-If you don't wish to learn about this yet, you can disable this more
-general facility by doing
-\fB:se\ nomagic\fR\s-2CR\s0;
-by putting this command in
-EXINIT
-in your environment, you can have this always be in effect (more
-about
-.I EXINIT
-later.)
-.FE
-.PP
-The command \fBG\fR, when preceded by a number will position the cursor
-at that line in the file.
-Thus \fB1G\fR will move the cursor to
-the first line of the file. If you give \fBG\fR no count, then it moves
-to the end of the file.
-.PP
-If you are near the end of the file, and the last line is not at the bottom
-of the screen, the editor will place only the character `~' on each remaining
-line. This indicates that the last line in the file is on the screen;
-that is, the `~' lines are past the end of the file.
-.PP
-You can find out the state of the file you are editing by typing a \fB^G\fR.
-The editor will show you the name of the file you are editing, the number
-of the current line, the number of lines in the buffer, and the percentage
-of the way through the buffer which you are.
-Try doing this now, and remember the number of the line you are on.
-Give a \fBG\fR command to get to the end and then another \fBG\fR command
-to get back where you were.
-.PP
-You can also get back to a previous position by using the command
-\fB\(ga\(ga\fR (two back quotes).
-This is often more convenient than \fBG\fR because it requires no advance
-preparation.
-Try giving a \fBG\fR or a search with \fB/\fR or \fB?\fR and then a
-\fB\(ga\(ga\fR to get back to where you were. If you accidentally hit
-\fBn\fR or any command which moves you far away from a context of interest, you
-can quickly get back by hitting \fB\(ga\(ga\fR.
-.NH 2
-Moving around on the screen
-.PP
-Now try just moving the cursor around on the screen.
-If your terminal has arrow keys (4 or 5 keys with arrows
-going in each direction) try them and convince yourself
-that they work.
-If you don't have working arrow keys, you can always use
-.B h ,
-.B j ,
-.B k ,
-and
-.B l .
-Experienced users of
-.I vi
-prefer these keys to arrow keys,
-because they are usually right underneath their fingers.
-.PP
-Hit the \fB+\fR key. Each time you do, notice that the cursor
-advances to the next line in the file, at the first non-white position
-on the line. The \fB\-\fR key is like \fB+\fR but goes the other way.
-.PP
-These are very common keys for moving up and down lines in the file.
-Notice that if you go off the bottom or top with these keys then the
-screen will scroll down (and up if possible) to bring a line at a time
-into view. The \s-2RETURN\s0 key has the same effect as the \fB+\fR
-key.
-.PP
-.I Vi
-also has commands to take you to the top, middle and bottom of the screen.
-\fBH\fR will take you to the top (home) line on the screen.
-Try preceding it with a
-number as in \fB3H\fR.
-This will take you to the third line on the screen.
-Many
-.I vi
-commands take preceding numbers and do interesting things with them.
-Try \fBM\fR,
-which takes you to the middle line on the screen,
-and \fBL\fR,
-which takes you to the last line on the screen.
-\fBL\fR also takes counts, thus
-\fB5L\fR will take you to the fifth line from the bottom.
-.NH 2
-Moving within a line
-.PP
-Now try picking a word on some line on the screen, not the
-first word on the line.
-move the cursor using \s-2RETURN\s0 and \fB\-\fR to be on the line where
-the word is.
-Try hitting the \fBw\fR key. This will advance the cursor to the
-next word on the line.
-Try hitting the \fBb\fR key to back up words
-in the line.
-Also try the \fBe\fR key which advances you to the end of the current
-word rather than to the beginning of the next word.
-Also try \s-2SPACE\s0 (the space bar) which moves right one character
-and the \s-2BS\s0 (backspace or \fB^H\fR) key which moves left one character.
-The key \fBh\fR works as \fB^H\fR does and is useful if you don't have
-a \s-2BS\s0 key.
-(Also, as noted just above, \fBl\fR will move to the right.)
-.PP
-If the line had punctuation in it you may have noticed that
-that the \fBw\fR and \fBb\fR
-keys stopped at each group of punctuation. You can also go back and
-forwards words without stopping at punctuation by using \fBW\fR and \fBB\fR
-rather than the lower case equivalents. Think of these as bigger words.
-Try these on a few lines with punctuation to see how they differ from
-the lower case \fBw\fR and \fBb\fR.
-.PP
-The word keys wrap around the end of line,
-rather than stopping at the end. Try moving to a word on a line below
-where you are by repeatedly hitting \fBw\fR.
-.NH 2
-Summary
-.IP
-.TS
-lw(.50i)b a.
-\fR\s-2SPACE\s0\fP advance the cursor one position
-^B backwards to previous page
-^D scrolls down in the file
-^E exposes another line at the bottom
-^F forward to next page
-^G tell what is going on
-^H backspace the cursor
-^N next line, same column
-^P previous line, same column
-^U scrolls up in the file
-^Y exposes another line at the top
-+ next line, at the beginning
-\- previous line, at the beginning
-/ scan for a following string forwards
-? scan backwards
-B back a word, ignoring punctuation
-G go to specified line, last default
-H home screen line
-M middle screen line
-L last screen line
-W forward a word, ignoring punctuation
-b back a word
-e end of current word
-n scan for next instance of \fB/\fR or \fB?\fR pattern
-w word after this word
-.TE
-.NH 2
-View
-.PP
-If you want to use the editor to look at a file,
-rather than to make changes,
-invoke it as
-.I view
-instead of
-.I vi .
-This will set the
-.I readonly
-option which will prevent you from
-accidently overwriting the file.
-.NH 1
-Making simple changes
-.NH 2
-Inserting
-.PP
-One of the most useful commands is the
-\fBi\fR (insert) command.
-After you type \fBi\fR, everything you type until you hit \s-2ESC\s0
-is inserted into the file.
-Try this now; position yourself to some word in the file and try inserting
-text before this word.
-If you are on an dumb terminal it will seem, for a minute,
-that some of the characters in your line have been overwritten, but they will
-reappear when you hit \s-2ESC\s0.
-.PP
-Now try finding a word which can, but does not, end in an `s'.
-Position yourself at this word and type \fBe\fR (move to end of word), then
-\fBa\fR for append and then `s\s-2ESC\s0' to terminate the textual insert.
-This sequence of commands can be used to easily pluralize a word.
-.PP
-Try inserting and appending a few times to make sure you understand how
-this works; \fBi\fR placing text to the left of the cursor, \fBa\fR to
-the right.
-.PP
-It is often the case that you want to add new lines to the file you are
-editing, before or after some specific line in the file. Find a line
-where this makes sense and then give the command \fBo\fR to create a
-new line after the line you are on, or the command \fBO\fR to create
-a new line before the line you are on. After you create a new line in
-this way, text you type up to an \s-2ESC\s0 is inserted on the new line.
-.PP
-Many related editor commands
-are invoked by the same letter key and differ only in that one is given
-by a lower
-case key and the other is given by
-an upper case key. In these cases, the
-upper case key often differs from the lower case key in its sense of
-direction, with
-the upper case key working backward and/or up, while the lower case
-key moves forward and/or down.
-.PP
-Whenever you are typing in text, you can give many lines of input or
-just a few characters.
-To type in more than one line of text,
-hit a \s-2RETURN\s0 at the middle of your input. A new line will be created
-for text, and you can continue to type. If you are on a slow
-and dumb terminal the editor may choose to wait to redraw the
-tail of the screen, and will let you type over the existing screen lines.
-This avoids the lengthy delay which would occur if the editor attempted
-to keep the tail of the screen always up to date. The tail of the screen will
-be fixed up, and the missing lines will reappear, when you hit \s-2ESC\s0.
-.PP
-While you are inserting new text, you can use the characters you normally use
-at the system command level (usually \fB^H\fR or \fB#\fR) to backspace
-over the last
-character which you typed, and the character which you use to kill input lines
-(usually \fB@\fR, \fB^X\fR, or \fB^U\fR)
-to erase the input you have typed on the current line.\*(dg
-.FS
-\*(dg In fact, the character \fB^H\fR (backspace) always works to erase the
-last input character here, regardless of what your erase character is.
-.FE
-The character \fB^W\fR
-will erase a whole word and leave you after the space after the previous
-word; it is useful for quickly backing up in an insert.
-.PP
-Notice that when you backspace during an insertion the characters you
-backspace over are not erased; the cursor moves backwards, and the characters
-remain on the display. This is often useful if you are planning to type
-in something similar. In any case the characters disappear when when
-you hit \s-2ESC\s0; if you want to get rid of them immediately, hit an
-\s-2ESC\s0 and then \fBa\fR again.
-.PP
-Notice also that you can't erase characters which you didn't insert, and that
-you can't backspace around the end of a line. If you need to back up
-to the previous line to make a correction, just hit \s-2ESC\s0 and move
-the cursor back to the previous line. After making the correction you
-can return to where you were and use the insert or append command again.
-.NH 2
-Making small corrections
-.PP
-You can make small corrections in existing text quite easily.
-Find a single character which is wrong or just pick any character.
-Use the arrow keys to find the character, or
-get near the character with the word motion keys and then either
-backspace (hit the \s-2BS\s0 key or \fB^H\fR or even just \fBh\fR) or
-\s-2SPACE\s0 (using the space bar)
-until the cursor is on the character which is wrong.
-If the character is not needed then hit the \fBx\fP key; this deletes
-the character from the file. It is analogous to the way you \fBx\fP
-out characters when you make mistakes on a typewriter (except it's not
-as messy).
-.PP
-If the character
-is incorrect, you can replace it with the correct character by giving
-the command \fBr\fR\fIc\fR,
-where \fIc\fR is replaced by the correct character.
-Finally if the character which is incorrect should be replaced
-by more than one character, give the command \fBs\fR which substitutes
-a string of characters, ending with \s-2ESC\s0, for it.
-If there are a small number of characters
-which are wrong you can precede \fBs\fR with a count of the number of
-characters to be replaced. Counts are also useful with \fBx\fR to specify
-the number of characters to be deleted.
-.NH 2
-More corrections: operators
-.PP
-You already know almost enough to make changes at a higher level.
-All you need to know now is that the
-.B d
-key acts as a delete operator. Try the command
-.B dw
-to delete a word.
-Try hitting \fB.\fR a few times. Notice that this repeats the effect
-of the \fBdw\fR. The command \fB.\fR repeats the last command which
-made a change. You can remember it by analogy with an ellipsis `\fB...\fR'.
-.PP
-Now try
-\fBdb\fR.
-This deletes a word backwards, namely the preceding word.
-Try
-\fBd\fR\s-2SPACE\s0. This deletes a single character, and is equivalent
-to the \fBx\fR command.
-.PP
-Another very useful operator is
-.B c
-or change. The command
-.B cw
-thus changes the text of a single word.
-You follow it by the replacement text ending with an \s-2ESC\s0.
-Find a word which you can change to another, and try this
-now.
-Notice that the end of the text to be changed was marked with the character
-`$' so that you can see this as you are typing in the new material.
-.NH 2
-Operating on lines
-.PP
-It is often the case that you want to operate on lines.
-Find a line which you want to delete, and type
-\fBdd\fR,
-the
-.B d
-operator twice. This will delete the line.
-If you are on a dumb terminal, the editor may just erase the line on
-the screen, replacing it with a line with only an @ on it. This line
-does not correspond to any line in your file, but only acts as a place
-holder. It helps to avoid a lengthy redraw of the rest of the screen
-which would be necessary to close up the hole created by the deletion
-on a terminal without a delete line capability.
-.PP
-Try repeating the
-.B c
-operator twice; this will change a whole line, erasing its previous contents and
-replacing them with text you type up to an \s-2ESC\s0.\*(dg
-.FS
-\*(dg The command \fBS\fR is a convenient synonym for for \fBcc\fR, by
-analogy with \fBs\fR. Think of \fBS\fR as a substitute on lines, while
-\fBs\fR is a substitute on characters.
-.FE
-.PP
-You can delete or change more than one line by preceding the
-.B dd
-or
-.B cc
-with a count, i.e. \fB5dd\fR deletes 5 lines.
-You can also give a command like \fBdL\fR to delete all the lines up to
-and including
-the last line on the screen, or \fBd3L\fR to delete through the third from
-the bottom line. Try some commands like this now.*
-.FS
-* One subtle point here involves using the \fB/\fR search after a \fBd\fR.
-This will normally delete characters from the current position to the
-point of the match. If what is desired is to delete whole lines
-including the two points, give the pattern as \fB/pat/+0\fR, a line address.
-.FE
-Notice that the editor lets you know when you change a large number of
-lines so that you can see the extent of the change.
-The editor will also always tell you when a change you make affects text which
-you cannot see.
-.NH 2
-Undoing
-.PP
-Now suppose that the last change which you made was incorrect;
-you could use the insert, delete and append commands to put the correct
-material back. However, since it is often the case that we regret a
-change or make a change incorrectly, the editor provides a
-.B u
-(undo) command to reverse the last change which you made.
-Try this a few times, and give it twice in a row to notice that an
-.B u
-also undoes a
-.B u.
-.PP
-The undo command lets you reverse only a single change. After you make
-a number of changes to a line, you may decide that you would rather have
-the original state of the line back. The
-.B U
-command restores the current line to the state before you started changing
-it.
-.PP
-You can recover text which you delete, even if
-undo will not bring it back; see the section on recovering lost text
-below.
-.NH 2
-Summary
-.IP
-.TS
-lw(.50i)b a.
-\fR\s-2SPACE\s0\fP advance the cursor one position
-^H backspace the cursor
-^W erase a word during an insert
-\fRerase\fP your erase (usually ^H or #), erases a character during an insert
-\fRkill\fP your kill (usually @, ^X, or ^U), kills the insert on this line
-\&\fB.\fP repeats the changing command
-O opens and inputs new lines, above the current
-U undoes the changes you made to the current line
-a appends text after the cursor
-c changes the object you specify to the following text
-d deletes the object you specify
-i inserts text before the cursor
-o opens and inputs new lines, below the current
-u undoes the last change
-.TE
-.NH 1
-Moving about; rearranging and duplicating text
-.NH 2
-Low level character motions
-.PP
-Now move the cursor to a line where there is a punctuation or a bracketing
-character such as a parenthesis or a comma or period. Try the command
-\fBf\fR\fIx\fR where \fIx\fR is this character. This command finds
-the next \fIx\fR character to the right of the cursor in the current
-line. Try then hitting a \fB;\fR, which finds the next instance of the
-same character. By using the \fBf\fR command and then a sequence of
-\fB;\fR's you can often
-get to a particular place in a line much faster than with a sequence
-of word motions or \s-2SPACE\s0s.
-There is also a \fBF\fR command, which is like \fBf\fR, but searches
-backward. The \fB;\fR command repeats \fBF\fR also.
-.PP
-When you are operating on the text in a line it is often desirable to
-deal with the characters up to, but not including, the first instance of
-a character. Try \fBdf\fR\fIx\fR for some \fIx\fR now and
-notice that the \fIx\fR character is deleted. Undo this with \fBu\fR
-and then try \fBdt\fR\fIx\fR; the \fBt\fR here stands for to, i.e.
-delete up to the next \fIx\fR, but not the \fIx\fR. The command \fBT\fR
-is the reverse of \fBt\fR.
-.PP
-When working with the text of a single line, an \fB\(ua\fR moves the
-cursor to the first non-white position on the line, and a
-\fB$\fR moves it to the end of the line. Thus \fB$a\fR will append new
-text at the end of the current line.
-.PP
-Your file may have tab (\fB^I\fR) characters in it. These
-characters are represented as a number of spaces expanding to a tab stop,
-where tab stops are every 8 positions.*
-.FS
-* This is settable by a command of the form \fB:se ts=\fR\fIx\fR\s-2CR\s0,
-where \fIx\fR is 4 to set tabstops every four columns. This has
-effect on the screen representation within the editor.
-.FE
-When the cursor is at a tab, it sits on the last of the several spaces
-which represent that tab. Try moving the cursor back and forth over
-tabs so you understand how this works.
-.PP
-On rare occasions, your file may have nonprinting characters in it.
-These characters are displayed in the same way they are represented in
-this document, that is with a two character code, the first character
-of which is `^'. On the screen non-printing characters resemble a `^'
-character adjacent to another, but spacing or backspacing over the character
-will reveal that the two characters are, like the spaces representing
-a tab character, a single character.
-.PP
-The editor sometimes discards control characters,
-depending on the character and the setting of the
-.I beautify
-option,
-if you attempt to insert them in your file.
-You can get a control character in the file by beginning
-an insert and then typing a \fB^V\fR before the control
-character. The
-\fB^V\fR quotes the following character, causing it to be
-inserted directly into the file.
-.PP
-.NH 2
-Higher level text objects
-.PP
-In working with a document it is often advantageous to work in terms
-of sentences, paragraphs, and sections. The operations \fB(\fR and \fB)\fR
-move to the beginning of the previous and next sentences respectively.
-Thus the command \fBd)\fR will delete the rest of the current sentence;
-likewise \fBd(\fR will delete the previous sentence if you are at the
-beginning of the current sentence, or the current sentence up to where
-you are if you are not at the beginning of the current sentence.
-.PP
-A sentence is defined to end at a `.', `!' or `?' which is followed by
-either the end of a line, or by two spaces. Any number of closing `)',
-`]', `"' and `\(aa' characters may appear after the `.', `!' or `?' before
-the spaces or end of line.
-.PP
-The operations \fB{\fR and \fB}\fR move over paragraphs and the operations
-\fB[[\fR and \fB]]\fR move over sections.\*(dg
-.FS
-\*(dg The \fB[[\fR and \fB]]\fR operations
-require the operation character to be doubled because they can move the
-cursor far from where it currently is. While it is easy to get back
-with the command \fB\(ga\(ga\fP,
-these commands would still be frustrating
-if they were easy to hit accidentally.
-.FE
-.PP
-A paragraph begins after each empty line, and also
-at each of a set of paragraph macros, specified by the pairs of characters
-in the definition of the string valued option \fIparagraphs\fR.
-The default setting for this option defines the paragraph macros of the
-\fI\-ms\fR and \fI\-mm\fR macro packages, i.e. the `.IP', `.LP', `.PP'
-and `.QP', `.P' and `.LI' macros.\*(dd
-.FS
-\*(dd You can easily change or extend this set of macros by assigning a
-different string to the \fIparagraphs\fR option in your EXINIT.
-See section 6.2 for details.
-The `.bp' directive is also considered to start a paragraph.
-.FE
-Each paragraph boundary is also a sentence boundary. The sentence
-and paragraph commands can
-be given counts to operate over groups of sentences and paragraphs.
-.PP
-Sections in the editor begin after each macro in the \fIsections\fR option,
-normally `.NH', `.SH', `.H' and `.HU', and each line with a formfeed \fB^L\fR
-in the first column.
-Section boundaries are always line and paragraph boundaries also.
-.PP
-Try experimenting with the sentence and paragraph commands until you are
-sure how they work. If you have a large document, try looking through
-it using the section commands.
-The section commands interpret a preceding count as a different window size in
-which to redraw the screen at the new location, and this window size
-is the base size for newly drawn windows until another size is specified.
-This is very useful
-if you are on a slow terminal and are looking for a particular section.
-You can give the first section command a small count to then see each successive
-section heading in a small window.
-.NH 2
-Rearranging and duplicating text
-.PP
-The editor has a single unnamed buffer where the last deleted or
-changed away text is saved, and a set of named buffers \fBa\fR\-\fBz\fR
-which you can use to save copies of text and to move text around in
-your file and between files.
-.PP
-The operator
-.B y
-yanks a copy of the object which follows into the unnamed buffer.
-If preceded by a buffer name, \fB"\fR\fIx\fR\|\fBy\fR, where
-\fIx\fR here is replaced by a letter \fBa\-z\fR, it places the text in the named
-buffer. The text can then be put back in the file with the commands
-.B p
-and
-.B P;
-\fBp\fR puts the text after or below the cursor, while \fBP\fR puts the text
-before or above the cursor.
-.PP
-If the text which you
-yank forms a part of a line, or is an object such as a sentence which
-partially spans more than one line, then when you put the text back,
-it will be placed after the cursor (or before if you
-use \fBP\fR). If the yanked text forms whole lines, they will be put
-back as whole lines, without changing the current line. In this case,
-the put acts much like a \fBo\fR or \fBO\fR command.
-.PP
-Try the command \fBYP\fR. This makes a copy of the current line and
-leaves you on this copy, which is placed before the current line.
-The command \fBY\fR is a convenient abbreviation for \fByy\fR.
-The command \fBYp\fR will also make a copy of the current line, and place
-it after the current line. You can give \fBY\fR a count of lines to
-yank, and thus duplicate several lines; try \fB3YP\fR.
-.PP
-To move text within the buffer, you need to delete it in one place, and
-put it back in another. You can precede a delete operation by the
-name of a buffer in which the text is to be stored as in \fB"a5dd\fR
-deleting 5 lines into the named buffer \fIa\fR. You can then move the
-cursor to the eventual resting place of the these lines and do a \fB"ap\fR
-or \fB"aP\fR to put them back.
-In fact, you can switch and edit another file before you put the lines
-back, by giving a command of the form \fB:e \fR\fIname\fR\s-2CR\s0 where
-\fIname\fR is the name of the other file you want to edit. You will
-have to write back the contents of the current editor buffer (or discard
-them) if you have made changes before the editor will let you switch
-to the other file.
-An ordinary delete command saves the text in the unnamed buffer,
-so that an ordinary put can move it elsewhere.
-However, the unnamed buffer is lost when you change files,
-so to move text from one file to another you should use an unnamed buffer.
-.NH 2
-Summary.
-.IP
-.TS
-lw(.50i)b a.
-\(ua first non-white on line
-$ end of line
-) forward sentence
-} forward paragraph
-]] forward section
-( backward sentence
-{ backward paragraph
-[[ backward section
-f\fIx\fR find \fIx\fR forward in line
-p put text back, after cursor or below current line
-y yank operator, for copies and moves
-t\fIx\fR up to \fIx\fR forward, for operators
-F\fIx\fR f backward in line
-P put text back, before cursor or above current line
-T\fIx\fR t backward in line
-.TE
-.NH 1
-High level commands
-.NH 2
-Writing, quitting, editing new files
-.PP
-So far we have seen how to enter
-.I vi
-and to write out our file using either
-\fBZZ\fR or \fB:w\fR\s-2CR\s0. The first exits from
-the editor,
-(writing if changes were made),
-the second writes and stays in the editor.
-.PP
-If you have changed the editor's copy of the file but do not wish to
-save your changes, either because you messed up the file or decided that the
-changes are not an improvement to the file, then you can give the command
-\fB:q!\fR\s-2CR\s0 to quit from the editor without writing the changes.
-You can also reedit the same file (starting over) by giving the command
-\fB:e!\fR\s-2CR\s0. These commands should be used only rarely, and with
-caution, as it is not possible to recover the changes you have made after
-you discard them in this manner.
-.PP
-You can edit a different file without leaving the editor by giving the
-command \fB:e\fR\ \fIname\fR\s-2CR\s0. If you have not written out
-your file before you try to do this, then the editor will tell you this,
-and delay editing the other file. You can then give the command
-\fB:w\fR\s-2CR\s0 to save your work and then the \fB:e\fR\ \fIname\fR\s-2CR\s0
-command again, or carefully give the command \fB:e!\fR\ \fIname\fR\s-2CR\s0,
-which edits the other file discarding the changes you have made to the
-current file.
-To have the editor automatically save changes,
-include
-.I "set autowrite"
-in your EXINIT,
-and use \fB:n\fP instead of \fB:e\fP.
-.NH 2
-Escaping to a shell
-.PP
-You can get to a shell to execute a single command by giving a
-.I vi
-command of the form \fB:!\fIcmd\fR\s-2CR\s0.
-The system will run the single command
-.I cmd
-and when the command finishes, the editor will ask you to hit a \s-2RETURN\s0
-to continue. When you have finished looking at the output on the screen,
-you should hit \s-2RETURN\s0 and the editor will clear the screen and
-redraw it. You can then continue editing.
-You can also give another \fB:\fR command when it asks you for a \s-2RETURN\s0;
-in this case the screen will not be redrawn.
-.PP
-If you wish to execute more than one command in the shell, then you can
-give the command \fB:sh\fR\s-2CR\s0.
-This will give you a new shell, and when you finish with the shell, ending
-it by typing a \fB^D\fR, the editor will clear the screen and continue.
-.PP
-On systems which support it, \fB^Z\fP will suspend the editor
-and return to the (top level) shell.
-When the editor is resumed, the screen will be redrawn.
-.NH 2
-Marking and returning
-.PP
-The command \fB\(ga\(ga\fR returned to the previous place
-after a motion of the cursor by a command such as \fB/\fR, \fB?\fR or
-\fBG\fR. You can also mark lines in the file with single letter tags
-and return to these marks later by naming the tags. Try marking the
-current line with the command \fBm\fR\fIx\fR, where you should pick some
-letter for \fIx\fR, say `a'. Then move the cursor to a different line
-(any way you like) and hit \fB\(gaa\fR. The cursor will return to the
-place which you marked.
-Marks last only until you edit another file.
-.PP
-When using operators such as
-.B d
-and referring to marked lines, it is often desirable to delete whole lines
-rather than deleting to the exact position in the line marked by \fBm\fR.
-In this case you can use the form \fB\(aa\fR\fIx\fR rather than
-\fB\(ga\fR\fIx\fR. Used without an operator, \fB\(aa\fR\fIx\fR will move to
-the first non-white character of the marked line; similarly \fB\(aa\(aa\fR
-moves to the first non-white character of the line containing the previous
-context mark \fB\(ga\(ga\fR.
-.NH 2
-Adjusting the screen
-.PP
-If the screen image is messed up because of a transmission error to your
-terminal, or because some program other than the editor wrote output
-to your terminal, you can hit a \fB^L\fR, the \s-2ASCII\s0 form-feed
-character, to cause the screen to be refreshed.
-.PP
-On a dumb terminal, if there are @ lines in the middle of the screen
-as a result of line deletion, you may get rid of these lines by typing
-\fB^R\fR to cause the editor to retype the screen, closing up these holes.
-.PP
-Finally, if you wish to place a certain line on the screen at the top
-middle or bottom of the screen, you can position the cursor to that line,
-and then give a \fBz\fR command.
-You should follow the \fBz\fR command with a \s-2RETURN\s0 if you want
-the line to appear at the top of the window, a \fB.\fR if you want it
-at the center, or a \fB\-\fR if you want it at the bottom.
-.NH 1
-Special topics
-.NH 2
-Editing on slow terminals
-.PP
-When you are on a slow terminal, it is important to limit the amount
-of output which is generated to your screen so that you will not suffer
-long delays, waiting for the screen to be refreshed. We have already
-pointed out how the editor optimizes the updating of the screen during
-insertions on dumb terminals to limit the delays, and how the editor erases
-lines to @ when they are deleted on dumb terminals.
-.PP
-The use of the slow terminal insertion mode is controlled by the
-.I slowopen
-option. You can force the editor to use this mode even on faster terminals
-by giving the command \fB:se slow\fR\s-2CR\s0. If your system is sluggish
-this helps lessen the amount of output coming to your terminal.
-You can disable this option by \fB:se noslow\fR\s-2CR\s0.
-.PP
-The editor can simulate an intelligent terminal on a dumb one. Try
-giving the command \fB:se redraw\fR\s-2CR\s0. This simulation generates
-a great deal of output and is generally tolerable only on lightly loaded
-systems and fast terminals. You can disable this by giving the command
- \fB:se noredraw\fR\s-2CR\s0.
-.PP
-The editor also makes editing more pleasant at low speed by starting
-editing in a small window, and letting the window expand as you edit.
-This works particularly well on intelligent terminals. The editor can
-expand the window easily when you insert in the middle of the screen
-on these terminals. If possible, try the editor on an intelligent terminal
-to see how this works.
-.PP
-You can control the size of the window which is redrawn each time the
-screen is cleared by giving window sizes as argument to the commands
-which cause large screen motions:
-.DS
-.B ": / ? [[ ]] \(ga \(aa"
-.DE
-Thus if you are searching for a particular instance of a common string
-in a file you can precede the first search command by a small number,
-say 3, and the editor will draw three line windows around each instance
-of the string which it locates.
-.PP
-You can easily expand or contract the window, placing the current line
-as you choose, by giving a number on a \fBz\fR command, after the \fBz\fR
-and before the following \s-2RETURN\s0, \fB.\fR or \fB\-\fR. Thus the
-command \fBz5.\fR redraws the screen with the current line in the center
-of a five line window.\*(dg
-.FS
-\*(dg Note that the command \fB5z.\fR has an entirely different effect,
-placing line 5 in the center of a new window.
-.FE
-.PP
-If the editor is redrawing or otherwise updating large portions of the
-display, you can interrupt this updating by hitting a \s-2DEL\s0 or \s-2RUB\s0
-as usual. If you do this you may partially confuse the editor about
-what is displayed on the screen. You can still edit the text on
-the screen if you wish; clear up the confusion
-by hitting a \fB^L\fR; or move or search again, ignoring the
-current state of the display.
-.PP
-See section 7.8 on \fIopen\fR mode for another way to use the
-.I vi
-command set on slow terminals.
-.NH 2
-Options, set, and editor startup files
-.PP
-The editor has a set of options, some of which have been mentioned above.
-The most useful options are given in the following table.
-.KF
-.TS
-lb lb lb lb
-l l l a.
-Name Default Description
-_
-autoindent noai Supply indentation automatically
-autowrite noaw Automatic write before \fB:n\fR, \fB:ta\fR, \fB^\(ua\fR, \fB!\fR
-ignorecase noic Ignore case in searching
-lisp nolisp \fB( { ) }\fR commands deal with S-expressions
-list nolist Tabs print as ^I; end of lines marked with $
-magic nomagic The characters . [ and * are special in scans
-number nonu Lines are displayed prefixed with line numbers
-paragraphs para=IPLPPPQPbpP LI Macro names which start paragraphs
-redraw nore Simulate a smart terminal on a dumb one
-sections sect=NHSHH HU Macro names which start new sections
-shiftwidth sw=8 Shift distance for <, > and input \fB^D\fP and \fB^T\fR
-showmatch nosm Show matching \fB(\fP or \fB{\fP as \fB)\fP or \fB}\fR is typed
-slowopen slow Postpone display updates during inserts
-term dumb The kind of terminal you are using.
-.TE
-.KE
-.PP
-The options are of three kinds: numeric options, string options, and
-toggle options. You can set numeric and string options by a statement
-of the form
-.DS
-\fBset\fR \fIopt\fR\fB=\fR\fIval\fR
-.DE
-and toggle options can be set or unset by statements of one of the forms
-.DS
-\fBset\fR \fIopt\fR
-\fBset\fR \fBno\fR\fIopt\fR
-.DE
-These statements can be placed in your EXINIT in your environment,
-or given while you are running
-.I vi
-by preceding them with a \fB:\fR and following them with a \s-2CR\s0.
-.PP
-You can get a list of all options which you have changed by the
-command \fB:set\fR\s-2CR\s0, or the value of a single option by the
-command \fB:set\fR \fIopt\fR\fB?\fR\s-2CR\s0.
-A list of all possible options and their values is generated by
-\fB:set all\fP\s-2CR\s0.
-Set can be abbreviated \fBse\fP.
-Multiple options can be placed on one line, e.g.
-\fB:se ai aw nu\fP\s-2CR\s0.
-.PP
-Options set by the \fBset\fP command only last
-while you stay in the editor.
-It is common to want to have certain options set whenever you
-use the editor.
-This can be accomplished by creating a list of \fIex\fP commands\*(dg
-.FS
-\*(dg
-All commands which start with
-.B :
-are \fIex\fP commands.
-.FE
-which are to be run every time you start up \fIex\fP, \fIedit\fP,
-or \fIvi\fP.
-A typical list includes a \fBset\fP command, and possibly a few
-\fBmap\fP commands.
-Since it is advisable to get these commands on one line, they can
-be separated with the | character, for example:
-.DS
-\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x
-.DE
-which sets the options \fIautoindent\fP, \fIautowrite\fP, \fIterse\fP,
-(the
-.B set
-command),
-makes @ delete a line,
-(the first
-.B map ),
-and makes # delete a character,
-(the second
-.B map ).
-(See section 6.9 for a description of the \fBmap\fP command)
-This string should be placed in the variable EXINIT in your environment.
-If you use the shell \fIcsh\fP,
-put this line in the file
-.I .login
-in your home directory:
-.DS
-setenv EXINIT \(aa\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x\(aa
-.DE
-If you use the standard shell \fIsh\fP,
-put these lines in the file
-.I .profile
-in your home directory:
-.DS
-EXINIT=\(aa\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x\(aa
-export EXINIT
-.DE
-Of course, the particulars of the line would depend on which options
-you wanted to set.
-.NH 2
-Recovering lost lines
-.PP
-You might have a serious problem if you delete a number of lines and then
-regret that they were deleted. Despair not, the editor saves the last
-9 deleted blocks of text in a set of numbered registers 1\-9.
-You can get the \fIn\fR'th previous deleted text back in your file by
-the command
-"\fR\fIn\fR\|\fBp\fR.
-The "\fR here says that a buffer name is to follow,
-\fIn\fR is the number of the buffer you wish to try
-(use the number 1 for now),
-and
-.B p
-is the put command, which puts text in the buffer after the cursor.
-If this doesn't bring back the text you wanted, hit
-.B u
-to undo this and then
-\fB\&.\fR
-(period)
-to repeat the put command.
-In general the
-\fB\&.\fR
-command will repeat the last change you made.
-As a special case, when the last command refers to a numbered text buffer,
-the \fB.\fR command increments the number of the buffer before repeating
-the command. Thus a sequence of the form
-.DS
-\fB"1pu.u.u.\fR
-.DE
-will, if repeated long enough, show you all the deleted text which has
-been saved for you.
-You can omit the
-.B u
-commands here to gather up all this text in the buffer, or stop after any
-\fB\&.\fR command to keep just the then recovered text.
-The command
-.B P
-can also be used rather than
-.B p
-to put the recovered text before rather than after the cursor.
-.NH 2
-Recovering lost files
-.PP
-If the system crashes, you can recover the work you were doing
-to within a few changes. You will normally receive mail when you next
-login giving you the name of the file which has been saved for you.
-You should then change to the directory where you were when the system
-crashed and give a command of the form:
-.DS
-% \fBvi \-r\fR \fIname\fR
-.DE
-replacing \fIname\fR with the name of the file which you were editing.
-This will recover your work to a point near where you left off.\*(dg
-.FS
-\*(dg In rare cases, some of the lines of the file may be lost. The
-editor will give you the numbers of these lines and the text of the lines
-will be replaced by the string `LOST'. These lines will almost always
-be among the last few which you changed. You can either choose to discard
-the changes which you made (if they are easy to remake) or to replace
-the few lost lines by hand.
-.FE
-.PP
-You can get a listing of the files which are saved for you by giving
-the command:
-.DS
-% \fBvi \-r\fR
-.DE
-If there is more than one instance of a particular file saved, the editor
-gives you the newest instance each time you recover it. You can thus
-get an older saved copy back by first recovering the newer copies.
-.PP
-For this feature to work,
-.I vi
-must be correctly installed by a super user on your system,
-and the
-.I mail
-program must exist to receive mail.
-The invocation ``\fIvi -r\fP'' will not always list all saved files,
-but they can be recovered even if they are not listed.
-.NH 2
-Continuous text input
-.PP
-When you are typing in large amounts of text it is convenient to have
-lines broken near the right margin automatically. You can cause this
-to happen by giving the command
-\fB:se wm=10\fR\s-2CR\s0.
-This causes all lines to be broken at a space at least 10 columns
-from the right hand edge of the screen.
-.PP
-If the editor breaks an input line and you wish to put it back together
-you can tell it to join the lines with \fBJ\fR. You can give \fBJ\fR
-a count of the number of lines to be joined as in \fB3J\fR to join 3
-lines. The editor supplies white space, if appropriate,
-at the juncture of the joined
-lines, and leaves the cursor at this white space.
-You can kill the white space with \fBx\fR if you don't want it.
-.NH 2
-Features for editing programs
-.PP
-The editor has a number of commands for editing programs.
-The thing that most distinguishes editing of programs from editing of text
-is the desirability of maintaining an indented structure to the body of
-the program. The editor has a
-.I autoindent
-facility for helping you generate correctly indented programs.
-.PP
-To enable this facility you can give the command \fB:se ai\fR\s-2CR\s0.
-Now try opening a new line with \fBo\fR and type some characters on the
-line after a few tabs. If you now start another line, notice that the
-editor supplies white space at the beginning of the line to line it up
-with the previous line. You cannot backspace over this indentation,
-but you can use \fB^D\fR key to backtab over the supplied indentation.
-.PP
-Each time you type \fB^D\fR you back up one position, normally to an
-8 column boundary. This amount is settable; the editor has an option
-called
-.I shiftwidth
-which you can set to change this value.
-Try giving the command \fB:se sw=4\fR\s-2CR\s0
-and then experimenting with autoindent again.
-.PP
-For shifting lines in the program left and right, there are operators
-.B <
-and
-.B >.
-These shift the lines you specify right or left by one
-.I shiftwidth.
-Try
-.B <<
-and
-.B >>
-which shift one line left or right, and
-.B <L
-and
-.B >L
-shifting the rest of the display left and right.
-.PP
-If you have a complicated expression and wish to see how the parentheses
-match, put the cursor at a left or right parenthesis and hit \fB%\fR.
-This will show you the matching parenthesis.
-This works also for braces { and }, and brackets [ and ].
-.PP
-If you are editing C programs, you can use the \fB[[\fR and \fB]]\fR keys
-to advance or retreat to a line starting with a \fB{\fR, i.e. a function
-declaration at a time. When \fB]]\fR is used with an operator it stops
-after a line which starts with \fB}\fR; this is sometimes useful with
-\fBy]]\fR.
-.NH 2
-Filtering portions of the buffer
-.PP
-You can run system commands over portions of the buffer using the operator
-\fB!\fR.
-You can use this to sort lines in the buffer, or to reformat portions
-of the buffer with a pretty-printer.
-Try typing in a list of random words, one per line and ending them
-with a blank line. Back up to the beginning of the list, and then give
-the command \fB!}sort\fR\s-2CR\s0. This says to sort the next paragraph
-of material, and the blank line ends a paragraph.
-.NH 2
-Commands for editing \s-2LISP\s0
-.PP
-If you are editing a \s-2LISP\s0 program you should set the option
-.I lisp
-by doing
-\fB:se\ lisp\fR\s-2CR\s0.
-This changes the \fB(\fR and \fB)\fR commands to move backward and forward
-over s-expressions.
-The \fB{\fR and \fB}\fR commands are like \fB(\fR and \fB)\fR but don't
-stop at atoms. These can be used to skip to the next list, or through
-a comment quickly.
-.PP
-The
-.I autoindent
-option works differently for \s-2LISP\s0, supplying indent to align at
-the first argument to the last open list. If there is no such argument
-then the indent is two spaces more than the last level.
-.PP
-There is another option which is useful for typing in \s-2LISP\s0, the
-.I showmatch
-option.
-Try setting it with
-\fB:se sm\fR\s-2CR\s0
-and then try typing a `(' some words and then a `)'. Notice that the
-cursor shows the position of the `(' which matches the `)' briefly.
-This happens only if the matching `(' is on the screen, and the cursor
-stays there for at most one second.
-.PP
-The editor also has an operator to realign existing lines as though they
-had been typed in with
-.I lisp
-and
-.I autoindent
-set. This is the \fB=\fR operator.
-Try the command \fB=%\fR at the beginning of a function. This will realign
-all the lines of the function declaration.
-.PP
-When you are editing \s-2LISP\s0,, the \fB[[\fR and \fR]]\fR advance
-and retreat to lines beginning with a \fB(\fR, and are useful for dealing
-with entire function definitions.
-.NH 2
-Macros
-.PP
-.I Vi
-has a parameterless macro facility, which lets you set it up so that
-when you hit a single keystroke, the editor will act as though
-you had hit some longer sequence of keys. You can set this up if
-you find yourself typing the same sequence of commands repeatedly.
-.PP
-Briefly, there are two flavors of macros:
-.IP a)
-Ones where you put the macro body in a buffer register, say \fIx\fR.
-You can then type \fB@x\fR to invoke the macro. The \fB@\fR may be followed
-by another \fB@\fR to repeat the last macro.
-.IP b)
-You can use the
-.I map
-command from
-.I vi
-(typically in your
-.I EXINIT )
-with a command of the form:
-.DS
-:map \fIlhs\fR \fIrhs\fR\s-2CR\f0
-.DE
-mapping
-.I lhs
-into
-.I rhs.
-There are restrictions:
-.I lhs
-should be one keystroke (either 1 character or one function key)
-since it must be entered within one second
-(unless
-.I notimeout
-is set, in which case you can type it as slowly as you wish,
-and
-.I vi
-will wait for you to finish it before it echoes anything).
-The
-.I lhs
-can be no longer than 10 characters, the
-.I rhs
-no longer than 100.
-To get a space, tab or newline into
-.I lhs
-or
-.I rhs
-you should escape them with a \fB^V\fR.
-(It may be necessary to double the \fB^V\fR if the map
-command is given inside
-.I vi,
-rather than in
-.I ex.)
-Spaces and tabs inside the
-.I rhs
-need not be escaped.
-.PP
-Thus to make the \fBq\fR key write and exit the editor, you can give
-the command
-.DS
-:map q :wq\fB^V^V\fP\s-2CR CR\s0
-.DE
-which means that whenever you type \fBq\fR, it will be as though you
-had typed the four characters \fB:wq\fR\s-2CR\s0.
-A \fB^V\fR's is needed because without it the \s-2CR\s0 would end the
-\fB:\fR command, rather than becoming part of the
-.I map
-definition.
-There are two
-.B ^V 's
-because from within
-.I vi ,
-two
-.B ^V 's
-must be typed to get one.
-The first \s-2CR\s0 is part of the
-.I rhs ,
-the second terminates the : command.
-.PP
-Macros can be deleted with
-.DS
-unmap lhs
-.DE
-.PP
-If the
-.I lhs
-of a macro is ``#0'' through ``#9'', this maps the particular function key
-instead of the 2 character ``#'' sequence. So that terminals without
-function keys can access such definitions, the form ``#x'' will mean function
-key
-.I x
-on all terminals (and need not be typed within one second.)
-The character ``#'' can be changed by using a macro in the usual way:
-.DS
-:map \fB^V^V^I\fP #
-.DE
-to use tab, for example. (This won't affect the
-.I map
-command, which still uses
-.B #,
-but just the invocation from visual mode.
-.PP
-The undo command reverses an entire macro call as a unit,
-if it made any changes.
-.PP
-Placing a `!' after the word
-.B map
-causes the mapping to apply
-to input mode, rather than command mode.
-Thus, to arrange for \fB^T\fP to be the same as 4 spaces in input mode,
-you can type:
-.DS
-:map \fB^T\fP \fB^V\fP\o'b/'\o'b/'\o'b/'\o'b/'
-.DE
-where
-.B \o'b/'
-is a blank.
-The \fB^V\fP is necessary to prevent the blanks from being taken as
-white space between the
-.I lhs
-and
-.I rhs .
-.NH
-Word Abbreviations
-.PP
-A feature similar to macros in input mode is word abbreviation.
-This allows you to type a short word and have it expanded into
-a longer word or words.
-The commands are
-.B :abbreviate
-and
-.B :unabbreviate
-(\fB:ab\fP
-and
-.B :una )
-and have the same syntax as
-.B :map .
-For example:
-.DS
-:ab eecs Electrical Engineering and Computer Sciences
-.DE
-causes the word `eecs' to always be changed into the
-phrase `Electrical Engineering and Computer Sciences'.
-Word abbreviation is different from macros in that
-only whole words are affected.
-If `eecs' were typed as part of a larger word, it would
-be left alone.
-Also, the partial word is echoed as it is typed.
-There is no need for an abbreviation to be a single keystroke,
-as it should be with a macro.
-.NH 2
-Abbreviations
-.PP
-The editor has a number of short
-commands which abbreviate longer commands which we
-have introduced here. You can find these commands easily
-on the quick reference card.
-They often save a bit of typing and you can learn them as convenient.
-.NH 1
-Nitty-gritty details
-.NH 2
-Line representation in the display
-.PP
-The editor folds long logical lines onto many physical lines in the display.
-Commands which advance lines advance logical lines and will skip
-over all the segments of a line in one motion. The command \fB|\fR moves
-the cursor to a specific column, and may be useful for getting near the
-middle of a long line to split it in half. Try \fB80|\fR on a line which
-is more than 80 columns long.\*(dg
-.FS
-\*(dg You can make long lines very easily by using \fBJ\fR to join together
-short lines.
-.FE
-.PP
-The editor only puts full lines on the display; if there is not enough
-room on the display to fit a logical line, the editor leaves the physical
-line empty, placing only an @ on the line as a place holder. When you
-delete lines on a dumb terminal, the editor will often just clear the
-lines to @ to save time (rather than rewriting the rest of the screen.)
-You can always maximize the information on the screen by giving the \fB^R\fR
-command.
-.PP
-If you wish, you can have the editor place line numbers before each line
-on the display. Give the command \fB:se nu\fR\s-2CR\s0 to enable
-this, and the command \fB:se nonu\fR\s-2CR\s0 to turn it off.
-You can have tabs represented as \fB^I\fR and the ends of lines indicated
-with `$' by giving the command \fB:se list\fR\s-2CR\s0;
-\fB:se nolist\fR\s-2CR\s0 turns this off.
-.PP
-Finally, lines consisting of only the character `~' are displayed when
-the last line in the file is in the middle of the screen. These represent
-physical lines which are past the logical end of file.
-.NH 2
-Counts
-.PP
-Most
-.I vi
-commands will use a preceding count to affect their behavior in some way.
-The following table gives the common ways in which the counts are used:
-.DS
-.TS
-l lb.
-new window size : / ? [[ ]] \` \'
-scroll amount ^D ^U
-line/column number z G |
-repeat effect \fRmost of the rest\fP
-.TE
-.DE
-.PP
-The editor maintains a notion of the current default window size.
-On terminals which run at speeds greater than 1200 baud
-the editor uses the full terminal screen.
-On terminals which are slower than 1200 baud
-(most dialup lines are in this group)
-the editor uses 8 lines as the default window size.
-At 1200 baud the default is 16 lines.
-.PP
-This size is the size used when the editor clears and refills the screen
-after a search or other motion moves far from the edge of the current window.
-The commands which take a new window size as count all often cause the
-screen to be redrawn. If you anticipate this, but do not need as large
-a window as you are currently using, you may wish to change the screen
-size by specifying the new size before these commands.
-In any case, the number of lines used on the screen will expand if you
-move off the top with a \fB\-\fR or similar command or off the bottom
-with a command such as \s-2RETURN\s0 or \fB^D\fR.
-The window will revert to the last specified size the next time it is
-cleared and refilled.\*(dg
-.FS
-\*(dg But not by a \fB^L\fR which just redraws the screen as it is.
-.FE
-.PP
-The scroll commands \fB^D\fR and \fB^U\fR likewise remember the amount
-of scroll last specified, using half the basic window size initially.
-The simple insert commands use a count to specify a repetition of the
-inserted text. Thus \fB10a+\-\-\-\-\fR\s-2ESC\s0 will insert a grid-like
-string of text.
-A few commands also use a preceding count as a line or column number.
-.PP
-Except for a few commands which ignore any counts (such as \fB^R\fR),
-the rest of the editor commands use a count to indicate a simple repetition
-of their effect. Thus \fB5w\fR advances five words on the current line,
-while \fB5\fR\s-2RETURN\s0 advances five lines. A very useful instance
-of a count as a repetition is a count given to the \fB.\fR command, which
-repeats the last changing command. If you do \fBdw\fR and then \fB3.\fR,
-you will delete first one and then three words. You can then delete
-two more words with \fB2.\fR.
-.NH 2
-More file manipulation commands
-.PP
-The following table lists the file manipulation commands which you can
-use when you are in
-.I vi.
-.KF
-.DS
-.TS
-lb l.
-:w write back changes
-:wq write and quit
-:x write (if necessary) and quit (same as ZZ).
-:e \fIname\fP edit file \fIname\fR
-:e! reedit, discarding changes
-:e + \fIname\fP edit, starting at end
-:e +\fIn\fP edit, starting at line \fIn\fP
-:e # edit alternate file
-:w \fIname\fP write file \fIname\fP
-:w! \fIname\fP overwrite file \fIname\fP
-:\fIx,y\fPw \fIname\fP write lines \fIx\fP through \fIy\fP to \fIname\fP
-:r \fIname\fP read file \fIname\fP into buffer
-:r !\fIcmd\fP read output of \fIcmd\fP into buffer
-:n edit next file in argument list
-:n! edit next file, discarding changes to current
-:n \fIargs\fP specify new argument list
-:ta \fItag\fP edit file containing tag \fItag\fP, at \fItag\fP
-.TE
-.DE
-.KE
-All of these commands are followed by a \s-2CR\s0 or \s-2ESC\s0.
-The most basic commands are \fB:w\fR and \fB:e\fR.
-A normal editing session on a single file will end with a \fBZZ\fR command.
-If you are editing for a long period of time you can give \fB:w\fR commands
-occasionally after major amounts of editing, and then finish
-with a \fBZZ\fR. When you edit more than one file, you can finish
-with one with a \fB:w\fR and start editing a new file by giving a \fB:e\fR
-command,
-or set
-.I autowrite
-and use \fB:n\fP <file>.
-.PP
-If you make changes to the editor's copy of a file, but do not wish to
-write them back, then you must give an \fB!\fR after the command you
-would otherwise use; this forces the editor to discard any changes
-you have made. Use this carefully.
-.PP
-The \fB:e\fR command can be given a \fB+\fR argument to start at the
-end of the file, or a \fB+\fR\fIn\fR argument to start at line \fIn\fR\^.
-In actuality, \fIn\fR may be any editor command not containing a space,
-usefully a scan like \fB+/\fIpat\fR or \fB+?\fIpat\fR.
-In forming new names to the \fBe\fR command, you can use the character
-\fB%\fR which is replaced by the current file name, or the character
-\fB#\fR which is replaced by the alternate file name.
-The alternate file name is generally the last name you typed other than
-the current file. Thus if you try to do a \fB:e\fR and get a diagnostic
-that you haven't written the file, you can give a \fB:w\fR command and
-then a \fB:e #\fR command to redo the previous \fB:e\fR.
-.PP
-You can write part of the buffer to a file by finding out the lines
-that bound the range to be written using \fB^G\fR, and giving these
-numbers after the \fB:\fR
-and before the \fBw\fP, separated by \fB,\fR's.
-You can also mark these lines with \fBm\fR and
-then use an address of the form \fB\(aa\fR\fIx\fR\fB,\fB\(aa\fR\fIy\fR
-on the \fBw\fR command here.
-.PP
-You can read another file into the buffer after the current line by using
-the \fB:r\fR command.
-You can similarly read in the output from a command, just use \fB!\fR\fIcmd\fR
-instead of a file name.
-.PP
-If you wish to edit a set of files in succession, you can give all the
-names on the command line, and then edit each one in turn using the command
-\fB:n\fR. It is also possible to respecify the list of files to be edited
-by giving the \fB:n\fR command a list of file names, or a pattern to
-be expanded as you would have given it on the initial
-.I vi
-command.
-.PP
-If you are editing large programs, you will find the \fB:ta\fR command
-very useful. It utilizes a data base of function names and their locations,
-which can be created by programs such as
-.I ctags,
-to quickly find a function whose name you give.
-If the \fB:ta\fR command will require the editor to switch files, then
-you must \fB:w\fR or abandon any changes before switching. You can repeat
-the \fB:ta\fR command without any arguments to look for the same tag
-again.
-.NH 2
-More about searching for strings
-.PP
-When you are searching for strings in the file with \fB/\fR and \fB?\fR,
-the editor normally places you at the next or previous occurrence
-of the string. If you are using an operator such as \fBd\fR,
-\fBc\fR or \fBy\fR, then you may well wish to affect lines up to the
-line before the line containing the pattern. You can give a search of
-the form \fB/\fR\fIpat\fR\fB/\-\fR\fIn\fR to refer to the \fIn\fR'th line
-before the next line containing \fIpat\fR, or you can use \fB\+\fR instead
-of \fB\-\fR to refer to the lines after the one containing \fIpat\fR.
-If you don't give a line offset, then the editor will affect characters
-up to the match place, rather than whole lines; thus use ``+0'' to affect
-to the line which matches.
-.PP
-You can have the editor ignore the case of words in the searches it does
-by giving the command \fB:se ic\fR\s-2CR\s0.
-The command \fB:se noic\fR\s-2CR\s0 turns this off.
-.PP
-Strings given to searches may actually be regular expressions.
-If you do not want or need this facility, you should
-.DS
-set nomagic
-.DE
-in your EXINIT.
-In this case,
-only the characters \fB\(ua\fR and \fB$\fR are special in patterns.
-The character \fB\e\fR is also then special (as it is most everywhere in
-the system), and may be used to get at the
-an extended pattern matching facility.
-It is also necessary to use a \e before a
-\fB/\fR in a forward scan or a \fB?\fR in a backward scan, in any case.
-The following table gives the extended forms when \fBmagic\fR is set.
-.DS
-.TS
-bl l.
-\(ua at beginning of pattern, matches beginning of line
-$ at end of pattern, matches end of line
-\fB\&.\fR matches any character
-\e< matches the beginning of a word
-\e> matches the end of a word
-[\fIstr\fP] matches any single character in \fIstr\fP
-[\(ua\fIstr\fP] matches any single character not in \fIstr\fP
-[\fIx\fP\-\fIy\fP] matches any character between \fIx\fP and \fIy\fP
-* matches any number of the preceding pattern
-.TE
-.DE
-If you use \fBnomagic\fR mode, then
-the \fB. [\fR and \fB*\fR primitives are given with a preceding
-\e.
-.NH 2
-More about input mode
-.PP
-There are a number of characters which you can use to make corrections
-during input mode. These are summarized in the following table.
-.DS
-.TS
-lb l.
-^H deletes the last input character
-^W deletes the last input word, defined as by \fBb\fR
-erase your erase character, same as \fB^H\fP
-kill your kill character, deletes the input on this line
-\e escapes a following \fB^H\fP and your erase and kill
-\s-2ESC\s0 ends an insertion
-\s-2DEL\s0 interrupts an insertion, terminating it abnormally
-\s-2CR\s0 starts a new line
-^D backtabs over \fIautoindent\fP
-0^D kills all the \fIautoindent\fP
-\(ua^D same as \fB0^D\fP, but restores indent next line
-^V quotes the next non-printing character into the file
-.TE
-.DE
-.PP
-The most usual way of making corrections to input is by typing \fB^H\fR
-to correct a single character, or by typing one or more \fB^W\fR's to
-back over incorrect words. If you use \fB#\fR as your erase character
-in the normal system, it will work like \fB^H\fR.
-.PP
-Your system kill character, normally \fB@\fR, \fB^X\fP or \fB^U\fR,
-will erase all
-the input you have given on the current line.
-In general, you can neither
-erase input back around a line boundary nor can you erase characters
-which you did not insert with this insertion command. To make corrections
-on the previous line after a new line has been started you can hit \s-2ESC\s0
-to end the insertion, move over and make the correction, and then return
-to where you were to continue. The command \fBA\fR which appends at the
-end of the current line is often useful for continuing.
-.PP
-If you wish to type in your erase or kill character (say # or @) then
-you must precede it with a \fB\e\fR, just as you would do at the normal
-system command level. A more general way of typing non-printing characters
-into the file is to precede them with a \fB^V\fR. The \fB^V\fR echoes
-as a \fB\(ua\fR character on which the cursor rests. This indicates that
-the editor expects you to type a control character. In fact you may
-type any character and it will be inserted into the file at that point.*
-.FS
-* This is not quite true. The implementation of the editor does
-not allow the \s-2NULL\s0 (\fB^@\fR) character to appear in files. Also
-the \s-2LF\s0 (linefeed or \fB^J\fR) character is used by the editor
-to separate lines in the file, so it cannot appear in the middle of a
-line. You can insert any other character, however, if you wait for the
-editor to echo the \fB\(ua\fR before you type the character. In fact,
-the editor will treat a following letter as a request for the corresponding
-control character. This is the only way to type \fB^S\fR or \fB^Q\fP,
-since the system normally uses them to suspend and resume output
-and never gives them to the editor to process.
-.FE
-.PP
-If you are using \fIautoindent\fR you can backtab over the indent which
-it supplies by typing a \fB^D\fR. This backs up to a \fIshiftwidth\fR
-boundary.
-This only works immediately after the supplied \fIautoindent\fR.
-.PP
-When you are using \fIautoindent\fR you may wish to place a label at
-the left margin of a line. The way to do this easily is to type \fB\(ua\fR
-and then \fB^D\fR. The editor will move the cursor to the left margin
-for one line, and restore the previous indent on the next. You can also
-type a \fB0\fR followed immediately by a \fB^D\fR if you wish to kill
-all the indent and not have it come back on the next line.
-.NH 2
-Upper case only terminals
-.PP
-If your terminal has only upper case, you can still use
-.I vi
-by using the normal
-system convention for typing on such a terminal.
-Characters which you normally type are converted to lower case, and you
-can type upper case letters by preceding them with a \e.
-The characters { ~ } | \(ga are not available on such terminals, but you
-can escape them as \e( \e\(ua \e) \e! \e\(aa.
-These characters are represented on the display in the same way they
-are typed.\*(dd
-.FS
-\*(dd The \e character you give will not echo until you type another
-key.
-.FE
-.NH 2
-Vi and ex
-.PP
-.I Vi
-is actually one mode of editing within the editor
-.I ex.
-When you are running
-.I vi
-you can escape to the line oriented editor of
-.I ex
-by giving the command
-\fBQ\fR.
-All of the
-.B :
-commands which were introduced above are available in
-.I ex.
-Likewise, most
-.I ex
-commands can be invoked from
-.I vi
-using :.
-Just give them without the \fB:\fR and follow them with a \s-2CR\s0.
-.PP
-In rare instances, an internal error may occur in
-.I vi.
-In this case you will get a diagnostic and be left in the command mode of
-.I ex.
-You can then save your work and quit if you wish by giving a command
-\fBx\fR after the \fB:\fR which \fIex\fR prompts you with, or you can
-reenter \fIvi\fR by giving
-.I ex
-a
-.I vi
-command.
-.PP
-There are a number of things which you can do more easily in
-.I ex
-than in
-.I vi.
-Systematic changes in line oriented material are particularly easy.
-You can read the advanced editing documents for the editor
-.I ed
-to find out a lot more about this style of editing.
-Experienced
-users often mix their use of
-.I ex
-command mode and
-.I vi
-command mode to speed the work they are doing.
-.NH 2
-Open mode: vi on hardcopy terminals and ``glass tty's''
-\(dd
-.PP
-If you are on a hardcopy terminal or a terminal which does not have a cursor
-which can move off the bottom line, you can still use the command set of
-.I vi,
-but in a different mode.
-When you give a
-.I vi
-command, the editor will tell you that it is using
-.I open
-mode.
-This name comes from the
-.I open
-command in
-.I ex,
-which is used to get into the same mode.
-.PP
-The only difference between
-.I visual
-mode
-and
-.I open
-mode is the way in which the text is displayed.
-.PP
-In
-.I open
-mode the editor uses a single line window into the file, and moving backward
-and forward in the file causes new lines to be displayed, always below the
-current line.
-Two commands of
-.I vi
-work differently in
-.I open:
-.B z
-and
-\fB^R\fR.
-The
-.B z
-command does not take parameters, but rather draws a window of context around
-the current line and then returns you to the current line.
-.PP
-If you are on a hardcopy terminal,
-the
-.B ^R
-command will retype the current line.
-On such terminals, the editor normally uses two lines to represent the
-current line.
-The first line is a copy of the line as you started to edit it, and you work
-on the line below this line.
-When you delete characters, the editor types a number of \e's to show
-you the characters which are deleted. The editor also reprints the current
-line soon after such changes so that you can see what the line looks
-like again.
-.PP
-It is sometimes useful to use this mode on very slow terminals which
-can support
-.I vi
-in the full screen mode.
-You can do this by entering
-.I ex
-and using an
-.I open
-command.
-.LP
-.SH
-Acknowledgements
-.PP
-Bruce Englar encouraged the early development of this display editor.
-Peter Kessler helped bring sanity to version 2's command layout.
-Bill Joy wrote versions 1 and 2.0 through 2.7,
-and created the framework that users see in the present editor.
-Mark Horton added macros and other features and made the
-editor work on a large number of terminals and Unix systems.
diff --git a/usr.bin/vi/USD.doc/vitut/vi.summary b/usr.bin/vi/USD.doc/vitut/vi.summary
deleted file mode 100644
index a7d9938..0000000
--- a/usr.bin/vi/USD.doc/vitut/vi.summary
+++ /dev/null
@@ -1,468 +0,0 @@
-.\" Copyright (c) 1980, 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.
-.\"
-.\" @(#)vi.summary 8.1 (Berkeley) 6/8/93
-.\"
-.ds CH
-.ds CF
-.de TS
-.br
-.if !\\n(1T .RT
-.ul 0
-.ti \\n(.iu
-.if t .sp 0.25
-.if n .sp
-.if \\$1H .TQ
-.nr IX 1
-..
-.nr PS 9
-.ps 9
-.nr VS 11
-.vs 11
-.nr HM .50i
-.nr FM .25i
-.nr PO 0
-.po 0
-.nr LL 3.5i
-.ll 3.5i
-.de nc
-.bp
-..
-.de h
-.LG
-.B
-\\$1
-.R
-.NL
-..
-.LG
-.LG
-.B
-.ce
-Ex Quick Reference
-.R
-.NL
-.LP
-.LP
-.h "Entering/leaving ex"
-.TS
-aw(1.4i)b aw(1.8i).
-% ex \fIname\fP edit \fIname\fP, start at end
-% ex +\fIn\fP \fIname\fP ... at line \fIn\fP
-% ex \-t \fItag\fP start at \fItag\fP
-% ex \-r list saved files
-% ex \-r \fIname\fP recover file \fIname\fP
-% ex \fIname\fP ... edit first; rest via \fB:n\fP
-% ex \-R \fIname\fP read only mode
-: x exit, saving changes
-: q! exit, discarding changes
-.TE
-.h "Ex states"
-.TS
-lw(1i) lw(2.0i).
-Command T{
-Normal and initial state. Input prompted for by \fB:\fP.
-Your kill character cancels partial command.
-T}
-Insert T{
-Entered by \fBa\fP \fBi\fP and \fBc\fP.
-Arbitrary text then terminates with line having only \fB.\fP
-character on it or abnormally with interrupt.
-T}
-Open/visual T{
-Entered by \fBopen\fP or \fBvi\fP, terminates with \fBQ\fP
-or ^\e.
-T}
-.TE
-.h "Ex commands"
-.TS
-lw(.45i) lw(.08i)b lw(.45i) lw(.08i)b lw(.45i) lw(.08i)b.
-abbrev ab next n unabbrev una
-append a number nu undo u
-args ar open o unmap unm
-change c preserve pre version ve
-copy co print p visual vi
-delete d put pu write w
-edit e quit q xit x
-file f read re yank ya
-global g recover rec \fIwindow\fP z
-insert i rewind rew \fIescape\fP !
-join j set se \fIlshift\fP <
-list l shell sh \fIprint next\fP \fRCR\fP
-map source so \fIresubst\fP &
-mark ma stop st \fIrshift\fP >
-move m substitute s \fIscroll\fP ^D
-.TE
-.h "Ex command addresses"
-.TS
-lw(.3i)b lw(0.8i) lw(.3i)b lw(0.8i).
-\fIn\fP line \fIn\fP /\fIpat\fP next with \fIpat\fP
-\&. current ?\fIpat\fP previous with \fIpat\fP
-$ last \fIx\fP-\fIn\fP \fIn\fP before \fIx\fP
-+ next \fIx\fP,\fIy\fP \fIx\fP through \fIy\fP
-\- previous \(aa\fIx\fP marked with \fIx\fP
-+\fIn\fP \fIn\fP forward \(aa\(aa previous context
-% 1,$
-.TE
-.nc
-.h "Specifying terminal type"
-.TS
-aw(1.7i)b aw(1.5i).
-% setenv TERM \fItype\fP \fIcsh\fP and all version 6
-$ TERM=\fItype\fP; export TERM \fIsh\fP in Version 7
-See also \fItset\fR(1)
-.TE
-.h "Some terminal types"
-.TS
-lw(.4i) lw(.4i) lw(.4i) lw(.4i) lw(.4i).
-2621 43 adm31 dw1 h19
-2645 733 adm3a dw2 i100
-300s 745 c100 gt40 mime
-33 act4 dm1520 gt42 owl
-37 act5 dm2500 h1500 t1061
-4014 adm3 dm3025 h1510 vt52
-.TE
-.h "Initializing options"
-.TS
-lw(.9i)b aw(1.5i).
-EXINIT place \fBset\fP's here in environment var.
-set \fIx\fP enable option
-set no\fIx\fP disable option
-set \fIx\fP=\fIval\fP give value \fIval\fP
-set show changed options
-set all show all options
-set \fIx\fP? show value of option \fIx\fP
-.TE
-.h "Useful options"
-.TS
-lw(.9i)b lw(.3i) lw(1.0i).
-autoindent ai supply indent
-autowrite aw write before changing files
-ignorecase ic in scanning
-lisp \fB( ) { }\fP are s-exp's
-list print ^I for tab, $ at end
-magic \fB. [ *\fP special in patterns
-number nu number lines
-paragraphs para macro names which start ...
-redraw simulate smart terminal
-scroll command mode lines
-sections sect macro names ...
-shiftwidth sw for \fB< >\fP, and input \fB^D\fP
-showmatch sm to \fB)\fP and \fB}\fP as typed
-slowopen slow choke updates during insert
-window visual mode lines
-wrapscan ws around end of buffer?
-wrapmargin wm automatic line splitting
-.TE
-.LP
-.h "Scanning pattern formation"
-.TS
-aw(.9i)b aw(1.0i).
-\(ua beginning of line
-$ end of line
-\fB.\fR any character
-\e< beginning of word
-\e> end of word
-[\fIstr\fP] any char in \fIstr\fP
-[\(ua\fIstr\fP] ... not in \fIstr\fP
-[\fIx\-y\fP] ... between \fIx\fP and \fIy\fP
-* any number of preceding
-.TE
-.nc
-.LP
-.LG
-.LG
-.B
-.ce
-Vi Quick Reference
-.NL
-.R
-.LP
-.LP
-.h "Entering/leaving vi"
-.TS
-aw(1.4i)b aw(1.8i).
-% vi \fIname\fP edit \fIname\fP at top
-% vi +\fIn\fP \fIname\fP ... at line \fIn\fP
-% vi + \fIname\fP ... at end
-% vi \-r list saved files
-% vi \-r \fIname\fP recover file \fIname\fP
-% vi \fIname\fP ... edit first; rest via \fB:n\fP
-% vi \-t \fItag\fP start at \fItag\fP
-% vi +/\fIpat\fP \fIname\fP search for \fIpat\fP
-% view \fIname\fP read only mode
-ZZ exit from vi, saving changes
-^Z stop vi for later resumption
-.TE
-.h "The display"
-.TS
-lw(.75i) lw(2.2i).
-Last line T{
-Error messages, echoing input to \fB: / ?\fP and \fB!\fR,
-feedback about i/o and large changes.
-T}
-@ lines On screen only, not in file.
-~ lines Lines past end of file.
-^\fIx\fP Control characters, ^? is delete.
-tabs Expand to spaces, cursor at last.
-.TE
-.LP
-.h "Vi states"
-.TS
-lw(.75i) lw(2.2i).
-Command T{
-Normal and initial state. Others return here.
-ESC (escape) cancels partial command.
-T}
-Insert T{
-Entered by \fBa i A I o O c C s S\fP \fBR\fP.
-Arbitrary text then terminates with ESC character,
-or abnormally with interrupt.
-T}
-Last line T{
-Reading input for \fB: / ?\fP or \fB!\fP; terminate
-with ESC or CR to execute, interrupt to cancel.
-T}
-.TE
-.h "Counts before vi commands"
-.TS
-lw(1.5i) lw(1.7i)b.
-line/column number z G |
-scroll amount ^D ^U
-replicate insert a i A I
-repeat effect \fRmost rest\fP
-.TE
-.h "Simple commands"
-.TS
-lw(1.5i)b lw(1.7i).
-dw delete a word
-de ... leaving punctuation
-dd delete a line
-3dd ... 3 lines
-i\fItext\fP\fRESC\fP insert text \fIabc\fP
-cw\fInew\fP\fRESC\fP change word to \fInew\fP
-ea\fIs\fP\fRESC\fP pluralize word
-xp transpose characters
-.TE
-.nc
-.h "Interrupting, cancelling"
-.TS
-aw(0.75i)b aw(1.6i).
-ESC end insert or incomplete cmd
-^? (delete or rubout) interrupts
-^L reprint screen if \fB^?\fR scrambles it
-.TE
-.h "File manipulation"
-.TS
-aw(0.75i)b aw(1.6i).
-:w write back changes
-:wq write and quit
-:q quit
-:q! quit, discard changes
-:e \fIname\fP edit file \fIname\fP
-:e! reedit, discard changes
-:e + \fIname\fP edit, starting at end
-:e +\fIn\fR edit starting at line \fIn\fR
-:e # edit alternate file
-^\(ua synonym for \fB:e #\fP
-:w \fIname\fP write file \fIname\fP
-:w! \fIname\fP overwrite file \fIname\fP
-:sh run shell, then return
-:!\fIcmd\fP run \fIcmd\fR, then return
-:n edit next file in arglist
-:n \fIargs\fP specify new arglist
-:f show current file and line
-^G synonym for \fB:f\fP
-:ta \fItag\fP to tag file entry \fItag\fP
-^] \fB:ta\fP, following word is \fItag\fP
-.TE
-.h "Positioning within file"
-.TS
-aw(0.75i)b aw(1.6i).
-^F forward screenfull
-^B backward screenfull
-^D scroll down half screen
-^U scroll up half screen
-G goto line (end default)
-/\fIpat\fR next line matching \fIpat\fR
-?\fIpat\fR prev line matching \fIpat\fR
-n repeat last \fB/\fR or \fB?\fR
-N reverse last \fB/\fR or \fB?\fR
-/\fIpat\fP/+\fIn\fP n'th line after \fIpat\fR
-?\fIpat\fP?\-\fIn\fP n'th line before \fIpat\fR
-]] next section/function
-[[ previous section/function
-% find matching \fB( ) {\fP or \fB}\fP
-.TE
-.h "Adjusting the screen"
-.TS
-aw(0.75i)b aw(1.6i).
-^L clear and redraw
-^R retype, eliminate @ lines
-z\fRCR\fP redraw, current at window top
-z\- ... at bottom
-z\|. ... at center
-/\fIpat\fP/z\- \fIpat\fP line at bottom
-z\fIn\fP\|. use \fIn\fP line window
-^E scroll window down 1 line
-^Y scroll window up 1 line
-.TE
-.nc
-.h "Marking and returning
-.TS
-aw(0.5i)b aw(2.0i).
-\(ga\(ga previous context
-\(aa\(aa ... at first non-white in line
-m\fIx\fP mark position with letter \fIx\fP
-\(ga\fIx\fP to mark \fIx\fP
-\(aa\fIx\fP ... at first non-white in line
-.TE
-.h "Line positioning"
-.TS
-aw(0.5i)b aw(2.0i).
-H home window line
-L last window line
-M middle window line
-+ next line, at first non-white
-\- previous line, at first non-white
-\fRCR\fP return, same as +
-\(da \fRor\fP j next line, same column
-\(ua \fRor\fP k previous line, same column
-.TE
-.h "Character positioning"
-.TS
-aw(0.5i)b aw(2.0i).
-\(ua first non white
-0 beginning of line
-$ end of line
-h \fRor\fP \(-> forward
-l \fRor\fP \(<- backwards
-^H same as \fB\(<-\fP
-\fRspace\fP same as \fB\(->\fP
-f\fIx\fP find \fIx\fP forward
-F\fIx\fP \fBf\fR backward
-t\fIx\fP upto \fIx\fP forward
-T\fIx\fP back upto \fIx\fP
-; repeat last \fBf F t\fP or \fBT\fP
-, inverse of \fB;\fP
-| to specified column
-% find matching \fB( { )\fP or \fB}\fR
-.TE
-.h "Words, sentences, paragraphs"
-.TS
-aw(0.5i)b aw(2.0i).
-w word forward
-b back word
-e end of word
-) to next sentence
-} to next paragraph
-( back sentence
-{ back paragraph
-W blank delimited word
-B back \fBW\fP
-E to end of \fBW\fP
-.TE
-.h "Commands for \s-2LISP\s0"
-.TS
-aw(0.5i)b aw(2.0i).
-) Forward s-expression
-} ... but don't stop at atoms
-( Back s-expression
-{ ... but don't stop at atoms
-.TE
-.nc
-.h "Corrections during insert"
-.TS
-aw(.5i)b aw(2.0i).
-^H erase last character
-^W erases last word
-\fRerase\fP your erase, same as \fB^H\fP
-\fRkill\fP your kill, erase input this line
-\e escapes \fB^H\fR, your erase and kill
-\fRESC\fP ends insertion, back to command
-^? interrupt, terminates insert
-^D backtab over \fIautoindent\fP
-\(ua^D kill \fIautoindent\fP, save for next
-0^D ... but at margin next also
-^V quote non-printing character
-.TE
-.h "Insert and replace"
-.TS
-aw(.5i)b aw(2.0i).
-a append after cursor
-i insert before
-A append at end of line
-I insert before first non-blank
-o open line below
-O open above
-r\fIx\fP replace single char with \fIx\fP
-R replace characters
-.TE
-.h "Operators (double to affect lines)"
-.TS
-aw(0.5i)b aw(2.0i).
-d delete
-c change
-< left shift
-> right shift
-! filter through command
-\&\= indent for \s-2LISP\s0
-y yank lines to buffer
-.TE
-.h "Miscellaneous operations"
-.TS
-aw(0.5i)b aw(2.0i).
-C change rest of line
-D delete rest of line
-s substitute chars
-S substitute lines
-J join lines
-x delete characters
-X ... before cursor
-Y yank lines
-.TE
-.h "Yank and put"
-.TS
-aw(0.5i)b aw(2.0i).
-p put back lines
-P put before
-"\fIx\fPp put from buffer \fIx\fP
-"\fIx\fPy yank to buffer \fIx\fP
-"\fIx\fPd delete into buffer \fIx\fP
-.TE
-.h "Undo, redo, retrieve"
-.TS
-aw(0.5i)b aw(2.0i).
-u undo last change
-U restore current line
-\fB.\fP repeat last change
-"\fId\fP\|p retrieve \fId\fP'th last delete
-.TE
diff --git a/usr.bin/vi/common/Makefile b/usr.bin/vi/common/Makefile
deleted file mode 100644
index 67d88e7..0000000
--- a/usr.bin/vi/common/Makefile
+++ /dev/null
@@ -1,108 +0,0 @@
-# @(#)Makefile 8.51 (Berkeley) 8/17/94
-
-VI= nvi
-EX= nex
-VIEW= nview
-PROG= nvi
-LINKS= ${BINDIR}/${VI} ${BINDIR}/${EX} ${BINDIR}/${VI} ${BINDIR}/${VIEW}
-LINKS+= ${BINDIR}/${VI} ${BINDIR}/vi ${BINDIR}/${EX} ${BINDIR}/ex
-LINKS+= ${BINDIR}/${VI} ${BINDIR}/view
-MAN1= ${.CURDIR}/../USD.doc/vi.man/vi.1
-MLINKS+=vi.1 ex.1 vi.1 view.1
-MLINKS+=vi.1 nex.1 vi.1 nview.1 vi.1 nvi.1
-
-
-CFLAGS+=-I. -I${.CURDIR}
-DPADD+= ${LIBCURSES} ${LIBTERMCAP} ${LIBUTIL}
-LDADD+= -lcurses -ltermcap -lutil
-
-.PATH: ${.CURDIR}/../common ${.CURDIR}/../ex ${.CURDIR}/../sex \
- ${.CURDIR}/../vi ${.CURDIR}/../svi ${.CURDIR}/../xaw
-
-SPECHDR=compat.h excmd.h options.h
-
-CLEANFILES+=${SPECHDR} ${EX}
-
-# General sources.
-SRCS= cut.c delete.c exf.c line.c log.c main.c mark.c msg.c options.c \
- options_f.c put.c screen.c search.c seq.c signal.c recover.c \
- term.c trace.c util.c ${SPECHDR}
-
-# Ex source.
-SRCS+= ex.c ex_abbrev.c ex_append.c ex_args.c ex_argv.c ex_at.c ex_bang.c \
- ex_cd.c ex_delete.c ex_digraph.c ex_display.c ex_edit.c ex_equal.c \
- ex_exit.c ex_file.c ex_global.c ex_init.c ex_join.c ex_map.c \
- ex_mark.c ex_mkexrc.c ex_move.c ex_open.c ex_preserve.c ex_print.c \
- ex_put.c ex_read.c ex_screen.c ex_script.c ex_set.c ex_shell.c \
- ex_shift.c ex_source.c ex_stop.c ex_subst.c ex_tag.c ex_undo.c \
- ex_usage.c ex_util.c ex_version.c ex_visual.c ex_write.c ex_yank.c \
- ex_z.c excmd.c filter.c
-
-# Ex screen source.
-SRCS+= sex_confirm.c sex_get.c sex_refresh.c sex_screen.c sex_term.c \
- sex_util.c sex_window.c
-
-# Vi source.
-SRCS+= getc.c v_ch.c v_delete.c v_ex.c v_increment.c v_init.c v_left.c \
- v_mark.c v_match.c v_ntext.c v_paragraph.c v_put.c v_redraw.c \
- v_replace.c v_right.c v_screen.c v_scroll.c v_search.c v_section.c \
- v_sentence.c v_status.c v_stop.c v_text.c v_ulcase.c v_undo.c \
- v_util.c v_word.c v_xchar.c v_yank.c v_z.c v_zexit.c vcmd.c vi.c
-
-# Vi curses screen source.
-SRCS+= svi_confirm.c svi_curses.c svi_ex.c svi_get.c svi_line.c \
- svi_refresh.c svi_relative.c svi_screen.c svi_smap.c svi_split.c \
- svi_term.c svi_util.c
-
-# Athena widget set screen source.
-SRCS+= xaw_screen.c
-
-all: ${VI} ${EX}
-
-all: nvi nex
-nex: nvi
- rm -f nex
- ln nvi nex
-
-${EX}: ${VI}
- rm -f ${EX}
- ln ${VI} ${EX}
-
-compat.h:
- :> compat.h
-
-excmd.h: excmd.h.stub excmd.c excmd.awk
- rm -f excmd.h
- cat ${.CURDIR}/../ex/excmd.h.stub > excmd.h
- awk -f ${.CURDIR}/../ex/excmd.awk ${.CURDIR}/../ex/excmd.c >> excmd.h
-
-options.h: options.h.stub options.c options.awk
- rm -f options.h
- cat ${.CURDIR}/options.h.stub > options.h
- awk -f ${.CURDIR}/options.awk ${.CURDIR}/options.c >> options.h
-
-excmd.h: excmd.h.stub excmd.c excmd.awk
- rm -f excmd.h
- cat ${.CURDIR}/../ex/excmd.h.stub > excmd.h
- awk -f ${.CURDIR}/../ex/excmd.awk ${.CURDIR}/../ex/excmd.c >> excmd.h
-
-tags::
- -(cd ${.CURDIR} && rm -f tags && \
- ctags ../common/*.[ch] ../common/*.stub ../ex/*.[ch] ../ex/*.stub \
- ../vi/*.[ch] ../sex/*.[ch] ../svi/*.[ch] ../xaw/*.[ch])
-
-warn:: ${SRCS}
- -(cd ${.CURDIR} && gcc -Wall -O4 -DDEBUG \
- -Iobj -I. ${.ALLSRC} -lcurses -ltermcap 2>&1 | \
- sed -e "/warning: .*sccsid.*defined but not used/d" \
- -e "/warning: suggest parentheses around/d" \
- -e "/In function /d" \
- -e "/At top level:/d" \
- -e "/warning: .*inline call to/d" \
- -e "/warning: comparison is always 1 due /d") > \
- ${.CURDIR}/WARN.OUT
-
-.include "../../Makefile.inc"
-.include <bsd.prog.mk>
-
-.depend: ${SPECHDR}
diff --git a/usr.bin/vi/common/args.h b/usr.bin/vi/common/args.h
deleted file mode 100644
index 5e127de..0000000
--- a/usr.bin/vi/common/args.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)args.h 8.5 (Berkeley) 7/17/94
- */
-
-/*
- * Structure for building "argc/argv" vector of arguments.
- *
- * !!!
- * All arguments are nul terminated as well as having an associated length.
- * The argument vector is NOT necessarily NULL terminated. The proper way
- * to check the number of arguments is to use the argc value in the EXCMDARG
- * structure or to walk the array until an ARGS structure with a length of 0
- * is found.
- */
-typedef struct _args {
- CHAR_T *bp; /* Argument. */
- size_t blen; /* Buffer length. */
- size_t len; /* Argument length. */
-
-#define A_ALLOCATED 0x01 /* If allocated space. */
- u_int8_t flags;
-} ARGS;
diff --git a/usr.bin/vi/common/cut.c b/usr.bin/vi/common/cut.c
deleted file mode 100644
index 5700990..0000000
--- a/usr.bin/vi/common/cut.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)cut.c 8.34 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-static int cb_rotate __P((SCR *));
-
-/*
- * cut --
- * Put a range of lines/columns into a TEXT buffer.
- *
- * There are two buffer areas, both found in the global structure. The first
- * is the linked list of all the buffers the user has named, the second is the
- * unnamed buffer storage. There is a pointer, too, which is the current
- * default buffer, i.e. it may point to the unnamed buffer or a named buffer
- * depending on into what buffer the last text was cut. Logically, in both
- * delete and yank operations, if the user names a buffer, the text is cut
- * into it. If it's a delete of information on more than a single line, the
- * contents of the numbered buffers are rotated up one, the contents of the
- * buffer named '9' are discarded, and the text is cut into the buffer named
- * '1'. The text is always cut into the unnamed buffer.
- *
- * In all cases, upper-case buffer names are the same as lower-case names,
- * with the exception that they cause the buffer to be appended to instead
- * of replaced. Note, however, that if text is appended to a buffer, the
- * default buffer only contains the appended text, not the entire contents
- * of the buffer.
- *
- * !!!
- * The contents of the default buffer would disappear after most operations
- * in historic vi. It's unclear that this is useful, so we don't bother.
- *
- * When users explicitly cut text into the numeric buffers, historic vi became
- * genuinely strange. I've never been able to figure out what was supposed to
- * happen. It behaved differently if you deleted text than if you yanked text,
- * and, in the latter case, the text was appended to the buffer instead of
- * replacing the contents. Hopefully it's not worth getting right, and here
- * we just treat the numeric buffers like any other named buffer.
- */
-int
-cut(sp, ep, namep, fm, tm, flags)
- SCR *sp;
- EXF *ep;
- CHAR_T *namep;
- int flags;
- MARK *fm, *tm;
-{
- CB *cbp;
- CHAR_T name;
- recno_t lno;
- int append, copy_one, copy_def;
-
- /*
- * If the user specified a buffer, put it there. (This may require
- * a copy into the numeric buffers. We do the copy so that we don't
- * have to reference count and so we don't have to deal with things
- * like appends to buffers that are used multiple times.)
- *
- * Otherwise, if it's supposed to be put in a numeric buffer (usually
- * a delete) put it there. The rules for putting things in numeric
- * buffers were historically a little strange. There were three cases.
- *
- * 1: Some motions are always line mode motions, which means
- * that the cut always goes into the numeric buffers.
- * 2: Some motions aren't line mode motions, e.g. d10w, but
- * can cross line boundaries. For these commands, if the
- * cut crosses a line boundary, it goes into the numeric
- * buffers. This includes most of the commands.
- * 3: Some motions aren't line mode motions, e.g. d`<char>,
- * but always go into the numeric buffers, regardless. This
- * was the commands: % ` / ? ( ) N n { } -- and nvi adds ^A.
- *
- * Otherwise, put it in the unnamed buffer.
- */
- append = copy_one = copy_def = 0;
- if (namep != NULL) {
- name = *namep;
- if (LF_ISSET(CUT_NUMREQ) || LF_ISSET(CUT_NUMOPT) &&
- (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno)) {
- copy_one = 1;
- cb_rotate(sp);
- }
- if ((append = isupper(name)) == 1) {
- if (!copy_one)
- copy_def = 1;
- name = tolower(name);
- }
-namecb: CBNAME(sp, cbp, name);
- } else if (LF_ISSET(CUT_NUMREQ) || LF_ISSET(CUT_NUMOPT) &&
- (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno)) {
- name = '1';
- cb_rotate(sp);
- goto namecb;
- } else
- cbp = &sp->gp->dcb_store;
-
-copyloop:
- /*
- * If this is a new buffer, create it and add it into the list.
- * Otherwise, if it's not an append, free its current contents.
- */
- if (cbp == NULL) {
- CALLOC_RET(sp, cbp, CB *, 1, sizeof(CB));
- cbp->name = name;
- CIRCLEQ_INIT(&cbp->textq);
- LIST_INSERT_HEAD(&sp->gp->cutq, cbp, q);
- } else if (!append) {
- text_lfree(&cbp->textq);
- cbp->len = 0;
- cbp->flags = 0;
- }
-
-
-#define ENTIRE_LINE 0
- /* In line mode, it's pretty easy, just cut the lines. */
- if (LF_ISSET(CUT_LINEMODE)) {
- cbp->flags |= CB_LMODE;
- for (lno = fm->lno; lno <= tm->lno; ++lno)
- if (cut_line(sp, ep, lno, 0, 0, cbp))
- goto cut_line_err;
- } else {
- /*
- * Get the first line. A length of 0 causes cut_line
- * to cut from the MARK to the end of the line.
- */
- if (cut_line(sp, ep, fm->lno, fm->cno, fm->lno != tm->lno ?
- ENTIRE_LINE : (tm->cno - fm->cno) + 1, cbp))
- goto cut_line_err;
-
- /* Get the intermediate lines. */
- for (lno = fm->lno; ++lno < tm->lno;)
- if (cut_line(sp, ep, lno, 0, ENTIRE_LINE, cbp))
- goto cut_line_err;
-
- /* Get the last line. */
- if (tm->lno != fm->lno &&
- cut_line(sp, ep, lno, 0, tm->cno + 1, cbp)) {
-cut_line_err: text_lfree(&cbp->textq);
- cbp->len = 0;
- cbp->flags = 0;
- return (1);
- }
- }
-
- append = 0; /* Only append to the named buffer. */
- sp->gp->dcbp = cbp; /* Repoint the default buffer on each pass. */
-
- if (copy_one) { /* Copy into numeric buffer 1. */
- name = '1';
- CBNAME(sp, cbp, name);
- copy_one = 0;
- goto copyloop;
- }
- if (copy_def) { /* Copy into the default buffer. */
- cbp = &sp->gp->dcb_store;
- copy_def = 0;
- goto copyloop;
- }
- return (0);
-}
-
-/*
- * cb_rotate --
- * Rotate the numbered buffers up one.
- */
-static int
-cb_rotate(sp)
- SCR *sp;
-{
- CB *cbp, *del_cbp;
-
- del_cbp = NULL;
- for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next)
- switch(cbp->name) {
- case '1':
- cbp->name = '2';
- break;
- case '2':
- cbp->name = '3';
- break;
- case '3':
- cbp->name = '4';
- break;
- case '4':
- cbp->name = '5';
- break;
- case '5':
- cbp->name = '6';
- break;
- case '6':
- cbp->name = '7';
- break;
- case '7':
- cbp->name = '8';
- break;
- case '8':
- cbp->name = '9';
- break;
- case '9':
- del_cbp = cbp;
- break;
- }
- if (del_cbp != NULL) {
- LIST_REMOVE(del_cbp, q);
- text_lfree(&del_cbp->textq);
- FREE(del_cbp, sizeof(CB));
- }
- return (0);
-}
-
-/*
- * cut_line --
- * Cut a portion of a single line.
- */
-int
-cut_line(sp, ep, lno, fcno, clen, cbp)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- size_t fcno, clen;
- CB *cbp;
-{
- TEXT *tp;
- size_t len;
- char *p;
-
- /* Get the line. */
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
-
- /* Create a TEXT structure that can hold the entire line. */
- if ((tp = text_init(sp, NULL, 0, len)) == NULL)
- return (1);
-
- /*
- * If the line isn't empty and it's not the entire line,
- * copy the portion we want, and reset the TEXT length.
- */
- if (len != 0) {
- if (clen == 0)
- clen = len - fcno;
- memmove(tp->lb, p + fcno, clen);
- tp->len = clen;
- }
-
- /* Append to the end of the cut buffer. */
- CIRCLEQ_INSERT_TAIL(&cbp->textq, tp, q);
- cbp->len += tp->len;
-
- return (0);
-}
-
-/*
- * text_init --
- * Allocate a new TEXT structure.
- */
-TEXT *
-text_init(sp, p, len, total_len)
- SCR *sp;
- const char *p;
- size_t len, total_len;
-{
- TEXT *tp;
-
- CALLOC(sp, tp, TEXT *, 1, sizeof(TEXT));
- if (tp == NULL)
- return (NULL);
- /* ANSI C doesn't define a call to malloc(2) for 0 bytes. */
- if ((tp->lb_len = total_len) != 0) {
- MALLOC(sp, tp->lb, CHAR_T *, tp->lb_len);
- if (tp->lb == NULL) {
- free(tp);
- return (NULL);
- }
- if (p != NULL && len != 0)
- memmove(tp->lb, p, len);
- }
- tp->len = len;
- return (tp);
-}
-
-/*
- * text_lfree --
- * Free a chain of text structures.
- */
-void
-text_lfree(headp)
- TEXTH *headp;
-{
- TEXT *tp;
-
- while ((tp = headp->cqh_first) != (void *)headp) {
- CIRCLEQ_REMOVE(headp, tp, q);
- text_free(tp);
- }
-}
-
-/*
- * text_free --
- * Free a text structure.
- */
-void
-text_free(tp)
- TEXT *tp;
-{
- if (tp->lb != NULL)
- FREE(tp->lb, tp->lb_len);
- if (tp->wd != NULL)
- FREE(tp->wd, tp->wd_len);
- FREE(tp, sizeof(TEXT));
-}
diff --git a/usr.bin/vi/common/cut.h b/usr.bin/vi/common/cut.h
deleted file mode 100644
index 3113411..0000000
--- a/usr.bin/vi/common/cut.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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.
- *
- * @(#)cut.h 8.19 (Berkeley) 7/28/94
- */
-
-typedef struct _texth TEXTH; /* TEXT list head structure. */
-CIRCLEQ_HEAD(_texth, _text);
-
-/* Cut buffers. */
-struct _cb {
- LIST_ENTRY(_cb) q; /* Linked list of cut buffers. */
- TEXTH textq; /* Linked list of TEXT structures. */
- CHAR_T name; /* Cut buffer name. */
- size_t len; /* Total length of cut text. */
-
-#define CB_LMODE 0x01 /* Cut was in line mode. */
- u_int8_t flags;
-};
-
-/* Lines/blocks of text. */
-struct _text { /* Text: a linked list of lines. */
- CIRCLEQ_ENTRY(_text) q; /* Linked list of text structures. */
- char *lb; /* Line buffer. */
- size_t lb_len; /* Line buffer length. */
- size_t len; /* Line length. */
-
- /* These fields are used by the vi text input routine. */
- recno_t lno; /* 1-N: line number. */
- size_t ai; /* 0-N: autoindent bytes. */
- size_t insert; /* 0-N: bytes to insert (push). */
- size_t offset; /* 0-N: initial, unerasable chars. */
- size_t owrite; /* 0-N: chars to overwrite. */
- size_t R_erase; /* 0-N: 'R' erase count. */
- size_t sv_cno; /* 0-N: Saved line cursor. */
- size_t sv_len; /* 0-N: Saved line length. */
-
- /* These fields are used by the ex text input routine. */
- u_char *wd; /* Width buffer. */
- size_t wd_len; /* Width buffer length. */
-};
-
-/*
- * Get named buffer 'name'.
- * Translate upper-case buffer names to lower-case buffer names.
- */
-#define CBNAME(sp, cbp, nch) { \
- CHAR_T __name; \
- __name = isupper(nch) ? tolower(nch) : (nch); \
- for (cbp = sp->gp->cutq.lh_first; \
- cbp != NULL; cbp = cbp->q.le_next) \
- if (cbp->name == __name) \
- break; \
-}
-
-#define CUT_LINEMODE 0x01 /* Cut in line mode. */
-#define CUT_NUMOPT 0x02 /* Numeric buffer: optional. */
-#define CUT_NUMREQ 0x04 /* Numeric buffer: required. */
-int cut __P((SCR *, EXF *, CHAR_T *, MARK *, MARK *, int));
-
-int cut_line __P((SCR *, EXF *, recno_t, size_t, size_t, CB *));
-int delete __P((SCR *, EXF *, MARK *, MARK *, int));
-int put __P((SCR *, EXF *, CB *, CHAR_T *, MARK *, MARK *, int));
-
-void text_free __P((TEXT *));
-TEXT *text_init __P((SCR *, const char *, size_t, size_t));
-void text_lfree __P((TEXTH *));
diff --git a/usr.bin/vi/common/delete.c b/usr.bin/vi/common/delete.c
deleted file mode 100644
index 85eae5f..0000000
--- a/usr.bin/vi/common/delete.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)delete.c 8.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * delete --
- * Delete a range of text.
- */
-int
-delete(sp, ep, fm, tm, lmode)
- SCR *sp;
- EXF *ep;
- MARK *fm, *tm;
- int lmode;
-{
- recno_t lno;
- size_t blen, len, nlen, tlen;
- char *bp, *p;
- int eof;
-
- bp = NULL;
-
- /* Case 1 -- delete in line mode. */
- if (lmode) {
- for (lno = tm->lno; lno >= fm->lno; --lno)
- if (file_dline(sp, ep, lno))
- return (1);
- goto vdone;
- }
-
- /*
- * Case 2 -- delete to EOF. This is a special case because it's
- * easier to pick it off than try and find it in the other cases.
- */
- if (file_lline(sp, ep, &lno))
- return (1);
- if (tm->lno >= lno) {
- if (tm->lno == lno) {
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- eof = tm->cno >= len ? 1 : 0;
- } else
- eof = 1;
- if (eof) {
- for (lno = tm->lno; lno > fm->lno; --lno) {
- if (file_dline(sp, ep, lno))
- return (1);
- ++sp->rptlines[L_DELETED];
- }
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- GET_SPACE_RET(sp, bp, blen, fm->cno);
- memmove(bp, p, fm->cno);
- if (file_sline(sp, ep, fm->lno, bp, fm->cno))
- return (1);
- goto done;
- }
- }
-
- /* Case 3 -- delete within a single line. */
- if (tm->lno == fm->lno) {
- if ((p = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- if (len != 0) {
- GET_SPACE_RET(sp, bp, blen, len);
- if (fm->cno != 0)
- memmove(bp, p, fm->cno);
- memmove(bp + fm->cno, p + (tm->cno + 1), len - (tm->cno + 1));
- if (file_sline(sp, ep, fm->lno,
- bp, len - ((tm->cno - fm->cno) + 1)))
- goto err;
- }
- goto done;
- }
-
- /*
- * Case 4 -- delete over multiple lines.
- *
- * Copy the start partial line into place.
- */
- if ((tlen = fm->cno) != 0) {
- if ((p = file_gline(sp, ep, fm->lno, NULL)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- GET_SPACE_RET(sp, bp, blen, tlen + 256);
- memmove(bp, p, tlen);
- }
-
- /* Copy the end partial line into place. */
- if ((p = file_gline(sp, ep, tm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, tm->lno);
- goto err;
- }
- if (len != 0 && tm->cno != len - 1) {
- /*
- * XXX
- * We can overflow memory here, if the total length is greater
- * than SIZE_T_MAX. The only portable way I've found to test
- * is depending on the overflow being less than the value.
- */
- nlen = (len - (tm->cno + 1)) + tlen;
- if (tlen > nlen) {
- msgq(sp, M_ERR, "Error: line length overflow");
- goto err;
- }
- if (tlen == 0) {
- GET_SPACE_RET(sp, bp, blen, nlen);
- } else
- ADD_SPACE_RET(sp, bp, blen, nlen);
-
- memmove(bp + tlen, p + (tm->cno + 1), len - (tm->cno + 1));
- tlen += len - (tm->cno + 1);
- }
-
- /* Set the current line. */
- if (file_sline(sp, ep, fm->lno, bp, tlen))
- goto err;
-
- /* Delete the last and intermediate lines. */
- for (lno = tm->lno; lno > fm->lno; --lno)
- if (file_dline(sp, ep, lno))
- goto err;
-
- /* Reporting. */
-vdone: sp->rptlines[L_DELETED] += tm->lno - fm->lno + 1;
-
-done: if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
-
- return (0);
-
- /* Free memory. */
-err: if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
- return (1);
-}
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c
deleted file mode 100644
index 10ff7f1..0000000
--- a/usr.bin/vi/common/exf.c
+++ /dev/null
@@ -1,837 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)exf.c 8.97 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-/*
- * We include <sys/file.h>, because the flock(2) and open(2) #defines
- * were found there on historical systems. We also include <fcntl.h>
- * because the open(2) #defines are found there on newer systems.
- */
-#include <sys/file.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include <pathnames.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * file_add --
- * Insert a file name into the FREF list, if it doesn't already
- * appear in it.
- *
- * !!!
- * The "if it doesn't already appear" changes vi's semantics slightly. If
- * you do a "vi foo bar", and then execute "next bar baz", the edit of bar
- * will reflect the line/column of the previous edit session. Historic nvi
- * did not do this. The change is a logical extension of the change where
- * vi now remembers the last location in any file that it has ever edited,
- * not just the previously edited file.
- */
-FREF *
-file_add(sp, name)
- SCR *sp;
- CHAR_T *name;
-{
- FREF *frp;
-
- /*
- * Return it if it already exists. Note that we test against the
- * user's name, whatever that happens to be, including if it's a
- * temporary file.
- */
- if (name != NULL)
- for (frp = sp->frefq.cqh_first;
- frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next)
- if (!strcmp(frp->name, name))
- return (frp);
-
- /* Allocate and initialize the FREF structure. */
- CALLOC(sp, frp, FREF *, 1, sizeof(FREF));
- if (frp == NULL)
- return (NULL);
-
- /*
- * If no file name specified, or if the file name is a request
- * for something temporary, file_init() will allocate the file
- * name. Temporary files are always ignored.
- */
- if (name != NULL && strcmp(name, TEMPORARY_FILE_STRING) &&
- (frp->name = strdup(name)) == NULL) {
- FREE(frp, sizeof(FREF));
- msgq(sp, M_SYSERR, NULL);
- return (NULL);
- }
-
- /* Append into the chain of file names. */
- CIRCLEQ_INSERT_TAIL(&sp->frefq, frp, q);
-
- return (frp);
-}
-
-/*
- * file_init --
- * Start editing a file, based on the FREF structure. If successsful,
- * let go of any previous file. Don't release the previous file until
- * absolutely sure we have the new one.
- */
-int
-file_init(sp, frp, rcv_name, force)
- SCR *sp;
- FREF *frp;
- char *rcv_name;
- int force;
-{
- EXF *ep;
- RECNOINFO oinfo;
- struct stat sb;
- size_t psize;
- int fd;
- char *oname, tname[MAXPATHLEN];
-
- /*
- * If the file is a recovery file, let the recovery code handle it.
- * Clear the FR_RECOVER flag first -- the recovery code does set up,
- * and then calls us! If the recovery call fails, it's probably
- * because the named file doesn't exist. So, move boldly forward,
- * presuming that there's an error message the user will get to see.
- */
- if (F_ISSET(frp, FR_RECOVER)) {
- F_CLR(frp, FR_RECOVER);
- return (rcv_read(sp, frp));
- }
-
- /*
- * Required FRP initialization; the only flag we keep is the
- * cursor information.
- */
- F_CLR(frp, ~FR_CURSORSET);
-
- /*
- * Required EXF initialization:
- * Flush the line caches.
- * Default recover mail file fd to -1.
- * Set initial EXF flag bits.
- */
- CALLOC_RET(sp, ep, EXF *, 1, sizeof(EXF));
- ep->c_lno = ep->c_nlines = OOBLNO;
- ep->rcv_fd = ep->fcntl_fd = -1;
- LIST_INIT(&ep->marks);
- F_SET(ep, F_FIRSTMODIFY);
-
- /*
- * If no name or backing file, create a backing temporary file, saving
- * the temp file name so we can later unlink it. If the user never
- * named this file, copy the temporary file name to the real name (we
- * display that until the user renames it).
- */
- if ((oname = frp->name) == NULL || stat(oname, &sb)) {
- (void)snprintf(tname,
- sizeof(tname), "%s/vi.XXXXXX", O_STR(sp, O_DIRECTORY));
- if ((fd = mkstemp(tname)) == -1) {
- msgq(sp, M_SYSERR, "Temporary file");
- goto err;
- }
- (void)close(fd);
-
- if (frp->name == NULL)
- F_SET(frp, FR_TMPFILE);
- if ((frp->tname = strdup(tname)) == NULL ||
- frp->name == NULL && (frp->name = strdup(tname)) == NULL) {
- if (frp->tname != NULL)
- free(frp->tname);
- msgq(sp, M_SYSERR, NULL);
- (void)unlink(tname);
- goto err;
- }
- oname = frp->tname;
- psize = 4 * 1024;
- F_SET(frp, FR_NEWFILE);
- } else {
- /*
- * Try to keep it at 10 pages or less per file. This
- * isn't friendly on a loaded machine, btw.
- */
- if (sb.st_size < 40 * 1024)
- psize = 4 * 1024;
- else if (sb.st_size < 320 * 1024)
- psize = 32 * 1024;
- else
- psize = 64 * 1024;
-
- ep->mtime = sb.st_mtime;
-
- if (!S_ISREG(sb.st_mode))
- msgq(sp, M_ERR,
- "Warning: %s is not a regular file", oname);
- }
-
- /* Set up recovery. */
- memset(&oinfo, 0, sizeof(RECNOINFO));
- oinfo.bval = '\n'; /* Always set. */
- oinfo.psize = psize;
- oinfo.flags = F_ISSET(sp->gp, G_SNAPSHOT) ? R_SNAPSHOT : 0;
- if (rcv_name == NULL) {
- if (!rcv_tmp(sp, ep, frp->name))
- oinfo.bfname = ep->rcv_path;
- } else {
- if ((ep->rcv_path = strdup(rcv_name)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- goto err;
- }
- oinfo.bfname = ep->rcv_path;
- F_SET(ep, F_MODIFIED);
- }
-
- /* Open a db structure. */
- if ((ep->db = dbopen(rcv_name == NULL ? oname : NULL,
- O_NONBLOCK | O_RDONLY, DEFFILEMODE, DB_RECNO, &oinfo)) == NULL) {
- msgq(sp, M_SYSERR, rcv_name == NULL ? oname : rcv_name);
- goto err;
- }
-
- /*
- * Do the remaining things that can cause failure of the new file,
- * mark and logging initialization.
- */
- if (mark_init(sp, ep) || log_init(sp, ep))
- goto err;
-
- /*
- * Close the previous file; if that fails, close the new one and
- * run for the border.
- *
- * !!!
- * There's a nasty special case. If the user edits a temporary file,
- * and then does an ":e! %", we need to re-initialize the backing
- * file, but we can't change the name. (It's worse -- we're dealing
- * with *names* here, we can't even detect that it happened.) Set a
- * flag so that the file_end routine ignores the backing information
- * of the old file if it happens to be the same as the new one.
- *
- * !!!
- * Side-effect: after the call to file_end(), sp->frp may be NULL.
- */
- F_SET(frp, FR_DONTDELETE);
- if (sp->ep != NULL && file_end(sp, sp->ep, force)) {
- (void)file_end(sp, ep, 1);
- goto err;
- }
- F_CLR(frp, FR_DONTDELETE);
-
- /*
- * Lock the file; if it's a recovery file, it should already be
- * locked. Note, we acquire the lock after the previous file
- * has been ended, so that we don't get an "already locked" error
- * for ":edit!".
- *
- * XXX
- * While the user can't interrupt us between the open and here,
- * there's a race between the dbopen() and the lock. Not much
- * we can do about it.
- *
- * XXX
- * We don't make a big deal of not being able to lock the file. As
- * locking rarely works over NFS, and often fails if the file was
- * mmap(2)'d, it's far too common to do anything like print an error
- * message, let alone make the file readonly. At some future time,
- * when locking is a little more reliable, this should change to be
- * an error.
- */
- if (rcv_name == NULL)
- switch (file_lock(oname,
- &ep->fcntl_fd, ep->db->fd(ep->db), 0)) {
- case LOCK_FAILED:
- F_SET(frp, FR_UNLOCKED);
- break;
- case LOCK_UNAVAIL:
- msgq(sp, M_INFO,
- "%s already locked, session is read-only", oname);
- F_SET(frp, FR_RDONLY);
- break;
- case LOCK_SUCCESS:
- break;
- }
-
- /*
- * The -R flag, or doing a "set readonly" during a session causes
- * all files edited during the session (using an edit command, or
- * even using tags) to be marked read-only. Changing the file name
- * (see ex/ex_file.c), clears this flag.
- *
- * Otherwise, try and figure out if a file is readonly. This is a
- * dangerous thing to do. The kernel is the only arbiter of whether
- * or not a file is writeable, and the best that a user program can
- * do is guess. Obvious loopholes are files that are on a file system
- * mounted readonly (access catches this one on a few systems), or
- * alternate protection mechanisms, ACL's for example, that we can't
- * portably check. Lots of fun, and only here because users whined.
- *
- * !!!
- * Historic vi displayed the readonly message if none of the file
- * write bits were set, or if an an access(2) call on the path
- * failed. This seems reasonable. If the file is mode 444, root
- * users may want to know that the owner of the file did not expect
- * it to be written.
- *
- * Historic vi set the readonly bit if no write bits were set for
- * a file, even if the access call would have succeeded. This makes
- * the superuser force the write even when vi expects that it will
- * succeed. I'm less supportive of this semantic, but it's historic
- * practice and the conservative approach to vi'ing files as root.
- *
- * It would be nice if there was some way to update this when the user
- * does a "^Z; chmod ...". The problem is that we'd first have to
- * distinguish between readonly bits set because of file permissions
- * and those set for other reasons. That's not too hard, but deciding
- * when to reevaluate the permissions is trickier. An alternative
- * might be to turn off the readonly bit if the user forces a write
- * and it succeeds.
- *
- * XXX
- * Access(2) doesn't consider the effective uid/gid values. This
- * probably isn't a problem for vi when it's running standalone.
- */
- if (O_ISSET(sp, O_READONLY) || !F_ISSET(frp, FR_NEWFILE) &&
- (!(sb.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) ||
- access(frp->name, W_OK)))
- F_SET(frp, FR_RDONLY);
-
- /*
- * Set the alternate file name to be the file we've just discarded.
- *
- * !!!
- * If the current file was a temporary file, the call to file_end()
- * unlinked it and free'd the name. So, there is no previous file,
- * and there is no alternate file name. This matches historical
- * practice, although in historical vi it could only happen as the
- * result of the initial command, i.e. if vi was executed without a
- * file name.
- */
- set_alt_name(sp, sp->frp == NULL ? NULL : sp->frp->name);
-
- /*
- * Switch...
- *
- * !!!
- * Note, because the EXF structure is examine at interrupt time,
- * the underlying DB structures have to be consistent as soon as
- * it's assigned to an SCR structure.
- */
- ++ep->refcnt;
- sp->ep = ep;
- sp->frp = frp;
- return (0);
-
-err: if (frp->name != NULL) {
- free(frp->name);
- frp->name = NULL;
- }
- if (frp->tname != NULL) {
- (void)unlink(frp->tname);
- free(frp->tname);
- frp->tname = NULL;
- }
- if (ep->rcv_path != NULL) {
- free(ep->rcv_path);
- ep->rcv_path = NULL;
- }
- if (ep->db != NULL)
- (void)ep->db->close(ep->db);
- FREE(ep, sizeof(EXF));
- return (1);
-}
-
-/*
- * file_end --
- * Stop editing a file.
- */
-int
-file_end(sp, ep, force)
- SCR *sp;
- EXF *ep;
- int force;
-{
- FREF *frp;
-
- /*
- * Clean up the FREF structure.
- *
- * Save the cursor location.
- *
- * XXX
- * It would be cleaner to do this somewhere else, but by the time
- * ex or vi knows that we're changing files it's already happened.
- */
- frp = sp->frp;
- frp->lno = sp->lno;
- frp->cno = sp->cno;
- F_SET(frp, FR_CURSORSET);
-
- /*
- * We may no longer need the temporary backing file, so clean it
- * up. We don't need the FREF structure either, if the file was
- * never named, so lose it.
- *
- * !!!
- * Re: FR_DONTDELETE, see the comment above in file_init().
- */
- if (!F_ISSET(frp, FR_DONTDELETE) && frp->tname != NULL) {
- if (unlink(frp->tname))
- msgq(sp, M_SYSERR, "%s: remove", frp->tname);
- free(frp->tname);
- frp->tname = NULL;
- if (F_ISSET(frp, FR_TMPFILE)) {
- CIRCLEQ_REMOVE(&sp->frefq, frp, q);
- free(frp->name);
- free(frp);
- }
- sp->frp = NULL;
- }
-
- /*
- * Clean up the EXF structure.
- *
- * sp->ep MAY NOT BE THE SAME AS THE ARGUMENT ep, SO DON'T USE IT!
- *
- * If multiply referenced, just decrement the count and return.
- */
- if (--ep->refcnt != 0)
- return (0);
-
- /* Close the db structure. */
- if (ep->db->close != NULL && ep->db->close(ep->db) && !force) {
- msgq(sp, M_ERR, "%s: close: %s", frp->name, strerror(errno));
- ++ep->refcnt;
- return (1);
- }
-
- /* COMMITTED TO THE CLOSE. THERE'S NO GOING BACK... */
-
- /* Stop logging. */
- (void)log_end(sp, ep);
-
- /* Free up any marks. */
- (void)mark_end(sp, ep);
-
- /*
- * Delete recovery files, close the open descriptor, free recovery
- * memory. See recover.c for a description of the protocol.
- *
- * XXX
- * Unlink backup file first, we can detect that the recovery file
- * doesn't reference anything when the user tries to recover it.
- * There's a race, here, obviously, but it's fairly small.
- */
- if (!F_ISSET(ep, F_RCV_NORM)) {
- if (ep->rcv_path != NULL && unlink(ep->rcv_path))
- msgq(sp, M_ERR,
- "%s: remove: %s", ep->rcv_path, strerror(errno));
- if (ep->rcv_mpath != NULL && unlink(ep->rcv_mpath))
- msgq(sp, M_ERR,
- "%s: remove: %s", ep->rcv_mpath, strerror(errno));
- }
- if (ep->fcntl_fd != -1)
- (void)close(ep->fcntl_fd);
- if (ep->rcv_fd != -1)
- (void)close(ep->rcv_fd);
- if (ep->rcv_path != NULL)
- free(ep->rcv_path);
- if (ep->rcv_mpath != NULL)
- free(ep->rcv_mpath);
-
- FREE(ep, sizeof(EXF));
- return (0);
-}
-
-/*
- * file_write --
- * Write the file to disk. Historic vi had fairly convoluted
- * semantics for whether or not writes would happen. That's
- * why all the flags.
- */
-int
-file_write(sp, ep, fm, tm, name, flags)
- SCR *sp;
- EXF *ep;
- MARK *fm, *tm;
- char *name;
- int flags;
-{
- struct stat sb;
- FILE *fp;
- FREF *frp;
- MARK from, to;
- u_long nlno, nch;
- int btear, fd, noname, oflags, rval;
- char *msg;
-
- frp = sp->frp;
- if (name == NULL) {
- noname = 1;
- name = frp->name;
- } else
- noname = 0;
-
- /* Can't write files marked read-only, unless forced. */
- if (!LF_ISSET(FS_FORCE) && noname && F_ISSET(frp, FR_RDONLY)) {
- if (LF_ISSET(FS_POSSIBLE))
- msgq(sp, M_ERR,
- "Read-only file, not written; use ! to override");
- else
- msgq(sp, M_ERR, "Read-only file, not written");
- return (1);
- }
-
- /* If not forced, not appending, and "writeany" not set ... */
- if (!LF_ISSET(FS_FORCE | FS_APPEND) && !O_ISSET(sp, O_WRITEANY)) {
- /* Don't overwrite anything but the original file. */
- if ((!noname || F_ISSET(frp, FR_NAMECHANGE)) &&
- !stat(name, &sb)) {
- if (LF_ISSET(FS_POSSIBLE))
- msgq(sp, M_ERR,
- "%s exists, not written; use ! to override", name);
- else
- msgq(sp, M_ERR, "%s exists, not written", name);
- return (1);
- }
-
- /*
- * Don't write part of any existing file. Only test for the
- * original file, the previous test catches anything else.
- */
- if (!LF_ISSET(FS_ALL) && noname && !stat(name, &sb)) {
- if (LF_ISSET(FS_POSSIBLE))
- msgq(sp, M_ERR,
- "Use ! to write a partial file");
- else
- msgq(sp, M_ERR, "Partial file, not written");
- return (1);
- }
- }
-
- /*
- * Figure out if the file already exists -- if it doesn't, we display
- * the "new file" message. The stat might not be necessary, but we
- * just repeat it because it's easier than hacking the previous tests.
- * The information is only used for the user message and modification
- * time test, so we can ignore the obvious race condition.
- *
- * If the user is overwriting a file other than the original file, and
- * O_WRITEANY was what got us here (neither force nor append was set),
- * display the "existing file" messsage. Since the FR_NAMECHANGE flag
- * is cleared on a successful write, the message only appears once when
- * the user changes a file name. This is historic practice.
- *
- * One final test. If we're not forcing or appending, and we have a
- * saved modification time, stop the user if it's been written since
- * we last edited or wrote it, and make them force it.
- */
- if (stat(name, &sb))
- msg = ": new file";
- else {
- msg = "";
- if (!LF_ISSET(FS_FORCE | FS_APPEND)) {
- if (ep->mtime && sb.st_mtime > ep->mtime) {
- msgq(sp, M_ERR,
- "%s: file modified more recently than this copy%s",
- name, LF_ISSET(FS_POSSIBLE) ?
- "; use ! to override" : "");
- return (1);
- }
- if (!noname || F_ISSET(frp, FR_NAMECHANGE))
- msg = ": existing file";
- }
- }
-
- /* Set flags to either append or truncate. */
- oflags = O_CREAT | O_WRONLY;
- if (LF_ISSET(FS_APPEND))
- oflags |= O_APPEND;
- else
- oflags |= O_TRUNC;
-
- /* Open the file. */
- if ((fd = open(name, oflags, DEFFILEMODE)) < 0) {
- msgq(sp, M_SYSERR, name);
- return (1);
- }
-
- /* Use stdio for buffering. */
- if ((fp = fdopen(fd, "w")) == NULL) {
- (void)close(fd);
- msgq(sp, M_SYSERR, name);
- return (1);
- }
-
- /* Build fake addresses, if necessary. */
- if (fm == NULL) {
- from.lno = 1;
- from.cno = 0;
- fm = &from;
- if (file_lline(sp, ep, &to.lno))
- return (1);
- to.cno = 0;
- tm = &to;
- }
-
- /* Turn on the busy message. */
- btear = F_ISSET(sp, S_EXSILENT) ? 0 : !busy_on(sp, "Writing...");
- rval = ex_writefp(sp, ep, name, fp, fm, tm, &nlno, &nch);
- if (btear)
- busy_off(sp);
-
- /*
- * Save the new last modification time -- even if the write fails
- * we re-init the time. That way the user can clean up the disk
- * and rewrite without having to force it.
- */
- ep->mtime = stat(name, &sb) ? 0 : sb.st_mtime;
-
- /* If the write failed, complain loudly. */
- if (rval) {
- if (!LF_ISSET(FS_APPEND))
- msgq(sp, M_ERR, "%s: WARNING: file truncated!", name);
- return (1);
- }
-
- /*
- * Once we've actually written the file, it doesn't matter that the
- * file name was changed -- if it was, we've already whacked it.
- */
- F_CLR(frp, FR_NAMECHANGE);
-
- /*
- * If wrote the entire file clear the modified bit. If the file was
- * written back to the original file name and the file is a temporary,
- * set the "no exit" bit. This permits the user to write the file and
- * use it in the context of the file system, but still keeps them from
- * losing their changes by exiting.
- */
- if (LF_ISSET(FS_ALL)) {
- F_CLR(ep, F_MODIFIED);
- if (F_ISSET(frp, FR_TMPFILE))
- if (noname)
- F_SET(frp, FR_TMPEXIT);
- else
- F_CLR(frp, FR_TMPEXIT);
- }
-
- msgq(sp, M_INFO, "%s%s%s: %lu line%s, %lu characters",
- INTERRUPTED(sp) ? "Interrupted write: " : "",
- name, msg, nlno, nlno == 1 ? "" : "s", nch);
-
- return (0);
-}
-
-/*
- * file_m1 --
- * First modification check routine. The :next, :prev, :rewind, :tag,
- * :tagpush, :tagpop, ^^ modifications check.
- */
-int
-file_m1(sp, ep, force, flags)
- SCR *sp;
- EXF *ep;
- int force, flags;
-{
- /*
- * If the file has been modified, we'll want to write it back or
- * fail. If autowrite is set, we'll write it back automatically,
- * unless force is also set. Otherwise, we fail unless forced or
- * there's another open screen on this file.
- */
- if (F_ISSET(ep, F_MODIFIED))
- if (O_ISSET(sp, O_AUTOWRITE)) {
- if (!force &&
- file_write(sp, ep, NULL, NULL, NULL, flags))
- return (1);
- } else if (ep->refcnt <= 1 && !force) {
- msgq(sp, M_ERR,
- "File modified since last complete write; write or use %s to override",
- LF_ISSET(FS_POSSIBLE) ? "!" : ":edit!");
- return (1);
- }
-
- return (file_m3(sp, ep, force));
-}
-
-/*
- * file_m2 --
- * Second modification check routine. The :edit, :quit, :recover
- * modifications check.
- */
-int
-file_m2(sp, ep, force)
- SCR *sp;
- EXF *ep;
- int force;
-{
- /*
- * If the file has been modified, we'll want to fail, unless forced
- * or there's another open screen on this file.
- */
- if (F_ISSET(ep, F_MODIFIED) && ep->refcnt <= 1 && !force) {
- msgq(sp, M_ERR,
- "File modified since last complete write; write or use ! to override");
- return (1);
- }
-
- return (file_m3(sp, ep, force));
-}
-
-/*
- * file_m3 --
- * Third modification check routine.
- */
-int
-file_m3(sp, ep, force)
- SCR *sp;
- EXF *ep;
- int force;
-{
- /*
- * Don't exit while in a temporary files if the file was ever modified.
- * The problem is that if the user does a ":wq", we write and quit,
- * unlinking the temporary file. Not what the user had in mind at all.
- * We permit writing to temporary files, so that user maps using file
- * system names work with temporary files.
- */
- if (F_ISSET(sp->frp, FR_TMPEXIT) && ep->refcnt <= 1 && !force) {
- msgq(sp, M_ERR,
- "File is a temporary; exit will discard modifications");
- return (1);
- }
- return (0);
-}
-
-/*
- * file_lock --
- * Get an exclusive lock on a file.
- *
- * XXX
- * The default locking is flock(2) style, not fcntl(2). The latter is
- * known to fail badly on some systems, and its only advantage is that
- * it occasionally works over NFS.
- *
- * Furthermore, the semantics of fcntl(2) are wrong. The problems are
- * two-fold: you can't close any file descriptor associated with the file
- * without losing all of the locks, and you can't get an exclusive lock
- * unless you have the file open for writing. Someone ought to be shot,
- * but it's probably too late, they may already have reproduced. To get
- * around these problems, nvi opens the files for writing when it can and
- * acquires a second file descriptor when it can't. The recovery files
- * are examples of the former, they're always opened for writing. The DB
- * files can't be opened for writing because the semantics of DB are that
- * files opened for writing are flushed back to disk when the DB session
- * is ended. So, in that case we have to acquire an extra file descriptor.
- */
-enum lockt
-file_lock(name, fdp, fd, iswrite)
- char *name;
- int fd, *fdp, iswrite;
-{
-#if !defined(USE_FCNTL) && defined(LOCK_EX)
- /* Hurrah! We've got flock(2). */
- /*
- * !!!
- * We need to distinguish a lock not being available for the file
- * from the file system not supporting locking. Flock is documented
- * as returning EWOULDBLOCK; add EAGAIN for good measure, and assume
- * they are the former. There's no portable way to do this.
- */
- errno = 0;
- return (flock(fd, LOCK_EX | LOCK_NB) ?
- errno == EAGAIN || errno == EWOULDBLOCK ?
- LOCK_UNAVAIL : LOCK_FAILED : LOCK_SUCCESS);
-
-#else /* Gag me. We've got fcntl(2). */
- struct flock arg;
- int didopen, sverrno;
-
- arg.l_type = F_WRLCK;
- arg.l_whence = 0; /* SEEK_SET */
- arg.l_start = arg.l_len = 0;
- arg.l_pid = 0;
-
- /* If the file descriptor isn't opened for writing, it must fail. */
- if (!iswrite) {
- if (name == NULL || fdp == NULL)
- return (LOCK_FAILED);
- if ((fd = open(name, O_RDWR, 0)) == -1)
- return (LOCK_FAILED);
- *fdp = fd;
- didopen = 1;
- }
-
- errno = 0;
- if (!fcntl(fd, F_SETLK, &arg))
- return (LOCK_SUCCESS);
- if (didopen) {
- sverrno = errno;
- (void)close(fd);
- errno = sverrno;
- }
-
- /*
- * !!!
- * We need to distinguish a lock not being available for the file
- * from the file system not supporting locking. Fcntl is documented
- * as returning EACCESS and EAGAIN; add EWOULDBLOCK for good measure,
- * and assume they are the former. There's no portable way to do this.
- */
- return (errno == EACCES || errno == EAGAIN || errno == EWOULDBLOCK ?
- LOCK_UNAVAIL : LOCK_FAILED);
-#endif
-}
diff --git a/usr.bin/vi/common/exf.h b/usr.bin/vi/common/exf.h
deleted file mode 100644
index 1b06649..0000000
--- a/usr.bin/vi/common/exf.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)exf.h 8.35 (Berkeley) 8/4/94
- */
- /* Undo direction. */
-/*
- * exf --
- * The file structure.
- */
-struct _exf {
- int refcnt; /* Reference count. */
-
- /* Underlying database state. */
- DB *db; /* File db structure. */
- char *c_lp; /* Cached line. */
- size_t c_len; /* Cached line length. */
- recno_t c_lno; /* Cached line number. */
- recno_t c_nlines; /* Cached lines in the file. */
-
- DB *log; /* Log db structure. */
- char *l_lp; /* Log buffer. */
- size_t l_len; /* Log buffer length. */
- recno_t l_high; /* Log last + 1 record number. */
- recno_t l_cur; /* Log current record number. */
- MARK l_cursor; /* Log cursor position. */
- enum direction lundo; /* Last undo direction. */
-
- LIST_HEAD(_markh, _lmark) marks;/* Linked list of file MARK's. */
-
- time_t mtime; /* Last modification time. */
-
- int fcntl_fd; /* Fcntl locking fd; see exf.c. */
-
- /*
- * Recovery in general, and these fields specifically, are described
- * in recover.c.
- */
-#define RCV_PERIOD 120 /* Sync every two minutes. */
- char *rcv_path; /* Recover file name. */
- char *rcv_mpath; /* Recover mail file name. */
- int rcv_fd; /* Locked mail file descriptor. */
- struct timeval rcv_tod; /* ITIMER_REAL: recovery time-of-day. */
-
-#define F_FIRSTMODIFY 0x001 /* File not yet modified. */
-#define F_MODIFIED 0x002 /* File is currently dirty. */
-#define F_MULTILOCK 0x004 /* Multiple processes running, lock. */
-#define F_NOLOG 0x008 /* Logging turned off. */
-#define F_RCV_NORM 0x010 /* Don't delete recovery files. */
-#define F_RCV_ON 0x020 /* Recovery is possible. */
-#define F_UNDO 0x040 /* No change since last undo. */
- u_int8_t flags;
-};
-
-#define GETLINE_ERR(sp, lno) { \
- msgq(sp, M_ERR, \
- "Error: %s/%d: unable to retrieve line %u", \
- tail(__FILE__), __LINE__, lno); \
-}
-
-/* EXF routines. */
-FREF *file_add __P((SCR *, CHAR_T *));
-int file_end __P((SCR *, EXF *, int));
-int file_init __P((SCR *, FREF *, char *, int));
-int file_m1 __P((SCR *, EXF *, int, int));
-int file_m2 __P((SCR *, EXF *, int));
-int file_m3 __P((SCR *, EXF *, int));
-
-enum lockt { LOCK_FAILED, LOCK_SUCCESS, LOCK_UNAVAIL };
-enum lockt
- file_lock __P((char *, int *, int, int));
-
-#define FS_ALL 0x01 /* Write the entire file. */
-#define FS_APPEND 0x02 /* Append to the file. */
-#define FS_FORCE 0x04 /* Force is set. */
-#define FS_POSSIBLE 0x08 /* Force could be set. */
-int file_write __P((SCR *, EXF *, MARK *, MARK *, char *, int));
-
-/* Recovery routines. */
-int rcv_init __P((SCR *, EXF *));
-int rcv_list __P((SCR *));
-int rcv_on __P((SCR *, EXF *));
-int rcv_read __P((SCR *, FREF *));
-
-#define RCV_EMAIL 0x01 /* Send the user email, IFF file modified. */
-#define RCV_ENDSESSION 0x02 /* End the file session. */
-#define RCV_PRESERVE 0x04 /* Preserve backup file, IFF file modified. */
-#define RCV_SNAPSHOT 0x08 /* Snapshot the recovery, and send email. */
-int rcv_sync __P((SCR *, EXF *, u_int));
-int rcv_tmp __P((SCR *, EXF *, char *));
-
-/* DB interface routines */
-int file_aline __P((SCR *, EXF *, int, recno_t, char *, size_t));
-int file_dline __P((SCR *, EXF *, recno_t));
-char *file_gline __P((SCR *, EXF *, recno_t, size_t *));
-int file_iline __P((SCR *, EXF *, recno_t, char *, size_t));
-int file_lline __P((SCR *, EXF *, recno_t *));
-char *file_rline __P((SCR *, EXF *, recno_t, size_t *));
-int file_sline __P((SCR *, EXF *, recno_t, char *, size_t));
diff --git a/usr.bin/vi/common/gs.h b/usr.bin/vi/common/gs.h
deleted file mode 100644
index 36343f4..0000000
--- a/usr.bin/vi/common/gs.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)gs.h 8.39 (Berkeley) 7/23/94
- */
-
-struct _gs {
- CIRCLEQ_HEAD(_dqh, _scr) dq; /* Displayed screens. */
- CIRCLEQ_HEAD(_hqh, _scr) hq; /* Hidden screens. */
-
- mode_t origmode; /* Original terminal mode. */
- struct termios
- original_termios; /* Original terminal values. */
-
- MSGH msgq; /* User message list. */
-
- char *tmp_bp; /* Temporary buffer. */
- size_t tmp_blen; /* Size of temporary buffer. */
-
- sigset_t blockset; /* Signal mask. */
-
-#ifdef DEBUG
- FILE *tracefp; /* Trace file pointer. */
-#endif
-
-/* INFORMATION SHARED BY ALL SCREENS. */
- IBUF *tty; /* Key input buffer. */
-
- CB *dcbp; /* Default cut buffer pointer. */
- CB dcb_store; /* Default cut buffer storage. */
- LIST_HEAD(_cuth, _cb) cutq; /* Linked list of cut buffers. */
-
-#define MAX_BIT_SEQ 128 /* Max + 1 fast check character. */
- LIST_HEAD(_seqh, _seq) seqq; /* Linked list of maps, abbrevs. */
- bitstr_t bit_decl(seqb, MAX_BIT_SEQ);
-
-#define MAX_FAST_KEY 254 /* Max fast check character.*/
-#define KEY_LEN(sp, ch) \
- ((ch) <= MAX_FAST_KEY ? \
- sp->gp->cname[ch].len : __key_len(sp, ch))
-#define KEY_NAME(sp, ch) \
- ((ch) <= MAX_FAST_KEY ? \
- sp->gp->cname[ch].name : __key_name(sp, ch))
- struct {
- CHAR_T name[MAX_CHARACTER_COLUMNS + 1];
- u_int8_t len;
- } cname[MAX_FAST_KEY + 1]; /* Fast lookup table. */
-
-#define KEY_VAL(sp, ch) \
- ((ch) <= MAX_FAST_KEY ? sp->gp->special_key[ch] : \
- (ch) > sp->gp->max_special ? 0 : __key_val(sp, ch))
- CHAR_T max_special; /* Max special character. */
- u_char /* Fast lookup table. */
- special_key[MAX_FAST_KEY + 1];
-
-/* Interrupt macros. */
-#define INTERRUPTED(sp) \
- (F_ISSET((sp), S_INTERRUPTED) || F_ISSET((sp)->gp, G_SIGINT))
-#define CLR_INTERRUPT(sp) { \
- F_CLR((sp), S_INTERRUPTED | S_INTERRUPTIBLE); \
- F_CLR((sp)->gp, G_SIGINT); \
-}
-
-#define G_ABBREV 0x0001 /* If have abbreviations. */
-#define G_BELLSCHED 0x0002 /* Bell scheduled. */
-#define G_RECOVER_SET 0x0004 /* Recover system initialized. */
-#define G_SETMODE 0x0008 /* Tty mode changed. */
-#define G_SIGALRM 0x0010 /* SIGALRM arrived. */
-#define G_SIGINT 0x0020 /* SIGINT arrived. */
-#define G_SIGWINCH 0x0040 /* SIGWINCH arrived. */
-#define G_SNAPSHOT 0x0080 /* Always snapshot files. */
-#define G_STDIN_TTY 0x0100 /* Standard input is a tty. */
-#define G_TERMIOS_SET 0x0200 /* Termios structure is valid. */
-#define G_TMP_INUSE 0x0400 /* Temporary buffer in use. */
- u_int16_t flags;
-};
-
-extern GS *__global_list; /* List of screens. */
diff --git a/usr.bin/vi/common/line.c b/usr.bin/vi/common/line.c
deleted file mode 100644
index 847c132..0000000
--- a/usr.bin/vi/common/line.c
+++ /dev/null
@@ -1,492 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)line.c 8.32 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-static __inline int scr_update
- __P((SCR *, EXF *, recno_t, enum operation, int));
-
-/*
- * file_gline --
- * Look in the text buffers for a line; if it's not there
- * call file_rline to retrieve it from the database.
- */
-char *
-file_gline(sp, ep, lno, lenp)
- SCR *sp;
- EXF *ep;
- recno_t lno; /* Line number. */
- size_t *lenp; /* Length store. */
-{
- TEXT *tp;
- recno_t l1, l2;
-
- /*
- * The underlying recno stuff handles zero by returning NULL, but
- * have to have an oob condition for the look-aside into the input
- * buffer anyway.
- */
- if (lno == 0)
- return (NULL);
-
- /*
- * Look-aside into the TEXT buffers and see if the line we want
- * is there.
- */
- if (F_ISSET(sp, S_INPUT)) {
- l1 = ((TEXT *)sp->tiqp->cqh_first)->lno;
- l2 = ((TEXT *)sp->tiqp->cqh_last)->lno;
- if (l1 <= lno && l2 >= lno) {
- for (tp = sp->tiqp->cqh_first;
- tp->lno != lno; tp = tp->q.cqe_next);
- if (lenp)
- *lenp = tp->len;
- return (tp->lb);
- }
- /*
- * Adjust the line number for the number of lines used
- * by the text input buffers.
- */
- if (lno > l2)
- lno -= l2 - l1;
- }
- return (file_rline(sp, ep, lno, lenp));
-}
-
-/*
- * file_rline --
- * Look in the cache for a line; if it's not there retrieve
- * it from the file.
- */
-char *
-file_rline(sp, ep, lno, lenp)
- SCR *sp;
- EXF *ep;
- recno_t lno; /* Line number. */
- size_t *lenp; /* Length store. */
-{
- DBT data, key;
-
- /* Check the cache. */
- if (lno == ep->c_lno) {
- if (lenp)
- *lenp = ep->c_len;
- return (ep->c_lp);
- }
- ep->c_lno = OOBLNO;
-
- /* Get the line from the underlying database. */
- key.data = &lno;
- key.size = sizeof(lno);
- switch (ep->db->get(ep->db, &key, &data, 0)) {
- case -1:
- msgq(sp, M_ERR,
- "Error: %s/%d: unable to get line %u: %s",
- tail(__FILE__), __LINE__, lno, strerror(errno));
- /* FALLTHROUGH */
- case 1:
- return (NULL);
- /* NOTREACHED */
- }
- if (lenp)
- *lenp = data.size;
-
- /* Fill the cache. */
- ep->c_lno = lno;
- ep->c_len = data.size;
- ep->c_lp = data.data;
-
- return (data.data);
-}
-
-/*
- * file_dline --
- * Delete a line from the file.
- */
-int
-file_dline(sp, ep, lno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
-{
- DBT key;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "delete line %lu\n", lno);
-#endif
- /*
- * XXX
- * Marks and global commands have to know when lines are
- * inserted or deleted.
- */
- mark_insdel(sp, ep, LINE_DELETE, lno);
- global_insdel(sp, ep, LINE_DELETE, lno);
-
- /* Log change. */
- log_line(sp, ep, lno, LOG_LINE_DELETE);
-
- /* Update file. */
- key.data = &lno;
- key.size = sizeof(lno);
- SIGBLOCK(sp->gp);
- if (ep->db->del(ep->db, &key, 0) == 1) {
- msgq(sp, M_ERR,
- "Error: %s/%d: unable to delete line %u: %s",
- tail(__FILE__), __LINE__, lno, strerror(errno));
- return (1);
- }
- SIGUNBLOCK(sp->gp);
-
- /* Flush the cache, update line count, before screen update. */
- if (lno <= ep->c_lno)
- ep->c_lno = OOBLNO;
- if (ep->c_nlines != OOBLNO)
- --ep->c_nlines;
-
- /* File now dirty. */
- if (F_ISSET(ep, F_FIRSTMODIFY))
- (void)rcv_init(sp, ep);
- F_SET(ep, F_MODIFIED);
-
- /* Update screen. */
- return (scr_update(sp, ep, lno, LINE_DELETE, 1));
-}
-
-/*
- * file_aline --
- * Append a line into the file.
- */
-int
-file_aline(sp, ep, update, lno, p, len)
- SCR *sp;
- EXF *ep;
- int update;
- recno_t lno;
- char *p;
- size_t len;
-{
- DBT data, key;
- recno_t lline;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "append to %lu: len %u {%.*s}\n", lno, len, MIN(len, 20), p);
-#endif
- /*
- * XXX
- * Very nasty special case. The historic vi code displays a single
- * space (or a '$' if the list option is set) for the first line in
- * an "empty" file. If we "insert" a line, that line gets scrolled
- * down, not repainted, so it's incorrect when we refresh the the
- * screen. This is really hard to find and fix in the vi code -- the
- * text input functions detect it explicitly and don't insert a new
- * line. The hack here is to repaint the screen if we're appending
- * to an empty file. The reason that the test is in file_aline, and
- * not in file_iline or file_sline, is that all of the ex commands
- * that work in empty files end up here.
- */
- if (lno == 0) {
- if (file_lline(sp, ep, &lline))
- return (1);
- if (lline == 0)
- F_SET(sp, S_REDRAW);
- }
-
- /* Update file. */
- key.data = &lno;
- key.size = sizeof(lno);
- data.data = p;
- data.size = len;
- SIGBLOCK(sp->gp);
- if (ep->db->put(ep->db, &key, &data, R_IAFTER) == -1) {
- msgq(sp, M_ERR,
- "Error: %s/%d: unable to append to line %u: %s",
- tail(__FILE__), __LINE__, lno, strerror(errno));
- return (1);
- }
- SIGUNBLOCK(sp->gp);
-
- /* Flush the cache, update line count, before screen update. */
- if (lno < ep->c_lno)
- ep->c_lno = OOBLNO;
- if (ep->c_nlines != OOBLNO)
- ++ep->c_nlines;
-
- /* File now dirty. */
- if (F_ISSET(ep, F_FIRSTMODIFY))
- (void)rcv_init(sp, ep);
- F_SET(ep, F_MODIFIED);
-
- /* Log change. */
- log_line(sp, ep, lno + 1, LOG_LINE_APPEND);
-
- /*
- * XXX
- * Marks and global commands have to know when lines are
- * inserted or deleted.
- *
- * XXX
- * See comment above about empty files. If the file was empty,
- * then we're adding the first line, which is a replacement, not
- * an append. So, we shouldn't whack the marks.
- */
- if (lno != 0) {
- mark_insdel(sp, ep, LINE_INSERT, lno + 1);
- global_insdel(sp, ep, LINE_INSERT, lno + 1);
- }
-
- /*
- * Update screen.
- *
- * XXX
- * Nasty hack. If multiple lines are input by the user, they aren't
- * committed until an <ESC> is entered. The problem is the screen was
- * updated/scrolled as each line was entered. So, when this routine
- * is called to copy the new lines from the cut buffer into the file,
- * it has to know not to update the screen again.
- */
- return (scr_update(sp, ep, lno, LINE_APPEND, update));
-}
-
-/*
- * file_iline --
- * Insert a line into the file.
- */
-int
-file_iline(sp, ep, lno, p, len)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- char *p;
- size_t len;
-{
- DBT data, key;
- recno_t lline;
-
-#if defined(DEBUG) && 0
- TRACE(sp,
- "insert before %lu: len %u {%.*s}\n", lno, len, MIN(len, 20), p);
-#endif
-
- /* Very nasty special case. See comment in file_aline(). */
- if (lno == 1) {
- if (file_lline(sp, ep, &lline))
- return (1);
- if (lline == 0)
- F_SET(sp, S_REDRAW);
- }
-
- /* Update file. */
- key.data = &lno;
- key.size = sizeof(lno);
- data.data = p;
- data.size = len;
- SIGBLOCK(sp->gp);
- if (ep->db->put(ep->db, &key, &data, R_IBEFORE) == -1) {
- msgq(sp, M_ERR,
- "Error: %s/%d: unable to insert at line %u: %s",
- tail(__FILE__), __LINE__, lno, strerror(errno));
- return (1);
- }
- SIGUNBLOCK(sp->gp);
-
- /* Flush the cache, update line count, before screen update. */
- if (lno >= ep->c_lno)
- ep->c_lno = OOBLNO;
- if (ep->c_nlines != OOBLNO)
- ++ep->c_nlines;
-
- /* File now dirty. */
- if (F_ISSET(ep, F_FIRSTMODIFY))
- (void)rcv_init(sp, ep);
- F_SET(ep, F_MODIFIED);
-
- /* Log change. */
- log_line(sp, ep, lno, LOG_LINE_INSERT);
-
- /*
- * XXX
- * Marks and global commands have to know when lines are
- * inserted or deleted.
- */
- mark_insdel(sp, ep, LINE_INSERT, lno);
- global_insdel(sp, ep, LINE_INSERT, lno);
-
- /* Update screen. */
- return (scr_update(sp, ep, lno, LINE_INSERT, 1));
-}
-
-/*
- * file_sline --
- * Store a line in the file.
- */
-int
-file_sline(sp, ep, lno, p, len)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- char *p;
- size_t len;
-{
- DBT data, key;
-
-#if defined(DEBUG) && 0
- TRACE(sp,
- "replace line %lu: len %u {%.*s}\n", lno, len, MIN(len, 20), p);
-#endif
- /* Log before change. */
- log_line(sp, ep, lno, LOG_LINE_RESET_B);
-
- /* Update file. */
- key.data = &lno;
- key.size = sizeof(lno);
- data.data = p;
- data.size = len;
- SIGBLOCK(sp->gp);
- if (ep->db->put(ep->db, &key, &data, 0) == -1) {
- msgq(sp, M_ERR,
- "Error: %s/%d: unable to store line %u: %s",
- tail(__FILE__), __LINE__, lno, strerror(errno));
- return (1);
- }
- SIGUNBLOCK(sp->gp);
-
- /* Flush the cache, before logging or screen update. */
- if (lno == ep->c_lno)
- ep->c_lno = OOBLNO;
-
- /* File now dirty. */
- if (F_ISSET(ep, F_FIRSTMODIFY))
- (void)rcv_init(sp, ep);
- F_SET(ep, F_MODIFIED);
-
- /* Log after change. */
- log_line(sp, ep, lno, LOG_LINE_RESET_F);
-
- /* Update screen. */
- return (scr_update(sp, ep, lno, LINE_RESET, 1));
-}
-
-/*
- * file_lline --
- * Return the number of lines in the file.
- */
-int
-file_lline(sp, ep, lnop)
- SCR *sp;
- EXF *ep;
- recno_t *lnop;
-{
- DBT data, key;
- recno_t lno;
-
- /* Check the cache. */
- if (ep->c_nlines != OOBLNO) {
- *lnop = (F_ISSET(sp, S_INPUT) &&
- ((TEXT *)sp->tiqp->cqh_last)->lno > ep->c_nlines ?
- ((TEXT *)sp->tiqp->cqh_last)->lno : ep->c_nlines);
- return (0);
- }
-
- key.data = &lno;
- key.size = sizeof(lno);
-
- switch (ep->db->seq(ep->db, &key, &data, R_LAST)) {
- case -1:
- msgq(sp, M_ERR,
- "Error: %s/%d: unable to get last line: %s",
- tail(__FILE__), __LINE__, strerror(errno));
- *lnop = 0;
- return (1);
- case 1:
- *lnop = 0;
- return (0);
- default:
- break;
- }
-
- /* Fill the cache. */
- memmove(&lno, key.data, sizeof(lno));
- ep->c_nlines = ep->c_lno = lno;
- ep->c_len = data.size;
- ep->c_lp = data.data;
-
- /* Return the value. */
- *lnop = (F_ISSET(sp, S_INPUT) &&
- ((TEXT *)sp->tiqp->cqh_last)->lno > lno ?
- ((TEXT *)sp->tiqp->cqh_last)->lno : lno);
- return (0);
-}
-
-/*
- * scr_update --
- * Update all of the screens that are backed by the file that
- * just changed.
- */
-static __inline int
-scr_update(sp, ep, lno, op, current)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- enum operation op;
- int current;
-{
- SCR *tsp;
-
- if (ep->refcnt != 1)
- for (tsp = sp->gp->dq.cqh_first;
- tsp != (void *)&sp->gp->dq; tsp = tsp->q.cqe_next)
- if (sp != tsp && tsp->ep == ep)
- (void)sp->s_change(tsp, ep, lno, op);
- return (current && sp->s_change(sp, ep, lno, op));
-}
diff --git a/usr.bin/vi/common/log.c b/usr.bin/vi/common/log.c
deleted file mode 100644
index b3a2295..0000000
--- a/usr.bin/vi/common/log.c
+++ /dev/null
@@ -1,698 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)log.c 8.18 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * The log consists of records, each containing a type byte and a variable
- * length byte string, as follows:
- *
- * LOG_CURSOR_INIT MARK
- * LOG_CURSOR_END MARK
- * LOG_LINE_APPEND recno_t char *
- * LOG_LINE_DELETE recno_t char *
- * LOG_LINE_INSERT recno_t char *
- * LOG_LINE_RESET_F recno_t char *
- * LOG_LINE_RESET_B recno_t char *
- * LOG_MARK LMARK
- *
- * We do before image physical logging. This means that the editor layer
- * MAY NOT modify records in place, even if simply deleting or overwriting
- * characters. Since the smallest unit of logging is a line, we're using
- * up lots of space. This may eventually have to be reduced, probably by
- * doing logical logging, which is a much cooler database phrase.
- *
- * The implementation of the historic vi 'u' command, using roll-forward and
- * roll-back, is simple. Each set of changes has a LOG_CURSOR_INIT record,
- * followed by a number of other records, followed by a LOG_CURSOR_END record.
- * LOG_LINE_RESET records come in pairs. The first is a LOG_LINE_RESET_B
- * record, and is the line before the change. The second is LOG_LINE_RESET_F,
- * and is the line after the change. Roll-back is done by backing up to the
- * first LOG_CURSOR_INIT record before a change. Roll-forward is done in a
- * similar fashion.
- *
- * The 'U' command is implemented by rolling backward to a LOG_CURSOR_END
- * record for a line different from the current one. It should be noted that
- * this means that a subsequent 'u' command will make a change based on the
- * new position of the log's cursor. This is okay, and, in fact, historic vi
- * behaved that way.
- */
-
-static int log_cursor1 __P((SCR *, EXF *, int));
-#if defined(DEBUG) && 0
-static void log_trace __P((SCR *, char *, recno_t, u_char *));
-#endif
-
-/* Try and restart the log on failure, i.e. if we run out of memory. */
-#define LOG_ERR { \
- msgq(sp, M_ERR, "Error: %s/%d: put log error: %s", \
- tail(__FILE__), __LINE__, strerror(errno)); \
- (void)ep->log->close(ep->log); \
- if (!log_init(sp, ep)) \
- msgq(sp, M_ERR, "Log restarted"); \
- return (1); \
-}
-
-/*
- * log_init --
- * Initialize the logging subsystem.
- */
-int
-log_init(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- /*
- * Initialize the buffer. The logging subsystem has its own
- * buffers because the global ones are almost by definition
- * going to be in use when the log runs.
- */
- ep->l_lp = NULL;
- ep->l_len = 0;
- ep->l_cursor.lno = 1; /* XXX Any valid recno. */
- ep->l_cursor.cno = 0;
- ep->l_high = ep->l_cur = 1;
-
- ep->log = dbopen(NULL, O_CREAT | O_NONBLOCK | O_RDWR,
- S_IRUSR | S_IWUSR, DB_RECNO, NULL);
- if (ep->log == NULL) {
- msgq(sp, M_ERR, "log db: %s", strerror(errno));
- F_SET(ep, F_NOLOG);
- return (1);
- }
-
- return (0);
-}
-
-/*
- * log_end --
- * Close the logging subsystem.
- */
-int
-log_end(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- if (ep->log != NULL) {
- (void)(ep->log->close)(ep->log);
- ep->log = NULL;
- }
- if (ep->l_lp != NULL) {
- free(ep->l_lp);
- ep->l_lp = NULL;
- }
- ep->l_len = 0;
- ep->l_cursor.lno = 1; /* XXX Any valid recno. */
- ep->l_cursor.cno = 0;
- ep->l_high = ep->l_cur = 1;
- return (0);
-}
-
-/*
- * log_cursor --
- * Log the current cursor position, starting an event.
- */
-int
-log_cursor(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- /*
- * If any changes were made since the last cursor init,
- * put out the ending cursor record.
- */
- if (ep->l_cursor.lno == OOBLNO) {
- ep->l_cursor.lno = sp->lno;
- ep->l_cursor.cno = sp->cno;
- return (log_cursor1(sp, ep, LOG_CURSOR_END));
- }
- ep->l_cursor.lno = sp->lno;
- ep->l_cursor.cno = sp->cno;
- return (0);
-}
-
-/*
- * log_cursor1 --
- * Actually push a cursor record out.
- */
-static int
-log_cursor1(sp, ep, type)
- SCR *sp;
- EXF *ep;
- int type;
-{
- DBT data, key;
-
- BINC_RET(sp, ep->l_lp, ep->l_len, sizeof(u_char) + sizeof(MARK));
- ep->l_lp[0] = type;
- memmove(ep->l_lp + sizeof(u_char), &ep->l_cursor, sizeof(MARK));
-
- key.data = &ep->l_cur;
- key.size = sizeof(recno_t);
- data.data = ep->l_lp;
- data.size = sizeof(u_char) + sizeof(MARK);
- if (ep->log->put(ep->log, &key, &data, 0) == -1)
- LOG_ERR;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "%lu: %s: %u/%u\n", ep->l_cur,
- type == LOG_CURSOR_INIT ? "log_cursor_init" : "log_cursor_end",
- sp->lno, sp->cno);
-#endif
- /* Reset high water mark. */
- ep->l_high = ++ep->l_cur;
-
- return (0);
-}
-
-/*
- * log_line --
- * Log a line change.
- */
-int
-log_line(sp, ep, lno, action)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- u_int action;
-{
- DBT data, key;
- size_t len;
- char *lp;
-
- if (F_ISSET(ep, F_NOLOG))
- return (0);
-
- /*
- * XXX
- *
- * Kluge for vi. Clear the EXF undo flag so that the
- * next 'u' command does a roll-back, regardless.
- */
- F_CLR(ep, F_UNDO);
-
- /* Put out one initial cursor record per set of changes. */
- if (ep->l_cursor.lno != OOBLNO) {
- if (log_cursor1(sp, ep, LOG_CURSOR_INIT))
- return (1);
- ep->l_cursor.lno = OOBLNO;
- }
-
- /*
- * Put out the changes. If it's a LOG_LINE_RESET_B call, it's a
- * special case, avoid the caches. Also, if it fails and it's
- * line 1, it just means that the user started with an empty file,
- * so fake an empty length line.
- */
- if (action == LOG_LINE_RESET_B) {
- if ((lp = file_rline(sp, ep, lno, &len)) == NULL) {
- if (lno != 1) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- len = 0;
- lp = "";
- }
- } else
- if ((lp = file_gline(sp, ep, lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- BINC_RET(sp,
- ep->l_lp, ep->l_len, len + sizeof(u_char) + sizeof(recno_t));
- ep->l_lp[0] = action;
- memmove(ep->l_lp + sizeof(u_char), &lno, sizeof(recno_t));
- memmove(ep->l_lp + sizeof(u_char) + sizeof(recno_t), lp, len);
-
- key.data = &ep->l_cur;
- key.size = sizeof(recno_t);
- data.data = ep->l_lp;
- data.size = len + sizeof(u_char) + sizeof(recno_t);
- if (ep->log->put(ep->log, &key, &data, 0) == -1)
- LOG_ERR;
-
-#if defined(DEBUG) && 0
- switch (action) {
- case LOG_LINE_APPEND:
- TRACE(sp, "%u: log_line: append: %lu {%u}\n",
- ep->l_cur, lno, len);
- break;
- case LOG_LINE_DELETE:
- TRACE(sp, "%lu: log_line: delete: %lu {%u}\n",
- ep->l_cur, lno, len);
- break;
- case LOG_LINE_INSERT:
- TRACE(sp, "%lu: log_line: insert: %lu {%u}\n",
- ep->l_cur, lno, len);
- break;
- case LOG_LINE_RESET_F:
- TRACE(sp, "%lu: log_line: reset_f: %lu {%u}\n",
- ep->l_cur, lno, len);
- break;
- case LOG_LINE_RESET_B:
- TRACE(sp, "%lu: log_line: reset_b: %lu {%u}\n",
- ep->l_cur, lno, len);
- break;
- }
-#endif
- /* Reset high water mark. */
- ep->l_high = ++ep->l_cur;
-
- return (0);
-}
-
-/*
- * log_mark --
- * Log a mark position. For the log to work, we assume that there
- * aren't any operations that just put out a log record -- this
- * would mean that undo operations would only reset marks, and not
- * cause any other change.
- */
-int
-log_mark(sp, ep, lmp)
- SCR *sp;
- EXF *ep;
- LMARK *lmp;
-{
- DBT data, key;
-
- if (F_ISSET(ep, F_NOLOG))
- return (0);
-
- /* Put out one initial cursor record per set of changes. */
- if (ep->l_cursor.lno != OOBLNO) {
- if (log_cursor1(sp, ep, LOG_CURSOR_INIT))
- return (1);
- ep->l_cursor.lno = OOBLNO;
- }
-
- BINC_RET(sp, ep->l_lp,
- ep->l_len, sizeof(u_char) + sizeof(LMARK));
- ep->l_lp[0] = LOG_MARK;
- memmove(ep->l_lp + sizeof(u_char), lmp, sizeof(LMARK));
-
- key.data = &ep->l_cur;
- key.size = sizeof(recno_t);
- data.data = ep->l_lp;
- data.size = sizeof(u_char) + sizeof(LMARK);
- if (ep->log->put(ep->log, &key, &data, 0) == -1)
- LOG_ERR;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "%lu: mark %c: %lu/%u\n",
- ep->l_cur, lmp->name, lmp->lno, lmp->cno);
-#endif
- /* Reset high water mark. */
- ep->l_high = ++ep->l_cur;
- return (0);
-}
-
-/*
- * Log_backward --
- * Roll the log backward one operation.
- */
-int
-log_backward(sp, ep, rp)
- SCR *sp;
- EXF *ep;
- MARK *rp;
-{
- DBT key, data;
- LMARK lm;
- MARK m;
- recno_t lno;
- int didop;
- u_char *p;
-
- if (F_ISSET(ep, F_NOLOG)) {
- msgq(sp, M_ERR,
- "Logging not being performed, undo not possible");
- return (1);
- }
-
- if (ep->l_cur == 1) {
- msgq(sp, M_BERR, "No changes to undo");
- return (1);
- }
-
- F_SET(ep, F_NOLOG); /* Turn off logging. */
-
- key.data = &ep->l_cur; /* Initialize db request. */
- key.size = sizeof(recno_t);
- for (didop = 0;;) {
- --ep->l_cur;
- if (ep->log->get(ep->log, &key, &data, 0))
- LOG_ERR;
-#if defined(DEBUG) && 0
- log_trace(sp, "log_backward", ep->l_cur, data.data);
-#endif
- switch (*(p = (u_char *)data.data)) {
- case LOG_CURSOR_INIT:
- if (didop) {
- memmove(rp, p + sizeof(u_char), sizeof(MARK));
- F_CLR(ep, F_NOLOG);
- return (0);
- }
- break;
- case LOG_CURSOR_END:
- break;
- case LOG_LINE_APPEND:
- case LOG_LINE_INSERT:
- didop = 1;
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (file_dline(sp, ep, lno))
- goto err;
- ++sp->rptlines[L_DELETED];
- break;
- case LOG_LINE_DELETE:
- didop = 1;
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (file_iline(sp, ep, lno, p + sizeof(u_char) +
- sizeof(recno_t), data.size - sizeof(u_char) -
- sizeof(recno_t)))
- goto err;
- ++sp->rptlines[L_ADDED];
- break;
- case LOG_LINE_RESET_F:
- break;
- case LOG_LINE_RESET_B:
- didop = 1;
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (file_sline(sp, ep, lno, p + sizeof(u_char) +
- sizeof(recno_t), data.size - sizeof(u_char) -
- sizeof(recno_t)))
- goto err;
- if (sp->rptlchange != lno) {
- sp->rptlchange = lno;
- ++sp->rptlines[L_CHANGED];
- }
- break;
- case LOG_MARK:
- didop = 1;
- memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
- m.lno = lm.lno;
- m.cno = lm.cno;
- if (mark_set(sp, ep, lm.name, &m, 0))
- goto err;
- break;
- default:
- abort();
- }
- }
-
-err: F_CLR(ep, F_NOLOG);
- return (1);
-}
-
-/*
- * Log_setline --
- * Reset the line to its original appearance.
- *
- * XXX
- * There's a bug in this code due to our not logging cursor movements
- * unless a change was made. If you do a change, move off the line,
- * then move back on and do a 'U', the line will be restored to the way
- * it was before the original change.
- */
-int
-log_setline(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- DBT key, data;
- LMARK lm;
- MARK m;
- recno_t lno;
- u_char *p;
-
- if (F_ISSET(ep, F_NOLOG)) {
- msgq(sp, M_ERR,
- "Logging not being performed, undo not possible");
- return (1);
- }
-
- if (ep->l_cur == 1)
- return (1);
-
- F_SET(ep, F_NOLOG); /* Turn off logging. */
-
- key.data = &ep->l_cur; /* Initialize db request. */
- key.size = sizeof(recno_t);
-
- for (;;) {
- --ep->l_cur;
- if (ep->log->get(ep->log, &key, &data, 0))
- LOG_ERR;
-#if defined(DEBUG) && 0
- log_trace(sp, "log_setline", ep->l_cur, data.data);
-#endif
- switch (*(p = (u_char *)data.data)) {
- case LOG_CURSOR_INIT:
- memmove(&m, p + sizeof(u_char), sizeof(MARK));
- if (m.lno != sp->lno || ep->l_cur == 1) {
- F_CLR(ep, F_NOLOG);
- return (0);
- }
- break;
- case LOG_CURSOR_END:
- memmove(&m, p + sizeof(u_char), sizeof(MARK));
- if (m.lno != sp->lno) {
- ++ep->l_cur;
- F_CLR(ep, F_NOLOG);
- return (0);
- }
- break;
- case LOG_LINE_APPEND:
- case LOG_LINE_INSERT:
- case LOG_LINE_DELETE:
- case LOG_LINE_RESET_F:
- break;
- case LOG_LINE_RESET_B:
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (lno == sp->lno &&
- file_sline(sp, ep, lno, p + sizeof(u_char) +
- sizeof(recno_t), data.size - sizeof(u_char) -
- sizeof(recno_t)))
- goto err;
- if (sp->rptlchange != lno) {
- sp->rptlchange = lno;
- ++sp->rptlines[L_CHANGED];
- }
- case LOG_MARK:
- memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
- m.lno = lm.lno;
- m.cno = lm.cno;
- if (mark_set(sp, ep, lm.name, &m, 0))
- goto err;
- break;
- default:
- abort();
- }
- }
-
-err: F_CLR(ep, F_NOLOG);
- return (1);
-}
-
-/*
- * Log_forward --
- * Roll the log forward one operation.
- */
-int
-log_forward(sp, ep, rp)
- SCR *sp;
- EXF *ep;
- MARK *rp;
-{
- DBT key, data;
- LMARK lm;
- MARK m;
- recno_t lno;
- int didop;
- u_char *p;
-
- if (F_ISSET(ep, F_NOLOG)) {
- msgq(sp, M_ERR,
- "Logging not being performed, roll-forward not possible");
- return (1);
- }
-
- if (ep->l_cur == ep->l_high) {
- msgq(sp, M_BERR, "No changes to re-do");
- return (1);
- }
-
- F_SET(ep, F_NOLOG); /* Turn off logging. */
-
- key.data = &ep->l_cur; /* Initialize db request. */
- key.size = sizeof(recno_t);
- for (didop = 0;;) {
- ++ep->l_cur;
- if (ep->log->get(ep->log, &key, &data, 0))
- LOG_ERR;
-#if defined(DEBUG) && 0
- log_trace(sp, "log_forward", ep->l_cur, data.data);
-#endif
- switch (*(p = (u_char *)data.data)) {
- case LOG_CURSOR_END:
- if (didop) {
- ++ep->l_cur;
- memmove(rp, p + sizeof(u_char), sizeof(MARK));
- F_CLR(ep, F_NOLOG);
- return (0);
- }
- break;
- case LOG_CURSOR_INIT:
- break;
- case LOG_LINE_APPEND:
- case LOG_LINE_INSERT:
- didop = 1;
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (file_iline(sp, ep, lno, p + sizeof(u_char) +
- sizeof(recno_t), data.size - sizeof(u_char) -
- sizeof(recno_t)))
- goto err;
- ++sp->rptlines[L_ADDED];
- break;
- case LOG_LINE_DELETE:
- didop = 1;
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (file_dline(sp, ep, lno))
- goto err;
- ++sp->rptlines[L_DELETED];
- break;
- case LOG_LINE_RESET_B:
- break;
- case LOG_LINE_RESET_F:
- didop = 1;
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- if (file_sline(sp, ep, lno, p + sizeof(u_char) +
- sizeof(recno_t), data.size - sizeof(u_char) -
- sizeof(recno_t)))
- goto err;
- if (sp->rptlchange != lno) {
- sp->rptlchange = lno;
- ++sp->rptlines[L_CHANGED];
- }
- break;
- case LOG_MARK:
- didop = 1;
- memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
- m.lno = lm.lno;
- m.cno = lm.cno;
- if (mark_set(sp, ep, lm.name, &m, 0))
- goto err;
- break;
- default:
- abort();
- }
- }
-
-err: F_CLR(ep, F_NOLOG);
- return (1);
-}
-
-#if defined(DEBUG) && 0
-static void
-log_trace(sp, msg, rno, p)
- SCR *sp;
- char *msg;
- recno_t rno;
- u_char *p;
-{
- LMARK lm;
- MARK m;
- recno_t lno;
-
- switch (*p) {
- case LOG_CURSOR_INIT:
- memmove(&m, p + sizeof(u_char), sizeof(MARK));
- TRACE(sp, "%lu: %s: C_INIT: %u/%u\n", rno, msg, m.lno, m.cno);
- break;
- case LOG_CURSOR_END:
- memmove(&m, p + sizeof(u_char), sizeof(MARK));
- TRACE(sp, "%lu: %s: C_END: %u/%u\n", rno, msg, m.lno, m.cno);
- break;
- case LOG_LINE_APPEND:
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- TRACE(sp, "%lu: %s: APPEND: %lu\n", rno, msg, lno);
- break;
- case LOG_LINE_INSERT:
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- TRACE(sp, "%lu: %s: INSERT: %lu\n", rno, msg, lno);
- break;
- case LOG_LINE_DELETE:
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- TRACE(sp, "%lu: %s: DELETE: %lu\n", rno, msg, lno);
- break;
- case LOG_LINE_RESET_F:
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- TRACE(sp, "%lu: %s: RESET_F: %lu\n", rno, msg, lno);
- break;
- case LOG_LINE_RESET_B:
- memmove(&lno, p + sizeof(u_char), sizeof(recno_t));
- TRACE(sp, "%lu: %s: RESET_B: %lu\n", rno, msg, lno);
- break;
- case LOG_MARK:
- memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
- TRACE(sp,
- "%lu: %s: MARK: %u/%u\n", rno, msg, lm.lno, lm.cno);
- break;
- default:
- abort();
- }
-}
-#endif
diff --git a/usr.bin/vi/common/log.h b/usr.bin/vi/common/log.h
deleted file mode 100644
index 2974df4..0000000
--- a/usr.bin/vi/common/log.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)log.h 8.5 (Berkeley) 3/16/94
- */
-
-#define LOG_NOTYPE 0
-#define LOG_CURSOR_INIT 1
-#define LOG_CURSOR_END 2
-#define LOG_LINE_APPEND 3
-#define LOG_LINE_DELETE 4
-#define LOG_LINE_INSERT 5
-#define LOG_LINE_RESET_F 6
-#define LOG_LINE_RESET_B 7
-#define LOG_MARK 8
-
-int log_backward __P((SCR *, EXF *, MARK *));
-int log_cursor __P((SCR *, EXF *));
-int log_end __P((SCR *, EXF *));
-int log_forward __P((SCR *, EXF *, MARK *));
-int log_init __P((SCR *, EXF *));
-int log_line __P((SCR *, EXF *, recno_t, u_int));
-int log_mark __P((SCR *, EXF *, LMARK *));
-int log_setline __P((SCR *, EXF *));
diff --git a/usr.bin/vi/common/main.c b/usr.bin/vi/common/main.c
deleted file mode 100644
index 33cb4b2..0000000
--- a/usr.bin/vi/common/main.c
+++ /dev/null
@@ -1,720 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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 copyright[] =
-"@(#) Copyright (c) 1992, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)main.c 8.106 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include <pathnames.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../ex/tag.h"
-
-enum rc { NOEXIST, NOPERM, OK };
-
-static enum rc exrc_isok __P((SCR *, struct stat *, char *, int, int));
-static void gs_end __P((GS *));
-static GS *gs_init __P((void));
-static void obsolete __P((char *[]));
-static void usage __P((int));
-
-GS *__global_list; /* GLOBAL: List of screens. */
-
-int
-main(argc, argv)
- int argc;
- char *argv[];
-{
- extern int optind;
- extern char *optarg;
- static int reenter; /* STATIC: Re-entrancy check. */
- struct stat hsb, lsb;
- GS *gp;
- FREF *frp;
- SCR *sp;
- u_int flags, saved_vi_mode;
- int ch, eval, flagchk, readonly, silent, snapshot;
- char *excmdarg, *myname, *p, *tag_f, *trace_f, *wsizearg;
- char path[MAXPATHLEN];
-
- /* Stop if indirecting through a NULL pointer. */
- if (reenter++)
- abort();
-
-#ifdef GDBATTACH
- (void)printf("%u waiting...\n", getpid());
- (void)read(0, &eval, 1);
-#endif
-
- /* Set screen type and mode based on the program name. */
- readonly = 0;
- if ((myname = strrchr(*argv, '/')) == NULL)
- myname = *argv;
- else
- ++myname;
- if (!strcmp(myname, "ex") || !strcmp(myname, "nex"))
- LF_INIT(S_EX);
- else {
- /* View is readonly. */
- if (!strcmp(myname, "view"))
- readonly = 1;
- LF_INIT(S_VI_CURSES);
- }
- saved_vi_mode = S_VI_CURSES;
-
- /* Convert old-style arguments into new-style ones. */
- obsolete(argv);
-
- /* Parse the arguments. */
- flagchk = '\0';
- excmdarg = tag_f = trace_f = wsizearg = NULL;
- silent = 0;
- snapshot = 1;
- while ((ch = getopt(argc, argv, "c:eFRrsT:t:vw:X:")) != EOF)
- switch (ch) {
- case 'c': /* Run the command. */
- excmdarg = optarg;
- break;
- case 'e': /* Ex mode. */
- LF_CLR(S_SCREENS);
- LF_SET(S_EX);
- break;
- case 'F': /* No snapshot. */
- snapshot = 0;
- break;
- case 'R': /* Readonly. */
- readonly = 1;
- break;
- case 'r': /* Recover. */
- if (flagchk == 't')
- errx(1,
- "only one of -r and -t may be specified.");
- flagchk = 'r';
- break;
- case 's':
- silent = 1;
- break;
- case 'T': /* Trace. */
- trace_f = optarg;
- break;
- case 't': /* Tag. */
- if (flagchk == 'r')
- errx(1,
- "only one of -r and -t may be specified.");
- if (flagchk == 't')
- errx(1,
- "only one tag file may be specified.");
- flagchk = 't';
- tag_f = optarg;
- break;
- case 'v': /* Vi mode. */
- LF_CLR(S_SCREENS);
- LF_SET(S_VI_CURSES);
- break;
- case 'w':
- wsizearg = optarg;
- break;
- case 'X':
- if (!strcmp(optarg, "aw")) {
- LF_CLR(S_SCREENS);
- LF_SET(S_VI_XAW);
- saved_vi_mode = S_VI_XAW;
- break;
- }
- /* FALLTHROUGH */
- case '?':
- default:
- usage(LF_ISSET(S_EX));
- }
- argc -= optind;
- argv += optind;
-
- /* Silent is only applicable to ex. */
- if (silent && !LF_ISSET(S_EX))
- errx(1, "-s only applicable to ex.");
-
- /* Build and initialize the GS structure. */
- __global_list = gp = gs_init();
-
- /*
- * If not reading from a terminal, it's like -s was specified.
- * Vi always reads from the terminal, so fail if it's not a
- * terminal.
- */
- if (!F_ISSET(gp, G_STDIN_TTY)) {
- silent = 1;
- if (!LF_ISSET(S_EX)) {
- msgq(NULL, M_ERR,
- "Vi's standard input must be a terminal");
- goto err;
- }
- }
-
- /*
- * Build and initialize the first/current screen. This is a bit
- * tricky. If an error is returned, we may or may not have a
- * screen structure. If we have a screen structure, put it on a
- * display queue so that the error messages get displayed.
- *
- * !!!
- * Signals not on, no need to block them for queue manipulation.
- */
- if (screen_init(NULL, &sp, flags)) {
- if (sp != NULL)
- CIRCLEQ_INSERT_HEAD(&__global_list->dq, sp, q);
- goto err;
- }
- sp->saved_vi_mode = saved_vi_mode;
- CIRCLEQ_INSERT_HEAD(&__global_list->dq, sp, q);
-
- if (trace_f != NULL) {
-#ifdef DEBUG
- if ((gp->tracefp = fopen(trace_f, "w")) == NULL)
- err(1, "%s", trace_f);
- (void)fprintf(gp->tracefp, "\n===\ntrace: open %s\n", trace_f);
-#else
- msgq(sp, M_ERR, "-T support not compiled into this version");
-#endif
- }
-
- if (opts_init(sp)) /* Options initialization. */
- goto err;
- if (readonly) /* Global read-only bit. */
- O_SET(sp, O_READONLY);
- if (silent) { /* Ex batch mode. */
- O_CLR(sp, O_AUTOPRINT);
- O_CLR(sp, O_PROMPT);
- O_CLR(sp, O_VERBOSE);
- O_CLR(sp, O_WARN);
- F_SET(sp, S_EXSILENT);
- }
- if (wsizearg != NULL) {
- ARGS *av[2], a, b;
- errno = 0;
- if (strtol(wsizearg, &p, 10) < 0 || errno || *p)
- errx(1, "illegal window size -- %s.", wsizearg);
- (void)snprintf(path, sizeof(path), "window=%s", wsizearg);
- a.bp = (CHAR_T *)path;
- a.len = strlen(path);
- b.bp = NULL;
- b.len = 0;
- av[0] = &a;
- av[1] = &b;
- if (opts_set(sp, NULL, av))
- msgq(sp, M_ERR,
- "Unable to set command line window size option");
- }
-
- /* Keymaps, special keys, must follow option initializations. */
- if (term_init(sp))
- goto err;
-
-#ifdef DIGRAPHS
- if (digraph_init(sp)) /* Digraph initialization. */
- goto err;
-#endif
-
- /*
- * Source the system, environment, $HOME and local .exrc values.
- * Vi historically didn't check $HOME/.exrc if the environment
- * variable EXINIT was set. This is all done before the file is
- * read in, because things in the .exrc information can set, for
- * example, the recovery directory.
- *
- * !!!
- * While nvi can handle any of the options settings of historic vi,
- * the converse is not true. Since users are going to have to have
- * files and environmental variables that work with both, we use nvi
- * versions of both the $HOME and local startup files if they exist,
- * otherwise the historic ones.
- *
- * !!!
- * For a discussion of permissions and when what .exrc files are
- * read, see the the comment above the exrc_isok() function below.
- *
- * !!!
- * If the user started the historic of vi in $HOME, vi read the user's
- * .exrc file twice, as $HOME/.exrc and as ./.exrc. We avoid this, as
- * it's going to make some commands behave oddly, and I can't imagine
- * anyone depending on it.
- */
- if (!silent) {
- switch (exrc_isok(sp, &hsb, _PATH_SYSEXRC, 1, 0)) {
- case NOEXIST:
- case NOPERM:
- break;
- case OK:
- (void)ex_cfile(sp, NULL, _PATH_SYSEXRC, 0);
- break;
- }
-
- if ((p = getenv("NEXINIT")) != NULL ||
- (p = getenv("EXINIT")) != NULL)
- if ((p = strdup(p)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- goto err;
- } else {
- F_SET(sp, S_VLITONLY);
- (void)ex_icmd(sp, NULL, p, strlen(p), 0);
- F_CLR(sp, S_VLITONLY);
- free(p);
- }
- else if ((p = getenv("HOME")) != NULL && *p) {
- (void)snprintf(path,
- sizeof(path), "%s/%s", p, _PATH_NEXRC);
- switch (exrc_isok(sp, &hsb, path, 0, 1)) {
- case NOEXIST:
- (void)snprintf(path,
- sizeof(path), "%s/%s", p, _PATH_EXRC);
- if (exrc_isok(sp, &hsb, path, 0, 1) == OK)
- (void)ex_cfile(sp, NULL, path, 0);
- break;
- case NOPERM:
- break;
- case OK:
- (void)ex_cfile(sp, NULL, path, 0);
- break;
- }
- }
-
- if (O_ISSET(sp, O_EXRC))
- switch (exrc_isok(sp, &lsb, _PATH_NEXRC, 0, 0)) {
- case NOEXIST:
- if (exrc_isok(sp,
- &lsb, _PATH_EXRC, 0, 0) == OK &&
- (lsb.st_dev != hsb.st_dev ||
- lsb.st_ino != hsb.st_ino))
- (void)ex_cfile(sp, NULL, _PATH_EXRC, 0);
- break;
- case NOPERM:
- break;
- case OK:
- if (lsb.st_dev != hsb.st_dev ||
- lsb.st_ino != hsb.st_ino)
- (void)ex_cfile(sp,
- NULL, _PATH_NEXRC, 0);
- break;
- }
- }
-
- /* List recovery files if -r specified without file arguments. */
- if (flagchk == 'r' && argv[0] == NULL)
- exit(rcv_list(sp));
-
- /* Set the file snapshot flag. */
- if (snapshot)
- F_SET(gp, G_SNAPSHOT);
-
- /* Use a tag file if specified. */
- if (tag_f != NULL && ex_tagfirst(sp, tag_f))
- goto err;
-
- /*
- * Append any remaining arguments as file names. Files are
- * recovery files if -r specified.
- */
- if (*argv != NULL) {
- sp->argv = sp->cargv = argv;
- F_SET(sp, S_ARGNOFREE);
- if (flagchk == 'r')
- F_SET(sp, S_ARGRECOVER);
- }
-
- /*
- * If the tag option hasn't already created a file, create one.
- * If no files as arguments, use a temporary file.
- */
- if (tag_f == NULL) {
- if ((frp = file_add(sp,
- sp->argv == NULL ? NULL : (CHAR_T *)(sp->argv[0]))) == NULL)
- goto err;
- if (F_ISSET(sp, S_ARGRECOVER))
- F_SET(frp, FR_RECOVER);
- if (file_init(sp, frp, NULL, 0))
- goto err;
- }
-
- /*
- * If there's an initial command, push it on the command stack.
- * Historically, it was always an ex command, not vi in vi mode
- * or ex in ex mode. So, make it look like an ex command to vi.
- *
- * !!!
- * Historically, all such commands were executed with the last
- * line of the file as the current line, and not the first, so
- * set up vi to be at the end of the file.
- */
- if (excmdarg != NULL)
- if (IN_EX_MODE(sp)) {
- if (term_push(sp, "\n", 1, 0))
- goto err;
- if (term_push(sp, excmdarg, strlen(excmdarg), 0))
- goto err;
- } else if (IN_VI_MODE(sp)) {
- if (term_push(sp, "\n", 1, 0))
- goto err;
- if (term_push(sp, excmdarg, strlen(excmdarg), 0))
- goto err;
- if (term_push(sp, ":", 1, 0))
- goto err;
- if (file_lline(sp, sp->ep, &sp->frp->lno))
- goto err;
- F_SET(sp->frp, FR_CURSORSET);
- }
-
- /* Set up signals. */
- if (sig_init(sp))
- goto err;
-
- for (;;) {
- /* Ignore errors -- other screens may succeed. */
- (void)sp->s_edit(sp, sp->ep);
-
- /*
- * Edit the next screen on the display queue, or, move
- * a screen from the hidden queue to the display queue.
- */
- if ((sp = __global_list->dq.cqh_first) ==
- (void *)&__global_list->dq)
- if ((sp = __global_list->hq.cqh_first) !=
- (void *)&__global_list->hq) {
- SIGBLOCK(__global_list);
- CIRCLEQ_REMOVE(&sp->gp->hq, sp, q);
- CIRCLEQ_INSERT_TAIL(&sp->gp->dq, sp, q);
- SIGUNBLOCK(__global_list);
- } else
- break;
-
- /*
- * The screen type may have changed -- reinitialize the
- * functions in case it has.
- */
- switch (F_ISSET(sp, S_SCREENS)) {
- case S_EX:
- if (sex_screen_init(sp))
- goto err;
- break;
- case S_VI_CURSES:
- if (svi_screen_init(sp))
- goto err;
- break;
- case S_VI_XAW:
- if (xaw_screen_init(sp))
- goto err;
- break;
- default:
- abort();
- }
- }
-
- eval = 0;
- if (0)
-err: eval = 1;
-
- /*
- * NOTE: sp may be GONE when the screen returns, so only
- * the gp can be trusted.
- */
- gs_end(gp);
-
- exit(eval);
-}
-
-/*
- * gs_init --
- * Build and initialize the GS structure.
- */
-static GS *
-gs_init()
-{
- GS *gp;
- int fd;
-
- CALLOC_NOMSG(NULL, gp, GS *, 1, sizeof(GS));
- if (gp == NULL)
- err(1, NULL);
-
- /*
- * !!!
- * Signals not on, no need to block them for queue manipulation.
- */
- CIRCLEQ_INIT(&gp->dq);
- CIRCLEQ_INIT(&gp->hq);
- LIST_INIT(&gp->msgq);
-
- /* Structures shared by screens so stored in the GS structure. */
- CALLOC_NOMSG(NULL, gp->tty, IBUF *, 1, sizeof(IBUF));
- if (gp->tty == NULL)
- err(1, NULL);
-
- CIRCLEQ_INIT(&gp->dcb_store.textq);
- LIST_INIT(&gp->cutq);
- LIST_INIT(&gp->seqq);
-
- /* Set a flag if we're reading from the tty. */
- if (isatty(STDIN_FILENO))
- F_SET(gp, G_STDIN_TTY);
-
- /*
- * Set the G_STDIN_TTY flag. It's purpose is to avoid setting and
- * resetting the tty if the input isn't from there.
- *
- * Set the G_TERMIOS_SET flag. It's purpose is to avoid using the
- * original_termios information (mostly special character values)
- * if it's not valid. We expect that if we've lost our controlling
- * terminal that the open() (but not the tcgetattr()) will fail.
- */
- if (F_ISSET(gp, G_STDIN_TTY)) {
- if (tcgetattr(STDIN_FILENO, &gp->original_termios) == -1)
- err(1, "tcgetattr");
- F_SET(gp, G_TERMIOS_SET);
- } else if ((fd = open(_PATH_TTY, O_RDONLY, 0)) != -1) {
- if (tcgetattr(fd, &gp->original_termios) == -1)
- err(1, "tcgetattr");
- F_SET(gp, G_TERMIOS_SET);
- (void)close(fd);
- }
- return (gp);
-}
-
-
-/*
- * gs_end --
- * End the GS structure.
- */
-static void
-gs_end(gp)
- GS *gp;
-{
- MSG *mp;
- SCR *sp;
- char *tty;
-
- /* Default buffer storage. */
- (void)text_lfree(&gp->dcb_store.textq);
-
- /* Reset anything that needs resetting. */
- if (gp->flags & G_SETMODE) /* O_MESG */
- if ((tty = ttyname(STDERR_FILENO)) == NULL)
- warn("ttyname");
- else if (chmod(tty, gp->origmode) < 0)
- warn("%s", tty);
-
- /* Ring the bell if scheduled. */
- if (F_ISSET(gp, G_BELLSCHED))
- (void)fprintf(stderr, "\07"); /* \a */
-
- /* If there are any remaining screens, flush their messages. */
- for (sp = __global_list->dq.cqh_first;
- sp != (void *)&__global_list->dq; sp = sp->q.cqe_next)
- for (mp = sp->msgq.lh_first;
- mp != NULL && !(F_ISSET(mp, M_EMPTY)); mp = mp->q.le_next)
- (void)fprintf(stderr,
- "%.*s.\n", (int)mp->len, mp->mbuf);
- for (sp = __global_list->hq.cqh_first;
- sp != (void *)&__global_list->hq; sp = sp->q.cqe_next)
- for (mp = sp->msgq.lh_first;
- mp != NULL && !(F_ISSET(mp, M_EMPTY)); mp = mp->q.le_next)
- (void)fprintf(stderr,
- "%.*s.\n", (int)mp->len, mp->mbuf);
- /* Flush messages on the global queue. */
- for (mp = gp->msgq.lh_first;
- mp != NULL && !(F_ISSET(mp, M_EMPTY)); mp = mp->q.le_next)
- (void)fprintf(stderr, "%.*s.\n", (int)mp->len, mp->mbuf);
-
- /*
- * DON'T FREE THE GLOBAL STRUCTURE -- WE DIDN'T TURN
- * OFF SIGNALS/TIMERS, SO IT MAY STILL BE REFERENCED.
- */
-}
-
-/*
- * exrc_isok --
- * Check a .exrc file for source-ability.
- *
- * !!!
- * Historically, vi read the $HOME and local .exrc files if they were owned
- * by the user's real ID, or the "sourceany" option was set, regardless of
- * any other considerations. We no longer support the sourceany option as
- * it's a security problem of mammoth proportions. We require the system
- * .exrc file to be owned by root, the $HOME .exrc file to be owned by the
- * user's effective ID (or that the user's effective ID be root) and the
- * local .exrc files to be owned by the user's effective ID. In all cases,
- * the file cannot be writeable by anyone other than its owner.
- *
- * In O'Reilly ("Learning the VI Editor", Fifth Ed., May 1992, page 106),
- * it notes that System V release 3.2 and later has an option "[no]exrc".
- * The behavior is that local .exrc files are read only if the exrc option
- * is set. The default for the exrc option was off, so, by default, local
- * .exrc files were not read. The problem this was intended to solve was
- * that System V permitted users to give away files, so there's no possible
- * ownership or writeability test to ensure that the file is safe.
- *
- * POSIX 1003.2-1992 standardized exrc as an option. It required the exrc
- * option to be off by default, thus local .exrc files are not to be read
- * by default. The Rationale noted (incorrectly) that this was a change
- * to historic practice, but correctly noted that a default of off improves
- * system security. POSIX also required that vi check the effective user
- * ID instead of the real user ID, which is why we've switched from historic
- * practice.
- *
- * We initialize the exrc variable to off. If it's turned on by the system
- * or $HOME .exrc files, and the local .exrc file passes the ownership and
- * writeability tests, then we read it. This breaks historic 4BSD practice,
- * but it gives us a measure of security on systems where users can give away
- * files.
- */
-static enum rc
-exrc_isok(sp, sbp, path, rootown, rootid)
- SCR *sp;
- struct stat *sbp;
- char *path;
- int rootown, rootid;
-{
- uid_t euid;
- char *emsg, buf[MAXPATHLEN];
-
- /* Check for the file's existence. */
- if (stat(path, sbp))
- return (NOEXIST);
-
- /* Check ownership permissions. */
- euid = geteuid();
- if (!(rootown && sbp->st_uid == 0) &&
- !(rootid && euid == 0) && sbp->st_uid != euid) {
- emsg = rootown ?
- "not owned by you or root" : "not owned by you";
- goto denied;
- }
-
- /* Check writeability. */
- if (sbp->st_mode & (S_IWGRP | S_IWOTH)) {
- emsg = "writeable by a user other than the owner";
-denied: if (strchr(path, '/') == NULL &&
- getcwd(buf, sizeof(buf)) != NULL)
- msgq(sp, M_ERR,
- "%s/%s: not sourced: %s", buf, path, emsg);
- else
- msgq(sp, M_ERR,
- "%s: not sourced: %s", path, emsg);
- return (NOPERM);
- }
- return (OK);
-}
-
-static void
-obsolete(argv)
- char *argv[];
-{
- size_t len;
- char *p;
-
- /*
- * Translate old style arguments into something getopt will like.
- * Make sure it's not text space memory, because ex changes the
- * strings.
- * Change "+" into "-c$".
- * Change "+<anything else>" into "-c<anything else>".
- * Change "-" into "-s"
- */
- while (*++argv)
- if (argv[0][0] == '+') {
- if (argv[0][1] == '\0') {
- MALLOC_NOMSG(NULL, argv[0], char *, 4);
- if (argv[0] == NULL)
- err(1, NULL);
- (void)strcpy(argv[0], "-c$");
- } else {
- p = argv[0];
- len = strlen(argv[0]);
- MALLOC_NOMSG(NULL, argv[0], char *, len + 2);
- if (argv[0] == NULL)
- err(1, NULL);
- argv[0][0] = '-';
- argv[0][1] = 'c';
- (void)strcpy(argv[0] + 2, p + 1);
- }
- } else if (argv[0][0] == '-' && argv[0][1] == '\0') {
- MALLOC_NOMSG(NULL, argv[0], char *, 3);
- if (argv[0] == NULL)
- err(1, NULL);
- (void)strcpy(argv[0], "-s");
- }
-}
-
-static void
-usage(is_ex)
- int is_ex;
-{
-#define EX_USAGE \
- "ex [-eFRrsv] [-c command] [-t tag] [-w size] [files ...]"
-#define VI_USAGE \
- "vi [-eFRrv] [-c command] [-t tag] [-w size] [files ...]"
-
- (void)fprintf(stderr, "usage: %s\n", is_ex ? EX_USAGE : VI_USAGE);
- exit(1);
-}
diff --git a/usr.bin/vi/common/mark.c b/usr.bin/vi/common/mark.c
deleted file mode 100644
index 930ce6e..0000000
--- a/usr.bin/vi/common/mark.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)mark.c 8.21 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-static LMARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T));
-
-/*
- * Marks are maintained in a key sorted doubly linked list. We can't
- * use arrays because we have no idea how big an index key could be.
- * The underlying assumption is that users don't have more than, say,
- * 10 marks at any one time, so this will be is fast enough.
- *
- * Marks are fixed, and modifications to the line don't update the mark's
- * position in the line. This can be hard. If you add text to the line,
- * place a mark in that text, undo the addition and use ` to move to the
- * mark, the location will have disappeared. It's tempting to try to adjust
- * the mark with the changes in the line, but this is hard to do, especially
- * if we've given the line to v_ntext.c:v_ntext() for editing. Historic vi
- * would move to the first non-blank on the line when the mark location was
- * past the end of the line. This can be complicated by deleting to a mark
- * that has disappeared using the ` command. Historic vi vi treated this as
- * a line-mode motion and deleted the line. This implementation complains to
- * the user.
- *
- * In historic vi, marks returned if the operation was undone, unless the
- * mark had been subsequently reset. Tricky. This is hard to start with,
- * but in the presence of repeated undo it gets nasty. When a line is
- * deleted, we delete (and log) any marks on that line. An undo will create
- * the mark. Any mark creations are noted as to whether the user created
- * it or if it was created by an undo. The former cannot be reset by another
- * undo, but the latter may.
- *
- * All of these routines translate ABSMARK2 to ABSMARK1. Setting either of
- * the absolute mark locations sets both, so that "m'" and "m`" work like
- * they, ah, for lack of a better word, "should".
- */
-
-/*
- * mark_init --
- * Set up the marks.
- */
-int
-mark_init(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- LMARK *lmp;
-
- /*
- * Make sure the marks have been set up. If they
- * haven't, do so, and create the absolute mark.
- */
- MALLOC_RET(sp, lmp, LMARK *, sizeof(LMARK));
- lmp->lno = 1;
- lmp->cno = 0;
- lmp->name = ABSMARK1;
- lmp->flags = 0;
- LIST_INSERT_HEAD(&ep->marks, lmp, q);
- return (0);
-}
-
-/*
- * mark_end --
- * Free up the marks.
- */
-int
-mark_end(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- LMARK *lmp;
-
- while ((lmp = ep->marks.lh_first) != NULL) {
- LIST_REMOVE(lmp, q);
- FREE(lmp, sizeof(LMARK));
- }
- return (0);
-}
-
-/*
- * mark_get --
- * Get the location referenced by a mark.
- */
-int
-mark_get(sp, ep, key, mp)
- SCR *sp;
- EXF *ep;
- ARG_CHAR_T key;
- MARK *mp;
-{
- LMARK *lmp;
- size_t len;
-
- if (key == ABSMARK2)
- key = ABSMARK1;
-
- lmp = mark_find(sp, ep, key);
- if (lmp == NULL || lmp->name != key) {
- msgq(sp, M_BERR, "Mark %s: not set", KEY_NAME(sp, key));
- return (1);
- }
- if (F_ISSET(lmp, MARK_DELETED)) {
- msgq(sp, M_BERR,
- "Mark %s: the line was deleted", KEY_NAME(sp, key));
- return (1);
- }
- if (file_gline(sp, ep, lmp->lno, &len) == NULL ||
- lmp->cno > len || lmp->cno == len && len != 0) {
- msgq(sp, M_BERR, "Mark %s: cursor position no longer exists",
- KEY_NAME(sp, key));
- return (1);
- }
- mp->lno = lmp->lno;
- mp->cno = lmp->cno;
- return (0);
-}
-
-/*
- * mark_set --
- * Set the location referenced by a mark.
- */
-int
-mark_set(sp, ep, key, value, userset)
- SCR *sp;
- EXF *ep;
- ARG_CHAR_T key;
- MARK *value;
- int userset;
-{
- LMARK *lmp, *lmt;
-
- if (key == ABSMARK2)
- key = ABSMARK1;
-
- /*
- * The rules are simple. If the user is setting a mark (if it's a
- * new mark this is always true), it always happens. If not, it's
- * an undo, and we set it if it's not already set or if it was set
- * by a previous undo.
- */
- lmp = mark_find(sp, ep, key);
- if (lmp == NULL || lmp->name != key) {
- MALLOC_RET(sp, lmt, LMARK *, sizeof(LMARK));
- if (lmp == NULL) {
- LIST_INSERT_HEAD(&ep->marks, lmt, q);
- } else
- LIST_INSERT_AFTER(lmp, lmt, q);
- lmp = lmt;
- } else if (!userset &&
- !F_ISSET(lmp, MARK_DELETED) && F_ISSET(lmp, MARK_USERSET))
- return (0);
-
- lmp->lno = value->lno;
- lmp->cno = value->cno;
- lmp->name = key;
- lmp->flags = userset ? MARK_USERSET : 0;
- return (0);
-}
-
-/*
- * mark_find --
- * Find the requested mark, or, the slot immediately before
- * where it would go.
- */
-static LMARK *
-mark_find(sp, ep, key)
- SCR *sp;
- EXF *ep;
- ARG_CHAR_T key;
-{
- LMARK *lmp, *lastlmp;
-
- /*
- * Return the requested mark or the slot immediately before
- * where it should go.
- */
- for (lastlmp = NULL, lmp = ep->marks.lh_first;
- lmp != NULL; lastlmp = lmp, lmp = lmp->q.le_next)
- if (lmp->name >= key)
- return (lmp->name == key ? lmp : lastlmp);
- return (lastlmp);
-}
-
-/*
- * mark_insdel --
- * Update the marks based on an insertion or deletion.
- */
-void
-mark_insdel(sp, ep, op, lno)
- SCR *sp;
- EXF *ep;
- enum operation op;
- recno_t lno;
-{
- LMARK *lmp;
-
- switch (op) {
- case LINE_APPEND:
- return;
- case LINE_DELETE:
- for (lmp = ep->marks.lh_first;
- lmp != NULL; lmp = lmp->q.le_next)
- if (lmp->lno >= lno)
- if (lmp->lno == lno) {
- F_SET(lmp, MARK_DELETED);
- (void)log_mark(sp, ep, lmp);
- } else
- --lmp->lno;
- return;
- case LINE_INSERT:
- for (lmp = ep->marks.lh_first;
- lmp != NULL; lmp = lmp->q.le_next)
- if (lmp->lno >= lno)
- ++lmp->lno;
- return;
- case LINE_RESET:
- return;
- }
- /* NOTREACHED */
-}
diff --git a/usr.bin/vi/common/mark.h b/usr.bin/vi/common/mark.h
deleted file mode 100644
index 2c42e50..0000000
--- a/usr.bin/vi/common/mark.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)mark.h 8.9 (Berkeley) 7/17/94
- */
-
-/*
- * The MARK and LMARK structures define positions in the file. There are
- * two structures because the mark subroutines are the only places where
- * anything cares about something other than line and column.
- *
- * Because of the different interfaces used by the db(3) package, curses,
- * and users, the line number is 1 based and the column number is 0 based.
- * Additionally, it is known that the out-of-band line number is less than
- * any legal line number. The line number is of type recno_t, as that's
- * the underlying type of the database. The column number is of type size_t,
- * guaranteeing that we can malloc a line.
- */
-struct _mark {
-#define OOBLNO 0 /* Out-of-band line number. */
- recno_t lno; /* Line number. */
- size_t cno; /* Column number. */
-};
-
-struct _lmark {
- LIST_ENTRY(_lmark) q; /* Linked list of marks. */
- recno_t lno; /* Line number. */
- size_t cno; /* Column number. */
- CHAR_T name; /* Mark name. */
-
-#define MARK_DELETED 0x01 /* Mark was deleted. */
-#define MARK_USERSET 0x02 /* User set this mark. */
- u_int8_t flags;
-};
-
-#define ABSMARK1 '\'' /* Absolute mark name. */
-#define ABSMARK2 '`' /* Absolute mark name. */
-
-/* Mark routines. */
-int mark_end __P((SCR *, EXF *));
-int mark_get __P((SCR *, EXF *, ARG_CHAR_T, MARK *));
-int mark_init __P((SCR *, EXF *));
-void mark_insdel __P((SCR *, EXF *, enum operation, recno_t));
-int mark_set __P((SCR *, EXF *, ARG_CHAR_T, MARK *, int));
diff --git a/usr.bin/vi/common/mem.h b/usr.bin/vi/common/mem.h
deleted file mode 100644
index 53aeb79..0000000
--- a/usr.bin/vi/common/mem.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)mem.h 8.8 (Berkeley) 8/16/94
- */
-
-/* Increase the size of a malloc'd buffer. Two versions, one that
- * returns, one that jumps to an error label.
- */
-#define BINC_GOTO(sp, lp, llen, nlen) { \
- void *__bincp; \
- if ((nlen) > llen) { \
- if ((__bincp = binc(sp, lp, &(llen), nlen)) == NULL) \
- goto binc_err; \
- /* \
- * !!! \
- * Possible pointer conversion. \
- */ \
- lp = __bincp; \
- } \
-}
-#define BINC_RET(sp, lp, llen, nlen) { \
- void *__bincp; \
- if ((nlen) > llen) { \
- if ((__bincp = binc(sp, lp, &(llen), nlen)) == NULL) \
- return (1); \
- /* \
- * !!! \
- * Possible pointer conversion. \
- */ \
- lp = __bincp; \
- } \
-}
-
-/*
- * Get some temporary space, preferably from the global temporary buffer,
- * from a malloc'd buffer otherwise. Two versions, one that returns, one
- * that jumps to an error label.
- */
-#define GET_SPACE_GOTO(sp, bp, blen, nlen) { \
- GS *__gp = (sp)->gp; \
- if (F_ISSET(__gp, G_TMP_INUSE)) { \
- bp = NULL; \
- blen = 0; \
- BINC_GOTO(sp, bp, blen, nlen); \
- } else { \
- BINC_GOTO(sp, __gp->tmp_bp, __gp->tmp_blen, nlen); \
- bp = __gp->tmp_bp; \
- blen = __gp->tmp_blen; \
- F_SET(__gp, G_TMP_INUSE); \
- } \
-}
-#define GET_SPACE_RET(sp, bp, blen, nlen) { \
- GS *__gp = (sp)->gp; \
- if (F_ISSET(__gp, G_TMP_INUSE)) { \
- bp = NULL; \
- blen = 0; \
- BINC_RET(sp, bp, blen, nlen); \
- } else { \
- BINC_RET(sp, __gp->tmp_bp, __gp->tmp_blen, nlen); \
- bp = __gp->tmp_bp; \
- blen = __gp->tmp_blen; \
- F_SET(__gp, G_TMP_INUSE); \
- } \
-}
-
-/*
- * Add space to a GET_SPACE returned buffer. Two versions, one that
- * returns, one that jumps to an error label.
- */
-#define ADD_SPACE_GOTO(sp, bp, blen, nlen) { \
- GS *__gp = (sp)->gp; \
- if (bp == __gp->tmp_bp) { \
- F_CLR(__gp, G_TMP_INUSE); \
- BINC_GOTO(sp, __gp->tmp_bp, __gp->tmp_blen, nlen); \
- bp = __gp->tmp_bp; \
- blen = __gp->tmp_blen; \
- F_SET(__gp, G_TMP_INUSE); \
- } else \
- BINC_GOTO(sp, bp, blen, nlen); \
-}
-#define ADD_SPACE_RET(sp, bp, blen, nlen) { \
- GS *__gp = (sp)->gp; \
- if (bp == __gp->tmp_bp) { \
- F_CLR(__gp, G_TMP_INUSE); \
- BINC_RET(sp, __gp->tmp_bp, __gp->tmp_blen, nlen); \
- bp = __gp->tmp_bp; \
- blen = __gp->tmp_blen; \
- F_SET(__gp, G_TMP_INUSE); \
- } else \
- BINC_RET(sp, bp, blen, nlen); \
-}
-
-/* Free memory, optionally making pointers unusable. */
-#ifdef DEBUG
-#define FREE(p, sz) { \
- memset(p, 0xff, sz); \
- free(p); \
-}
-#else
-#define FREE(p, sz) free(p);
-#endif
-
-/* Free a GET_SPACE returned buffer. */
-#define FREE_SPACE(sp, bp, blen) { \
- if (bp == sp->gp->tmp_bp) \
- F_CLR(sp->gp, G_TMP_INUSE); \
- else \
- FREE(bp, blen); \
-}
-
-/*
- * Malloc a buffer, casting the return pointer. Various versions.
- *
- * !!!
- * The cast should be unnecessary, malloc(3) and friends return void *'s,
- * which is all we need. However, some systems that nvi needs to run on
- * don't do it right yet, resulting in the compiler printing out roughly
- * a million warnings. After awhile, it seemed easier to put the casts
- * in instead of explaining it all the time.
- */
-#define CALLOC_NOMSG(sp, p, cast, nmemb, size) { \
- p = (cast)calloc(nmemb, size); \
-}
-#define CALLOC(sp, p, cast, nmemb, size) { \
- if ((p = (cast)calloc(nmemb, size)) == NULL) \
- msgq(sp, M_SYSERR, NULL); \
-}
-#define CALLOC_RET(sp, p, cast, nmemb, size) { \
- if ((p = (cast)calloc(nmemb, size)) == NULL) { \
- msgq(sp, M_SYSERR, NULL); \
- return (1); \
- } \
-}
-#define MALLOC_NOMSG(sp, p, cast, size) { \
- p = (cast)malloc(size); \
-}
-#define MALLOC(sp, p, cast, size) { \
- if ((p = (cast)malloc(size)) == NULL) \
- msgq(sp, M_SYSERR, NULL); \
-}
-#define MALLOC_RET(sp, p, cast, size) { \
- if ((p = (cast)malloc(size)) == NULL) { \
- msgq(sp, M_SYSERR, NULL); \
- return (1); \
- } \
-}
-/*
- * XXX
- * Don't depend on realloc(NULL, size) working.
- */
-#define REALLOC(sp, p, cast, size) { \
- if ((p = (cast)(p == NULL ? \
- malloc(size) : realloc(p, size))) == NULL) \
- msgq(sp, M_SYSERR, NULL); \
-}
-
-/*
- * Versions of memmove(3) and memset(3) that use the size of the
- * initial pointer to figure out how much memory to manipulate.
- */
-#define MEMMOVE(p, t, len) memmove(p, t, (len) * sizeof(*(p)))
-#define MEMSET(p, value, len) memset(p, value, (len) * sizeof(*(p)))
-
-void *binc __P((SCR *, void *, size_t *, size_t));
diff --git a/usr.bin/vi/common/msg.c b/usr.bin/vi/common/msg.c
deleted file mode 100644
index 36639c1..0000000
--- a/usr.bin/vi/common/msg.c
+++ /dev/null
@@ -1,428 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)msg.c 8.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * msgq --
- * Display a message.
- */
-void
-#ifdef __STDC__
-msgq(SCR *sp, enum msgtype mt, const char *fmt, ...)
-#else
-msgq(sp, mt, fmt, va_alist)
- SCR *sp;
- enum msgtype mt;
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
- size_t len;
- char msgbuf[1024];
-
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- /*
- * It's possible to enter msg when there's no screen to hold
- * the message. If sp is NULL, ignore the special cases and
- * just build the message, using __global_list.
- */
- if (sp == NULL)
- goto nullsp;
-
- switch (mt) {
- case M_BERR:
- if (!F_ISSET(sp, S_EXSILENT) &&
- F_ISSET(sp->gp, G_STDIN_TTY) && !O_ISSET(sp, O_VERBOSE)) {
- F_SET(sp, S_BELLSCHED);
- return;
- }
- mt = M_ERR;
- break;
- case M_VINFO:
- if (!O_ISSET(sp, O_VERBOSE))
- return;
- mt = M_INFO;
- /* FALLTHROUGH */
- case M_INFO:
- if (F_ISSET(sp, S_EXSILENT))
- return;
- break;
- case M_ERR:
- case M_SYSERR:
- break;
- default:
- abort();
- }
-
-nullsp: len = 0;
-
-#define EPREFIX "Error: "
- if (mt == M_SYSERR) {
- memmove(msgbuf, EPREFIX, sizeof(EPREFIX) - 1);
- len += sizeof(EPREFIX) - 1;
- }
-
- if (sp != NULL && sp->if_name != NULL) {
- len += snprintf(msgbuf + len, sizeof(msgbuf) - len,
- "%s, %d: ", sp->if_name, sp->if_lno);
- if (len >= sizeof(msgbuf))
- goto err;
- }
-
- if (fmt != NULL) {
- len += vsnprintf(msgbuf + len, sizeof(msgbuf) - len, fmt, ap);
- if (len >= sizeof(msgbuf))
- goto err;
- }
-
- if (mt == M_SYSERR) {
- len += snprintf(msgbuf + len,
- sizeof(msgbuf) - len, ": %s", strerror(errno));
- if (len >= sizeof(msgbuf))
- goto err;
- }
-
- /*
- * If len >= the size, some characters were discarded.
- * Ignore trailing nul.
- */
-err: if (len >= sizeof(msgbuf))
- len = sizeof(msgbuf) - 1;
-
-#ifdef DEBUG
- if (sp != NULL)
- TRACE(sp, "%.*s\n", len, msgbuf);
-#endif
- msg_app(__global_list, sp, mt == M_ERR ? 1 : 0, msgbuf, len);
-}
-
-/*
- * msg_app --
- * Append a message into the queue. This can fail, but there's
- * nothing we can do if it does.
- */
-void
-msg_app(gp, sp, inv_video, p, len)
- GS *gp;
- SCR *sp;
- int inv_video;
- char *p;
- size_t len;
-{
- static int reenter; /* STATIC: Re-entrancy check. */
- MSG *mp, *nmp;
-
- /*
- * It's possible to reenter msg when it allocates space.
- * We're probably dead anyway, but no reason to drop core.
- */
- if (reenter)
- return;
- reenter = 1;
-
- /*
- * We can be entered as the result of a signal arriving, trying
- * to sync the file and failing. This shouldn't be a hot spot,
- * block the signals.
- */
- SIGBLOCK(gp);
-
- /*
- * Find an empty structure, or allocate a new one. Use the
- * screen structure if it exists, otherwise the global one.
- */
- if (sp != NULL) {
- if ((mp = sp->msgq.lh_first) == NULL) {
- CALLOC(sp, mp, MSG *, 1, sizeof(MSG));
- if (mp == NULL)
- goto ret;
- LIST_INSERT_HEAD(&sp->msgq, mp, q);
- goto store;
- }
- } else if ((mp = gp->msgq.lh_first) == NULL) {
- CALLOC(sp, mp, MSG *, 1, sizeof(MSG));
- if (mp == NULL)
- goto ret;
- LIST_INSERT_HEAD(&gp->msgq, mp, q);
- goto store;
- }
- while (!F_ISSET(mp, M_EMPTY) && mp->q.le_next != NULL)
- mp = mp->q.le_next;
- if (!F_ISSET(mp, M_EMPTY)) {
- CALLOC(sp, nmp, MSG *, 1, sizeof(MSG));
- if (nmp == NULL)
- goto ret;
- LIST_INSERT_AFTER(mp, nmp, q);
- mp = nmp;
- }
-
- /* Get enough memory for the message. */
-store: if (len > mp->blen &&
- (mp->mbuf = binc(sp, mp->mbuf, &mp->blen, len)) == NULL)
- goto ret;
-
- /* Store the message. */
- memmove(mp->mbuf, p, len);
- mp->len = len;
- mp->flags = inv_video ? M_INV_VIDEO : 0;
-
-ret: reenter = 0;
- SIGUNBLOCK(gp);
-}
-
-/*
- * msg_rpt --
- * Report on the lines that changed.
- *
- * !!!
- * Historic vi documentation (USD:15-8) claimed that "The editor will also
- * always tell you when a change you make affects text which you cannot see."
- * This isn't true -- edit a large file and do "100d|1". We don't implement
- * this semantic as it would require that we track each line that changes
- * during a command instead of just keeping count.
- *
- * Line counts weren't right in historic vi, either. For example, given the
- * file:
- * abc
- * def
- * the command 2d}, from the 'b' would report that two lines were deleted,
- * not one.
- */
-int
-msg_rpt(sp, is_message)
- SCR *sp;
- int is_message;
-{
- static char * const action[] = {
- "added", "changed", "deleted", "joined", "moved",
- "left shifted", "right shifted", "yanked",
- NULL,
- };
- recno_t total;
- u_long rptval;
- int first, cnt;
- size_t blen, len;
- char * const *ap;
- char *bp, *p, number[40];
-
- if (F_ISSET(sp, S_EXSILENT))
- return (0);
-
- if ((rptval = O_VAL(sp, O_REPORT)) == 0)
- goto norpt;
-
- GET_SPACE_RET(sp, bp, blen, 512);
- p = bp;
-
- total = 0;
- for (ap = action, cnt = 0, first = 1; *ap != NULL; ++ap, ++cnt)
- if (sp->rptlines[cnt] != 0) {
- total += sp->rptlines[cnt];
- len = snprintf(number, sizeof(number),
- "%s%lu lines %s",
- first ? "" : "; ", sp->rptlines[cnt], *ap);
- memmove(p, number, len);
- p += len;
- first = 0;
- }
-
- /*
- * If nothing to report, return.
- *
- * !!!
- * And now, a special vi clone test. Historically, vi reported if
- * the number of changed lines was > than the value, not >=. Which
- * means that users can't report on single line changes, btw.) In
- * any case, if it was a yank command, it was >=, not >. No lie. I
- * got complaints, so we do it right.
- */
- if (total > rptval || sp->rptlines[L_YANKED] >= rptval) {
- *p = '\0';
- if (is_message)
- msgq(sp, M_INFO, "%s", bp);
- else
- ex_printf(EXCOOKIE, "%s\n", bp);
- }
-
- FREE_SPACE(sp, bp, blen);
-
- /* Clear after each report. */
-norpt: sp->rptlchange = OOBLNO;
- memset(sp->rptlines, 0, sizeof(sp->rptlines));
- return (0);
-}
-
-/*
- * msg_status --
- * Report on the file's status.
- */
-int
-msg_status(sp, ep, lno, showlast)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- int showlast;
-{
- recno_t last;
- char *mo, *nc, *nf, *pid, *ro, *ul;
-#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.
- *
- * !!!
- * 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 (F_ISSET(sp->frp, FR_NAMECHANGE)) {
- 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" : "";
- ul = F_ISSET(sp->frp, FR_UNLOCKED) ? ", UNLOCKED" : "";
- if (showlast) {
- if (file_lline(sp, ep, &last))
- return (1);
- if (last >= 1)
- msgq(sp, M_INFO,
- "%s: %s%s%s%s%s: line %lu of %lu [%ld%%]%s",
- sp->frp->name, nf, nc, mo, ul, ro, lno,
- last, (lno * 100) / last, pid);
- else
- msgq(sp, M_INFO, "%s: %s%s%s%s%s: empty file%s",
- sp->frp->name, nf, nc, mo, ul, ro, pid);
- } else
- msgq(sp, M_INFO, "%s: %s%s%s%s%s: line %lu%s",
- sp->frp->name, nf, nc, mo, ul, ro, lno, pid);
- return (0);
-}
-
-#ifdef MSG_CATALOG
-/*
- * get_msg --
- * Return a format based on a message number.
- */
-char *
-get_msg(sp, msgno)
- SCR *sp;
- char *s_msgno;
-{
- DBT data, key;
- GS *gp;
- recno_t msgno;
- char *msg, *p;
-
- gp = sp == NULL ? __global_list : sp->gp;
- if (gp->msgdb == NULL) {
- p = sp == NULL ? _PATH_MSGDEF : O_STR(sp, O_CATALOG);
- if ((gp->msgdb = dbopen(p,
- O_NONBLOCK | O_RDONLY, 444, DB_RECNO, NULL)) == NULL) {
- if ((fmt = malloc(256)) == NULL)
- return ("");
- (void)snprintf(fmt,
- "unable to open %s: %s", p, strerror(errno));
- return (fmt);
- }
- }
- msgno = atoi(s_msgno);
- key.data = &msgno;
- key.size = sizeof(recno_t);
- switch (gp->msgdb->get(gp->msgdb, &key, &data, 0)) {
- case 0:
- return (data.data);
- case 1:
- p = "no catalog record %ls";
- break;
- case -1:
- p = "catalog record %s: %s";
- break;
- }
- if ((fmt = malloc(256)) == NULL)
- return ("");
- (void)snprintf(fmt, p, msgno, strerror(errno));
- return (fmt);
-}
-#endif
diff --git a/usr.bin/vi/common/msg.h b/usr.bin/vi/common/msg.h
deleted file mode 100644
index fc6e365..0000000
--- a/usr.bin/vi/common/msg.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)msg.h 8.13 (Berkeley) 8/8/94
- */
-
-/*
- * Message types.
- *
- * !!!
- * In historical vi, O_VERBOSE didn't exist, and O_TERSE made the error
- * messages shorter. In this implementation, O_TERSE has no effect and
- * O_VERBOSE results in informational displays about common errors for
- * naive users.
- *
- * M_BERR Error: M_ERR if O_VERBOSE, else bell.
- * M_ERR Error: Display in inverse video.
- * M_INFO Info: Display in normal video.
- * M_SYSERR Error: M_ERR, using strerror(3) message.
- * M_VINFO Info: M_INFO if O_VERBOSE, else ignore.
- */
-enum msgtype { M_BERR, M_ERR, M_INFO, M_SYSERR, M_VINFO };
-
-typedef struct _msgh MSGH; /* MESG list head structure. */
-LIST_HEAD(_msgh, _msg);
-
-struct _msg {
- LIST_ENTRY(_msg) q; /* Linked list of messages. */
- char *mbuf; /* Message buffer. */
- size_t blen; /* Message buffer length. */
- size_t len; /* Message length. */
-
-#define M_EMPTY 0x01 /* No message. */
-#define M_INV_VIDEO 0x02 /* Inverse video. */
- u_int8_t flags;
-};
-
-/*
- * Define MSG_CATALOG for the Makefile compile command
- * line to enable message catalogs.
- */
-#ifdef MSG_CATALOG
-#define M(number, fmt) number
-char *get_msg __P((SCR *, char *));
-#else
-#define M(number, fmt) fmt
-#endif
-
-/* Messages. */
-void msg_app __P((GS *, SCR *, int, char *, size_t));
-int msg_rpt __P((SCR *, int));
-int msg_status __P((SCR *, EXF *, recno_t, int));
-void msgq __P((SCR *, enum msgtype, const char *, ...));
diff --git a/usr.bin/vi/common/options.awk b/usr.bin/vi/common/options.awk
deleted file mode 100644
index a6755d9..0000000
--- a/usr.bin/vi/common/options.awk
+++ /dev/null
@@ -1,9 +0,0 @@
-# @(#)options.awk 8.1 (Berkeley) 4/17/94
-
-/^\/\* O_[0-9A-Z_]*/ {
- printf("#define %s %d\n", $2, cnt++);
- next;
-}
-END {
- printf("#define O_OPTIONCOUNT %d\n", cnt);
-}
diff --git a/usr.bin/vi/common/options.c b/usr.bin/vi/common/options.c
deleted file mode 100644
index 61396a3..0000000
--- a/usr.bin/vi/common/options.c
+++ /dev/null
@@ -1,890 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)options.c 8.66 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include <pathnames.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-static int opts_abbcmp __P((const void *, const void *));
-static int opts_cmp __P((const void *, const void *));
-static OPTLIST const *opts_prefix __P((char *));
-static int opts_print __P((SCR *, OPTLIST const *));
-
-/*
- * O'Reilly noted options and abbreviations are from "Learning the VI Editor",
- * Fifth Edition, May 1992. There's no way of knowing what systems they are
- * actually from.
- *
- * HPUX noted options and abbreviations are from "The Ultimate Guide to the
- * VI and EX Text Editors", 1990.
- */
-static OPTLIST const optlist[] = {
-/* O_ALTWERASE 4.4BSD */
- {"altwerase", f_altwerase, OPT_0BOOL, 0},
-/* O_AUTOINDENT 4BSD */
- {"autoindent", NULL, OPT_0BOOL, 0},
-/* O_AUTOPRINT 4BSD */
- {"autoprint", NULL, OPT_1BOOL, 0},
-/* O_AUTOWRITE 4BSD */
- {"autowrite", NULL, OPT_0BOOL, 0},
-/* O_BEAUTIFY 4BSD */
- {"beautify", NULL, OPT_0BOOL, 0},
-/* O_CDPATH 4.4BSD */
- {"cdpath", f_cdpath, OPT_STR, 0},
-/* O_COLUMNS 4.4BSD */
- {"columns", f_columns, OPT_NUM, OPT_NOSAVE},
-/* O_COMMENT 4.4BSD */
- {"comment", NULL, OPT_0BOOL, 0},
-/* O_DIGRAPH XXX: Elvis */
- {"digraph", NULL, OPT_0BOOL, 0},
-/* O_DIRECTORY 4BSD */
- {"directory", NULL, OPT_STR, 0},
-/* O_EDCOMPATIBLE 4BSD */
- {"edcompatible",NULL, OPT_0BOOL, 0},
-/* O_ERRORBELLS 4BSD */
- {"errorbells", NULL, OPT_0BOOL, 0},
-/* O_EXRC System V (undocumented) */
- {"exrc", NULL, OPT_0BOOL, 0},
-/* O_EXTENDED 4.4BSD */
- {"extended", NULL, OPT_0BOOL, 0},
-/* O_FLASH HPUX */
- {"flash", NULL, OPT_1BOOL, 0},
-/* O_HARDTABS 4BSD */
- {"hardtabs", NULL, OPT_NUM, 0},
-/* O_IGNORECASE 4BSD */
- {"ignorecase", NULL, OPT_0BOOL, 0},
-/* O_KEYTIME 4.4BSD */
- {"keytime", NULL, OPT_NUM, 0},
-/* O_LEFTRIGHT 4.4BSD */
- {"leftright", f_leftright, OPT_0BOOL, 0},
-/* O_LINES 4.4BSD */
- {"lines", f_lines, OPT_NUM, OPT_NOSAVE},
-/* O_LISP 4BSD */
-/*
- * XXX
- * When the lisp option is implemented, delete
- * the OPT_NOSAVE flag, so that :mkexrc dumps it.
- */
- {"lisp", f_lisp, OPT_0BOOL, OPT_NOSAVE},
-/* O_LIST 4BSD */
- {"list", f_list, OPT_0BOOL, 0},
-/* O_MAGIC 4BSD */
- {"magic", NULL, OPT_1BOOL, 0},
-/* O_MATCHTIME 4.4BSD */
- {"matchtime", NULL, OPT_NUM, 0},
-/* O_MESG 4BSD */
- {"mesg", f_mesg, OPT_1BOOL, 0},
-/* O_META 4.4BSD */
- {"meta", NULL, OPT_STR, 0},
-/* O_MODELINE 4BSD */
- {"modeline", f_modeline, OPT_0BOOL, 0},
-/* O_NUMBER 4BSD */
- {"number", f_number, OPT_0BOOL, 0},
-/* O_OCTAL 4.4BSD */
- {"octal", f_octal, OPT_0BOOL, 0},
-/* O_OPEN 4BSD */
- {"open", NULL, OPT_1BOOL, 0},
-/* O_OPTIMIZE 4BSD */
- {"optimize", NULL, OPT_1BOOL, 0},
-/* O_PARAGRAPHS 4BSD */
- {"paragraphs", f_paragraph, OPT_STR, 0},
-/* O_PROMPT 4BSD */
- {"prompt", NULL, OPT_1BOOL, 0},
-/* O_READONLY 4BSD (undocumented) */
- {"readonly", f_readonly, OPT_0BOOL, 0},
-/* O_RECDIR 4.4BSD */
- {"recdir", NULL, OPT_STR, 0},
-/* O_REDRAW 4BSD */
- {"redraw", NULL, OPT_0BOOL, 0},
-/* O_REMAP 4BSD */
- {"remap", NULL, OPT_1BOOL, 0},
-/* O_REPORT 4BSD */
- {"report", NULL, OPT_NUM, OPT_NOSTR},
-/* O_RULER 4.4BSD */
- {"ruler", NULL, OPT_0BOOL, 0},
-/* O_SCROLL 4BSD */
- {"scroll", NULL, OPT_NUM, 0},
-/* O_SECTIONS 4BSD */
- {"sections", f_section, OPT_STR, 0},
-/* O_SHELL 4BSD */
- {"shell", NULL, OPT_STR, 0},
-/* O_SHIFTWIDTH 4BSD */
- {"shiftwidth", f_shiftwidth, OPT_NUM, 0},
-/* O_SHOWDIRTY 4.4BSD */
- {"showdirty", NULL, OPT_0BOOL, 0},
-/* O_SHOWMATCH 4BSD */
- {"showmatch", NULL, OPT_0BOOL, 0},
-/* O_SHOWMODE 4.4BSD */
- {"showmode", NULL, OPT_0BOOL, 0},
-/* O_SIDESCROLL 4.4BSD */
- {"sidescroll", NULL, OPT_NUM, 0},
-/* O_SLOWOPEN 4BSD */
- {"slowopen", NULL, OPT_0BOOL, 0},
-/* O_SOURCEANY 4BSD (undocumented) */
- {"sourceany", f_sourceany, OPT_0BOOL, 0},
-/* O_TABSTOP 4BSD */
- {"tabstop", f_tabstop, OPT_NUM, 0},
-/* O_TAGLENGTH 4BSD */
- {"taglength", NULL, OPT_NUM, OPT_NOSTR},
-/* O_TAGS 4BSD */
- {"tags", f_tags, OPT_STR, 0},
-/* O_TERM 4BSD */
- {"term", f_term, OPT_STR, OPT_NOSAVE},
-/* O_TERSE 4BSD */
- {"terse", NULL, OPT_0BOOL, 0},
-/* O_TILDEOP 4.4BSD */
- {"tildeop", NULL, OPT_0BOOL, 0},
-/* O_TIMEOUT 4BSD (undocumented) */
- {"timeout", NULL, OPT_1BOOL, 0},
-/* O_TTYWERASE 4.4BSD */
- {"ttywerase", f_ttywerase, OPT_0BOOL, 0},
-/* O_VERBOSE 4.4BSD */
- {"verbose", NULL, OPT_0BOOL, 0},
-/* O_W1200 4BSD */
- {"w1200", f_w1200, OPT_NUM, OPT_NEVER|OPT_NOSAVE},
-/* O_W300 4BSD */
- {"w300", f_w300, OPT_NUM, OPT_NEVER|OPT_NOSAVE},
-/* O_W9600 4BSD */
- {"w9600", f_w9600, OPT_NUM, OPT_NEVER|OPT_NOSAVE},
-/* O_WARN 4BSD */
- {"warn", NULL, OPT_1BOOL, 0},
-/* O_WINDOW 4BSD */
- {"window", f_window, OPT_NUM, 0},
-/* O_WRAPMARGIN 4BSD */
- {"wrapmargin", NULL, OPT_NUM, OPT_NOSTR},
-/* O_WRAPSCAN 4BSD */
- {"wrapscan", NULL, OPT_1BOOL, 0},
-/* O_WRITEANY 4BSD */
- {"writeany", NULL, OPT_0BOOL, 0},
- {NULL},
-};
-
-typedef struct abbrev {
- char *name;
- int offset;
-} OABBREV;
-
-static OABBREV const abbrev[] = {
- {"ai", O_AUTOINDENT}, /* 4BSD */
- {"ap", O_AUTOPRINT}, /* 4BSD */
- {"aw", O_AUTOWRITE}, /* 4BSD */
- {"bf", O_BEAUTIFY}, /* 4BSD */
- {"co", O_COLUMNS}, /* 4.4BSD */
- {"dir", O_DIRECTORY}, /* 4BSD */
- {"eb", O_ERRORBELLS}, /* 4BSD */
- {"ed", O_EDCOMPATIBLE}, /* 4BSD */
- {"ex", O_EXRC}, /* System V (undocumented) */
- {"ht", O_HARDTABS}, /* 4BSD */
- {"ic", O_IGNORECASE}, /* 4BSD */
- {"li", O_LINES}, /* 4.4BSD */
- {"modelines", O_MODELINE}, /* HPUX */
- {"nu", O_NUMBER}, /* 4BSD */
- {"opt", O_OPTIMIZE}, /* 4BSD */
- {"para", O_PARAGRAPHS}, /* 4BSD */
- {"re", O_REDRAW}, /* O'Reilly */
- {"ro", O_READONLY}, /* 4BSD (undocumented) */
- {"scr", O_SCROLL}, /* 4BSD (undocumented) */
- {"sect", O_SECTIONS}, /* O'Reilly */
- {"sh", O_SHELL}, /* 4BSD */
- {"slow", O_SLOWOPEN}, /* 4BSD */
- {"sm", O_SHOWMATCH}, /* 4BSD */
- {"sw", O_SHIFTWIDTH}, /* 4BSD */
- {"tag", O_TAGS}, /* 4BSD (undocumented) */
- {"tl", O_TAGLENGTH}, /* 4BSD */
- {"to", O_TIMEOUT}, /* 4BSD (undocumented) */
- {"ts", O_TABSTOP}, /* 4BSD */
- {"tty", O_TERM}, /* 4BSD (undocumented) */
- {"ttytype", O_TERM}, /* 4BSD (undocumented) */
- {"w", O_WINDOW}, /* O'Reilly */
- {"wa", O_WRITEANY}, /* 4BSD */
- {"wi", O_WINDOW}, /* 4BSD (undocumented) */
- {"wm", O_WRAPMARGIN}, /* 4BSD */
- {"ws", O_WRAPSCAN}, /* 4BSD */
- {NULL},
-};
-
-/*
- * opts_init --
- * Initialize some of the options. Since the user isn't really
- * "setting" these variables, don't set their OPT_SET bits.
- */
-int
-opts_init(sp)
- SCR *sp;
-{
- ARGS *argv[2], a, b;
- OPTLIST const *op;
- u_long v;
- int cnt;
- char *s, b1[1024];
-
- a.bp = b1;
- a.len = 0;
- b.bp = NULL;
- b.len = 0;
- argv[0] = &a;
- argv[1] = &b;
-
-#define SET_DEF(opt, str) { \
- if (str != b1) /* GCC puts strings in text-space. */ \
- (void)strcpy(b1, str); \
- a.len = strlen(b1); \
- if (opts_set(sp, NULL, argv)) { \
- msgq(sp, M_ERR, \
- "Unable to set default %s option", optlist[opt]); \
- return (1); \
- } \
- F_CLR(&sp->opts[opt], OPT_SET); \
-}
- /* Set default values. */
- for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt)
- if (op->type == OPT_0BOOL)
- O_CLR(sp, cnt);
- else if (op->type == OPT_1BOOL)
- O_SET(sp, cnt);
-
- (void)snprintf(b1, sizeof(b1), "cdpath=%s",
- (s = getenv("CDPATH")) == NULL ? ":" : s);
- SET_DEF(O_CDPATH, b1);
-
- /*
- * !!!
- * Vi historically stored temporary files in /var/tmp. We store them
- * in /tmp by default, hoping it's a memory based file system. There
- * are two ways to change this -- the user can set either the directory
- * option or the TMPDIR environmental variable.
- */
- (void)snprintf(b1, sizeof(b1), "directory=%s",
- (s = getenv("TMPDIR")) == NULL ? _PATH_TMP : s);
- SET_DEF(O_DIRECTORY, b1);
- SET_DEF(O_KEYTIME, "keytime=6");
- SET_DEF(O_MATCHTIME, "matchtime=7");
- SET_DEF(O_META, "meta=~{[*?$`'\"\\");
- SET_DEF(O_REPORT, "report=5");
- SET_DEF(O_PARAGRAPHS, "paragraphs=IPLPPPQPP LIpplpipbp");
- (void)snprintf(b1, sizeof(b1), "recdir=%s", _PATH_PRESERVE);
- SET_DEF(O_RECDIR, b1);
- SET_DEF(O_SECTIONS, "sections=NHSHH HUnhsh");
- (void)snprintf(b1, sizeof(b1), "shell=%s",
- (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s);
- SET_DEF(O_SHELL, b1);
- SET_DEF(O_SHIFTWIDTH, "shiftwidth=8");
- SET_DEF(O_SIDESCROLL, "sidescroll=16");
- SET_DEF(O_TABSTOP, "tabstop=8");
- (void)snprintf(b1, sizeof(b1), "tags=%s", _PATH_TAGS);
- SET_DEF(O_TAGS, b1);
- (void)snprintf(b1, sizeof(b1), "term=%s",
- (s = getenv("TERM")) == NULL ? "unknown" : s);
- SET_DEF(O_TERM, b1);
-
- /*
- * XXX
- * Initialize ^D, ^U scrolling value here, after TERM. (We didn't
- * have the options information when the screen was initialized.)
- * Initializing term should have created a LINES/COLUMNS value.
- */
- sp->defscroll = O_VAL(sp, O_LINES) / 2;
- (void)snprintf(b1, sizeof(b1), "scroll=%ld", sp->defscroll);
- SET_DEF(O_SCROLL, b1);
-
- /*
- * The default window option values are:
- * 8 if baud rate <= 600
- * 16 if baud rate <= 1200
- * LINES - 1 if baud rate > 1200
- */
- v = baud_from_bval(sp);
- if (v <= 600)
- v = 8;
- else if (v <= 1200)
- v = 16;
- else
- v = O_VAL(sp, O_LINES) - 1;
- (void)snprintf(b1, sizeof(b1), "window=%lu", v);
- SET_DEF(O_WINDOW, b1);
-
- SET_DEF(O_WRAPMARGIN, "wrapmargin=0");
-
- /*
- * By default, the historic vi always displayed information
- * about two options, redraw and term. Term seems sufficient.
- */
- F_SET(&sp->opts[O_TERM], OPT_SET);
- return (0);
-}
-
-/*
- * opts_set --
- * Change the values of one or more options.
- */
-int
-opts_set(sp, usage, argv)
- SCR *sp;
- char *usage;
- ARGS *argv[];
-{
- enum optdisp disp;
- OABBREV atmp, *ap;
- OPTLIST const *op;
- OPTLIST otmp;
- OPTION *spo;
- u_long value, turnoff;
- int ch, equals, offset, qmark, rval;
- char *endp, *name, *p, *sep;
-
- disp = NO_DISPLAY;
- for (rval = 0; argv[0]->len != 0; ++argv) {
- /*
- * The historic vi dumped the options for each occurrence of
- * "all" in the set list. Puhleeze.
- */
- if (!strcmp(argv[0]->bp, "all")) {
- disp = ALL_DISPLAY;
- continue;
- }
-
- /* Find equals sign or question mark. */
- for (sep = NULL, equals = qmark = 0,
- p = name = argv[0]->bp; (ch = *p) != '\0'; ++p)
- if (ch == '=' || ch == '?') {
- if (p == name) {
- if (usage != NULL)
- msgq(sp,
- M_ERR, "Usage: %s", usage);
- return (1);
- }
- sep = p;
- if (ch == '=')
- equals = 1;
- else
- qmark = 1;
- break;
- }
-
- turnoff = 0;
- op = NULL;
- if (sep != NULL)
- *sep++ = '\0';
-
- /* Check list of abbreviations. */
- atmp.name = name;
- if ((ap = bsearch(&atmp, abbrev,
- sizeof(abbrev) / sizeof(OABBREV) - 1,
- sizeof(OABBREV), opts_abbcmp)) != NULL) {
- op = optlist + ap->offset;
- goto found;
- }
-
- /* Check list of options. */
- otmp.name = name;
- if ((op = bsearch(&otmp, optlist,
- sizeof(optlist) / sizeof(OPTLIST) - 1,
- sizeof(OPTLIST), opts_cmp)) != NULL)
- goto found;
-
- /* Try the name without any leading "no". */
- if (name[0] == 'n' && name[1] == 'o') {
- turnoff = 1;
- name += 2;
- } else
- goto prefix;
-
- /* Check list of abbreviations. */
- atmp.name = name;
- if ((ap = bsearch(&atmp, abbrev,
- sizeof(abbrev) / sizeof(OABBREV) - 1,
- sizeof(OABBREV), opts_abbcmp)) != NULL) {
- op = optlist + ap->offset;
- goto found;
- }
-
- /* Check list of options. */
- otmp.name = name;
- if ((op = bsearch(&otmp, optlist,
- sizeof(optlist) / sizeof(OPTLIST) - 1,
- sizeof(OPTLIST), opts_cmp)) != NULL)
- goto found;
-
- /* Check for prefix match. */
-prefix: op = opts_prefix(name);
-
-found: if (op == NULL) {
- msgq(sp, M_ERR,
- "no %s option: 'set all' gives all option values",
- name);
- continue;
- }
-
- /* Find current option values. */
- offset = op - optlist;
- spo = sp->opts + offset;
-
- /*
- * !!!
- * Historically, the question mark could be a separate
- * argument.
- */
- if (!equals && !qmark &&
- argv[1]->len == 1 && argv[1]->bp[0] == '?') {
- ++argv;
- qmark = 1;
- }
-
- /* Set name, value. */
- switch (op->type) {
- case OPT_0BOOL:
- case OPT_1BOOL:
- if (equals) {
- msgq(sp, M_ERR,
- "set: [no]%s option doesn't take a value",
- name);
- break;
- }
- if (qmark) {
- if (!disp)
- disp = SELECT_DISPLAY;
- F_SET(spo, OPT_SELECTED);
- break;
- }
- if (op->func != NULL) {
- if (op->func(sp, spo, NULL, turnoff)) {
- rval = 1;
- break;
- }
- } else if (turnoff)
- O_CLR(sp, offset);
- else
- O_SET(sp, offset);
- goto change;
- case OPT_NUM:
- /*
- * !!!
- * Extension to historic vi. If the OPT_NOSTR flag is
- * set, a numeric option may be turned off by using a
- * "no" prefix, e.g. "nowrapmargin". (We assume that
- * setting the value to 0 turns a numeric option off.)
- */
- if (turnoff) {
- if (F_ISSET(op, OPT_NOSTR)) {
- value = 0;
- goto nostr;
- }
- msgq(sp, M_ERR,
- "set: %s option isn't a boolean", name);
- break;
- }
- if (qmark || !equals) {
- if (!disp)
- disp = SELECT_DISPLAY;
- F_SET(spo, OPT_SELECTED);
- break;
- }
- value = strtol(sep, &endp, 10);
- if (*endp && !isblank(*endp)) {
- msgq(sp, M_ERR,
- "set %s: illegal number %s", name, sep);
- break;
- }
-nostr: if (op->func != NULL) {
- if (op->func(sp, spo, sep, value)) {
- rval = 1;
- break;
- }
- } else
- O_VAL(sp, offset) = value;
- goto change;
- case OPT_STR:
- if (turnoff) {
- msgq(sp, M_ERR,
- "set: %s option isn't a boolean", name);
- break;
- }
- if (qmark || !equals) {
- if (!disp)
- disp = SELECT_DISPLAY;
- F_SET(spo, OPT_SELECTED);
- break;
- }
- if (op->func != NULL) {
- if (op->func(sp, spo, sep, (u_long)0)) {
- rval = 1;
- break;
- }
- } else {
- if (F_ISSET(&sp->opts[offset], OPT_ALLOCATED))
- free(O_STR(sp, offset));
- if ((O_STR(sp, offset) = strdup(sep)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- rval = 1;
- break;
- } else
- F_SET(&sp->opts[offset], OPT_ALLOCATED);
- }
-change: if (sp->s_optchange != NULL)
- (void)sp->s_optchange(sp, offset);
- F_SET(&sp->opts[offset], OPT_SET);
- break;
- default:
- abort();
- }
- }
- if (disp != NO_DISPLAY)
- opts_dump(sp, disp);
- return (rval);
-}
-
-/*
- * opts_dump --
- * List the current values of selected options.
- */
-void
-opts_dump(sp, type)
- SCR *sp;
- enum optdisp type;
-{
- OPTLIST const *op;
- int base, b_num, cnt, col, colwidth, curlen, s_num;
- int numcols, numrows, row;
- int b_op[O_OPTIONCOUNT], s_op[O_OPTIONCOUNT];
- char nbuf[20];
-
- /*
- * XXX
- * It's possible to get here by putting "set option" in the
- * .exrc file. I can't think of a clean way to layer this,
- * or a reasonable check to make, so we block it here.
- */
- if (sp->stdfp == NULL) {
- msgq(sp, M_ERR,
- "Option display requires that the screen be initialized");
- return;
- }
-
- /*
- * Options are output in two groups -- those that fit in a column and
- * those that don't. Output is done on 6 character "tab" boundaries
- * for no particular reason. (Since we don't output tab characters,
- * we can ignore the terminal's tab settings.) Ignore the user's tab
- * setting because we have no idea how reasonable it is.
- *
- * Find a column width we can live with.
- */
- for (cnt = 6; cnt > 1; --cnt) {
- colwidth = (sp->cols - 1) / cnt & ~(STANDARD_TAB - 1);
- if (colwidth >= 10) {
- colwidth =
- (colwidth + STANDARD_TAB) & ~(STANDARD_TAB - 1);
- break;
- }
- colwidth = 0;
- }
-
- /*
- * Get the set of options to list, entering them into
- * the column list or the overflow list.
- */
- for (b_num = s_num = 0, op = optlist; op->name != NULL; ++op) {
- cnt = op - optlist;
-
- /* If OPT_NEVER set, it's never displayed. */
- if (F_ISSET(op, OPT_NEVER))
- continue;
-
- switch (type) {
- case ALL_DISPLAY: /* Display all. */
- break;
- case CHANGED_DISPLAY: /* Display changed. */
- if (!F_ISSET(&sp->opts[cnt], OPT_SET))
- continue;
- break;
- case SELECT_DISPLAY: /* Display selected. */
- if (!F_ISSET(&sp->opts[cnt], OPT_SELECTED))
- continue;
- break;
- default:
- case NO_DISPLAY:
- abort();
- /* NOTREACHED */
- }
- F_CLR(&sp->opts[cnt], OPT_SELECTED);
-
- curlen = strlen(op->name);
- switch (op->type) {
- case OPT_0BOOL:
- case OPT_1BOOL:
- if (!O_ISSET(sp, cnt))
- curlen += 2;
- break;
- case OPT_NUM:
- (void)snprintf(nbuf,
- sizeof(nbuf), "%ld", O_VAL(sp, cnt));
- curlen += strlen(nbuf);
- break;
- case OPT_STR:
- curlen += strlen(O_STR(sp, cnt)) + 3;
- break;
- }
- /* Offset by two so there's a gap. */
- if (curlen < colwidth - 2)
- s_op[s_num++] = cnt;
- else
- b_op[b_num++] = cnt;
- }
-
- if (s_num > 0) {
- /* Figure out the number of columns. */
- numcols = (sp->cols - 1) / colwidth;
- if (s_num > numcols) {
- numrows = s_num / numcols;
- if (s_num % numcols)
- ++numrows;
- } else
- numrows = 1;
-
- /* Display the options in sorted order. */
- for (row = 0; row < numrows;) {
- for (base = row, col = 0; col < numcols; ++col) {
- cnt = opts_print(sp, &optlist[s_op[base]]);
- if ((base += numrows) >= s_num)
- break;
- (void)ex_printf(EXCOOKIE,
- "%*s", (int)(colwidth - cnt), "");
- }
- if (++row < numrows || b_num)
- (void)ex_printf(EXCOOKIE, "\n");
- }
- }
-
- for (row = 0; row < b_num;) {
- (void)opts_print(sp, &optlist[b_op[row]]);
- if (++row < b_num)
- (void)ex_printf(EXCOOKIE, "\n");
- }
- (void)ex_printf(EXCOOKIE, "\n");
-}
-
-/*
- * opts_print --
- * Print out an option.
- */
-static int
-opts_print(sp, op)
- SCR *sp;
- OPTLIST const *op;
-{
- int curlen, offset;
-
- curlen = 0;
- offset = op - optlist;
- switch (op->type) {
- case OPT_0BOOL:
- case OPT_1BOOL:
- curlen += ex_printf(EXCOOKIE,
- "%s%s", O_ISSET(sp, offset) ? "" : "no", op->name);
- break;
- case OPT_NUM:
- curlen += ex_printf(EXCOOKIE,
- "%s=%ld", op->name, O_VAL(sp, offset));
- break;
- case OPT_STR:
- curlen += ex_printf(EXCOOKIE,
- "%s=\"%s\"", op->name, O_STR(sp, offset));
- break;
- }
- return (curlen);
-}
-
-/*
- * opts_save --
- * Write the current configuration to a file.
- */
-int
-opts_save(sp, fp)
- SCR *sp;
- FILE *fp;
-{
- OPTLIST const *op;
- int ch, cnt;
- char *p;
-
- for (op = optlist; op->name != NULL; ++op) {
- if (F_ISSET(op, OPT_NOSAVE))
- continue;
- cnt = op - optlist;
- switch (op->type) {
- case OPT_0BOOL:
- case OPT_1BOOL:
- if (O_ISSET(sp, cnt))
- (void)fprintf(fp, "set %s\n", op->name);
- else
- (void)fprintf(fp, "set no%s\n", op->name);
- break;
- case OPT_NUM:
- (void)fprintf(fp,
- "set %s=%-3d\n", op->name, O_VAL(sp, cnt));
- break;
- case OPT_STR:
- (void)fprintf(fp, "set ");
- for (p = op->name; (ch = *p) != '\0'; ++p) {
- if (isblank(ch) || ch == '\\')
- (void)putc('\\', fp);
- (void)putc(ch, fp);
- }
- (void)putc('=', fp);
- for (p = O_STR(sp, cnt); (ch = *p) != '\0'; ++p) {
- if (isblank(ch) || ch == '\\')
- (void)putc('\\', fp);
- (void)putc(ch, fp);
- }
- (void)putc('\n', fp);
- break;
- }
- if (ferror(fp)) {
- msgq(sp, M_ERR, "I/O error: %s", strerror(errno));
- return (1);
- }
- }
- return (0);
-}
-
-/*
- * opts_prefix --
- * Check to see if the name is the prefix of one (and only one)
- * option. If so, return the option.
- */
-static OPTLIST const *
-opts_prefix(name)
- char *name;
-{
- OPTLIST const *op, *save_op;
- size_t len;
-
- save_op = NULL;
- len = strlen(name);
- for (op = optlist; op->name != NULL; ++op) {
- if (op->name[0] < name[0])
- continue;
- if (op->name[0] > name[0])
- break;
- if (!memcmp(op->name, name, len)) {
- if (save_op != NULL)
- return (NULL);
- save_op = op;
- }
- }
- return (save_op);
-}
-
-static int
-opts_abbcmp(a, b)
- const void *a, *b;
-{
- return(strcmp(((OABBREV *)a)->name, ((OABBREV *)b)->name));
-}
-
-static int
-opts_cmp(a, b)
- const void *a, *b;
-{
- return(strcmp(((OPTLIST *)a)->name, ((OPTLIST *)b)->name));
-}
-
-/*
- * opts_free --
- * Free all option strings
- */
-void
-opts_free(sp)
- SCR *sp;
-{
- int cnt;
- char *p;
-
- for (cnt = 0; cnt < O_OPTIONCOUNT; ++cnt)
- if (F_ISSET(&sp->opts[cnt], OPT_ALLOCATED)) {
- p = O_STR(sp, cnt);
- FREE(p, strlen(p) + 1);
- }
-}
-
-/*
- * opts_copy --
- * Copy a screen's OPTION array.
- */
-int
-opts_copy(orig, sp)
- SCR *orig, *sp;
-{
- OPTION *op;
- int cnt;
-
- /* Copy most everything without change. */
- memmove(sp->opts, orig->opts, sizeof(orig->opts));
-
- /*
- * Allocate copies of the strings -- keep trying to reallocate
- * after ENOMEM failure, otherwise end up with more than one
- * screen referencing the original memory.
- */
- for (op = sp->opts, cnt = 0; cnt < O_OPTIONCOUNT; ++cnt, ++op)
- if (F_ISSET(&sp->opts[cnt], OPT_ALLOCATED) &&
- (O_STR(sp, cnt) = strdup(O_STR(sp, cnt))) == NULL) {
- msgq(orig, M_SYSERR, NULL);
- return (1);
- }
- return (0);
-}
diff --git a/usr.bin/vi/common/options.h.stub b/usr.bin/vi/common/options.h.stub
deleted file mode 100644
index 0e2051d..0000000
--- a/usr.bin/vi/common/options.h.stub
+++ /dev/null
@@ -1,108 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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.
- *
- * @(#)options.h.stub 8.22 (Berkeley) 8/8/94
- */
-
-struct _option {
- union {
- u_long val; /* Value or boolean. */
- char *str; /* String. */
- } o_u;
- size_t len; /* String length. */
-
-#define OPT_ALLOCATED 0x01 /* Allocated space. */
-#define OPT_SELECTED 0x02 /* Selected for display. */
-#define OPT_SET 0x04 /* Set (display for the user). */
- u_char flags;
-};
-
-struct _optlist {
- char *name; /* Name. */
- /* Change function. */
- int (*func) __P((SCR *, OPTION *, char *, u_long));
- /* Type of object. */
- enum { OPT_0BOOL, OPT_1BOOL, OPT_NUM, OPT_STR } type;
-
-#define OPT_NEVER 0x01 /* Never display the option. */
-#define OPT_NOSAVE 0x02 /* Mkexrc command doesn't save. */
-#define OPT_NOSTR 0x04 /* String that takes a "no". */
- u_int flags;
-};
-
-/* Clear, set, test boolean options. */
-#define O_SET(sp, o) (sp)->opts[(o)].o_u.val = 1
-#define O_CLR(sp, o) (sp)->opts[(o)].o_u.val = 0
-#define O_ISSET(sp, o) ((sp)->opts[(o)].o_u.val)
-
-/* Get option values. */
-#define O_LEN(sp, o) (sp)->opts[(o)].len
-#define O_STR(sp, o) (sp)->opts[(o)].o_u.str
-#define O_VAL(sp, o) (sp)->opts[(o)].o_u.val
-
-/* Option routines. */
-u_long baud_from_bval __P((SCR *));
-
-int opts_copy __P((SCR *, SCR *));
-void opts_free __P((SCR *));
-int opts_init __P((SCR *));
-int opts_save __P((SCR *, FILE *));
-int opts_set __P((SCR *, char *, ARGS *[]));
-
-enum optdisp { NO_DISPLAY, ALL_DISPLAY, CHANGED_DISPLAY, SELECT_DISPLAY };
-void opts_dump __P((SCR *, enum optdisp));
-
-/* Per-option change routines. */
-int f_altwerase __P((SCR *, OPTION *, char *, u_long));
-int f_cdpath __P((SCR *, OPTION *, char *, u_long));
-int f_columns __P((SCR *, OPTION *, char *, u_long));
-int f_leftright __P((SCR *, OPTION *, char *, u_long));
-int f_lines __P((SCR *, OPTION *, char *, u_long));
-int f_lisp __P((SCR *, OPTION *, char *, u_long));
-int f_list __P((SCR *, OPTION *, char *, u_long));
-int f_mesg __P((SCR *, OPTION *, char *, u_long));
-int f_modeline __P((SCR *, OPTION *, char *, u_long));
-int f_number __P((SCR *, OPTION *, char *, u_long));
-int f_octal __P((SCR *, OPTION *, char *, u_long));
-int f_paragraph __P((SCR *, OPTION *, char *, u_long));
-int f_readonly __P((SCR *, OPTION *, char *, u_long));
-int f_section __P((SCR *, OPTION *, char *, u_long));
-int f_shiftwidth __P((SCR *, OPTION *, char *, u_long));
-int f_sourceany __P((SCR *, OPTION *, char *, u_long));
-int f_tabstop __P((SCR *, OPTION *, char *, u_long));
-int f_tags __P((SCR *, OPTION *, char *, u_long));
-int f_term __P((SCR *, OPTION *, char *, u_long));
-int f_ttywerase __P((SCR *, OPTION *, char *, u_long));
-int f_w1200 __P((SCR *, OPTION *, char *, u_long));
-int f_w300 __P((SCR *, OPTION *, char *, u_long));
-int f_w9600 __P((SCR *, OPTION *, char *, u_long));
-int f_window __P((SCR *, OPTION *, char *, u_long));
diff --git a/usr.bin/vi/common/options_f.c b/usr.bin/vi/common/options_f.c
deleted file mode 100644
index bb3cf1b..0000000
--- a/usr.bin/vi/common/options_f.c
+++ /dev/null
@@ -1,518 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)options_f.c 8.36 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../ex/tag.h"
-
-static int opt_dup __P((SCR *, int, char *));
-static int opt_putenv __P((char *));
-
-#define DECL(f) \
- int \
- f(sp, op, str, val) \
- SCR *sp; \
- OPTION *op; \
- char *str; \
- u_long val;
-#define CALL(f) \
- f(sp, op, str, val)
-
-#define turnoff val
-
-DECL(f_altwerase)
-{
- if (turnoff)
- O_CLR(sp, O_ALTWERASE);
- else {
- O_SET(sp, O_ALTWERASE);
- O_CLR(sp, O_TTYWERASE);
- }
- return (0);
-}
-
-DECL(f_cdpath)
-{
- return (opt_dup(sp, O_CDPATH, str));
-}
-
-DECL(f_columns)
-{
- char buf[25];
-
- /* Validate the number. */
- if (val < MINIMUM_SCREEN_COLS) {
- msgq(sp, M_ERR, "Screen columns too small, less than %d",
- MINIMUM_SCREEN_COLS);
- return (1);
- }
- /* Set the columns value in the environment for curses. */
- (void)snprintf(buf, sizeof(buf), "COLUMNS=%lu", val);
- if (opt_putenv(buf))
- return (1);
-
- /* This is expensive, don't do it unless it's necessary. */
- if (O_VAL(sp, O_COLUMNS) == val)
- return (0);
-
- /* Set the value. */
- O_VAL(sp, O_COLUMNS) = val;
-
- F_SET(sp, S_RESIZE);
- return (0);
-}
-
-DECL(f_leftright)
-{
- if (turnoff)
- O_CLR(sp, O_LEFTRIGHT);
- else
- O_SET(sp, O_LEFTRIGHT);
- F_SET(sp, S_REFORMAT | S_REDRAW);
- return (0);
-}
-
-DECL(f_lines)
-{
- char buf[25];
-
- /* Validate the number. */
- if (val < MINIMUM_SCREEN_ROWS) {
- msgq(sp, M_ERR, "Screen lines too small, less than %d",
- MINIMUM_SCREEN_ROWS);
- return (1);
- }
-
- /* Set the rows value in the environment for curses. */
- (void)snprintf(buf, sizeof(buf), "ROWS=%lu", val);
- if (opt_putenv(buf))
- return (1);
-
- /* This is expensive, don't do it unless it's necessary. */
- if (O_VAL(sp, O_LINES) == val)
- return (0);
-
- /* Set the value. */
- O_VAL(sp, O_LINES) = val;
-
- /*
- * If no window value set, set a new default window and,
- * optionally, a new scroll value.
- */
- if (!F_ISSET(&sp->opts[O_WINDOW], OPT_SET)) {
- O_VAL(sp, O_WINDOW) = val - 1;
- if (!F_ISSET(&sp->opts[O_SCROLL], OPT_SET))
- O_VAL(sp, O_SCROLL) = val / 2;
- }
-
- F_SET(sp, S_RESIZE);
- return (0);
-}
-
-DECL(f_lisp)
-{
- msgq(sp, M_ERR, "The lisp option is not implemented");
- return (0);
-}
-
-DECL(f_list)
-{
- if (turnoff)
- O_CLR(sp, O_LIST);
- else
- O_SET(sp, O_LIST);
-
- F_SET(sp, S_REFORMAT | S_REDRAW);
- return (0);
-}
-
-DECL(f_mesg)
-{
- struct stat sb;
- char *tty;
-
- /* Find the tty. */
- if ((tty = ttyname(STDERR_FILENO)) == NULL) {
- msgq(sp, M_ERR, "ttyname: %s", strerror(errno));
- return (1);
- }
-
- /* Save the tty mode for later; only save it once. */
- if (!F_ISSET(sp->gp, G_SETMODE)) {
- F_SET(sp->gp, G_SETMODE);
- if (stat(tty, &sb) < 0) {
- msgq(sp, M_ERR, "%s: %s", tty, strerror(errno));
- return (1);
- }
- sp->gp->origmode = sb.st_mode;
- }
-
- if (turnoff) {
- if (chmod(tty, sp->gp->origmode & ~S_IWGRP) < 0) {
- msgq(sp, M_ERR, "messages not turned off: %s: %s",
- tty, strerror(errno));
- return (1);
- }
- O_CLR(sp, O_MESG);
- } else {
- if (chmod(tty, sp->gp->origmode | S_IWGRP) < 0) {
- msgq(sp, M_ERR, "messages not turned on: %s: %s",
- tty, strerror(errno));
- return (1);
- }
- O_SET(sp, O_MESG);
- }
- return (0);
-}
-
-/*
- * f_modeline --
- * This has been documented in historical systems as both "modeline"
- * and as "modelines". Regardless of the name, this option represents
- * a security problem of mammoth proportions, not to mention a stunning
- * example of what your intro CS professor referred to as the perils of
- * mixing code and data. Don't add it, or I will kill you.
- */
-DECL(f_modeline)
-{
- if (!turnoff)
- msgq(sp, M_ERR, "The modeline(s) option may never be set");
- return (0);
-}
-
-DECL(f_number)
-{
- if (turnoff)
- O_CLR(sp, O_NUMBER);
- else
- O_SET(sp, O_NUMBER);
-
- F_SET(sp, S_REFORMAT | S_REDRAW);
- return (0);
-}
-
-DECL(f_octal)
-{
- if (turnoff)
- O_CLR(sp, O_OCTAL);
- else
- O_SET(sp, O_OCTAL);
-
- key_init(sp);
- F_SET(sp, S_REFORMAT | S_REDRAW);
- return (0);
-}
-
-DECL(f_paragraph)
-{
- if (strlen(str) & 1) {
- msgq(sp, M_ERR,
- "Paragraph options must be in sets of two characters");
- return (1);
- }
- return (opt_dup(sp, O_PARAGRAPHS, str));
-}
-
-DECL(f_readonly)
-{
- if (turnoff) {
- O_CLR(sp, O_READONLY);
- if (sp->frp != NULL)
- F_CLR(sp->frp, FR_RDONLY);
- } else {
- O_SET(sp, O_READONLY);
- if (sp->frp != NULL)
- F_SET(sp->frp, FR_RDONLY);
- }
- return (0);
-}
-
-DECL(f_section)
-{
- if (strlen(str) & 1) {
- msgq(sp, M_ERR,
- "Section options must be in sets of two characters");
- return (1);
- }
- return (opt_dup(sp, O_SECTIONS, str));
-}
-
-DECL(f_shiftwidth)
-{
- if (val == 0) {
- msgq(sp, M_ERR, "The shiftwidth can't be set to 0");
- return (1);
- }
- O_VAL(sp, O_SHIFTWIDTH) = val;
- return (0);
-}
-
-/*
- * f_sourceany --
- * Historic vi, on startup, source'd $HOME/.exrc and ./.exrc, if they
- * were owned by the user. The sourceany option was an undocumented
- * feature of historic vi which permitted the startup source'ing of
- * .exrc files the user didn't own. This is an obvious security problem,
- * and we ignore the option.
- */
-DECL(f_sourceany)
-{
- if (!turnoff)
- msgq(sp, M_ERR, "The sourceany option may never be set");
- return (0);
-}
-
-DECL(f_tabstop)
-{
- if (val == 0) {
- msgq(sp, M_ERR, "Tab stops can't be set to 0");
- return (1);
- }
-#define MAXTABSTOP 20
- if (val > MAXTABSTOP) {
- msgq(sp, M_ERR,
- "Tab stops can't be larger than %d", MAXTABSTOP);
- return (1);
- }
- O_VAL(sp, O_TABSTOP) = val;
-
- F_SET(sp, S_REFORMAT | S_REDRAW);
- return (0);
-}
-
-DECL(f_tags)
-{
- return (opt_dup(sp, O_TAGS, str));
-}
-
-DECL(f_term)
-{
- char buf[256];
-
- if (opt_dup(sp, O_TERM, str))
- return (1);
-
- /* Set the terminal value in the environment for curses. */
- (void)snprintf(buf, sizeof(buf), "TERM=%s", str);
- if (opt_putenv(buf))
- return (1);
- return (0);
-}
-
-DECL(f_ttywerase)
-{
- if (turnoff)
- O_CLR(sp, O_TTYWERASE);
- else {
- O_SET(sp, O_TTYWERASE);
- O_CLR(sp, O_ALTWERASE);
- }
- return (0);
-}
-
-DECL(f_w300)
-{
- /* Historical behavior for w300 was < 1200. */
- if (baud_from_bval(sp) >= 1200)
- return (0);
-
- if (CALL(f_window))
- return (1);
-
- if (val > O_VAL(sp, O_LINES) - 1)
- val = O_VAL(sp, O_LINES) - 1;
- O_VAL(sp, O_W300) = val;
- return (0);
-}
-
-DECL(f_w1200)
-{
- u_long v;
-
- /* Historical behavior for w1200 was == 1200. */
- v = baud_from_bval(sp);
- if (v < 1200 || v > 4800)
- return (0);
-
- if (CALL(f_window))
- return (1);
-
- if (val > O_VAL(sp, O_LINES) - 1)
- val = O_VAL(sp, O_LINES) - 1;
- O_VAL(sp, O_W1200) = val;
- return (0);
-}
-
-DECL(f_w9600)
-{
- speed_t v;
-
- /* Historical behavior for w9600 was > 1200. */
- v = baud_from_bval(sp);
- if (v <= 4800)
- return (0);
-
- if (CALL(f_window))
- return (1);
-
- if (val > O_VAL(sp, O_LINES) - 1)
- val = O_VAL(sp, O_LINES) - 1;
- O_VAL(sp, O_W9600) = val;
- return (0);
-}
-
-DECL(f_window)
-{
- if (val < MINIMUM_SCREEN_ROWS) {
- msgq(sp, M_ERR, "Window too small, less than %d",
- MINIMUM_SCREEN_ROWS);
- return (1);
- }
- if (val > O_VAL(sp, O_LINES) - 1)
- val = O_VAL(sp, O_LINES) - 1;
- O_VAL(sp, O_WINDOW) = val;
- O_VAL(sp, O_SCROLL) = val / 2;
-
- return (0);
-}
-
-/*
- * opt_dup --
- * Copy a string value for user display.
- */
-static int
-opt_dup(sp, opt, str)
- SCR *sp;
- int opt;
- char *str;
-{
- char *p;
-
- /* Copy for user display. */
- if ((p = strdup(str)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
-
- /* Free the old contents. */
- if (F_ISSET(&sp->opts[opt], OPT_ALLOCATED))
- free(O_STR(sp, opt));
-
- /* Note that it's set and allocated. */
- F_SET(&sp->opts[opt], OPT_ALLOCATED | OPT_SET);
-
- /* Assign new contents. */
- O_STR(sp, opt) = p;
- return (0);
-}
-
-/*
- * opt_putenv --
- * Put a value into the environment. We use putenv(3) because it's
- * more portable. The following hack is because some moron decided
- * to keep a reference to the memory passed to putenv(3), instead of
- * having it allocate its own. Someone clearly needs to get promoted
- * into management.
- */
-static int
-opt_putenv(s)
- char *s;
-{
- char *t;
-
- /*
- * XXX
- * Memory leak.
- */
- if ((t = strdup(s)) == NULL)
- return (1);
- return (putenv(t));
-}
-
-/*
- * baud_from_bval --
- * Return the baud rate using the standard defines.
- */
-u_long
-baud_from_bval(sp)
- SCR *sp;
-{
- if (!F_ISSET(sp->gp, G_TERMIOS_SET))
- return (9600);
-
- /*
- * XXX
- * There's no portable way to get a "baud rate" -- cfgetospeed(3)
- * returns the value associated with some #define, which we may
- * never have heard of, or which may be a purely local speed. Vi
- * only cares if it's SLOW (w300), slow (w1200) or fast (w9600).
- * Try and detect the slow ones, and default to fast.
- */
- switch (cfgetospeed(&sp->gp->original_termios)) {
- case B50:
- case B75:
- case B110:
- case B134:
- case B150:
- case B200:
- case B300:
- case B600:
- return (600);
- case B1200:
- return (1200);
- }
- return (9600);
-}
diff --git a/usr.bin/vi/common/pathnames.h b/usr.bin/vi/common/pathnames.h
deleted file mode 100644
index 6ad165f..0000000
--- a/usr.bin/vi/common/pathnames.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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.
- *
- * @(#)pathnames.h 8.7 (Berkeley) 3/28/94
- */
-
-#define _PATH_BSHELL "/bin/sh"
-#define _PATH_DEVNULL "/dev/null"
-#define _PATH_EXRC ".exrc"
-#define _PATH_NEXRC ".nexrc"
-#define _PATH_PRESERVE "/var/tmp/vi.recover"
-#define _PATH_SENDMAIL "/usr/sbin/sendmail"
-#define _PATH_SYSEXRC "/etc/vi.exrc"
-#define _PATH_TAGS "tags"
-#define _PATH_TMP "/tmp"
-#define _PATH_TTY "/dev/tty"
diff --git a/usr.bin/vi/common/put.c b/usr.bin/vi/common/put.c
deleted file mode 100644
index 6ed14a8..0000000
--- a/usr.bin/vi/common/put.c
+++ /dev/null
@@ -1,254 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)put.c 8.11 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * put --
- * Put text buffer contents into the file.
- */
-int
-put(sp, ep, cbp, namep, cp, rp, append)
- SCR *sp;
- EXF *ep;
- CB *cbp;
- CHAR_T *namep;
- MARK *cp, *rp;
- int append;
-{
- CHAR_T name;
- TEXT *ltp, *tp;
- recno_t lno;
- size_t blen, clen, len;
- int rval;
- char *bp, *p, *t;
-
- if (cbp == NULL)
- if (namep == NULL) {
- cbp = sp->gp->dcbp;
- if (cbp == NULL) {
- msgq(sp, M_ERR, "The default buffer is empty");
- return (1);
- }
- } else {
- name = *namep;
- CBNAME(sp, cbp, name);
- if (cbp == NULL) {
- msgq(sp, M_ERR,
- "Buffer %s is empty", KEY_NAME(sp, name));
- return (1);
- }
- }
- tp = cbp->textq.cqh_first;
-
- /*
- * It's possible to do a put into an empty file, meaning that the cut
- * buffer simply becomes the file. It's a special case so that we can
- * ignore it in general.
- *
- * !!!
- * Historically, pasting into a file with no lines in vi would preserve
- * the single blank line. This is surely a result of the fact that the
- * historic vi couldn't deal with a file that had no lines in it. This
- * implementation treats that as a bug, and does not retain the blank
- * line.
- *
- * Historical practice is that the cursor ends at the first character
- * in the file.
- */
- if (cp->lno == 1) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0) {
- for (; tp != (void *)&cbp->textq;
- ++lno, ++sp->rptlines[L_ADDED], tp = tp->q.cqe_next)
- if (file_aline(sp, ep, 1, lno, tp->lb, tp->len))
- return (1);
- rp->lno = 1;
- rp->cno = 0;
- return (0);
- }
- }
-
- /* If a line mode buffer, append each new line into the file. */
- if (F_ISSET(cbp, CB_LMODE)) {
- lno = append ? cp->lno : cp->lno - 1;
- rp->lno = lno + 1;
- for (; tp != (void *)&cbp->textq;
- ++lno, ++sp->rptlines[L_ADDED], tp = tp->q.cqe_next)
- if (file_aline(sp, ep, 1, lno, tp->lb, tp->len))
- return (1);
- rp->cno = 0;
- (void)nonblank(sp, ep, rp->lno, &rp->cno);
- return (0);
- }
-
- /*
- * If buffer was cut in character mode, replace the current line with
- * one built from the portion of the first line to the left of the
- * split plus the first line in the CB. Append each intermediate line
- * in the CB. Append a line built from the portion of the first line
- * to the right of the split plus the last line in the CB.
- *
- * Get the first line.
- */
- lno = cp->lno;
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
-
- GET_SPACE_RET(sp, bp, blen, tp->len + len + 1);
- t = bp;
-
- /* Original line, left of the split. */
- if (len > 0 && (clen = cp->cno + (append ? 1 : 0)) > 0) {
- memmove(bp, p, clen);
- p += clen;
- t += clen;
- }
-
- /* First line from the CB. */
- memmove(t, tp->lb, tp->len);
- t += tp->len;
-
- /* Calculate length left in original line. */
- clen = len ? len - cp->cno - (append ? 1 : 0) : 0;
-
- /*
- * If no more lines in the CB, append the rest of the original
- * line and quit. Otherwise, build the last line before doing
- * the intermediate lines, because the line changes will lose
- * the cached line.
- */
- rval = 0;
- if (tp->q.cqe_next == (void *)&cbp->textq) {
- /*
- * Historical practice is that if a non-line mode put
- * is inside a single line, the cursor ends up on the
- * last character inserted.
- */
- rp->lno = lno;
- rp->cno = (t - bp) - 1;
-
- if (clen > 0) {
- memmove(t, p, clen);
- t += clen;
- }
- if (file_sline(sp, ep, lno, bp, t - bp))
- goto mem;
- if (sp->rptlchange != lno) {
- sp->rptlchange = lno;
- ++sp->rptlines[L_CHANGED];
- }
- } else {
- /*
- * Have to build both the first and last lines of the
- * put before doing any sets or we'll lose the cached
- * line. Build both the first and last lines in the
- * same buffer, so we don't have to have another buffer
- * floating around.
- *
- * Last part of original line; check for space, reset
- * the pointer into the buffer.
- */
- ltp = cbp->textq.cqh_last;
- len = t - bp;
- ADD_SPACE_RET(sp, bp, blen, ltp->len + clen);
- t = bp + len;
-
- /* Add in last part of the CB. */
- memmove(t, ltp->lb, ltp->len);
- if (clen)
- memmove(t + ltp->len, p, clen);
- clen += ltp->len;
-
- /*
- * Now: bp points to the first character of the first
- * line, t points to the last character of the last
- * line, t - bp is the length of the first line, and
- * clen is the length of the last. Just figured you'd
- * want to know.
- *
- * Output the line replacing the original line.
- */
- if (file_sline(sp, ep, lno, bp, t - bp))
- goto mem;
- if (sp->rptlchange != lno) {
- sp->rptlchange = lno;
- ++sp->rptlines[L_CHANGED];
- }
-
- /*
- * Historical practice is that if a non-line mode put
- * covers multiple lines, the cursor ends up on the
- * first character inserted. (Of course.)
- */
- rp->lno = lno;
- rp->cno = (t - bp) - 1;
-
- /* Output any intermediate lines in the CB. */
- for (tp = tp->q.cqe_next;
- tp->q.cqe_next != (void *)&cbp->textq;
- ++lno, ++sp->rptlines[L_ADDED], tp = tp->q.cqe_next)
- if (file_aline(sp, ep, 1, lno, tp->lb, tp->len))
- goto mem;
-
- if (file_aline(sp, ep, 1, lno, t, clen))
-mem: rval = 1;
- ++sp->rptlines[L_ADDED];
- }
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
diff --git a/usr.bin/vi/common/recover.c b/usr.bin/vi/common/recover.c
deleted file mode 100644
index a94b65a..0000000
--- a/usr.bin/vi/common/recover.c
+++ /dev/null
@@ -1,869 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)recover.c 8.74 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-/*
- * We include <sys/file.h>, because the open #defines were found there
- * on historical systems. We also include <fcntl.h> because the open(2)
- * #defines are found there on newer systems.
- */
-#include <sys/file.h>
-
-#include <netdb.h> /* MAXHOSTNAMELEN on some systems. */
-
-#include <bitstring.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include <pathnames.h>
-
-#include "vi.h"
-
-/*
- * Recovery code.
- *
- * The basic scheme is as follows. In the EXF structure, we maintain full
- * paths of a b+tree file and a mail recovery file. The former is the file
- * used as backing store by the DB package. The latter is the file that
- * contains an email message to be sent to the user if we crash. The two
- * simple states of recovery are:
- *
- * + first starting the edit session:
- * the b+tree file exists and is mode 700, the mail recovery
- * file doesn't exist.
- * + after the file has been modified:
- * the b+tree file exists and is mode 600, the mail recovery
- * file exists, and is exclusively locked.
- *
- * In the EXF structure we maintain a file descriptor that is the locked
- * file descriptor for the mail recovery file. NOTE: we sometimes have to
- * do locking with fcntl(2). This is a problem because if you close(2) any
- * file descriptor associated with the file, ALL of the locks go away. Be
- * sure to remember that if you have to modify the recovery code. (It has
- * been rhetorically asked of what the designers could have been thinking
- * when they did that interface. The answer is simple: they weren't.)
- *
- * To find out if a recovery file/backing file pair are in use, try to get
- * a lock on the recovery file.
- *
- * To find out if a backing file can be deleted at boot time, check for an
- * owner execute bit. (Yes, I know it's ugly, but it's either that or put
- * special stuff into the backing file itself, or correlate the files at
- * boot time, neither or which looks like fun.) Note also that there's a
- * window between when the file is created and the X bit is set. It's small,
- * but it's there. To fix the window, check for 0 length files as well.
- *
- * To find out if a file can be recovered, check the F_RCV_ON bit. Note,
- * this DOES NOT mean that any initialization has been done, only that we
- * haven't yet failed at setting up or doing recovery.
- *
- * To preserve a recovery file/backing file pair, set the F_RCV_NORM bit.
- * If that bit is not set when ending a file session:
- * If the EXF structure paths (rcv_path and rcv_mpath) are not NULL,
- * they are unlink(2)'d, and free(3)'d.
- * If the EXF file descriptor (rcv_fd) is not -1, it is closed.
- *
- * The backing b+tree file is set up when a file is first edited, so that
- * the DB package can use it for on-disk caching and/or to snapshot the
- * file. When the file is first modified, the mail recovery file is created,
- * the backing file permissions are updated, the file is sync(2)'d to disk,
- * and the timer is started. Then, at RCV_PERIOD second intervals, the
- * b+tree file is synced to disk. RCV_PERIOD is measured using SIGALRM, which
- * means that the data structures (SCR, EXF, the underlying tree structures)
- * must be consistent when the signal arrives.
- *
- * The recovery mail file contains normal mail headers, with two additions,
- * which occur in THIS order, as the FIRST TWO headers:
- *
- * X-vi-recover-file: file_name
- * X-vi-recover-path: recover_path
- *
- * Since newlines delimit the headers, this means that file names cannot have
- * newlines in them, but that's probably okay. As these files aren't intended
- * to be long-lived, changing their format won't be too painful.
- *
- * Btree files are named "vi.XXXX" and recovery files are named "recover.XXXX".
- */
-
-#define VI_FHEADER "X-vi-recover-file: "
-#define VI_PHEADER "X-vi-recover-path: "
-
-static int rcv_copy __P((SCR *, int, char *));
-static void rcv_email __P((SCR *, char *));
-static char *rcv_gets __P((char *, size_t, int));
-static int rcv_mailfile __P((SCR *, EXF *, int, char *));
-static int rcv_mktemp __P((SCR *, char *, char *, int));
-
-/*
- * rcv_tmp --
- * Build a file name that will be used as the recovery file.
- */
-int
-rcv_tmp(sp, ep, name)
- SCR *sp;
- EXF *ep;
- char *name;
-{
- struct stat sb;
- int fd;
- char *dp, *p, path[MAXPATHLEN];
-
- /*
- * If the recovery directory doesn't exist, try and create it. As
- * the recovery files are themselves protected from reading/writing
- * by other than the owner, the worst that can happen is that a user
- * would have permission to remove other user's recovery files. If
- * the sticky bit has the BSD semantics, that too will be impossible.
- */
- dp = O_STR(sp, O_RECDIR);
- if (stat(dp, &sb)) {
- if (errno != ENOENT || mkdir(dp, 0)) {
- msgq(sp, M_SYSERR, "%s", dp);
- goto err;
- }
- (void)chmod(dp, S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX);
- }
-
- /* Newlines delimit the mail messages. */
- for (p = name; *p; ++p)
- if (*p == '\n') {
- msgq(sp, M_ERR,
- "Files with newlines in the name are unrecoverable");
- goto err;
- }
-
- (void)snprintf(path, sizeof(path), "%s/vi.XXXXXX", dp);
- if ((fd = rcv_mktemp(sp, path, dp, S_IRWXU)) == -1)
- goto err;
- (void)close(fd);
-
- if ((ep->rcv_path = strdup(path)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- (void)unlink(path);
-err: msgq(sp, M_ERR,
- "Modifications not recoverable if the session fails");
- return (1);
- }
-
- /* We believe the file is recoverable. */
- F_SET(ep, F_RCV_ON);
- return (0);
-}
-
-/*
- * rcv_init --
- * Force the file to be snapshotted for recovery.
- */
-int
-rcv_init(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- recno_t lno;
- int btear;
-
- /* Only do this once. */
- F_CLR(ep, F_FIRSTMODIFY);
-
- /* If we already know the file isn't recoverable, we're done. */
- if (!F_ISSET(ep, F_RCV_ON))
- return (0);
-
- /* Turn off recoverability until we figure out if this will work. */
- F_CLR(ep, F_RCV_ON);
-
- /* Test if we're recovering a file, not editing one. */
- if (ep->rcv_mpath == NULL) {
- /* Build a file to mail to the user. */
- if (rcv_mailfile(sp, ep, 0, NULL))
- goto err;
-
- /* Force a read of the entire file. */
- if (file_lline(sp, ep, &lno))
- goto err;
-
- /* Turn on a busy message, and sync it to backing store. */
- btear = F_ISSET(sp, S_EXSILENT) ? 0 :
- !busy_on(sp, "Copying file for recovery...");
- if (ep->db->sync(ep->db, R_RECNOSYNC)) {
- msgq(sp, M_ERR, "Preservation failed: %s: %s",
- ep->rcv_path, strerror(errno));
- if (btear)
- busy_off(sp);
- goto err;
- }
- if (btear)
- busy_off(sp);
- }
-
- /* Turn on the recovery timer, if it's not yet running. */
- if (!F_ISSET(sp->gp, G_RECOVER_SET) && rcv_on(sp, ep)) {
-err: msgq(sp, M_ERR,
- "Modifications not recoverable if the session fails");
- return (1);
- }
-
- /* Turn off the owner execute bit. */
- (void)chmod(ep->rcv_path, S_IRUSR | S_IWUSR);
-
- /* We believe the file is recoverable. */
- F_SET(ep, F_RCV_ON);
- return (0);
-}
-
-/*
- * rcv_sync --
- * Sync the file, optionally:
- * flagging the backup file to be preserved
- * snapshotting the backup file and send email to the user
- * sending email to the user if the file was modified
- * ending the file session
- */
-int
-rcv_sync(sp, ep, flags)
- SCR *sp;
- EXF *ep;
- u_int flags;
-{
- int btear, fd, rval;
- char *dp, buf[1024];
-
- /* Make sure that there's something to recover/sync. */
- if (ep == NULL || !F_ISSET(ep, F_RCV_ON))
- return (0);
-
- /* Sync the file if it's been modified. */
- if (F_ISSET(ep, F_MODIFIED)) {
- if (ep->db->sync(ep->db, R_RECNOSYNC)) {
- F_CLR(ep, F_RCV_ON | F_RCV_NORM);
- msgq(sp, M_SYSERR,
- "File backup failed: %s", ep->rcv_path);
- return (1);
- }
-
- /* REQUEST: don't remove backing file on exit. */
- if (LF_ISSET(RCV_PRESERVE))
- F_SET(ep, F_RCV_NORM);
-
- /* REQUEST: send email. */
- if (LF_ISSET(RCV_EMAIL))
- rcv_email(sp, ep->rcv_mpath);
- }
-
- /*
- * !!!
- * Each time the user exec's :preserve, we have to snapshot all of
- * the recovery information, i.e. it's like the user re-edited the
- * file. We copy the DB(3) backing file, and then create a new mail
- * recovery file, it's simpler than exiting and reopening all of the
- * underlying files.
- *
- * REQUEST: snapshot the file.
- */
- rval = 0;
- if (LF_ISSET(RCV_SNAPSHOT)) {
- btear = F_ISSET(sp, S_EXSILENT) ? 0 :
- !busy_on(sp, "Copying file for recovery...");
- dp = O_STR(sp, O_RECDIR);
- (void)snprintf(buf, sizeof(buf), "%s/vi.XXXXXX", dp);
- if ((fd = rcv_mktemp(sp, buf, dp, S_IRUSR | S_IWUSR)) == -1)
- goto e1;
- if (rcv_copy(sp, fd, ep->rcv_path) || close(fd))
- goto e2;
- if (rcv_mailfile(sp, ep, 1, buf)) {
-e2: (void)unlink(buf);
-e1: if (fd != -1)
- (void)close(fd);
- rval = 1;
- }
- if (btear)
- busy_off(sp);
- }
-
- /* REQUEST: end the file session. */
- if (LF_ISSET(RCV_ENDSESSION) && file_end(sp, ep, 1))
- rval = 1;
-
- return (rval);
-}
-
-/*
- * rcv_mailfile --
- * Build the file to mail to the user.
- */
-static int
-rcv_mailfile(sp, ep, issync, cp_path)
- SCR *sp;
- EXF *ep;
- int issync;
- char *cp_path;
-{
- struct passwd *pw;
- size_t len;
- time_t now;
- uid_t uid;
- int fd;
- char *dp, *p, *t, buf[4096], host[MAXHOSTNAMELEN], mpath[MAXPATHLEN];
- char *t1, *t2, *t3;
-
- if ((pw = getpwuid(uid = getuid())) == NULL) {
- msgq(sp, M_ERR, "Information on user id %u not found", uid);
- return (1);
- }
-
- dp = O_STR(sp, O_RECDIR);
- (void)snprintf(mpath, sizeof(mpath), "%s/recover.XXXXXX", dp);
- if ((fd = rcv_mktemp(sp, mpath, dp, S_IRUSR | S_IWUSR)) == -1)
- return (1);
-
- /*
- * XXX
- * We keep an open lock on the file so that the recover option can
- * distinguish between files that are live and those that need to
- * be recovered. There's an obvious window between the mkstemp call
- * and the lock, but it's pretty small.
- */
- if (file_lock(NULL, NULL, fd, 1) != LOCK_SUCCESS)
- msgq(sp, M_SYSERR, "Unable to lock recovery file");
- if (!issync) {
- /* Save the recover file descriptor, and mail path. */
- ep->rcv_fd = fd;
- if ((ep->rcv_mpath = strdup(mpath)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- goto err;
- }
- cp_path = ep->rcv_path;
- }
-
- /*
- * XXX
- * We can't use stdio(3) here. The problem is that we may be using
- * fcntl(2), so if ANY file descriptor into the file is closed, the
- * lock is lost. So, we could never close the FILE *, even if we
- * dup'd the fd first.
- */
- t = sp->frp->name;
- if ((p = strrchr(t, '/')) == NULL)
- p = t;
- else
- ++p;
- (void)time(&now);
- (void)gethostname(host, sizeof(host));
- len = snprintf(buf, sizeof(buf),
- "%s%s\n%s%s\n%s\n%s\n%s%s\n%s%s\n%s\n\n",
- VI_FHEADER, t, /* Non-standard. */
- VI_PHEADER, cp_path, /* Non-standard. */
- "Reply-To: root",
- "From: root (Nvi recovery program)",
- "To: ", pw->pw_name,
- "Subject: Nvi saved the file ", p,
- "Precedence: bulk"); /* For vacation(1). */
- if (len > sizeof(buf) - 1)
- goto lerr;
- if (write(fd, buf, len) != len)
- goto werr;
-
- len = snprintf(buf, sizeof(buf), "%s%.24s%s%s%s%s%s%s%s%s%s%s%s\n\n",
- "On ", ctime(&now), ", the user ", pw->pw_name,
- " was editing a file named ", t, " on the machine ",
- host, ", when it was saved for recovery. ",
- "You can recover most, if not all, of the changes ",
- "to this file using the -r option to nex or nvi:\n\n",
- "\tnvi -r ", t);
- if (len > sizeof(buf) - 1) {
-lerr: msgq(sp, M_ERR, "recovery file buffer overrun");
- goto err;
- }
-
- /*
- * Format the message. (Yes, I know it's silly.)
- * Requires that the message end in a <newline>.
- */
-#define FMTCOLS 60
- for (t1 = buf; len > 0; len -= t2 - t1, t1 = t2) {
- /* Check for a short length. */
- if (len <= FMTCOLS) {
- t2 = t1 + (len - 1);
- goto wout;
- }
-
- /* Check for a required <newline>. */
- t2 = strchr(t1, '\n');
- if (t2 - t1 <= FMTCOLS)
- goto wout;
-
- /* Find the closest space, if any. */
- for (t3 = t2; t2 > t1; --t2)
- if (*t2 == ' ') {
- if (t2 - t1 <= FMTCOLS)
- goto wout;
- t3 = t2;
- }
- t2 = t3;
-
- /* t2 points to the last character to display. */
-wout: *t2++ = '\n';
-
- /* t2 points one after the last character to display. */
- if (write(fd, t1, t2 - t1) != t2 - t1) {
-werr: msgq(sp, M_SYSERR, "recovery file");
- goto err;
- }
- }
-
- if (issync)
- rcv_email(sp, mpath);
-
- return (0);
-
-err: if (!issync)
- ep->rcv_fd = -1;
- if (fd != -1)
- (void)close(fd);
- return (1);
-}
-
-/*
- * people making love
- * never exactly the same
- * just like a snowflake
- *
- * rcv_list --
- * List the files that can be recovered by this user.
- */
-int
-rcv_list(sp)
- SCR *sp;
-{
- struct dirent *dp;
- struct stat sb;
- DIR *dirp;
- FILE *fp;
- int found;
- char *p, *t, file[MAXPATHLEN], path[MAXPATHLEN];
-
- /*
- * XXX
- * Messages aren't yet set up.
- */
- if (chdir(O_STR(sp, O_RECDIR)) || (dirp = opendir(".")) == NULL) {
- (void)fprintf(stderr,
- "vi: %s: %s\n", O_STR(sp, O_RECDIR), strerror(errno));
- return (1);
- }
-
- for (found = 0; (dp = readdir(dirp)) != NULL;) {
- if (strncmp(dp->d_name, "recover.", 8))
- continue;
-
- /*
- * If it's readable, it's recoverable.
- *
- * XXX
- * Should be "r", we don't want to write the file. However,
- * if we're using fcntl(2), there's no way to lock a file
- * descriptor that's not open for writing.
- */
- if ((fp = fopen(dp->d_name, "r+")) == NULL)
- continue;
-
- switch (file_lock(NULL, NULL, fileno(fp), 1)) {
- case LOCK_FAILED:
- /*
- * XXX
- * Assume that a lock can't be acquired, but that we
- * should permit recovery anyway. If this is wrong,
- * and someone else is using the file, we're going to
- * die horribly.
- */
- break;
- case LOCK_SUCCESS:
- break;
- case LOCK_UNAVAIL:
- /* If it's locked, it's live. */
- (void)fclose(fp);
- continue;
- }
-
- /* Check the headers. */
- if (fgets(file, sizeof(file), fp) == NULL ||
- strncmp(file, VI_FHEADER, sizeof(VI_FHEADER) - 1) ||
- (p = strchr(file, '\n')) == NULL ||
- fgets(path, sizeof(path), fp) == NULL ||
- strncmp(path, VI_PHEADER, sizeof(VI_PHEADER) - 1) ||
- (t = strchr(path, '\n')) == NULL) {
- msgq(sp, M_ERR,
- "%s: malformed recovery file", dp->d_name);
- goto next;
- }
- *p = *t = '\0';
-
- /*
- * If the file doesn't exist, it's an orphaned recovery file,
- * toss it.
- *
- * XXX
- * This can occur if the backup file was deleted and we crashed
- * before deleting the email file.
- */
- errno = 0;
- if (stat(path + sizeof(VI_PHEADER) - 1, &sb) &&
- errno == ENOENT) {
- (void)unlink(dp->d_name);
- goto next;
- }
-
- /* Get the last modification time and display. */
- (void)fstat(fileno(fp), &sb);
- (void)printf("%s: %s",
- file + sizeof(VI_FHEADER) - 1, ctime(&sb.st_mtime));
- found = 1;
-
- /* Close, discarding lock. */
-next: (void)fclose(fp);
- }
- if (found == 0)
- (void)printf("vi: no files to recover.\n");
- (void)closedir(dirp);
- return (0);
-}
-
-/*
- * rcv_read --
- * Start a recovered file as the file to edit.
- */
-int
-rcv_read(sp, frp)
- SCR *sp;
- FREF *frp;
-{
- struct dirent *dp;
- struct stat sb;
- DIR *dirp;
- EXF *ep;
- time_t rec_mtime;
- int fd, found, locked, requested, sv_fd;
- char *name, *p, *t, *recp, *pathp;
- char file[MAXPATHLEN], path[MAXPATHLEN], recpath[MAXPATHLEN];
-
- if ((dirp = opendir(O_STR(sp, O_RECDIR))) == NULL) {
- msgq(sp, M_ERR,
- "%s: %s", O_STR(sp, O_RECDIR), strerror(errno));
- return (1);
- }
-
- name = frp->name;
- sv_fd = -1;
- rec_mtime = 0;
- recp = pathp = NULL;
- for (found = requested = 0; (dp = readdir(dirp)) != NULL;) {
- if (strncmp(dp->d_name, "recover.", 8))
- continue;
- (void)snprintf(recpath, sizeof(recpath),
- "%s/%s", O_STR(sp, O_RECDIR), dp->d_name);
-
- /*
- * If it's readable, it's recoverable. It would be very
- * nice to use stdio(3), but, we can't because that would
- * require closing and then reopening the file so that we
- * could have a lock and still close the FP. Another tip
- * of the hat to fcntl(2).
- *
- * XXX
- * Should be O_RDONLY, we don't want to write it. However,
- * if we're using fcntl(2), there's no way to lock a file
- * descriptor that's not open for writing.
- */
- if ((fd = open(recpath, O_RDWR, 0)) == -1)
- continue;
-
- switch (file_lock(NULL, NULL, fd, 1)) {
- case LOCK_FAILED:
- /*
- * XXX
- * Assume that a lock can't be acquired, but that we
- * should permit recovery anyway. If this is wrong,
- * and someone else is using the file, we're going to
- * die horribly.
- */
- locked = 0;
- break;
- case LOCK_SUCCESS:
- locked = 1;
- break;
- case LOCK_UNAVAIL:
- /* If it's locked, it's live. */
- (void)close(fd);
- continue;
- }
-
- /* Check the headers. */
- if (rcv_gets(file, sizeof(file), fd) == NULL ||
- strncmp(file, VI_FHEADER, sizeof(VI_FHEADER) - 1) ||
- (p = strchr(file, '\n')) == NULL ||
- rcv_gets(path, sizeof(path), fd) == NULL ||
- strncmp(path, VI_PHEADER, sizeof(VI_PHEADER) - 1) ||
- (t = strchr(path, '\n')) == NULL) {
- msgq(sp, M_ERR,
- "%s: malformed recovery file", recpath);
- goto next;
- }
- *p = *t = '\0';
- ++found;
-
- /*
- * If the file doesn't exist, it's an orphaned recovery file,
- * toss it.
- *
- * XXX
- * This can occur if the backup file was deleted and we crashed
- * before deleting the email file.
- */
- errno = 0;
- if (stat(path + sizeof(VI_PHEADER) - 1, &sb) &&
- errno == ENOENT) {
- (void)unlink(dp->d_name);
- goto next;
- }
-
- /* Check the file name. */
- if (strcmp(file + sizeof(VI_FHEADER) - 1, name))
- goto next;
-
- ++requested;
-
- /*
- * If we've found more than one, take the most recent.
- *
- * XXX
- * Since we're using st_mtime, for portability reasons,
- * we only get a single second granularity, instead of
- * getting it right.
- */
- (void)fstat(fd, &sb);
- if (recp == NULL || rec_mtime < sb.st_mtime) {
- p = recp;
- t = pathp;
- if ((recp = strdup(recpath)) == NULL) {
- msgq(sp, M_ERR,
- "vi: Error: %s.\n", strerror(errno));
- recp = p;
- goto next;
- }
- if ((pathp = strdup(path)) == NULL) {
- msgq(sp, M_ERR,
- "vi: Error: %s.\n", strerror(errno));
- FREE(recp, strlen(recp) + 1);
- recp = p;
- pathp = t;
- goto next;
- }
- if (p != NULL) {
- FREE(p, strlen(p) + 1);
- FREE(t, strlen(t) + 1);
- }
- rec_mtime = sb.st_mtime;
- if (sv_fd != -1)
- (void)close(sv_fd);
- sv_fd = fd;
- } else
-next: (void)close(fd);
- }
- (void)closedir(dirp);
-
- if (recp == NULL) {
- msgq(sp, M_INFO,
- "No files named %s, readable by you, to recover", name);
- return (1);
- }
- if (found) {
- if (requested > 1)
- msgq(sp, M_INFO,
- "There are older versions of this file for you to recover");
- if (found > requested)
- msgq(sp, M_INFO,
- "There are other files for you to recover");
- }
-
- /*
- * Create the FREF structure, start the btree file.
- *
- * XXX
- * file_init() is going to set ep->rcv_path.
- */
- if (file_init(sp, frp, pathp + sizeof(VI_PHEADER) - 1, 0)) {
- free(recp);
- free(pathp);
- (void)close(sv_fd);
- return (1);
- }
-
- /*
- * We keep an open lock on the file so that the recover option can
- * distinguish between files that are live and those that need to
- * be recovered. The lock is already acquired, just copy it.
- */
- ep = sp->ep;
- ep->rcv_mpath = recp;
- ep->rcv_fd = sv_fd;
- if (!locked)
- F_SET(frp, FR_UNLOCKED);
-
- /* We believe the file is recoverable. */
- F_SET(ep, F_RCV_ON);
- return (0);
-}
-
-/*
- * rcv_copy --
- * Copy a recovery file.
- */
-static int
-rcv_copy(sp, wfd, fname)
- SCR *sp;
- int wfd;
- char *fname;
-{
- int nr, nw, off, rfd;
- char buf[8 * 1024];
-
- if ((rfd = open(fname, O_RDONLY, 0)) == -1)
- goto err;
- while ((nr = read(rfd, buf, sizeof(buf))) > 0)
- for (off = 0; nr; nr -= nw, off += nw)
- if ((nw = write(wfd, buf + off, nr)) < 0)
- goto err;
- if (nr == 0)
- return (0);
-
-err: msgq(sp, M_SYSERR, "%s", fname);
- return (1);
-}
-
-/*
- * rcv_gets --
- * Fgets(3) for a file descriptor.
- */
-static char *
-rcv_gets(buf, len, fd)
- char *buf;
- size_t len;
- int fd;
-{
- ssize_t nr;
- char *p;
-
- if ((nr = read(fd, buf, len - 1)) == -1)
- return (NULL);
- if ((p = strchr(buf, '\n')) == NULL)
- return (NULL);
- (void)lseek(fd, (off_t)((p - buf) + 1), SEEK_SET);
- return (buf);
-}
-
-/*
- * rcv_mktemp --
- * Paranoid make temporary file routine.
- */
-static int
-rcv_mktemp(sp, path, dname, perms)
- SCR *sp;
- char *path, *dname;
- int perms;
-{
- int fd;
-
- /*
- * !!!
- * We expect mkstemp(3) to set the permissions correctly. On
- * historic System V systems, mkstemp didn't. Do it here, on
- * GP's.
- *
- * XXX
- * The variable perms should really be a mode_t, and it would
- * be nice to use fchmod(2) instead of chmod(2), here.
- */
- if ((fd = mkstemp(path)) == -1)
- msgq(sp, M_SYSERR, "%s", dname);
- else
- (void)chmod(path, perms);
- return (fd);
-}
-
-/*
- * rcv_email --
- * Send email.
- */
-static void
-rcv_email(sp, fname)
- SCR *sp;
- char *fname;
-{
- struct stat sb;
- char buf[MAXPATHLEN * 2 + 20];
-
- if (stat(_PATH_SENDMAIL, &sb))
- msgq(sp, M_SYSERR, "not sending email: %s", _PATH_SENDMAIL);
- else {
- /*
- * !!!
- * If you need to port this to a system that doesn't have
- * sendmail, the -t flag causes sendmail to read the message
- * for the recipients instead of specifying them some other
- * way.
- */
- (void)snprintf(buf, sizeof(buf),
- "%s -t < %s", _PATH_SENDMAIL, fname);
- (void)system(buf);
- }
-}
diff --git a/usr.bin/vi/common/screen.c b/usr.bin/vi/common/screen.c
deleted file mode 100644
index 2756969..0000000
--- a/usr.bin/vi/common/screen.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)screen.c 8.67 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "excmd.h"
-#include "../ex/tag.h"
-
-/*
- * screen_init --
- * Do the default initialization of an SCR structure.
- */
-int
-screen_init(orig, spp, flags)
- SCR *orig, **spp;
- u_int flags;
-{
- SCR *sp;
- size_t len;
-
- *spp = NULL;
- CALLOC_RET(orig, sp, SCR *, 1, sizeof(SCR));
- *spp = sp;
-
-/* INITIALIZED AT SCREEN CREATE. */
- sp->gp = __global_list; /* All ref the GS structure. */
-
- LIST_INIT(&sp->msgq);
- CIRCLEQ_INIT(&sp->frefq);
-
- sp->ccnt = 2; /* Anything > 1 */
-
- FD_ZERO(&sp->rdfd);
-
- /*
- * XXX
- * sp->defscroll is initialized by the opts_init() code because
- * we don't have the option information yet.
- */
-
- sp->tiqp = &sp->__tiq;
- CIRCLEQ_INIT(&sp->__tiq);
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
- if (orig == NULL) {
- sp->searchdir = NOTSET;
-
- switch (flags & S_SCREENS) {
- case S_EX:
- if (sex_screen_init(sp))
- return (1);
- break;
- case S_VI_CURSES:
- if (svi_screen_init(sp))
- return (1);
- break;
- case S_VI_XAW:
- if (xaw_screen_init(sp))
- return (1);
- break;
- default:
- abort();
- }
-
- sp->flags = flags;
- } else {
- if (orig->alt_name != NULL &&
- (sp->alt_name = strdup(orig->alt_name)) == NULL)
- goto mem;
-
- /* Retain all searching/substitution information. */
- if (F_ISSET(orig, S_SRE_SET)) {
- F_SET(sp, S_SRE_SET);
- sp->sre = orig->sre;
- }
- if (F_ISSET(orig, S_SUBRE_SET)) {
- F_SET(sp, S_SUBRE_SET);
- sp->subre = orig->subre;
- }
- sp->searchdir = orig->searchdir == NOTSET ? NOTSET : FORWARD;
-
- if (orig->repl_len) {
- MALLOC(sp, sp->repl, char *, orig->repl_len);
- if (sp->repl == NULL)
- goto mem;
- sp->repl_len = orig->repl_len;
- memmove(sp->repl, orig->repl, orig->repl_len);
- }
- if (orig->newl_len) {
- len = orig->newl_len * sizeof(size_t);
- MALLOC(sp, sp->newl, size_t *, len);
- if (sp->newl == NULL)
- goto mem;
- sp->newl_len = orig->newl_len;
- sp->newl_cnt = orig->newl_cnt;
- memmove(sp->newl, orig->newl, len);
- }
-
- sp->saved_vi_mode = orig->saved_vi_mode;
-
- if (opts_copy(orig, sp)) {
-mem: msgq(orig, M_SYSERR, "new screen attributes");
- (void)screen_end(sp);
- return (1);
- }
-
- sp->s_bell = orig->s_bell;
- sp->s_bg = orig->s_bg;
- sp->s_busy = orig->s_busy;
- sp->s_change = orig->s_change;
- sp->s_clear = orig->s_clear;
- sp->s_colpos = orig->s_colpos;
- sp->s_column = orig->s_column;
- sp->s_confirm = orig->s_confirm;
- sp->s_crel = orig->s_crel;
- sp->s_edit = orig->s_edit;
- sp->s_end = orig->s_end;
- sp->s_ex_cmd = orig->s_ex_cmd;
- sp->s_ex_run = orig->s_ex_run;
- sp->s_ex_write = orig->s_ex_write;
- sp->s_fg = orig->s_fg;
- sp->s_fill = orig->s_fill;
- sp->s_get = orig->s_get;
- sp->s_key_read = orig->s_key_read;
- sp->s_fmap = orig->s_fmap;
- sp->s_optchange = orig->s_optchange;
- sp->s_position = orig->s_position;
- sp->s_rabs = orig->s_rabs;
- sp->s_rcm = orig->s_rcm;
- sp->s_refresh = orig->s_refresh;
- sp->s_scroll = orig->s_scroll;
- sp->s_split = orig->s_split;
- sp->s_suspend = orig->s_suspend;
- sp->s_window = orig->s_window;
-
- F_SET(sp, F_ISSET(orig, S_SCREENS));
- }
-
- if (xaw_screen_copy(orig, sp)) /* Init S_VI_XAW screen. */
- return (1);
- if (svi_screen_copy(orig, sp)) /* Init S_VI_CURSES screen. */
- return (1);
- if (sex_screen_copy(orig, sp)) /* Init S_EX screen. */
- return (1);
- if (v_screen_copy(orig, sp)) /* Init vi. */
- return (1);
- if (ex_screen_copy(orig, sp)) /* Init ex. */
- return (1);
-
- *spp = sp;
- return (0);
-}
-
-/*
- * screen_end --
- * Release a screen.
- */
-int
-screen_end(sp)
- SCR *sp;
-{
- int rval;
-
- rval = 0;
- if (xaw_screen_end(sp)) /* End S_VI_XAW screen. */
- rval = 1;
- if (svi_screen_end(sp)) /* End S_VI_CURSES screen. */
- rval = 1;
- if (sex_screen_end(sp)) /* End S_EX screen. */
- rval = 1;
- if (v_screen_end(sp)) /* End vi. */
- rval = 1;
- if (ex_screen_end(sp)) /* End ex. */
- rval = 1;
-
- /* Free FREF's. */
- { FREF *frp;
- while ((frp = sp->frefq.cqh_first) != (FREF *)&sp->frefq) {
- CIRCLEQ_REMOVE(&sp->frefq, frp, q);
- if (frp->name != NULL)
- free(frp->name);
- if (frp->tname != NULL)
- free(frp->tname);
- FREE(frp, sizeof(FREF));
- }
- }
-
- /* Free file names. */
- { char **ap;
- if (!F_ISSET(sp, S_ARGNOFREE) && sp->argv != NULL) {
- for (ap = sp->argv; *ap != NULL; ++ap)
- free(*ap);
- free(sp->argv);
- }
- }
-
- /* Free any text input. */
- text_lfree(&sp->__tiq);
-
- /* Free any script information. */
- if (F_ISSET(sp, S_SCRIPT))
- sscr_end(sp);
-
- /* Free alternate file name. */
- if (sp->alt_name != NULL)
- free(sp->alt_name);
-
- /* Free up search information. */
- if (sp->repl != NULL)
- FREE(sp->repl, sp->repl_len);
- if (sp->newl != NULL)
- FREE(sp->newl, sp->newl_len);
-
- /* Free all the options */
- opts_free(sp);
-
- /*
- * Free the message chain last, so previous failures have a place
- * to put messages. Copy messages to (in order) a related screen,
- * any screen, the global area.
- */
- { SCR *c_sp; MSG *mp, *next;
- if ((c_sp = sp->q.cqe_prev) != (void *)&sp->gp->dq) {
- if (F_ISSET(sp, S_BELLSCHED))
- F_SET(c_sp, S_BELLSCHED);
- } else if ((c_sp = sp->q.cqe_next) != (void *)&sp->gp->dq) {
- if (F_ISSET(sp, S_BELLSCHED))
- F_SET(c_sp, S_BELLSCHED);
- } else if ((c_sp =
- sp->gp->hq.cqh_first) != (void *)&sp->gp->hq) {
- if (F_ISSET(sp, S_BELLSCHED))
- F_SET(c_sp, S_BELLSCHED);
- } else {
- c_sp = NULL;
- if (F_ISSET(sp, S_BELLSCHED))
- F_SET(sp->gp, G_BELLSCHED);
- }
-
- for (mp = sp->msgq.lh_first; mp != NULL; mp = next) {
- if (!F_ISSET(mp, M_EMPTY))
- msg_app(sp->gp, c_sp,
- mp->flags & M_INV_VIDEO, mp->mbuf, mp->len);
- next = mp->q.le_next;
- if (mp->mbuf != NULL)
- FREE(mp->mbuf, mp->blen);
- FREE(mp, sizeof(MSG));
- }
- }
-
- /* Remove the screen from the displayed queue. */
- SIGBLOCK(sp->gp);
- CIRCLEQ_REMOVE(&sp->gp->dq, sp, q);
- SIGUNBLOCK(sp->gp);
-
- /* Free the screen itself. */
- FREE(sp, sizeof(SCR));
-
- return (rval);
-}
diff --git a/usr.bin/vi/common/screen.h b/usr.bin/vi/common/screen.h
deleted file mode 100644
index 31df988..0000000
--- a/usr.bin/vi/common/screen.h
+++ /dev/null
@@ -1,342 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)screen.h 8.127 (Berkeley) 8/8/94
- */
-
-/*
- * There are minimum values that vi has to have to display a screen. The
- * row minimum is fixed at 1 line for the text, and 1 line for any error
- * messages. The column calculation is a lot trickier. For example, you
- * have to have enough columns to display the line number, not to mention
- * guaranteeing that tabstop and shiftwidth values are smaller than the
- * current column value. It's a lot simpler to have a fixed value and not
- * worry about it.
- *
- * XXX
- * MINIMUM_SCREEN_COLS is probably wrong.
- */
-#define MINIMUM_SCREEN_ROWS 2
-#define MINIMUM_SCREEN_COLS 20
-
-enum adjust { /* Screen adjustment operations. */
- A_DECREASE, A_INCREASE, A_SET };
-enum operation { /* Line operations. */
- LINE_APPEND, LINE_DELETE, LINE_INSERT, LINE_RESET };
-enum position { /* Position operations. */
- P_BOTTOM, P_FILL, P_MIDDLE, P_TOP };
-enum sctype { /* Scroll operations. */
- CNTRL_B, CNTRL_D, CNTRL_E, CNTRL_F, CNTRL_U, CNTRL_Y, Z_CARAT, Z_PLUS };
-
-/*
- * Structure for holding file references. Each SCR structure contains a
- * linked list of these. The structure contains the name of the file,
- * along with the information that follows the name.
- *
- * !!!
- * The read-only bit follows the file name, not the file itself.
- *
- * XXX
- * The mtime field should be a struct timespec, but time_t is more portable.
- */
-struct _fref {
- CIRCLEQ_ENTRY(_fref) q; /* Linked list of file references. */
- char *name; /* File name. */
- char *tname; /* Backing temporary file name. */
-
- recno_t lno; /* 1-N: file cursor line. */
- size_t cno; /* 0-N: file cursor column. */
-
-#define FR_CURSORSET 0x001 /* If lno/cno values valid. */
-#define FR_DONTDELETE 0x002 /* Don't delete the temporary file. */
-#define FR_FNONBLANK 0x004 /* Move to the first non-<blank>. */
-#define FR_NAMECHANGE 0x008 /* If the name changed. */
-#define FR_NEWFILE 0x010 /* File doesn't really exist yet. */
-#define FR_RDONLY 0x020 /* File is read-only. */
-#define FR_READNAMED 0x040 /* Read renamed the file. */
-#define FR_RECOVER 0x080 /* File is being recovered. */
-#define FR_TMPEXIT 0x100 /* Modified temporary file, no exit. */
-#define FR_TMPFILE 0x200 /* If file has no name. */
-#define FR_UNLOCKED 0x400 /* File couldn't be locked. */
- u_int16_t flags;
-};
-
-#define TEMPORARY_FILE_STRING "/tmp" /* Default temporary file name. */
-
-/*
- * SCR --
- * The screen structure. To the extent possible, all screen information
- * is stored in the various private areas. The only information here
- * is used by global routines or is shared by too many screens.
- */
-struct _scr {
-/* INITIALIZED AT SCREEN CREATE. */
- CIRCLEQ_ENTRY(_scr) q; /* Screens. */
-
- GS *gp; /* Pointer to global area. */
-
- SCR *nextdisp; /* Next display screen. */
-
- EXF *ep; /* Screen's current EXF structure. */
-
- MSGH msgq; /* Message list. */
- /* FREF list. */
- CIRCLEQ_HEAD(_frefh, _fref) frefq;
- FREF *frp; /* FREF being edited. */
-
- char **argv; /* NULL terminated file name array. */
- char **cargv; /* Current file name. */
-
- u_long ccnt; /* Command count. */
- u_long q_ccnt; /* Quit or ZZ command count. */
-
- /* Screen's: */
- size_t rows; /* 1-N: number of rows. */
- size_t cols; /* 1-N: number of columns. */
- size_t woff; /* 0-N: row offset in screen. */
- size_t t_rows; /* 1-N: cur number of text rows. */
- size_t t_maxrows; /* 1-N: max number of text rows. */
- size_t t_minrows; /* 1-N: min number of text rows. */
-
- /* Cursor's: */
- recno_t lno; /* 1-N: file line. */
- size_t cno; /* 0-N: file character in line. */
-
- size_t rcm; /* Vi: 0-N: Most attractive column. */
- int rcm_last; /* Cursor drawn to the last column. */
-
-#define L_ADDED 0 /* Added lines. */
-#define L_CHANGED 1 /* Changed lines. */
-#define L_DELETED 2 /* Deleted lines. */
-#define L_JOINED 3 /* Joined lines. */
-#define L_MOVED 4 /* Moved lines. */
-#define L_LSHIFT 5 /* Left shift lines. */
-#define L_RSHIFT 6 /* Right shift lines. */
-#define L_YANKED 7 /* Yanked lines. */
- recno_t rptlchange; /* Ex/vi: last L_CHANGED lno. */
- recno_t rptlines[L_YANKED + 1];/* Ex/vi: lines changed by last op. */
-
- FILE *stdfp; /* Ex output file pointer. */
-
- char *if_name; /* Ex input file name, for messages. */
- recno_t if_lno; /* Ex input file line, for messages. */
-
- fd_set rdfd; /* Ex/vi: read fd select mask. */
-
- TEXTH __tiq; /* Ex/vi: text input queue. */
- TEXTH *tiqp; /* Ex/vi: text input queue reference. */
-
- SCRIPT *script; /* Vi: script mode information .*/
-
- recno_t defscroll; /* Vi: ^D, ^U scroll information. */
-
- struct timeval busy_tod; /* ITIMER_REAL: busy time-of-day. */
- char const *busy_msg; /* ITIMER_REAL: busy message. */
-
- /* Display character. */
- CHAR_T cname[MAX_CHARACTER_COLUMNS + 1];
- size_t clen; /* Length of display character. */
-
-#define MAX_MODE_NAME 12
- char *showmode; /* Mode. */
-
- void *ex_private; /* Ex private area. */
- void *sex_private; /* Ex screen private area. */
- void *vi_private; /* Vi private area. */
- void *svi_private; /* Vi curses screen private area. */
- void *xaw_private; /* Vi XAW screen private area. */
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
- char *alt_name; /* Ex/vi: alternate file name. */
-
- /* Ex/vi: search/substitute info. */
- regex_t sre; /* Last search RE. */
- regex_t subre; /* Last substitute RE. */
- enum direction searchdir; /* File search direction. */
- char *repl; /* Substitute replacement. */
- size_t repl_len; /* Substitute replacement length.*/
- size_t *newl; /* Newline offset array. */
- size_t newl_len; /* Newline array size. */
- size_t newl_cnt; /* Newlines in replacement. */
- u_char c_suffix; /* Edcompatible 'c' suffix value. */
- u_char g_suffix; /* Edcompatible 'g' suffix value. */
-
- u_int saved_vi_mode; /* Saved vi display type. */
-
- OPTION opts[O_OPTIONCOUNT]; /* Options. */
-
-/*
- * SCREEN SUPPORT ROUTINES.
- *
- * A SCR * MUST be the first argument to these routines.
- */
- /* Ring the screen bell. */
- void (*s_bell) __P((SCR *));
- /* Background the screen. */
- int (*s_bg) __P((SCR *));
- /* Put up a busy message. */
- int (*s_busy) __P((SCR *, char const *));
- /* Change a screen line. */
- int (*s_change) __P((SCR *, EXF *, recno_t, enum operation));
- /* Clear the screen. */
- int (*s_clear) __P((SCR *));
- /* Return column close to specified. */
- size_t (*s_colpos) __P((SCR *, EXF *, recno_t, size_t));
- /* Return the logical cursor column. */
- int (*s_column) __P((SCR *, EXF *, size_t *));
- enum confirm /* Confirm an action with the user. */
- (*s_confirm) __P((SCR *, EXF *, MARK *, MARK *));
- /* Change the relative screen size. */
- int (*s_crel) __P((SCR *, long));
- /* Edit a file. */
- int (*s_edit) __P((SCR *, EXF *));
- /* End a screen. */
- int (*s_end) __P((SCR *));
- /* Run a single ex command. */
- int (*s_ex_cmd) __P((SCR *, EXF *, EXCMDARG *, MARK *));
- /* Run user's ex commands. */
- int (*s_ex_run) __P((SCR *, EXF *, MARK *));
- /* Screen's ex write function. */
- int (*s_ex_write) __P((void *, const char *, int));
- /* Foreground the screen. */
- int (*s_fg) __P((SCR *, CHAR_T *));
- /* Fill the screen's map. */
- int (*s_fill) __P((SCR *, EXF *, recno_t, enum position));
- enum input /* Get a line from the user. */
- (*s_get) __P((SCR *, EXF *, TEXTH *, ARG_CHAR_T, u_int));
- enum input /* Get a key from the user. */
- (*s_key_read) __P((SCR *, int *, struct timeval *));
- /* Map a function key. */
- int (*s_fmap) __P((SCR *,
- enum seqtype, CHAR_T *, size_t, CHAR_T *, size_t));
- /* Tell the screen an option changed. */
- int (*s_optchange) __P((SCR *, int));
- /* Return column at screen position. */
- int (*s_position) __P((SCR *, EXF *,
- MARK *, u_long, enum position));
- /* Change the absolute screen size. */
- int (*s_rabs) __P((SCR *, long, enum adjust));
- /* Return column close to selection. */
- size_t (*s_rcm) __P((SCR *, EXF *, recno_t));
- /* Refresh the screen. */
- int (*s_refresh) __P((SCR *, EXF *));
- /* Move down the screen. */
- int (*s_scroll) __P((SCR *, EXF *, MARK *, recno_t, enum sctype));
- /* Split the screen. */
- int (*s_split) __P((SCR *, ARGS *[], int));
- /* Suspend the screen. */
- int (*s_suspend) __P((SCR *));
- /* Set the window size. */
- int (*s_window) __P((SCR *, int));
-
-/* Editor screens. */
-#define S_EX 0x0000001 /* Ex screen. */
-#define S_VI_CURSES 0x0000002 /* Vi: curses screen. */
-#define S_VI_XAW 0x0000004 /* Vi: Athena widgets screen. */
-
-#define IN_EX_MODE(sp) /* If in ex mode. */ \
- (F_ISSET(sp, S_EX))
-#define IN_VI_MODE(sp) /* If in vi mode. */ \
- (F_ISSET(sp, S_VI_CURSES | S_VI_XAW))
-#define S_SCREENS /* Screens. */ \
- (S_EX | S_VI_CURSES | S_VI_XAW)
-
-/* Major screen/file changes. */
-#define S_EXIT 0x0000008 /* Exiting (not forced). */
-#define S_EXIT_FORCE 0x0000010 /* Exiting (forced). */
-#define S_FSWITCH 0x0000020 /* Switch files. */
-#define S_SSWITCH 0x0000040 /* Switch screens. */
-#define S_MAJOR_CHANGE /* Screen or file changes. */ \
- (S_EXIT | S_EXIT_FORCE | S_FSWITCH | S_SSWITCH)
-
-#define S_ARGNOFREE 0x0000080 /* Argument list wasn't allocated. */
-#define S_ARGRECOVER 0x0000100 /* Argument list is recovery files. */
-#define S_BELLSCHED 0x0000200 /* Bell scheduled. */
-#define S_CONTINUE 0x0000400 /* Need to ask the user to continue. */
-#define S_EXSILENT 0x0000800 /* Ex batch script. */
-#define S_GLOBAL 0x0001000 /* Doing a global command. */
-#define S_INPUT 0x0002000 /* Doing text input. */
-#define S_INTERRUPTED 0x0004000 /* If have been interrupted. */
-#define S_INTERRUPTIBLE 0x0008000 /* If can be interrupted. */
-#define S_IVIDEO 0x0010000 /* Display in inverse video. */
-#define S_REDRAW 0x0020000 /* Redraw the screen. */
-#define S_REFORMAT 0x0040000 /* Reformat the screen. */
-#define S_REFRESH 0x0080000 /* Refresh the screen. */
-#define S_RENUMBER 0x0100000 /* Renumber the screen. */
-#define S_RESIZE 0x0200000 /* Resize the screen. */
-#define S_SCRIPT 0x0400000 /* Window is a shell script. */
-#define S_SRE_SET 0x0800000 /* The search RE has been set. */
-#define S_SUBRE_SET 0x1000000 /* The substitute RE has been set. */
-#define S_UPDATE_MODE 0x2000000 /* Don't repaint modeline. */
-#define S_VLITONLY 0x4000000 /* ^V literal next only. */
- u_int32_t flags;
-};
-
-/*
- * Signals/timers have no structure, so it's all here.
- *
- * Block all signals that are being handled. Used to keep the underlying DB
- * system calls from being interrupted and not restarted, as it could cause
- * consistency problems. Also used when vi forks child processes, to avoid
- * a signal arriving after the fork and before the exec, causing both parent
- * and child to attempt recovery processing.
- */
-#define SIGBLOCK(gp) \
- (void)sigprocmask(SIG_BLOCK, &(gp)->blockset, NULL);
-#define SIGUNBLOCK(gp) \
- (void)sigprocmask(SIG_UNBLOCK, &(gp)->blockset, NULL);
-
-void busy_off __P((SCR *));
-int busy_on __P((SCR *, char const *));
-void sig_end __P((void));
-int sig_init __P((SCR *));
-
-/* Generic routines to start/stop a screen. */
-int screen_end __P((SCR *));
-int screen_init __P((SCR *, SCR **, u_int));
-
-/* Public interfaces to the underlying screens. */
-int ex_screen_copy __P((SCR *, SCR *));
-int ex_screen_end __P((SCR *));
-int ex_screen_init __P((SCR *));
-int sex_screen_copy __P((SCR *, SCR *));
-int sex_screen_end __P((SCR *));
-int sex_screen_init __P((SCR *));
-int svi_screen_copy __P((SCR *, SCR *));
-int svi_screen_end __P((SCR *));
-int svi_screen_init __P((SCR *));
-int v_screen_copy __P((SCR *, SCR *));
-int v_screen_end __P((SCR *));
-int v_screen_init __P((SCR *));
-int xaw_screen_copy __P((SCR *, SCR *));
-int xaw_screen_end __P((SCR *));
-int xaw_screen_init __P((SCR *));
diff --git a/usr.bin/vi/common/search.c b/usr.bin/vi/common/search.c
deleted file mode 100644
index f7e96eb..0000000
--- a/usr.bin/vi/common/search.c
+++ /dev/null
@@ -1,833 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)search.c 8.48 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-static int check_delta __P((SCR *, EXF *, long, recno_t));
-static int ctag_conv __P((SCR *, char **, int *));
-static int get_delta __P((SCR *, char **, long *, u_int *));
-static int resetup __P((SCR *, regex_t **, enum direction,
- char *, char **, long *, u_int *));
-
-/*
- * resetup --
- * Set up a search for a regular expression.
- */
-static int
-resetup(sp, rep, dir, ptrn, epp, deltap, flagp)
- SCR *sp;
- regex_t **rep;
- enum direction dir;
- char *ptrn, **epp;
- long *deltap;
- u_int *flagp;
-{
- u_int flags;
- int delim, eval, re_flags, replaced;
- char *p, *t;
-
- /* Set return information the default. */
- *deltap = 0;
-
- /*
- * Use saved pattern if no pattern supplied, or if only a delimiter
- * character is supplied. Only the pattern was saved, historic vi
- * did not reuse any delta supplied.
- */
- flags = *flagp;
- if (ptrn == NULL)
- goto prev;
- if (ptrn[1] == '\0') {
- if (epp != NULL)
- *epp = ptrn + 1;
- goto prev;
- }
- if (ptrn[0] == ptrn[1] && ptrn[2] == '\0') {
- if (epp != NULL)
- *epp = ptrn + 2;
-prev: if (!F_ISSET(sp, S_SRE_SET)) {
- msgq(sp, M_ERR, "No previous search pattern");
- return (1);
- }
- *rep = &sp->sre;
-
- /* Empty patterns set the direction. */
- if (LF_ISSET(SEARCH_SET)) {
- F_SET(sp, S_SRE_SET);
- sp->searchdir = dir;
- sp->sre = **rep;
- }
- return (0);
- }
-
- re_flags = 0; /* Set RE flags. */
- if (O_ISSET(sp, O_EXTENDED))
- re_flags |= REG_EXTENDED;
- if (O_ISSET(sp, O_IGNORECASE))
- re_flags |= REG_ICASE;
-
- replaced = 0;
- if (LF_ISSET(SEARCH_PARSE)) { /* Parse the string. */
- /* Set delimiter. */
- delim = *ptrn++;
-
- /* Find terminating delimiter, handling escaped delimiters. */
- for (p = t = ptrn;;) {
- if (p[0] == '\0' || p[0] == delim) {
- if (p[0] == delim)
- ++p;
- *t = '\0';
- break;
- }
- if (p[1] == delim && p[0] == '\\')
- ++p;
- *t++ = *p++;
- }
-
- /*
- * If characters after the terminating delimiter, it may
- * be an error, or may be an offset. In either case, we
- * return the end of the string, whatever it may be.
- */
- if (*p) {
- if (get_delta(sp, &p, deltap, flagp))
- return (1);
- if (*p && LF_ISSET(SEARCH_TERM)) {
- msgq(sp, M_ERR,
- "Characters after search string and/or delta");
- return (1);
- }
- }
- if (epp != NULL)
- *epp = p;
-
- /* Check for "/ " or other such silliness. */
- if (*ptrn == '\0')
- goto prev;
-
- if (re_conv(sp, &ptrn, &replaced))
- return (1);
- } else if (LF_ISSET(SEARCH_TAG)) {
- if (ctag_conv(sp, &ptrn, &replaced))
- return (1);
- re_flags &= ~(REG_EXTENDED | REG_ICASE);
- }
-
- /* Compile the RE. */
- if (eval = regcomp(*rep, ptrn, re_flags))
- re_error(sp, eval, *rep);
- else if (LF_ISSET(SEARCH_SET)) {
- F_SET(sp, S_SRE_SET);
- sp->searchdir = dir;
- sp->sre = **rep;
- }
-
- /* Free up any extra memory. */
- if (replaced)
- FREE_SPACE(sp, ptrn, 0);
- return (eval);
-}
-
-/*
- * ctag_conv --
- * Convert a tags search path into something that the POSIX
- * 1003.2 RE functions can handle.
- */
-static int
-ctag_conv(sp, ptrnp, replacedp)
- SCR *sp;
- char **ptrnp;
- int *replacedp;
-{
- size_t blen, len;
- int lastdollar;
- char *bp, *p, *t;
-
- *replacedp = 0;
-
- len = strlen(p = *ptrnp);
-
- /* Max memory usage is 2 times the length of the string. */
- GET_SPACE_RET(sp, bp, blen, len * 2);
-
- t = bp;
-
- /* The last character is a '/' or '?', we just strip it. */
- if (p[len - 1] == '/' || p[len - 1] == '?')
- p[len - 1] = '\0';
-
- /* The next-to-last character is a '$', and it's magic. */
- if (p[len - 2] == '$') {
- lastdollar = 1;
- p[len - 2] = '\0';
- } else
- lastdollar = 0;
-
- /* The first character is a '/' or '?', we just strip it. */
- if (p[0] == '/' || p[0] == '?')
- ++p;
-
- /* The second character is a '^', and it's magic. */
- if (p[0] == '^')
- *t++ = *p++;
-
- /*
- * Escape every other magic character we can find, stripping the
- * backslashes ctags inserts to escape the search delimiter
- * characters.
- */
- while (p[0]) {
- /* Ctags escapes the search delimiter characters. */
- if (p[0] == '\\' && (p[1] == '/' || p[1] == '?'))
- ++p;
- else if (strchr("^.[]$*", p[0]))
- *t++ = '\\';
- *t++ = *p++;
- }
- if (lastdollar)
- *t++ = '$';
- *t++ = '\0';
-
- *ptrnp = bp;
- *replacedp = 1;
- return (0);
-}
-
-#define EMPTYMSG "File empty; nothing to search"
-#define EOFMSG "Reached end-of-file without finding the pattern"
-#define NOTFOUND "Pattern not found"
-#define SOFMSG "Reached top-of-file without finding the pattern"
-#define WRAPMSG "Search wrapped"
-
-int
-f_search(sp, ep, fm, rm, ptrn, eptrn, flagp)
- SCR *sp;
- EXF *ep;
- MARK *fm, *rm;
- char *ptrn, **eptrn;
- u_int *flagp;
-{
- regmatch_t match[1];
- regex_t *re, lre;
- recno_t lno;
- size_t coff, len;
- long delta;
- u_int flags;
- int btear, eval, rval, wrapped;
- char *l;
-
- if (file_lline(sp, ep, &lno))
- return (1);
- flags = *flagp;
- if (lno == 0) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, EMPTYMSG);
- return (1);
- }
-
- re = &lre;
- if (resetup(sp, &re, FORWARD, ptrn, eptrn, &delta, flagp))
- return (1);
-
- /*
- * Start searching immediately after the cursor. If at the end of the
- * line, start searching on the next line. This is incompatible (read
- * bug fix) with the historic vi -- searches for the '$' pattern never
- * moved forward, and "-t foo" didn't work if "foo" was the first thing
- * in the file.
- */
- if (LF_ISSET(SEARCH_FILE)) {
- lno = 1;
- coff = 0;
- } else {
- if ((l = file_gline(sp, ep, fm->lno, &len)) == NULL) {
- GETLINE_ERR(sp, fm->lno);
- return (1);
- }
- if (fm->cno + 1 >= len) {
- if (fm->lno == lno) {
- if (!O_ISSET(sp, O_WRAPSCAN)) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, EOFMSG);
- return (1);
- }
- lno = 1;
- } else
- lno = fm->lno + 1;
- coff = 0;
- } else {
- lno = fm->lno;
- coff = fm->cno + 1;
- }
- }
-
- /* Turn on busy message. */
- btear = F_ISSET(sp, S_EXSILENT) ? 0 : !busy_on(sp, "Searching...");
-
- for (rval = 1, wrapped = 0;; ++lno, coff = 0) {
- if (INTERRUPTED(sp)) {
- msgq(sp, M_INFO, "Interrupted.");
- break;
- }
- if (wrapped && lno > fm->lno ||
- (l = file_gline(sp, ep, lno, &len)) == NULL) {
- if (wrapped) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, NOTFOUND);
- break;
- }
- if (!O_ISSET(sp, O_WRAPSCAN)) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, EOFMSG);
- break;
- }
- lno = 0;
- wrapped = 1;
- continue;
- }
-
- /* If already at EOL, just keep going. */
- if (len && coff == len)
- continue;
-
- /* Set the termination. */
- match[0].rm_so = coff;
- match[0].rm_eo = len;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "F search: %lu from %u to %u\n",
- lno, coff, len ? len - 1 : len);
-#endif
- /* Search the line. */
- eval = regexec(re, l, 1, match,
- (match[0].rm_so == 0 ? 0 : REG_NOTBOL) | REG_STARTEND);
- if (eval == REG_NOMATCH)
- continue;
- if (eval != 0) {
- re_error(sp, eval, re);
- break;
- }
-
- /* Warn if wrapped. */
- if (wrapped && O_ISSET(sp, O_WARN) && LF_ISSET(SEARCH_MSG))
- msgq(sp, M_VINFO, WRAPMSG);
-
- /*
- * If an offset, see if it's legal. It's possible to match
- * past the end of the line with $, so check for that case.
- */
- if (delta) {
- if (check_delta(sp, ep, delta, lno))
- break;
- rm->lno = delta + lno;
- rm->cno = 0;
- } else {
-#if defined(DEBUG) && 0
- TRACE(sp, "found: %qu to %qu\n",
- match[0].rm_so, match[0].rm_eo);
-#endif
- rm->lno = lno;
- rm->cno = match[0].rm_so;
-
- /*
- * If a change command, it's possible to move beyond
- * the end of a line. Historic vi generally got this
- * wrong (try "c?$<cr>"). Not all that sure this gets
- * it right, there are lots of strange cases.
- */
- if (!LF_ISSET(SEARCH_EOL) && rm->cno >= len)
- rm->cno = len ? len - 1 : 0;
- }
- rval = 0;
- break;
- }
-
- /* Turn off busy message, interrupts. */
- if (btear)
- busy_off(sp);
- return (rval);
-}
-
-int
-b_search(sp, ep, fm, rm, ptrn, eptrn, flagp)
- SCR *sp;
- EXF *ep;
- MARK *fm, *rm;
- char *ptrn, **eptrn;
- u_int *flagp;
-{
- regmatch_t match[1];
- regex_t *re, lre;
- recno_t lno;
- size_t coff, len, last;
- long delta;
- u_int flags;
- int btear, eval, rval, wrapped;
- char *l;
-
- if (file_lline(sp, ep, &lno))
- return (1);
- flags = *flagp;
- if (lno == 0) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, EMPTYMSG);
- return (1);
- }
-
- re = &lre;
- if (resetup(sp, &re, BACKWARD, ptrn, eptrn, &delta, flagp))
- return (1);
-
- /* If in the first column, start searching on the previous line. */
- if (fm->cno == 0) {
- if (fm->lno == 1) {
- if (!O_ISSET(sp, O_WRAPSCAN)) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, SOFMSG);
- return (1);
- }
- } else
- lno = fm->lno - 1;
- } else
- lno = fm->lno;
-
- /* Turn on busy message. */
- btear = F_ISSET(sp, S_EXSILENT) ? 0 : !busy_on(sp, "Searching...");
-
- for (rval = 1, wrapped = 0, coff = fm->cno;; --lno, coff = 0) {
- if (INTERRUPTED(sp)) {
- msgq(sp, M_INFO, "Interrupted.");
- break;
- }
- if (wrapped && lno < fm->lno || lno == 0) {
- if (wrapped) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, NOTFOUND);
- break;
- }
- if (!O_ISSET(sp, O_WRAPSCAN)) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, SOFMSG);
- break;
- }
- if (file_lline(sp, ep, &lno))
- goto err;
- if (lno == 0) {
- if (LF_ISSET(SEARCH_MSG))
- msgq(sp, M_INFO, EMPTYMSG);
- break;
- }
- ++lno;
- wrapped = 1;
- continue;
- }
-
- if ((l = file_gline(sp, ep, lno, &len)) == NULL)
- goto err;
-
- /* Set the termination. */
- match[0].rm_so = 0;
- match[0].rm_eo = len;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "B search: %lu from 0 to %qu\n", lno, match[0].rm_eo);
-#endif
- /* Search the line. */
- eval = regexec(re, l, 1, match,
- (match[0].rm_eo == len ? 0 : REG_NOTEOL) | REG_STARTEND);
- if (eval == REG_NOMATCH)
- continue;
- if (eval != 0) {
- re_error(sp, eval, re);
- break;
- }
-
- /* Check for a match starting past the cursor. */
- if (coff != 0 && match[0].rm_so >= coff)
- continue;
-
- /* Warn if wrapped. */
- if (wrapped && O_ISSET(sp, O_WARN) && LF_ISSET(SEARCH_MSG))
- msgq(sp, M_VINFO, WRAPMSG);
-
- if (delta) {
- if (check_delta(sp, ep, delta, lno))
- break;
- rm->lno = delta + lno;
- rm->cno = 0;
- } else {
-#if defined(DEBUG) && 0
- TRACE(sp, "found: %qu to %qu\n",
- match[0].rm_so, match[0].rm_eo);
-#endif
- /*
- * We now have the first match on the line. Step
- * through the line character by character until we
- * find the last acceptable match. This is painful,
- * we need a better interface to regex to make this
- * work.
- */
- for (;;) {
- last = match[0].rm_so++;
- if (match[0].rm_so >= len)
- break;
- match[0].rm_eo = len;
- eval = regexec(re, l, 1, match,
- (match[0].rm_so == 0 ? 0 : REG_NOTBOL) |
- REG_STARTEND);
- if (eval == REG_NOMATCH)
- break;
- if (eval != 0) {
- re_error(sp, eval, re);
- goto err;
- }
- if (coff && match[0].rm_so >= coff)
- break;
- }
- rm->lno = lno;
-
- /* See comment in f_search(). */
- if (!LF_ISSET(SEARCH_EOL) && last >= len)
- rm->cno = len ? len - 1 : 0;
- else
- rm->cno = last;
- }
- rval = 0;
- break;
- }
-
- /* Turn off busy message, interrupts. */
-err: if (btear)
- busy_off(sp);
- return (rval);
-}
-
-/*
- * re_conv --
- * Convert vi's regular expressions into something that the
- * the POSIX 1003.2 RE functions can handle.
- *
- * There are three conversions we make to make vi's RE's (specifically
- * the global, search, and substitute patterns) work with POSIX RE's.
- *
- * 1: If O_MAGIC is not set, strip backslashes from the magic character
- * set (.[]*~) that have them, and add them to the ones that don't.
- * 2: If O_MAGIC is not set, the string "\~" is replaced with the text
- * from the last substitute command's replacement string. If O_MAGIC
- * is set, it's the string "~".
- * 3: The pattern \<ptrn\> does "word" searches, convert it to use the
- * new RE escapes.
- */
-int
-re_conv(sp, ptrnp, replacedp)
- SCR *sp;
- char **ptrnp;
- int *replacedp;
-{
- size_t blen, needlen;
- int magic;
- char *bp, *p, *t;
-
- /*
- * First pass through, we figure out how much space we'll need.
- * We do it in two passes, on the grounds that most of the time
- * the user is doing a search and won't have magic characters.
- * That way we can skip the malloc and memmove's.
- */
- for (p = *ptrnp, magic = 0, needlen = 0; *p != '\0'; ++p)
- switch (*p) {
- case '\\':
- switch (*++p) {
- case '<':
- magic = 1;
- needlen += sizeof(RE_WSTART);
- break;
- case '>':
- magic = 1;
- needlen += sizeof(RE_WSTOP);
- break;
- case '~':
- if (!O_ISSET(sp, O_MAGIC)) {
- magic = 1;
- needlen += sp->repl_len;
- }
- break;
- case '.':
- case '[':
- case ']':
- case '*':
- if (!O_ISSET(sp, O_MAGIC)) {
- magic = 1;
- needlen += 1;
- }
- break;
- default:
- needlen += 2;
- }
- break;
- case '~':
- if (O_ISSET(sp, O_MAGIC)) {
- magic = 1;
- needlen += sp->repl_len;
- }
- break;
- case '.':
- case '[':
- case ']':
- case '*':
- if (!O_ISSET(sp, O_MAGIC)) {
- magic = 1;
- needlen += 2;
- }
- break;
- default:
- needlen += 1;
- break;
- }
-
- if (!magic) {
- *replacedp = 0;
- return (0);
- }
-
- /*
- * Get enough memory to hold the final pattern.
- *
- * XXX
- * It's nul-terminated, for now.
- */
- GET_SPACE_RET(sp, bp, blen, needlen + 1);
-
- for (p = *ptrnp, t = bp; *p != '\0'; ++p)
- switch (*p) {
- case '\\':
- switch (*++p) {
- case '<':
- memmove(t, RE_WSTART, sizeof(RE_WSTART) - 1);
- t += sizeof(RE_WSTART) - 1;
- break;
- case '>':
- memmove(t, RE_WSTOP, sizeof(RE_WSTOP) - 1);
- t += sizeof(RE_WSTOP) - 1;
- break;
- case '~':
- if (O_ISSET(sp, O_MAGIC))
- *t++ = '~';
- else {
- memmove(t, sp->repl, sp->repl_len);
- t += sp->repl_len;
- }
- break;
- case '.':
- case '[':
- case ']':
- case '*':
- if (O_ISSET(sp, O_MAGIC))
- *t++ = '\\';
- *t++ = *p;
- break;
- default:
- *t++ = '\\';
- *t++ = *p;
- }
- break;
- case '~':
- if (O_ISSET(sp, O_MAGIC)) {
- memmove(t, sp->repl, sp->repl_len);
- t += sp->repl_len;
- } else
- *t++ = '~';
- break;
- case '.':
- case '[':
- case ']':
- case '*':
- if (!O_ISSET(sp, O_MAGIC))
- *t++ = '\\';
- *t++ = *p;
- break;
- default:
- *t++ = *p;
- break;
- }
- *t = '\0';
-
- *ptrnp = bp;
- *replacedp = 1;
- return (0);
-}
-
-/*
- * get_delta --
- * Get a line delta. The trickiness is that the delta can be pretty
- * complicated, i.e. "+3-2+3++- ++" is allowed.
- *
- * !!!
- * In historic vi, if you had a delta on a search pattern which was used as
- * a motion command, the command became a line mode command regardless of the
- * cursor positions. A fairly common trick is to use a delta of "+0" to make
- * the command a line mode command. This is the only place that knows about
- * delta's, so we set the return flag information here.
- */
-static int
-get_delta(sp, dp, valp, flagp)
- SCR *sp;
- char **dp;
- long *valp;
- u_int *flagp;
-{
- char *p;
- long val, tval;
-
- for (tval = 0, p = *dp; *p != '\0'; *flagp |= SEARCH_DELTA) {
- if (isblank(*p)) {
- ++p;
- continue;
- }
- if (*p == '+' || *p == '-') {
- if (!isdigit(*(p + 1))) {
- if (*p == '+') {
- if (tval == LONG_MAX)
- goto overflow;
- ++tval;
- } else {
- if (tval == LONG_MIN)
- goto underflow;
- --tval;
- }
- ++p;
- continue;
- }
- } else
- if (!isdigit(*p))
- break;
-
- errno = 0;
- val = strtol(p, &p, 10);
- if (errno == ERANGE) {
- if (val == LONG_MAX)
-overflow: msgq(sp, M_ERR, "Delta value overflow");
- else if (val == LONG_MIN)
-underflow: msgq(sp, M_ERR, "Delta value underflow");
- else
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- if (val >= 0) {
- if (LONG_MAX - val < tval)
- goto overflow;
- } else
- if (-(LONG_MIN - tval) > val)
- goto underflow;
- tval += val;
- }
- *dp = p;
- *valp = tval;
- return (0);
-}
-
-/*
- * check_delta --
- * Check a line delta to see if it's legal.
- */
-static int
-check_delta(sp, ep, delta, lno)
- SCR *sp;
- EXF *ep;
- long delta;
- recno_t lno;
-{
- /* A delta can overflow a record number. */
- if (delta < 0) {
- if (lno < LONG_MAX && delta >= (long)lno) {
- msgq(sp, M_ERR, "Search offset before line 1");
- return (1);
- }
- } else {
- if (ULONG_MAX - lno < delta) {
- msgq(sp, M_ERR, "Delta value overflow");
- return (1);
- }
- if (file_gline(sp, ep, lno + delta, NULL) == NULL) {
- msgq(sp, M_ERR, "Search offset past end-of-file");
- return (1);
- }
- }
- return (0);
-}
-
-/*
- * re_error --
- * Report a regular expression error.
- */
-void
-re_error(sp, errcode, preg)
- SCR *sp;
- int errcode;
- regex_t *preg;
-{
- size_t s;
- char *oe;
-
- s = regerror(errcode, preg, "", 0);
- if ((oe = malloc(s)) == NULL)
- msgq(sp, M_SYSERR, NULL);
- else {
- (void)regerror(errcode, preg, oe, s);
- msgq(sp, M_ERR, "RE error: %s", oe);
- }
- free(oe);
-}
diff --git a/usr.bin/vi/common/search.h b/usr.bin/vi/common/search.h
deleted file mode 100644
index 1483a04..0000000
--- a/usr.bin/vi/common/search.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)search.h 8.9 (Berkeley) 3/16/94
- */
-
-#define RE_WSTART "[[:<:]]" /* Not-in-word search patterns. */
-#define RE_WSTOP "[[:>:]]"
-
-#define SEARCH_DELTA 0x001 /* A delta part of the search.*/
-#define SEARCH_EOL 0x002 /* Offset past EOL is okay. */
-#define SEARCH_FILE 0x004 /* Search the entire file. */
-#define SEARCH_MSG 0x008 /* Display search warning messages. */
-#define SEARCH_PARSE 0x010 /* Parse the search pattern. */
-#define SEARCH_SET 0x020 /* Set search direction. */
-#define SEARCH_TAG 0x040 /* Search pattern is a tag pattern. */
-#define SEARCH_TERM 0x080 /* Search pattern should terminate. */
-
-enum direction { NOTSET, FORWARD, BACKWARD };
-
-/* Search functions. */
-int b_search __P((SCR *, EXF *, MARK *, MARK *, char *, char **, u_int *));
-int f_search __P((SCR *, EXF *, MARK *, MARK *, char *, char **, u_int *));
-int re_conv __P((SCR *, char **, int *));
-void re_error __P((SCR *, int, regex_t *));
diff --git a/usr.bin/vi/common/seq.c b/usr.bin/vi/common/seq.c
deleted file mode 100644
index 75b67a6..0000000
--- a/usr.bin/vi/common/seq.c
+++ /dev/null
@@ -1,351 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)seq.c 8.33 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * seq_set --
- * Internal version to enter a sequence.
- */
-int
-seq_set(sp, name, nlen, input, ilen, output, olen, stype, flags)
- SCR *sp;
- CHAR_T *name, *input, *output;
- size_t nlen, ilen, olen;
- enum seqtype stype;
- int flags;
-{
- CHAR_T *p;
- SEQ *lastqp, *qp;
- int sv_errno;
-
- /*
- * An input string must always be present. The output string
- * can be NULL, when set internally, that's how we throw away
- * input.
- *
- * Just replace the output field if the string already set.
- */
- if ((qp = seq_find(sp, &lastqp, input, ilen, stype, NULL)) != NULL) {
- if (output == NULL || olen == 0) {
- p = NULL;
- olen = 0;
- } else if ((p = v_strdup(sp, output, olen)) == NULL) {
- sv_errno = errno;
- goto mem1;
- }
- if (qp->output != NULL)
- free(qp->output);
- qp->olen = olen;
- qp->output = p;
- return (0);
- }
-
- /* Allocate and initialize SEQ structure. */
- CALLOC(sp, qp, SEQ *, 1, sizeof(SEQ));
- if (qp == NULL) {
- sv_errno = errno;
- goto mem1;
- }
-
- /* Name. */
- if (name == NULL || nlen == 0)
- qp->name = NULL;
- else if ((qp->name = v_strdup(sp, name, nlen)) == NULL) {
- sv_errno = errno;
- goto mem2;
- }
- qp->nlen = nlen;
-
- /* Input. */
- if ((qp->input = v_strdup(sp, input, ilen)) == NULL) {
- sv_errno = errno;
- goto mem3;
- }
- qp->ilen = ilen;
-
- /* Output. */
- if (output == NULL) {
- qp->output = NULL;
- olen = 0;
- } else if ((qp->output = v_strdup(sp, output, olen)) == NULL) {
- sv_errno = errno;
- free(qp->input);
-mem3: if (qp->name != NULL)
- free(qp->name);
-mem2: FREE(qp, sizeof(SEQ));
-mem1: errno = sv_errno;
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- qp->olen = olen;
-
- /* Type, flags. */
- qp->stype = stype;
- qp->flags = flags;
-
- /* Link into the chain. */
- if (lastqp == NULL) {
- LIST_INSERT_HEAD(&sp->gp->seqq, qp, q);
- } else {
- LIST_INSERT_AFTER(lastqp, qp, q);
- }
-
- /* Set the fast lookup bit. */
- if (qp->input[0] < MAX_BIT_SEQ)
- bit_set(sp->gp->seqb, qp->input[0]);
-
- return (0);
-}
-
-/*
- * seq_delete --
- * Delete a sequence.
- */
-int
-seq_delete(sp, input, ilen, stype)
- SCR *sp;
- CHAR_T *input;
- size_t ilen;
- enum seqtype stype;
-{
- SEQ *qp;
-
- if ((qp = seq_find(sp, NULL, input, ilen, stype, NULL)) == NULL)
- return (1);
- return (seq_mdel(qp));
-}
-
-/*
- * seq_mdel --
- * Delete a map entry, without lookup.
- */
-int
-seq_mdel(qp)
- SEQ *qp;
-{
- LIST_REMOVE(qp, q);
- if (qp->name != NULL)
- free(qp->name);
- free(qp->input);
- if (qp->output != NULL)
- free(qp->output);
- FREE(qp, sizeof(SEQ));
- return (0);
-}
-
-/*
- * seq_find --
- * Search the sequence list for a match to a buffer, if ispartial
- * isn't NULL, partial matches count.
- */
-SEQ *
-seq_find(sp, lastqp, input, ilen, stype, ispartialp)
- SCR *sp;
- SEQ **lastqp;
- CHAR_T *input;
- size_t ilen;
- enum seqtype stype;
- int *ispartialp;
-{
- SEQ *lqp, *qp;
- int diff;
-
- /*
- * Ispartialp is a location where we return if there was a
- * partial match, i.e. if the string were extended it might
- * match something.
- *
- * XXX
- * Overload the meaning of ispartialp; only the terminal key
- * search doesn't want the search limited to complete matches,
- * i.e. ilen may be longer than the match.
- */
- if (ispartialp != NULL)
- *ispartialp = 0;
- for (lqp = NULL, qp = sp->gp->seqq.lh_first;
- qp != NULL; lqp = qp, qp = qp->q.le_next) {
- /* Fast checks on the first character and type. */
- if (qp->input[0] > input[0])
- break;
- if (qp->input[0] < input[0] ||
- qp->stype != stype || F_ISSET(qp, SEQ_FUNCMAP))
- continue;
-
- /* Check on the real comparison. */
- diff = memcmp(qp->input, input, MIN(qp->ilen, ilen));
- if (diff > 0)
- break;
- if (diff < 0)
- continue;
- /*
- * If the entry is the same length as the string, return a
- * match. If the entry is shorter than the string, return a
- * match if called from the terminal key routine. Otherwise,
- * keep searching for a complete match.
- */
- if (qp->ilen <= ilen) {
- if (qp->ilen == ilen || ispartialp != NULL) {
- if (lastqp != NULL)
- *lastqp = lqp;
- return (qp);
- }
- continue;
- }
- /*
- * If the entry longer than the string, return partial match
- * if called from the terminal key routine. Otherwise, no
- * match.
- */
- if (ispartialp != NULL)
- *ispartialp = 1;
- break;
- }
- if (lastqp != NULL)
- *lastqp = lqp;
- return (NULL);
-}
-
-/*
- * seq_dump --
- * Display the sequence entries of a specified type.
- */
-int
-seq_dump(sp, stype, isname)
- SCR *sp;
- enum seqtype stype;
- int isname;
-{
- CHAR_T *p;
- SEQ *qp;
- int cnt, len, olen;
-
- cnt = 0;
- for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) {
- if (stype != qp->stype || F_ISSET(qp, SEQ_FUNCMAP))
- continue;
- ++cnt;
- for (p = qp->input,
- olen = qp->ilen, len = 0; olen > 0; --olen, ++p)
- len += ex_printf(EXCOOKIE, "%s", KEY_NAME(sp, *p));
- for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
- len -= ex_printf(EXCOOKIE, " ");
-
- if (qp->output != NULL)
- for (p = qp->output,
- olen = qp->olen, len = 0; olen > 0; --olen, ++p)
- len +=
- ex_printf(EXCOOKIE, "%s", KEY_NAME(sp, *p));
- else
- len = 0;
-
- if (isname && qp->name != NULL) {
- for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
- len -= ex_printf(EXCOOKIE, " ");
- for (p = qp->name,
- olen = qp->nlen; olen > 0; --olen, ++p)
- (void)ex_printf(EXCOOKIE,
- "%s", KEY_NAME(sp, *p));
- }
- (void)ex_printf(EXCOOKIE, "\n");
- }
- return (cnt);
-}
-
-/*
- * seq_save --
- * Save the sequence entries to a file.
- */
-int
-seq_save(sp, fp, prefix, stype)
- SCR *sp;
- FILE *fp;
- char *prefix;
- enum seqtype stype;
-{
- CHAR_T *p;
- SEQ *qp;
- size_t olen;
- int ch;
-
- /* Write a sequence command for all keys the user defined. */
- for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) {
- if (stype != qp->stype ||
- F_ISSET(qp, SEQ_FUNCMAP) || !F_ISSET(qp, SEQ_USERDEF))
- continue;
- if (prefix)
- (void)fprintf(fp, "%s", prefix);
- for (p = qp->input, olen = qp->ilen; olen > 0; --olen) {
- ch = *p++;
- if (ch == CH_LITERAL || ch == '|' ||
- isblank(ch) || KEY_VAL(sp, ch) == K_NL)
- (void)putc(CH_LITERAL, fp);
- (void)putc(ch, fp);
- }
- (void)putc(' ', fp);
- if (qp->output != NULL)
- for (p = qp->output,
- olen = qp->olen; olen > 0; --olen) {
- ch = *p++;
- if (ch == CH_LITERAL || ch == '|' ||
- KEY_VAL(sp, ch) == K_NL)
- (void)putc(CH_LITERAL, fp);
- (void)putc(ch, fp);
- }
- (void)putc('\n', fp);
- }
- return (0);
-}
diff --git a/usr.bin/vi/common/seq.h b/usr.bin/vi/common/seq.h
deleted file mode 100644
index 8eede33..0000000
--- a/usr.bin/vi/common/seq.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)seq.h 8.12 (Berkeley) 8/16/94
- */
-
-/*
- * Map and abbreviation structures.
- *
- * The map structure is doubly linked list, sorted by input string and by
- * input length within the string. (The latter is necessary so that short
- * matches will happen before long matches when the list is searched.)
- * Additionally, there is a bitmap which has bits set if there are entries
- * starting with the corresponding character. This keeps us from walking
- * the list unless it's necessary.
- *
- * The name and the output fields of a SEQ can be empty, i.e. NULL.
- * Only the input field is required.
- *
- * XXX
- * The fast-lookup bits are never turned off -- users don't usually unmap
- * things, though, so it's probably not a big deal.
- */
- /* Sequence type. */
-enum seqtype { SEQ_ABBREV, SEQ_COMMAND, SEQ_INPUT };
-
-struct _seq {
- LIST_ENTRY(_seq) q; /* Linked list of all sequences. */
- enum seqtype stype; /* Sequence type. */
- CHAR_T *name; /* Sequence name (if any). */
- size_t nlen; /* Name length. */
- CHAR_T *input; /* Sequence input keys. */
- size_t ilen; /* Input keys length. */
- CHAR_T *output; /* Sequence output keys. */
- size_t olen; /* Output keys length. */
-
-#define SEQ_FUNCMAP 0x01 /* If unresolved function key.*/
-#define SEQ_SCREEN 0x02 /* If screen specific. */
-#define SEQ_USERDEF 0x04 /* If user defined. */
- u_int8_t flags;
-};
-
-int seq_delete __P((SCR *, CHAR_T *, size_t, enum seqtype));
-int seq_dump __P((SCR *, enum seqtype, int));
-SEQ *seq_find __P((SCR *, SEQ **, CHAR_T *, size_t, enum seqtype, int *));
-void seq_init __P((SCR *));
-int seq_mdel __P((SEQ *));
-int seq_save __P((SCR *, FILE *, char *, enum seqtype));
-int seq_set __P((SCR *, CHAR_T *, size_t,
- CHAR_T *, size_t, CHAR_T *, size_t, enum seqtype, int));
diff --git a/usr.bin/vi/common/signal.c b/usr.bin/vi/common/signal.c
deleted file mode 100644
index 362c0fb..0000000
--- a/usr.bin/vi/common/signal.c
+++ /dev/null
@@ -1,569 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)signal.c 8.34 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-static void h_alrm __P((int));
-static void h_hup __P((int));
-static void h_int __P((int));
-static void h_term __P((int));
-static void h_winch __P((int));
-static void sig_sync __P((int, u_int));
-
-/*
- * There are seven normally asynchronous actions about which vi cares:
- * SIGALRM, SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGTSTP and SIGWINCH.
- *
- * The assumptions:
- * 1: The DB routines are not reentrant.
- * 2: The curses routines may not be reentrant.
- *
- * SIGALRM, SIGHUP, SIGTERM
- * Used for file recovery. The DB routines can't be reentered, so
- * the vi routines that call DB block all three signals (see line.c).
- * This means that DB routines can be called at interrupt time.
- *
- * SIGALRM
- * Used to paint busy messages on the screen. The curses routines
- * can't be reentered, so this function of SIGALRM can only be used
- * in sections of code that do not use any curses functions (see
- * busy_on, busy_off in signal.c). This means that curses can be
- * called at interrupt time.
- *
- * SIGQUIT
- * Disabled by the signal initialization routines. Historically,
- * ^\ switched vi into ex mode, and we continue that practice.
- *
- * SIGWINCH:
- * The interrupt routine sets a global bit which is checked by the
- * key-read routine, so there are no reentrancy issues. This means
- * that the screen will not resize until vi runs out of keys, but
- * that doesn't seem like a problem.
- *
- * SIGINT and SIGTSTP are a much more difficult issue to resolve. Vi has
- * to permit the user to interrupt long-running operations. Generally, a
- * search, substitution or read/write is done on a large file, or, the user
- * creates a key mapping with an infinite loop. This problem will become
- * worse as more complex semantics are added to vi. There are four major
- * solutions on the table, each of which have minor permutations.
- *
- * 1: Run in raw mode.
- *
- * The up side is that there's no asynchronous behavior to worry about,
- * and obviously no reentrancy problems. The down side is that it's easy
- * to misinterpret characters (e.g. :w big_file^Mi^V^C is going to look
- * like an interrupt) and it's easy to get into places where we won't see
- * interrupt characters (e.g. ":map a ixx^[hxxaXXX" infinitely loops in
- * historic implementations of vi). Periodically reading the terminal
- * input buffer might solve the latter problem, but it's not going to be
- * pretty.
- *
- * Also, we're going to be checking for ^C's and ^Z's both, all over
- * the place -- I hate to litter the source code with that. For example,
- * the historic version of vi didn't permit you to suspend the screen if
- * you were on the colon command line. This isn't right. ^Z isn't a vi
- * command, it's a terminal event. (Dammit.)
- *
- * 2: Run in cbreak mode. There are two problems in this area. First, the
- * current curses implementations (both System V and Berkeley) don't give
- * you clean cbreak modes. For example, the IEXTEN bit is left on, turning
- * on DISCARD and LNEXT. To clarify, what vi WANTS is 8-bit clean, with
- * the exception that flow control and signals are turned on, and curses
- * cbreak mode doesn't give you this.
- *
- * We can either set raw mode and twiddle the tty, or cbreak mode and
- * twiddle the tty. I chose to use raw mode, on the grounds that raw
- * mode is better defined and I'm less likely to be surprised by a curses
- * implementation down the road. The twiddling consists of setting ISIG,
- * IXON/IXOFF, and disabling some of the interrupt characters (see the
- * comments in svi/svi_screen.c). This is all found in historic System
- * V (SVID 3) and POSIX 1003.1-1992, so it should be fairly portable.
- *
- * The second problem is that vi permits you to enter literal signal
- * characters, e.g. ^V^C. There are two possible solutions. First, you
- * can turn off signals when you get a ^V, but that means that a network
- * packet containing ^V and ^C will lose, since the ^C may take effect
- * before vi reads the ^V. (This is particularly problematic if you're
- * talking over a protocol that recognizes signals locally and sends OOB
- * packets when it sees them.) Second, you can turn the ^C into a literal
- * character in vi, but that means that there's a race between entering
- * ^V<character>^C, i.e. the sequence may end up being ^V^C<character>.
- * Also, the second solution doesn't work for flow control characters, as
- * they aren't delivered to the program as signals.
- *
- * Generally, this is what historic vi did. (It didn't have the curses
- * problems because it didn't use curses.) It entered signals following
- * ^V characters into the input stream, (which is why there's no way to
- * enter a literal flow control character).
- *
- * 3: Run in mostly raw mode; turn signals on when doing an operation the
- * user might want to interrupt, but leave them off most of the time.
- *
- * This works well for things like file reads and writes. This doesn't
- * work well for trying to detect infinite maps. The problem is that
- * you can write the code so that you don't have to turn on interrupts
- * per keystroke, but the code isn't pretty and it's hard to make sure
- * that an optimization doesn't cover up an infinite loop. This also
- * requires interaction or state between the vi parser and the key
- * reading routines, as an infinite loop may still be returning keys
- * to the parser.
- *
- * Also, if the user inserts an interrupt into the tty queue while the
- * interrupts are turned off, the key won't be treated as an interrupt,
- * and requiring the user to pound the keyboard to catch an interrupt
- * window is nasty.
- *
- * 4: Run in mostly raw mode, leaving signals on all of the time. Done
- * by setting raw mode, and twiddling the tty's termios ISIG bit.
- *
- * This works well for the interrupt cases, because the code only has
- * to check to see if the interrupt flag has been set, and can otherwise
- * ignore signals. It's also less likely that we'll miss a case, and we
- * don't have to worry about synchronizing between the vi parser and the
- * key read routines.
- *
- * The down side is that we have to turn signals off if the user wants
- * to enter a literal character (e.g. ^V^C). If the user enters the
- * combination fast enough, or as part of a single network packet,
- * the text input routines will treat it as a signal instead of as a
- * literal character. To some extent, we have this problem already,
- * since we turn off flow control so that the user can enter literal
- * XON/XOFF characters.
- *
- * This is probably the easiest to code, and provides the smoothest
- * programming interface.
- *
- * There are a couple of other problems to consider.
- *
- * First, System V's curses doesn't handle SIGTSTP correctly. If you use the
- * newterm() interface, the TSTP signal will leave you in raw mode, and the
- * final endwin() will leave you in the correct shell mode. If you use the
- * initscr() interface, the TSTP signal will return you to the correct shell
- * mode, but the final endwin() will leave you in raw mode. There you have
- * it: proof that drug testing is not making any significant headway in the
- * computer industry. The 4BSD curses is deficient in that it does not have
- * an interface to the terminal keypad. So, regardless, we have to do our
- * own SIGTSTP handling.
- *
- * The problem with this is that if we do our own SIGTSTP handling, in either
- * models #3 or #4, we're going to have to call curses routines at interrupt
- * time, which means that we might be reentering curses, which is something we
- * don't want to do.
- *
- * Second, SIGTSTP has its own little problems. It's broadcast to the entire
- * process group, not sent to a single process. The scenario goes something
- * like this: the shell execs the mail program, which execs vi. The user hits
- * ^Z, and all three programs get the signal, in some random order. The mail
- * program goes to sleep immediately (since it probably didn't have a SIGTSTP
- * handler in place). The shell gets a SIGCHLD, does a wait, and finds out
- * that the only child in its foreground process group (of which it's aware)
- * is asleep. It then optionally resets the terminal (because the modes aren't
- * how it left them), and starts prompting the user for input. The problem is
- * that somewhere in the middle of all of this, vi is resetting the terminal,
- * and getting ready to send a SIGTSTP to the process group in order to put
- * itself to sleep. There's a solution to all of this: when vi starts, it puts
- * itself into its own process group, and then only it (and possible child
- * processes) receive the SIGTSTP. This permits it to clean up the terminal
- * and switch back to the original process group, where it sends that process
- * group a SIGTSTP, putting everyone to sleep and waking the shell.
- *
- * Third, handing SIGTSTP asynchronously is further complicated by the child
- * processes vi may fork off. If vi calls ex, ex resets the terminal and
- * starts running some filter, and SIGTSTP stops them both, vi has to know
- * when it restarts that it can't repaint the screen until ex's child has
- * finished running. This is solveable, but it's annoying.
- *
- * Well, somebody had to make a decision, and this is the way it's going to be
- * (unless I get talked out of it). SIGINT is handled asynchronously, so
- * that we can pretty much guarantee that the user can interrupt any operation
- * at any time. SIGTSTP is handled synchronously, so that we don't have to
- * reenter curses and so that we don't have to play the process group games.
- * ^Z is recognized in the standard text input and command modes. (^Z should
- * also be recognized during operations that may potentially take a long time.
- * The simplest solution is probably to twiddle the tty, install a handler for
- * SIGTSTP, and then restore normal tty modes when the operation is complete.)
- */
-
-/*
- * sig_init --
- * Initialize signals.
- */
-int
-sig_init(sp)
- SCR *sp;
-{
- GS *gp;
- struct sigaction act;
-
- /* Initialize the signals. */
- gp = sp->gp;
- (void)sigemptyset(&gp->blockset);
-
- /*
- * Use sigaction(2), not signal(3), since we don't always want to
- * restart system calls. The example is when waiting for a command
- * mode keystroke and SIGWINCH arrives. Try to set the restart bit
- * (SA_RESTART) on SIGALRM anyway, it should result in a lot fewer
- * interruptions. We also block every other signal that we can block
- * when a signal arrives. This is because the signal functions call
- * other nvi functions, which aren't guaranteed to be reentrant.
- */
-
-#ifndef SA_RESTART
-#define SA_RESTART 0
-#endif
-#define SETSIG(signal, flags, handler) { \
- if (sigaddset(&gp->blockset, signal)) \
- goto err; \
- act.sa_handler = handler; \
- sigfillset(&act.sa_mask); \
- act.sa_flags = flags; \
- if (sigaction(signal, &act, NULL)) \
- goto err; \
-}
- SETSIG(SIGALRM, SA_RESTART, h_alrm);
- SETSIG(SIGHUP, 0, h_hup);
- SETSIG(SIGINT, 0, h_int);
- SETSIG(SIGTERM, 0, h_term);
- SETSIG(SIGWINCH, 0, h_winch);
- return (0);
-
-err: msgq(sp, M_SYSERR, "signal init");
- return (1);
-}
-
-/*
- * sig_end --
- * End signal setup.
- */
-void
-sig_end()
-{
- /*
- * POSIX 1003.1-1990 requires that fork (and, presumably, vfork) clear
- * pending alarms, and that the exec functions clear pending signals.
- * In addition, after an exec, the child continues to ignore signals
- * ignored in the parent, and the child's action for signals caught in
- * the parent is set to the default action. So, as we currently don't
- * ignore any signals, there's no cleanup to be done. This routine is
- * left here as a stub function.
- */
- return;
-}
-
-/*
- * busy_on --
- * Set a busy message timer.
- */
-int
-busy_on(sp, msg)
- SCR *sp;
- char const *msg;
-{
- struct itimerval value;
- struct timeval tod;
-
- /*
- * Give the oldest busy message precedence, since it's
- * the longer running operation.
- */
- if (sp->busy_msg != NULL)
- return (1);
-
- /* Get the current time of day, and create a target time. */
- if (gettimeofday(&tod, NULL))
- return (1);
-#define USER_PATIENCE_USECS (8 * 100000L)
- sp->busy_tod.tv_sec = tod.tv_sec;
- sp->busy_tod.tv_usec = tod.tv_usec + USER_PATIENCE_USECS;
-
- /* We depend on this being an atomic instruction. */
- sp->busy_msg = msg;
-
- /*
- * Busy messages turn around fast. Reset the timer regardless
- * of its current state.
- */
- value.it_value.tv_sec = 0;
- value.it_value.tv_usec = USER_PATIENCE_USECS;
- value.it_interval.tv_sec = 0;
- value.it_interval.tv_usec = 0;
- if (setitimer(ITIMER_REAL, &value, NULL))
- msgq(sp, M_SYSERR, "timer: setitimer");
- return (0);
-}
-
-/*
- * busy_off --
- * Turn off a busy message timer.
- */
-void
-busy_off(sp)
- SCR *sp;
-{
- /* We depend on this being an atomic instruction. */
- sp->busy_msg = NULL;
-}
-
-/*
- * rcv_on --
- * Turn on recovery timer.
- */
-int
-rcv_on(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- struct itimerval value;
- struct timeval tod;
-
- /* Get the current time of day. */
- if (gettimeofday(&tod, NULL))
- return (1);
-
- /* Create target time of day. */
- ep->rcv_tod.tv_sec = tod.tv_sec + RCV_PERIOD;
- ep->rcv_tod.tv_usec = 0;
-
- /*
- * If there's a busy message happening, we're done, the
- * interrupt handler will start our timer as necessary.
- */
- if (sp->busy_msg != NULL)
- return (0);
-
- value.it_value.tv_sec = RCV_PERIOD;
- value.it_value.tv_usec = 0;
- value.it_interval.tv_sec = 0;
- value.it_interval.tv_usec = 0;
- if (setitimer(ITIMER_REAL, &value, NULL)) {
- msgq(sp, M_SYSERR, "timer: setitimer");
- return (1);
- }
- return (0);
-}
-
-/*
- * h_alrm --
- * Handle SIGALRM.
- *
- * There are two uses of the ITIMER_REAL timer (SIGALRM) in nvi. The first
- * is to push the recovery information out to disk at periodic intervals.
- * The second is to display a "busy" message if an operation takes more time
- * that users are willing to wait before seeing something happen. The SCR
- * structure has a wall clock timer structure for each of these. Since the
- * busy timer has a much faster timeout than the recovery timer, most of the
- * code ignores the recovery timer unless it's the only thing running.
- *
- * XXX
- * It would be nice to reimplement this with two timers, a la POSIX 1003.1,
- * but not many systems offer them yet.
- */
-static void
-h_alrm(signo)
- int signo;
-{
- struct itimerval value;
- struct timeval ntod, tod;
- SCR *sp;
- EXF *ep;
- int sverrno;
-
- sverrno = errno;
-
- /* XXX: Get the current time of day; if this fails, we're dead. */
- if (gettimeofday(&tod, NULL))
- goto ret;
-
- /*
- * Fire any timers that are past due, or any that are due
- * in a tenth of a second or less.
- */
- for (ntod.tv_sec = 0, sp = __global_list->dq.cqh_first;
- sp != (void *)&__global_list->dq; sp = sp->q.cqe_next) {
-
- /* Check the busy timer if the msg pointer is set. */
- if (sp->busy_msg == NULL)
- goto skip_busy;
- if (sp->busy_tod.tv_sec > tod.tv_sec ||
- sp->busy_tod.tv_sec == tod.tv_sec &&
- sp->busy_tod.tv_usec > tod.tv_usec &&
- sp->busy_tod.tv_usec - tod.tv_usec > 100000L) {
- if (ntod.tv_sec == 0 ||
- ntod.tv_sec > sp->busy_tod.tv_sec ||
- ntod.tv_sec == sp->busy_tod.tv_sec &&
- ntod.tv_usec > sp->busy_tod.tv_usec)
- ntod = sp->busy_tod;
- } else {
- (void)sp->s_busy(sp, sp->busy_msg);
- sp->busy_msg = NULL;
- }
-
- /*
- * Sync the file if the recovery timer has fired. If
- * the sync fails, we don't reschedule future sync's.
- */
-skip_busy: ep = sp->ep;
- if (ep->rcv_tod.tv_sec < tod.tv_sec ||
- ep->rcv_tod.tv_sec == tod.tv_sec &&
- ep->rcv_tod.tv_usec < tod.tv_usec + 100000L) {
- if (rcv_sync(sp, ep, 0))
- continue;
- ep->rcv_tod = tod;
- ep->rcv_tod.tv_sec += RCV_PERIOD;
- }
- if (ntod.tv_sec == 0 ||
- ntod.tv_sec > ep->rcv_tod.tv_sec ||
- ntod.tv_sec == ep->rcv_tod.tv_sec &&
- ntod.tv_usec > ep->rcv_tod.tv_usec)
- ntod = ep->rcv_tod;
- }
-
- if (ntod.tv_sec == 0)
- goto ret;
-
- /* XXX: Set the timer; if this fails, we're dead. */
- value.it_value.tv_sec = ntod.tv_sec - tod.tv_sec;
- value.it_value.tv_usec = ntod.tv_usec - tod.tv_usec;
- value.it_interval.tv_sec = 0;
- value.it_interval.tv_usec = 0;
- (void)setitimer(ITIMER_REAL, &value, NULL);
-
-ret: errno = sverrno;
-}
-
-/*
- * h_hup --
- * Handle SIGHUP.
- */
-static void
-h_hup(signo)
- int signo;
-{
- sig_sync(SIGHUP, RCV_EMAIL);
- /* NOTREACHED */
-}
-
-/*
- * h_int --
- * Handle SIGINT.
- *
- * XXX
- * This isn't right if windows are independent of each other.
- */
-static void
-h_int(signo)
- int signo;
-{
- F_SET(__global_list, G_SIGINT);
-}
-
-/*
- * h_term --
- * Handle SIGTERM.
- */
-static void
-h_term(signo)
- int signo;
-{
- sig_sync(SIGTERM, 0);
- /* NOTREACHED */
-}
-
-/*
- * h_winch --
- * Handle SIGWINCH.
- *
- * XXX
- * This isn't right if windows are independent of each other.
- */
-static void
-h_winch(signo)
- int signo;
-{
- F_SET(__global_list, G_SIGWINCH);
-}
-
-
-/*
- * sig_sync --
- *
- * Sync the files based on a signal.
- */
-static void
-sig_sync(signo, flags)
- int signo;
- u_int flags;
-{
- SCR *sp;
-
- /*
- * Walk the lists of screens, sync'ing the files; only sync
- * each file once.
- */
- for (sp = __global_list->dq.cqh_first;
- sp != (void *)&__global_list->dq; sp = sp->q.cqe_next)
- rcv_sync(sp, sp->ep, RCV_ENDSESSION | RCV_PRESERVE | flags);
- for (sp = __global_list->hq.cqh_first;
- sp != (void *)&__global_list->hq; sp = sp->q.cqe_next)
- rcv_sync(sp, sp->ep, RCV_ENDSESSION | RCV_PRESERVE | flags);
-
- /*
- * Die with the proper exit status. Don't bother using
- * sigaction(2) 'cause we want the default behavior.
- */
- (void)signal(signo, SIG_DFL);
- (void)kill(getpid(), signo);
- /* NOTREACHED */
-
- exit (1);
-}
diff --git a/usr.bin/vi/common/term.c b/usr.bin/vi/common/term.c
deleted file mode 100644
index 463b8f7..0000000
--- a/usr.bin/vi/common/term.c
+++ /dev/null
@@ -1,732 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)term.c 8.81 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <locale.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-/*
- * XXX
- * DON'T INCLUDE <curses.h> HERE, IT BREAKS OSF1 V2.0 WHERE IT
- * CHANGES THE VALUES OF VERASE/VKILL/VWERASE TO INCORRECT ONES.
- */
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-static int keycmp __P((const void *, const void *));
-static enum input term_key_queue __P((SCR *));
-static void term_key_set __P((GS *, int, int));
-
-/*
- * If we're reading less than 20 characters, up the size of the tty buffer.
- * This shouldn't ever happen, other than the first time through, but it's
- * possible if a map is large enough.
- */
-#define term_read_grow(sp, tty) \
- (tty)->nelem - ((tty)->cnt + (tty)->next) >= 20 ? \
- 0 : __term_read_grow(sp, tty, 64)
-static int __term_read_grow __P((SCR *, IBUF *, int));
-
-/*
- * !!!
- * Historic vi always used:
- *
- * ^D: autoindent deletion
- * ^H: last character deletion
- * ^W: last word deletion
- * ^Q: quote the next character (if not used in flow control).
- * ^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. Nvi wires
- * down the above characters, but in addition permits the VEOF, VERASE, VKILL
- * and VWERASE characters described by the user's termios structure.
- *
- * Ex was not consistent with this scheme, as it historically ran in tty
- * cooked mode. This meant that the scroll command and autoindent erase
- * characters were mapped to the user's EOF character, and the character
- * and word deletion characters were the user's tty character and word
- * deletion characters. This implementation makes it all consistent, as
- * described above for vi.
- *
- * XXX
- * THIS REQUIRES THAT ALL SCREENS SHARE A SPECIAL KEY SET.
- */
-KEYLIST keylist[] = {
- {K_CARAT, '^'}, /* ^ */
- {K_CNTRLD, '\004'}, /* ^D */
- {K_CNTRLR, '\022'}, /* ^R */
- {K_CNTRLT, '\024'}, /* ^T */
- {K_CNTRLZ, '\032'}, /* ^Z */
- {K_COLON, ':'}, /* : */
- {K_CR, '\r'}, /* \r */
- {K_ESCAPE, '\033'}, /* ^[ */
- {K_FORMFEED, '\f'}, /* \f */
- {K_HEXCHAR, '\030'}, /* ^X */
- {K_NL, '\n'}, /* \n */
- {K_RIGHTBRACE, '}'}, /* } */
- {K_RIGHTPAREN, ')'}, /* ) */
- {K_TAB, '\t'}, /* \t */
- {K_VERASE, '\b'}, /* \b */
- {K_VKILL, '\025'}, /* ^U */
- {K_VLNEXT, '\021'}, /* ^Q */
- {K_VLNEXT, '\026'}, /* ^V */
- {K_VWERASE, '\027'}, /* ^W */
- {K_ZERO, '0'}, /* 0 */
- {K_NOTUSED, 0}, /* VEOF, VERASE, VKILL, VWERASE */
- {K_NOTUSED, 0},
- {K_NOTUSED, 0},
- {K_NOTUSED, 0},
-};
-static int nkeylist = (sizeof(keylist) / sizeof(keylist[0])) - 4;
-
-/*
- * term_init --
- * Initialize the special key lookup table.
- */
-int
-term_init(sp)
- SCR *sp;
-{
- GS *gp;
- KEYLIST *kp;
- int cnt;
-
- /*
- * XXX
- * 8-bit only, for now. Recompilation should get you any
- * 8-bit character set, as long as nul isn't a character.
- */
- (void)setlocale(LC_ALL, "");
- key_init(sp);
-
- gp = sp->gp;
-#ifdef VEOF
- term_key_set(gp, VEOF, K_CNTRLD);
-#endif
-#ifdef VERASE
- term_key_set(gp, VERASE, K_VERASE);
-#endif
-#ifdef VKILL
- term_key_set(gp, VKILL, K_VKILL);
-#endif
-#ifdef VWERASE
- term_key_set(gp, VWERASE, K_VWERASE);
-#endif
-
- /* Sort the special key list. */
- qsort(keylist, nkeylist, sizeof(keylist[0]), keycmp);
-
- /* Initialize the fast lookup table. */
- for (gp->max_special = 0, kp = keylist, cnt = nkeylist; cnt--; ++kp) {
- if (gp->max_special < kp->value)
- gp->max_special = kp->value;
- if (kp->ch <= MAX_FAST_KEY)
- gp->special_key[kp->ch] = kp->value;
- }
- return (0);
-}
-
-/*
- * term_key_set --
- * Set keys found in the termios structure. VERASE and VKILL are required
- * by POSIX 1003.1-1990, VWERASE is a 4.4BSD extension. We've left three
- * open slots in the keylist table, if these values exist, put them into
- * place. Note, they may reset (or duplicate) values already in the table,
- * so we check for that first.
- */
-static void
-term_key_set(gp, name, val)
- GS *gp;
- int name, val;
-{
- KEYLIST *kp;
- cc_t ch;
-
- if (!F_ISSET(gp, G_TERMIOS_SET))
- return;
- if ((ch = gp->original_termios.c_cc[name]) == _POSIX_VDISABLE)
- return;
-
- /* Check for duplication. */
- for (kp = keylist; kp->value != K_NOTUSED; ++kp)
- if (kp->ch == ch) {
- kp->value = val;
- return;
- }
- /* Add a new entry. */
- if (kp->value == K_NOTUSED) {
- keylist[nkeylist].ch = ch;
- keylist[nkeylist].value = val;
- ++nkeylist;
- }
-}
-
-/*
- * key_init --
- * Build the fast-lookup key display array.
- */
-void
-key_init(sp)
- SCR *sp;
-{
- CHAR_T ch;
-
- for (ch = 0; ch <= MAX_FAST_KEY; ++ch) {
- (void)__key_name(sp, ch);
- (void)memmove(sp->gp->cname[ch].name, sp->cname, sp->clen);
- sp->gp->cname[ch].len = sp->clen;
- }
-}
-
-/*
- * __key_len --
- * Return the length of the string that will display the key.
- * This routine is the backup for the KEY_LEN() macro.
- */
-size_t
-__key_len(sp, ch)
- SCR *sp;
- ARG_CHAR_T ch;
-{
- (void)__key_name(sp, ch);
- return (sp->clen);
-}
-
-/*
- * __key_name --
- * Return the string that will display the key. This routine
- * is the backup for the KEY_NAME() macro.
- */
-CHAR_T *
-__key_name(sp, ach)
- SCR *sp;
- ARG_CHAR_T ach;
-{
- static const CHAR_T hexdigit[] = "0123456789abcdef";
- static const CHAR_T octdigit[] = "01234567";
- CHAR_T ch, *chp, mask;
- size_t len;
- int cnt, shift;
-
- /*
- * Historical (ARPA standard) mappings. Printable characters are left
- * alone. Control characters less than '\177' are represented as '^'
- * followed by the character offset from the '@' character in the ASCII
- * map. '\177' is represented as '^' followed by '?'.
- *
- * XXX
- * The following code depends on the current locale being identical to
- * the ASCII map from '\100' to '\076' (\076 since that's the largest
- * character for which we can offset from '@' and get something that's
- * a printable character in ASCII. I'm told that this is a reasonable
- * assumption...
- *
- * XXX
- * This code will only work with CHAR_T's that are multiples of 8-bit
- * bytes.
- *
- * XXX
- * NB: There's an assumption here that all printable characters take
- * up a single column on the screen. This is not always correct.
- */
- ch = ach;
- if (isprint(ch)) {
- sp->cname[0] = ch;
- len = 1;
- } else if (ch <= '\076' && iscntrl(ch)) {
- sp->cname[0] = '^';
- sp->cname[1] = ch == '\177' ? '?' : '@' + ch;
- len = 2;
- } else if (O_ISSET(sp, O_OCTAL)) {
-#define BITS (sizeof(CHAR_T) * 8)
-#define SHIFT (BITS - BITS % 3)
-#define TOPMASK (BITS % 3 == 2 ? 3 : 1) << (BITS - BITS % 3)
- sp->cname[0] = '\\';
- sp->cname[1] = octdigit[(ch & TOPMASK) >> SHIFT];
- shift = SHIFT - 3;
- for (len = 2, mask = 7 << (SHIFT - 3),
- cnt = BITS / 3; cnt-- > 0; mask >>= 3, shift -= 3)
- sp->cname[len++] = octdigit[(ch & mask) >> shift];
- } else {
- sp->cname[0] = '0';
- sp->cname[1] = 'x';
- for (len = 2, chp = (u_int8_t *)&ch,
- cnt = sizeof(CHAR_T); cnt-- > 0; ++chp) {
- sp->cname[len++] = hexdigit[(*chp & 0xf0) >> 4];
- sp->cname[len++] = hexdigit[*chp & 0x0f];
- }
- }
- sp->cname[sp->clen = len] = '\0';
- return (sp->cname);
-}
-
-/*
- * term_push --
- * Push keys onto the front of a buffer.
- *
- * There is a single input buffer in ex/vi. Characters are read onto the
- * end of the buffer by the terminal input routines, and pushed onto the
- * front of the buffer by various other functions in ex/vi. Each key has
- * an associated flag value, which indicates if it has already been quoted,
- * if it is the result of a mapping or an abbreviation, as well as a count
- * of the number of times it has been mapped.
- */
-int
-term_push(sp, s, nchars, flags)
- SCR *sp;
- CHAR_T *s; /* Characters. */
- size_t nchars; /* Number of chars. */
- u_int flags; /* CH_* flags. */
-{
- IBUF *tty;
- size_t total;
-
- /* If we have room, stuff the keys into the buffer. */
- tty = sp->gp->tty;
- if (nchars <= tty->next ||
- (tty->ch != NULL && tty->cnt == 0 && nchars <= tty->nelem)) {
- if (tty->cnt != 0)
- tty->next -= nchars;
- tty->cnt += nchars;
- MEMMOVE(tty->ch + tty->next, s, nchars);
- MEMSET(tty->chf + tty->next, flags, nchars);
- return (0);
- }
-
- /*
- * If there are currently characters in the queue, shift them up,
- * leaving some extra room. Get enough space plus a little extra.
- */
-#define TERM_PUSH_SHIFT 30
- total = tty->cnt + tty->next + nchars + TERM_PUSH_SHIFT;
- if (total >= tty->nelem && __term_read_grow(sp, tty, MAX(total, 64)))
- return (1);
- if (tty->cnt) {
- MEMMOVE(tty->ch + TERM_PUSH_SHIFT + nchars,
- tty->ch + tty->next, tty->cnt);
- MEMMOVE(tty->chf + TERM_PUSH_SHIFT + nchars,
- tty->chf + tty->next, tty->cnt);
- }
-
- /* Put the new characters into the queue. */
- tty->next = TERM_PUSH_SHIFT;
- tty->cnt += nchars;
- MEMMOVE(tty->ch + TERM_PUSH_SHIFT, s, nchars);
- MEMSET(tty->chf + TERM_PUSH_SHIFT, flags, nchars);
- return (0);
-}
-
-/*
- * Remove characters from the queue, simultaneously clearing the flag
- * and map counts.
- */
-#define QREM_HEAD(q, len) { \
- size_t __off = (q)->next; \
- if (len == 1) \
- tty->chf[__off] = 0; \
- else \
- MEMSET(tty->chf + __off, 0, len); \
- if (((q)->cnt -= len) == 0) \
- (q)->next = 0; \
- else \
- (q)->next += len; \
-}
-#define QREM_TAIL(q, len) { \
- size_t __off = (q)->next + (q)->cnt - 1; \
- if (len == 1) \
- tty->chf[__off] = 0; \
- else \
- MEMSET(tty->chf + __off, 0, len); \
- if (((q)->cnt -= len) == 0) \
- (q)->next = 0; \
-}
-
-/*
- * term_key --
- * Get the next key.
- *
- * !!!
- * The flag TXT_MAPNODIGIT probably needs some explanation. First, the idea
- * of mapping keys is that one or more keystrokes act like a function key.
- * What's going on is that vi is reading a number, and the character following
- * the number may or may not be mapped (TXT_MAPCOMMAND). For example, if the
- * user is entering the z command, a valid command is "z40+", and we don't want
- * to map the '+', i.e. if '+' is mapped to "xxx", we don't want to change it
- * into "z40xxx". However, if the user enters "35x", we want to put all of the
- * characters through the mapping code.
- *
- * Historical practice is a bit muddled here. (Surprise!) It always permitted
- * mapping digits as long as they weren't the first character of the map, e.g.
- * ":map ^A1 xxx" was okay. It also permitted the mapping of the digits 1-9
- * (the digit 0 was a special case as it doesn't indicate the start of a count)
- * as the first character of the map, but then ignored those mappings. While
- * it's probably stupid to map digits, vi isn't your mother.
- *
- * The way this works is that the TXT_MAPNODIGIT causes term_key to return the
- * end-of-digit without "looking" at the next character, i.e. leaving it as the
- * user entered it. Presumably, the next term_key call will tell us how the
- * user wants it handled.
- *
- * There is one more complication. Users might map keys to digits, and, as
- * it's described above, the commands "map g 1G|d2g" would return the keys
- * "d2<end-of-digits>1G", when the user probably wanted "d21<end-of-digits>G".
- * So, if a map starts off with a digit we continue as before, otherwise, we
- * pretend that we haven't mapped the character and return <end-of-digits>.
- *
- * Now that that's out of the way, let's talk about Energizer Bunny macros.
- * It's easy to create macros that expand to a loop, e.g. map x 3x. It's
- * fairly easy to detect this example, because it's all internal to term_key.
- * If we're expanding a macro and it gets big enough, at some point we can
- * assume it's looping and kill it. The examples that are tough are the ones
- * where the parser is involved, e.g. map x "ayyx"byy. We do an expansion
- * on 'x', and get "ayyx"byy. We then return the first 4 characters, and then
- * find the looping macro again. There is no way that we can detect this
- * without doing a full parse of the command, because the character that might
- * cause the loop (in this case 'x') may be a literal character, e.g. the map
- * map x "ayy"xyy"byy is perfectly legal and won't cause a loop.
- *
- * Historic vi tried to detect looping macros by disallowing obvious cases in
- * the map command, maps that that ended with the same letter as they started
- * (which wrongly disallowed "map x 'x"), and detecting macros that expanded
- * too many times before keys were returned to the command parser. It didn't
- * get many (most?) of the tricky cases right, however, and it was certainly
- * possible to create macros that ran forever. And, even if it did figure out
- * what was going on, the user was usually tossed into ex mode. Finally, any
- * changes made before vi realized that the macro was recursing were left in
- * place. We recover gracefully, but the only recourse the user has in an
- * infinite macro loop is to interrupt.
- *
- * !!!
- * It is historic practice that mapping characters to themselves as the first
- * part of the mapped string was legal, and did not cause infinite loops, i.e.
- * ":map! { {^M^T" and ":map n nz." were known to work. The initial, matching
- * characters were returned instead of being remapped.
- *
- * XXX
- * The final issue is recovery. It would be possible to undo all of the work
- * that was done by the macro if we entered a record into the log so that we
- * knew when the macro started, and, in fact, this might be worth doing at some
- * point. Given that this might make the log grow unacceptably (consider that
- * cursor keys are done with maps), for now we leave any changes made in place.
- */
-enum input
-term_key(sp, chp, flags)
- SCR *sp;
- CH *chp;
- u_int flags;
-{
- enum input rval;
- struct timeval t, *tp;
- CHAR_T ch;
- GS *gp;
- IBUF *tty;
- SEQ *qp;
- int init_nomap, ispartial, nr;
-
- /* If we've been interrupted, return an error. */
- if (INTERRUPTED(sp))
- return (INP_INTR);
-
- gp = sp->gp;
- tty = gp->tty;
-
- /*
- * If the queue is empty, read more keys in. Since no timeout is
- * requested, s_key_read will either return an error or will read
- * some number of characters.
- */
-loop: if (tty->cnt == 0) {
- if (term_read_grow(sp, tty))
- return (INP_ERR);
- if ((rval = sp->s_key_read(sp, &nr, NULL)) != INP_OK)
- return (rval);
- /*
- * If there's something on the mode line that we wanted
- * the user to see, they just entered a character so we
- * can presume they saw it.
- */
- if (F_ISSET(sp, S_UPDATE_MODE))
- F_CLR(sp, S_UPDATE_MODE);
- }
-
- /* If the key is mappable and should be mapped, look it up. */
- if (!(tty->chf[tty->next] & CH_NOMAP) &&
- LF_ISSET(TXT_MAPCOMMAND | TXT_MAPINPUT)) {
- /* Set up timeout value. */
- if (O_ISSET(sp, O_TIMEOUT)) {
- tp = &t;
- t.tv_sec = O_VAL(sp, O_KEYTIME) / 10;
- t.tv_usec = (O_VAL(sp, O_KEYTIME) % 10) * 100000L;
- } else
- tp = NULL;
-
- /* Get the next key. */
-newmap: ch = tty->ch[tty->next];
- if (ch < MAX_BIT_SEQ && !bit_test(gp->seqb, ch))
- goto nomap;
-
- /* Search the map. */
-remap: qp = seq_find(sp, NULL, &tty->ch[tty->next], tty->cnt,
- LF_ISSET(TXT_MAPCOMMAND) ? SEQ_COMMAND : SEQ_INPUT,
- &ispartial);
-
- /* If we've been interrupted, return an error. */
- if (INTERRUPTED(sp))
- return (INP_INTR);
-
- /*
- * If get a partial match, read more characters and retry
- * the map. If no characters read, return the characters
- * unmapped.
- */
- if (ispartial) {
- if (term_read_grow(sp, tty))
- return (INP_ERR);
- if ((rval = sp->s_key_read(sp, &nr, tp)) != INP_OK)
- return (rval);
- if (nr)
- goto remap;
- goto nomap;
- }
-
- /* If no map, return the character. */
- if (qp == NULL)
- goto nomap;
-
- /*
- * If looking for the end of a digit string, and the first
- * character of the map is it, pretend we haven't seen the
- * character.
- */
- if (LF_ISSET(TXT_MAPNODIGIT) &&
- qp->output != NULL && !isdigit(qp->output[0]))
- goto not_digit_ch;
-
- /* Find out if the initial segments are identical. */
- init_nomap = !memcmp(&tty->ch[tty->next], qp->output, qp->ilen);
-
- /* Delete the mapped characters from the queue. */
- QREM_HEAD(tty, qp->ilen);
-
- /* If keys mapped to nothing, go get more. */
- if (qp->output == NULL)
- goto loop;
-
- /* If remapping characters, push the character on the queue. */
- if (O_ISSET(sp, O_REMAP)) {
- if (init_nomap) {
- if (term_push(sp, qp->output + qp->ilen,
- qp->olen - qp->ilen, CH_MAPPED))
- return (INP_ERR);
- if (term_push(sp,
- qp->output, qp->ilen, CH_NOMAP | CH_MAPPED))
- return (INP_ERR);
- goto nomap;
- } else
- if (term_push(sp,
- qp->output, qp->olen, CH_MAPPED))
- return (INP_ERR);
- goto newmap;
- }
-
- /* Else, push the characters on the queue and return one. */
- if (term_push(sp, qp->output, qp->olen, CH_MAPPED | CH_NOMAP))
- return (INP_ERR);
- }
-
-nomap: ch = tty->ch[tty->next];
- if (LF_ISSET(TXT_MAPNODIGIT) && !isdigit(ch)) {
-not_digit_ch: chp->ch = CH_NOT_DIGIT;
- chp->value = 0;
- chp->flags = 0;
- return (INP_OK);
- }
-
- /* Fill in the return information. */
- chp->ch = ch;
- chp->flags = tty->chf[tty->next];
- chp->value = KEY_VAL(sp, ch);
-
- /* Delete the character from the queue. */
- QREM_HEAD(tty, 1);
- return (INP_OK);
-}
-
-/*
- * term_flush --
- * Flush any flagged keys.
- */
-void
-term_flush(sp, msg, flags)
- SCR *sp;
- char *msg;
- u_int flags;
-{
- IBUF *tty;
-
- tty = sp->gp->tty;
- if (!tty->cnt || !(tty->chf[tty->next] & flags))
- return;
- do {
- QREM_HEAD(tty, 1);
- } while (tty->cnt && tty->chf[tty->next] & flags);
- msgq(sp, M_ERR, "%s: keys flushed", msg);
-}
-
-/*
- * term_user_key --
- * Get the next key, but require the user enter one.
- */
-enum input
-term_user_key(sp, chp)
- SCR *sp;
- CH *chp;
-{
- enum input rval;
- IBUF *tty;
- int nr;
-
- /*
- * Read any keys the user has waiting. Make the race
- * condition as short as possible.
- */
- if ((rval = term_key_queue(sp)) != INP_OK)
- return (rval);
-
- /* Wait and read another key. */
- if ((rval = sp->s_key_read(sp, &nr, NULL)) != INP_OK)
- return (rval);
-
- /* Fill in the return information. */
- tty = sp->gp->tty;
- chp->ch = tty->ch[tty->next + (tty->cnt - 1)];
- chp->flags = 0;
- chp->value = KEY_VAL(sp, chp->ch);
-
- QREM_TAIL(tty, 1);
- return (INP_OK);
-}
-
-/*
- * term_key_queue --
- * Read the keys off of the terminal queue until it's empty.
- */
-static enum input
-term_key_queue(sp)
- SCR *sp;
-{
- enum input rval;
- struct timeval t;
- IBUF *tty;
- int nr;
-
- t.tv_sec = 0;
- t.tv_usec = 0;
- for (tty = sp->gp->tty;;) {
- if (term_read_grow(sp, tty))
- return (INP_ERR);
- if ((rval = sp->s_key_read(sp, &nr, &t)) != INP_OK)
- return (rval);
- if (nr == 0)
- break;
- }
- return (INP_OK);
-}
-
-/*
- * __key_val --
- * Fill in the value for a key. This routine is the backup
- * for the KEY_VAL() macro.
- */
-int
-__key_val(sp, ch)
- SCR *sp;
- ARG_CHAR_T ch;
-{
- KEYLIST k, *kp;
-
- k.ch = ch;
- kp = bsearch(&k, keylist, nkeylist, sizeof(keylist[0]), keycmp);
- return (kp == NULL ? K_NOTUSED : kp->value);
-}
-
-/*
- * __term_read_grow --
- * Grow the terminal queue. This routine is the backup for
- * the term_read_grow() macro.
- */
-static int
-__term_read_grow(sp, tty, add)
- SCR *sp;
- IBUF *tty;
- int add;
-{
- size_t new_nelem, olen;
-
- new_nelem = tty->nelem + add;
- olen = tty->nelem * sizeof(tty->ch[0]);
- BINC_RET(sp, tty->ch, olen, new_nelem * sizeof(tty->ch[0]));
-
- olen = tty->nelem * sizeof(tty->chf[0]);
- BINC_RET(sp, tty->chf, olen, new_nelem * sizeof(tty->chf[0]));
-
- tty->nelem = olen / sizeof(tty->chf[0]);
- return (0);
-}
-
-static int
-keycmp(ap, bp)
- const void *ap, *bp;
-{
- return (((KEYLIST *)ap)->ch - ((KEYLIST *)bp)->ch);
-}
diff --git a/usr.bin/vi/common/term.h b/usr.bin/vi/common/term.h
deleted file mode 100644
index 623a94c..0000000
--- a/usr.bin/vi/common/term.h
+++ /dev/null
@@ -1,205 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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.
- *
- * @(#)term.h 8.48 (Berkeley) 7/25/94
- */
-
-/*
- * Fundamental character types.
- *
- * CHAR_T An integral type that can hold any character.
- * ARG_CHAR_T The type of a CHAR_T when passed as an argument using
- * traditional promotion rules. It should also be able
- * to be compared against any CHAR_T for equality without
- * problems.
- * MAX_CHAR_T The maximum value of any character.
- *
- * If no integral type can hold a character, don't even try the port.
- */
-typedef u_char CHAR_T;
-typedef u_int ARG_CHAR_T;
-#define MAX_CHAR_T 0xff
-
-/* The maximum number of columns any character can take up on a screen. */
-#define MAX_CHARACTER_COLUMNS 4
-
-/* Structure to return a character and associated information. */
-struct _ch {
- CHAR_T ch; /* Character. */
-
-#define K_NOTUSED 0
-#define K_CARAT 1
-#define K_CNTRLD 2
-#define K_CNTRLR 3
-#define K_CNTRLT 4
-#define K_CNTRLZ 5
-#define K_COLON 6
-#define K_CR 7
-#define K_ESCAPE 8
-#define K_FORMFEED 9
-#define K_HEXCHAR 10
-#define K_NL 11
-#define K_RIGHTBRACE 12
-#define K_RIGHTPAREN 13
-#define K_TAB 14
-#define K_VERASE 15
-#define K_VKILL 16
-#define K_VLNEXT 17
-#define K_VWERASE 18
-#define K_ZERO 19
- u_int8_t value; /* Special character flag values. */
-
-#define CH_ABBREVIATED 0x01 /* Character from an abbreviation. */
-#define CH_MAPPED 0x02 /* Character from a map. */
-#define CH_NOMAP 0x04 /* Do not map the character. */
-#define CH_QUOTED 0x08 /* Character is already quoted. */
- u_int8_t flags;
-};
-
-typedef struct _keylist {
- u_int8_t value; /* Special value. */
- CHAR_T ch; /* Key. */
-} KEYLIST;
-
-extern KEYLIST keylist[];
-
-/* Structure for the key input buffer. */
-struct _ibuf {
- CHAR_T *ch; /* Array of characters. */
- u_int8_t *chf; /* Array of character flags (CH_*). */
-
- size_t cnt; /* Count of remaining characters. */
- size_t nelem; /* Numer of array elements. */
- size_t next; /* Offset of next array entry. */
-};
- /* Return if more keys in queue. */
-#define KEYS_WAITING(sp) ((sp)->gp->tty->cnt)
-#define MAPPED_KEYS_WAITING(sp) \
- (KEYS_WAITING(sp) && sp->gp->tty->chf[sp->gp->tty->next] & CH_MAPPED)
-
-/*
- * Routines that return a key as a side-effect return:
- *
- * INP_OK Returning a character; must be 0.
- * INP_EOF EOF.
- * INP_ERR Error.
- * INP_INTR Interrupted.
- *
- * The vi structure depends on the key routines being able to return INP_EOF
- * multiple times without failing -- eventually enough things will end due to
- * INP_EOF that vi will reach the command level for the screen, at which point
- * the exit flags will be set and vi will exit.
- */
-enum input { INP_OK=0, INP_EOF, INP_ERR, INP_INTR };
-
-/*
- * Routines that return a confirmation return:
- *
- * CONF_NO User answered no.
- * CONF_QUIT User answered quit, eof or an error.
- * CONF_YES User answered yes.
- */
-enum confirm { CONF_NO, CONF_QUIT, CONF_YES };
-
-/*
- * Ex/vi commands are generally separated by whitespace characters. We
- * can't use the standard isspace(3) macro because it returns true for
- * characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
- * macro does exactly what we want, but it's not portable yet.
- *
- * XXX
- * Note side effect, ch is evaluated multiple times.
- */
-#ifndef isblank
-#define isblank(ch) ((ch) == ' ' || (ch) == '\t')
-#endif
-
-/* The "standard" tab width, for displaying things to users. */
-#define STANDARD_TAB 6
-
-/* Various special characters, messages. */
-#define CH_BSEARCH '?' /* Backward search prompt. */
-#define CH_CURSOR ' ' /* Cursor character. */
-#define CH_ENDMARK '$' /* End of a range. */
-#define CH_EXPROMPT ':' /* Ex prompt. */
-#define CH_FSEARCH '/' /* Forward search prompt. */
-#define CH_HEX '\030' /* Leading hex character. */
-#define CH_LITERAL '\026' /* ASCII ^V. */
-#define CH_NO 'n' /* No. */
-#define CH_NOT_DIGIT 'a' /* A non-isdigit() character. */
-#define CH_QUIT 'q' /* Quit. */
-#define CH_YES 'y' /* Yes. */
-
-#define STR_CONFIRM "confirm? [ynq]"
-#define STR_CMSG "Enter return to continue: "
-#define STR_QMSG "Enter return to continue [q to quit]: "
-
-/* Flags describing how input is handled. */
-#define TXT_AICHARS 0x00000001 /* Leading autoindent chars. */
-#define TXT_ALTWERASE 0x00000002 /* Option: altwerase. */
-#define TXT_APPENDEOL 0x00000004 /* Appending after EOL. */
-#define TXT_AUTOINDENT 0x00000008 /* Autoindent set this line. */
-#define TXT_BACKSLASH 0x00000010 /* Backslashes escape characters. */
-#define TXT_BEAUTIFY 0x00000020 /* Only printable characters. */
-#define TXT_BS 0x00000040 /* Backspace returns the buffer. */
-#define TXT_CNTRLD 0x00000080 /* Control-D is a special command. */
-#define TXT_CNTRLT 0x00000100 /* Control-T is an indent special. */
-#define TXT_CR 0x00000200 /* CR returns the buffer. */
-#define TXT_DOTTERM 0x00000400 /* Leading '.' terminates the input. */
-#define TXT_EMARK 0x00000800 /* End of replacement mark. */
-#define TXT_ESCAPE 0x00001000 /* Escape returns the buffer. */
-#define TXT_EXSUSPEND 0x00002000 /* ^Z should suspend the session. */
-#define TXT_INFOLINE 0x00004000 /* Editing the info line. */
-#define TXT_MAPCOMMAND 0x00008000 /* Apply the command map. */
-#define TXT_MAPINPUT 0x00010000 /* Apply the input map. */
-#define TXT_MAPNODIGIT 0x00020000 /* Return to a digit. */
-#define TXT_NLECHO 0x00040000 /* Echo the newline. */
-#define TXT_OVERWRITE 0x00080000 /* Overwrite characters. */
-#define TXT_PROMPT 0x00100000 /* Display a prompt. */
-#define TXT_RECORD 0x00200000 /* Record for replay. */
-#define TXT_REPLACE 0x00400000 /* Replace; don't delete overwrite. */
-#define TXT_REPLAY 0x00800000 /* Replay the last input. */
-#define TXT_RESOLVE 0x01000000 /* Resolve the text into the file. */
-#define TXT_SHOWMATCH 0x02000000 /* Option: showmatch. */
-#define TXT_TTYWERASE 0x04000000 /* Option: ttywerase. */
-#define TXT_WRAPMARGIN 0x08000000 /* Option: wrapmargin. */
-
-/* Support keyboard routines. */
-size_t __key_len __P((SCR *, ARG_CHAR_T));
-CHAR_T *__key_name __P((SCR *, ARG_CHAR_T));
-int __key_val __P((SCR *, ARG_CHAR_T));
-void key_init __P((SCR *));
-void term_flush __P((SCR *, char *, u_int));
-enum input term_key __P((SCR *, CH *, u_int));
-enum input term_user_key __P((SCR *, CH *));
-int term_init __P((SCR *));
-int term_push __P((SCR *, CHAR_T *, size_t, u_int));
diff --git a/usr.bin/vi/common/trace.c b/usr.bin/vi/common/trace.c
deleted file mode 100644
index 1f63f66..0000000
--- a/usr.bin/vi/common/trace.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)trace.c 8.2 (Berkeley) 3/8/94
- */
-
-#ifdef DEBUG
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#ifdef __STDC__
-TRACE(SCR *sp, const char *fmt, ...)
-#else
-TRACE(sp, fmt, va_alist)
- SCR *sp;
- char *fmt;
- va_dcl
-#endif
-{
- FILE *tfp;
- va_list ap;
-
- if ((tfp = sp->gp->tracefp) == NULL)
- return;
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)vfprintf(tfp, fmt, ap);
- va_end(ap);
-
- (void)fflush(tfp);
-}
-#endif
diff --git a/usr.bin/vi/common/util.c b/usr.bin/vi/common/util.c
deleted file mode 100644
index 0268c0c..0000000
--- a/usr.bin/vi/common/util.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)util.c 8.74 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * binc --
- * Increase the size of a buffer.
- */
-void *
-binc(sp, bp, bsizep, min)
- SCR *sp; /* sp MAY BE NULL!!! */
- void *bp;
- size_t *bsizep, min;
-{
- size_t csize;
-
- /* If already larger than the minimum, just return. */
- if (min && *bsizep >= min)
- return (bp);
-
- csize = *bsizep + MAX(min, 256);
- REALLOC(sp, bp, void *, csize);
-
- if (bp == NULL) {
- /*
- * Theoretically, realloc is supposed to leave any already
- * held memory alone if it can't get more. Don't trust it.
- */
- *bsizep = 0;
- return (NULL);
- }
- /*
- * Memory is guaranteed to be zero-filled, various parts of
- * nvi depend on this.
- */
- memset((char *)bp + *bsizep, 0, csize - *bsizep);
- *bsizep = csize;
- return (bp);
-}
-
-/*
- * nonblank --
- * Set the column number of the first non-blank character
- * including or after the starting column. On error, set
- * the column to 0, it's safest.
- */
-int
-nonblank(sp, ep, lno, cnop)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- size_t *cnop;
-{
- char *p;
- size_t cnt, len, off;
-
- /* Default. */
- off = *cnop;
- *cnop = 0;
-
- /* Get the line. */
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- return (0);
- GETLINE_ERR(sp, lno);
- return (1);
- }
-
- /* Set the offset. */
- if (len == 0 || off >= len)
- return (0);
-
- for (cnt = off, p = &p[off],
- len -= off; len && isblank(*p); ++cnt, ++p, --len);
-
- /* Set the return. */
- *cnop = len ? cnt : cnt - 1;
- return (0);
-}
-
-/*
- * tail --
- * Return tail of a path.
- */
-char *
-tail(path)
- char *path;
-{
- char *p;
-
- if ((p = strrchr(path, '/')) == NULL)
- return (path);
- return (p + 1);
-}
-
-/*
- * set_alt_name --
- * Set the alternate file name.
- *
- * Swap the alternate file name. It's a routine because I wanted some place
- * to hang this comment. The alternate file name (normally referenced using
- * the special character '#' during file expansion) is set by many
- * operations. In the historic vi, the commands "ex", and "edit" obviously
- * set the alternate file name because they switched the underlying file.
- * Less obviously, the "read", "file", "write" and "wq" commands set it as
- * well. In this implementation, some new commands have been added to the
- * list. Where it gets interesting is that the alternate file name is set
- * multiple times by some commands. If an edit attempt fails (for whatever
- * reason, like the current file is modified but as yet unwritten), it is
- * set to the file name that the user was unable to edit. If the edit
- * succeeds, it is set to the last file name that was edited. Good fun.
- *
- * If the user edits a temporary file, there are time when there isn't an
- * alternative file name. A name argument of NULL turns it off.
- */
-void
-set_alt_name(sp, name)
- SCR *sp;
- char *name;
-{
- if (sp->alt_name != NULL)
- free(sp->alt_name);
- if (name == NULL)
- sp->alt_name = NULL;
- else if ((sp->alt_name = strdup(name)) == NULL)
- msgq(sp, M_SYSERR, NULL);
-}
-
-/*
- * v_strdup --
- * Strdup for wide character strings with an associated length.
- */
-CHAR_T *
-v_strdup(sp, str, len)
- SCR *sp;
- CHAR_T *str;
- size_t len;
-{
- CHAR_T *copy;
-
- MALLOC(sp, copy, CHAR_T *, len + 1);
- if (copy == NULL)
- return (NULL);
- memmove(copy, str, len * sizeof(CHAR_T));
- copy[len] = '\0';
- return (copy);
-}
-
-/*
- * vi_putchar --
- * Functional version of putchar, for tputs.
- */
-void
-vi_putchar(ch)
- int ch;
-{
- (void)putchar(ch);
-}
diff --git a/usr.bin/vi/common/vi.h b/usr.bin/vi/common/vi.h
deleted file mode 100644
index f98b870..0000000
--- a/usr.bin/vi/common/vi.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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.
- *
- * @(#)vi.h 8.46 (Berkeley) 8/8/94
- */
-
-/*
- * Forward structure declarations. Not pretty, but the include files
- * are far too interrelated for a clean solution.
- */
-typedef struct _cb CB;
-typedef struct _ch CH;
-typedef struct _excmdarg EXCMDARG;
-typedef struct _exf EXF;
-typedef struct _fref FREF;
-typedef struct _gs GS;
-typedef struct _ibuf IBUF;
-typedef struct _lmark LMARK;
-typedef struct _mark MARK;
-typedef struct _msg MSG;
-typedef struct _option OPTION;
-typedef struct _optlist OPTLIST;
-typedef struct _scr SCR;
-typedef struct _script SCRIPT;
-typedef struct _seq SEQ;
-typedef struct _tag TAG;
-typedef struct _tagf TAGF;
-typedef struct _text TEXT;
-
-/*
- * Local includes.
- */
-#include "term.h" /* Required by args.h. */
-#include "args.h" /* Required by options.h. */
-#include "options.h" /* Required by screen.h. */
-#include "search.h" /* Required by screen.h. */
-
-#include "msg.h" /* Required by gs.h. */
-#include "cut.h" /* Required by gs.h. */
-#include "seq.h" /* Required by screen.h. */
-#include "gs.h" /* Required by screen.h. */
-#include "screen.h" /* Required by exf.h. */
-#include "mark.h" /* Required by exf.h. */
-#include "exf.h"
-#include "log.h"
-#include "mem.h"
-
-#if FWOPEN_NOT_AVAILABLE /* See PORT/clib/fwopen.c. */
-#define EXCOOKIE sp
-int ex_fflush __P((SCR *));
-int ex_printf __P((SCR *, const char *, ...));
-FILE *fwopen __P((SCR *, void *));
-#else
-#define EXCOOKIE sp->stdfp
-#define ex_fflush fflush
-#define ex_printf fprintf
-#endif
-
-/* Macros to set/clear/test flags. */
-#define F_SET(p, f) (p)->flags |= (f)
-#define F_CLR(p, f) (p)->flags &= ~(f)
-#define F_ISSET(p, f) ((p)->flags & (f))
-
-#define LF_INIT(f) flags = (f)
-#define LF_SET(f) flags |= (f)
-#define LF_CLR(f) flags &= ~(f)
-#define LF_ISSET(f) (flags & (f))
-
-/*
- * XXX
- * MIN/MAX have traditionally been in <sys/param.h>. Don't
- * try to get them from there, it's just not worth the effort.
- */
-#ifndef MAX
-#define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))
-#endif
-#ifndef MIN
-#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
-#endif
-
-/* Function prototypes that don't seem to belong anywhere else. */
-int nonblank __P((SCR *, EXF *, recno_t, size_t *));
-void set_alt_name __P((SCR *, char *));
-char *tail __P((char *));
-CHAR_T *v_strdup __P((SCR *, CHAR_T *, size_t));
-void vi_putchar __P((int));
-
-#ifdef DEBUG
-void TRACE __P((SCR *, const char *, ...));
-#endif
-
-/* Digraphs (not currently real). */
-int digraph __P((SCR *, int, int));
-int digraph_init __P((SCR *));
-void digraph_save __P((SCR *, int));
diff --git a/usr.bin/vi/docs/README b/usr.bin/vi/docs/README
deleted file mode 100644
index 0fe3a12..0000000
--- a/usr.bin/vi/docs/README
+++ /dev/null
@@ -1,200 +0,0 @@
-# @(#)README 8.86 (Berkeley) 8/17/94
-
-This is the README for version 1.34 of nex/nvi, a freely redistributable
-replacement for the Berkeley ex and vi text editors. The compressed or
-gzip'd archives for this and future versions, can be retrieved by using
-anonymous ftp to ftp.cs.berkeley.edu, from the file ucb/4bsd/nvi.tar.Z,
-or ucb/4bsd/nvi.tar.gz.
-
-If you have any questions about nvi, or problems making it work, please
-contact me by electronic mail at one of the following addresses:
-
- uunet!bostic
- bostic@cs.berkeley.edu
-
-Keith Bostic
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-o Redistribution:
-
-This software is copyrighted by the The Regents of the University of
-California, but may be freely redistributed (or sold, or used to line
-your birdcage) under the following conditions:
-
-/*-
- * Copyright (c) 1991, 1992, 1993, 1994
- * 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.
- */
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-o Credit where it's due:
-
- This software was originally derived from software contributed
- to the University of California, Berkeley by Steve Kirkendall,
- the author of the vi clone elvis. Without his work, this work
- would have been far more difficult.
-
- POSIX 1003.2 style regular expression support is courtesy of
- Henry Spencer, for which I am *very* grateful.
-
- The curses library was originally done by Ken Arnold. Scrolling
- and general reworking for 4.4BSD was done by Elan Amir.
-
-o From the original vi acknowledgements, by William Joy and Mark Horton:
-
- Bruce Englar encouraged the early development of this display
- editor. Peter Kessler helped bring sanity to version 2's
- command layout. Bill Joy wrote versions 1 and 2.0 through 2.7,
- and created the framework that users see in the present editor.
- Mark Horton added macros and other features and made the editor
- work on a large number of terminals and Unix systems.
-
-o And...
- The financial support of UUNET Communications Services is gratefully
- acknowledged.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Status:
-
-This software is in beta test, and it's pretty stable. Almost all of
-the historic functionality in ex/vi is there, the only major missing
-pieces are open mode and the lisp option. (Also, the options hardtabs,
-optimize, redraw, and slowopen are recognized, but ignored.)
-
-Nvi is mostly 8-bit clean. This isn't difficult to fix, and was left
-in during initial development to keep things simple. Wide character
-support will be integrated at the same time that it is made fully 8-bit
-clean.
-
-There aren't a lot of new features in nex/nvi, but there are a few things
-you might like. The "Additional Features" section of the reference page
-(USD.doc/vi.ref/vi.ref.txt, USD.doc/vi.ref/vi.ref.ps) has more information.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Porting information:
-
-The directory "PORT" has directories for specific OS/machine combinations,
-including V7-style Makefiles, for building nex/nvi on different machines.
-See the file PORT/README for detailed information.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Debugging:
-
-Code fixes are appreciated, of course, but if you can't provide them,
-please email me as much information as you can as to how to reproduce
-the bug, and I'll try to fix it locally. Stack traces of core dumps
-are only rarely helpful -- an example file with a set of keystrokes that
-causes the problem is almost invariably necessary.
-
-Please include the following in the bug report;
-
- o The version of nvi you're running (use :version to get it).
- o The row/column dimensions of the screen (80 x 32).
- o Unless you're confident that they're not part of the problem,
- your startup files (.exrc, .nexrc) and the environment variable
- (EXININT, NEXINIT) values. (Cutting and pasting the output
- of ":set all" is usually sufficient.)
-
-If you're running a memory checker (e.g. Purify) on nvi, you will want
-to recompile everything with "-DPURIFY" in the CFLAGS, first. By
-default, allocated pages are not initialized by the DB code, and they
-will show up as reads of uninitialized memory in the buffer write routines.
-
-=-=-=-=-=-=-=-=-=-=-=
-o Directory layout:
-
-nvi/USD.doc:
- Ex/vi documentation, both historic and current.
-
- edit/ Roff source for "Edit: A tutorial", USD:14 in the
- 4.3BSD manuals.
- ex/ Roff source for "Ex Reference Manual -- Version
- 3.7", USD:16 in the 4.3BSD manuals.
- vi/ Roff source for "An Introduction to Display
- Editing with Vi", USD:15 in the 4.3BSD manuals.
- Includes the "Vi Quick Reference" card.
- vi.man/ Manual page for nex/nvi; an updated version of
- the document distributed with 4.4BSD-Lite.
- vi.ref/ Reference document for nex/nvi; an updated version
- of the document distributed with 4.4BSD-Lite.
-
-nvi/common:
- Source files for pieces of code that are shared by all the editors,
- like searching and logging code or code translating line numbers
- into requests to the dbopen(3) database code. It also has the
- interface code for modifying "records" in the underlying database.
-
-nvi/docs:
- Random nvi documentation:
-
- README -- Nvi main README file.
- bugs.current -- Major known bugs in the current nvi.
- changelog -- Log of changes from version to version.
- features -- Todo list, suggested features list.
- internals/
- autowrite -- Vi autowrite option discussion.
- gdb.script -- GDB debugging scripts.
- input -- Vi maps, executable buffers, and input discussion.
- quoting -- Vi quoting discussion.
- structures -- Out-of-date nvi internal structure description.
- tutorial/ -- Historic vi tutorial(s), of unknown quality.
-
-nvi/ex:
- The ex source code. Because vi has the colon command, lots of
- this code is used by vi. Generally, if functionality is shared
- by both ex and vi, it's in nvi/ex. If it's vi only, it's in
- nvi/vi. Files are generally named by the command(s) they support,
- but occasionally with a name that describes their functionality.
-
-nvi/install:
- Things to install on the local system.
-
- recover.script -- Vi recovery script.
-
-nvi/PORT:
- Porting directories, one per OS/architecture combination. See
- nvi/PORT/README for porting information.
-
- curses/ -- 4.4BSD curses implementation
- db/ -- 4.4BSD DB routines.
- regex/ -- Henry Spencer's POSIX.2 RE support.
-
-nvi/sex:
- The screen support for the ex editor.
-
-nvi/svi:
- The screen support for a curses based vi editor.
-
-nvi/vi:
- The vi source code.
-
-nvi/xaw:
- Place reserved for an X11 (Athena Widget) screen.
diff --git a/usr.bin/vi/docs/bugs.current b/usr.bin/vi/docs/bugs.current
deleted file mode 100644
index 500f3ba..0000000
--- a/usr.bin/vi/docs/bugs.current
+++ /dev/null
@@ -1,44 +0,0 @@
-List of known bugs:
-
-+ The number option doesn't display line numbers in ex append/insert
- mode.
-
-+ The option sidescroll is completely wrong, and setting it does more
- harm than good.
-
-+ When nvi edits files that don't have trailing newlines, it appends
- one, regardless.
-
-+ Open mode is not yet implemented.
-
-+ ^C isn't passed to the shell in the script windows as an interrupt
- character.
-
-+ The options:
-
- hardtabs, lisp, optimize, redraw, slowopen
-
- are recognized, but not implemented. These options are unlikely to
- be implemented, so if you want them you might want to say something!
- I will implement lisp if anyone ever documents how it worked.
-
-+ Screen repainting over slow lines, for some screen changes, isn't
- as good as the historic vi's.
-
-+ The line movement commands ('k', 'j' are easy examples) don't find the
- most attractive cursor position correctly when wrapped lines are longer
- than 80 characters, and they're on the second or subsequent lines.
-
-+ Colon commands longer than a single line cause the display to be
- incorrect.
-
-+ The usages of S_{REDRAW,REFORMAT,REFRESH,RENUMBER,RESIZE} are
- inconsistent, and should be reviewed. In particular, S_REFRESH
- in any screen redraws all screens.
-
-+ Historic vi permitted :g/xxx/vi, i.e. you could execute ex/vi as
- global commands. Need to review all of the old commands to verify
- which ones could/could not be used as global commands.
-
-+ If you run out of space in the recovery directory, the recovery
- file is left in place.
diff --git a/usr.bin/vi/docs/changelog b/usr.bin/vi/docs/changelog
deleted file mode 100644
index 54e98a2..0000000
--- a/usr.bin/vi/docs/changelog
+++ /dev/null
@@ -1,528 +0,0 @@
-1.33 -> 1.34 Wed Aug 17 14:37:32 1994 (PUBLICLY AVAILABLE VERSION)
- + Back out sccsid string fix, it won't work on SunOS 4.1.
-1.32 -> 1.33 Wed Aug 17 09:31:41 1994 (PUBLICLY AVAILABLE VERSION)
- + Get back 5K of data space for the sccsid strings.
- + Fix bug where cG fix in version 1.31 broke cw cursor positioning
- when the change command extended the line.
- + Fix core dump in map/seq code if character larger than 7 bits.
- + Block signals when manipulating the SCR chains.
- + Fix memory allocation for machines with multiple pointer sizes.
-1.31 -> 1.32 Mon Aug 15 14:27:49 1994
- + Turn off recno mmap call for Solaris 2.4/SunOS 5.4.
-1.30 -> 1.31 Sun Aug 14 13:13:35 1994
- + Fix bug were cG on the last line of a file wasn't done in line mode,
- and where the cursor wasn't positioned correctly after exiting text
- insert mode.
- + Add termcap workaround to make function keys greater than 9 work
- correctly (or fail if old-style termcap support).
- + Change ex/vi to not flush mapped keys on error -- this is historic
- practice, and people depended on it.
- + Rework vi parser so that no command including a mapped key ever
- becomes the '.' command, matching historic practice.
- + Make <escape> cancellation in the vi parser match POSIX 1003.2.
- + Fix curses bug where standout string was written for each standout
- character, and where standout mode was never exited explicitly.
- Fix bugs in curses SF/sf and SR/sr scrolling, as seen on Sun and
- x86 consoles.
- + The v/global commands execute the print command by default.
- + The number option historically applies to ex as well as vi.
-1.29 -> 1.30 Mon Aug 8 10:30:42 1994
- + Make first read into a temporary set the file's name.
- + Permit any key to continue scrolling or ex commands -- this
- allows stacked colon commands, and matches historic practice.
- + Don't output normal ! command commentary in ex silent mode.
- + Allow +/- flags after substitute commands, make line (flag)
- offsets from vi mode match historic practice.
- + Return <eof> to ex immediately, even if preceded by spaces. Rework
- ex parser to do erase the prompt instead of depending on the print
- routines to do it. Minor fixes to the ex parser for display of
- default and scrolling commands. MORE EX PARSER CHANGES.
-1.28 -> 1.29 Fri Aug 5 10:18:07 1994
- + Make the abbreviated ex delete command work (:dele---###lll for
- example, is historically legal.
- + When autoprint fires, multiple flags may be set, use ex_print
- directly instead of the stub routines.
- + Change v/global commands to turn off autoprint while running.
- + Minor changes to make the ! command display match historic output.
- + Rework the ex parser to permit multiple command separators without
- commands -- MAJOR CHANGE, likely to introduce all sorts of new bugs.
- + Fix cd command to expand argument in the context of each element
- of the cdpath option, make relative paths always relative to the
- current directory.
- + Rework write/quit cases for temporary files, so that user's don't
- discard them accidentally.
- + Check for window size changes when continuing after a suspend.
- + Fix memory problem in svi_screen, used free'd memory.
- + Change the ex change, insert, append commands to match historic
- cursor positions if no data entered by the user.
- + Change ex format flags (#, l, p) to affect future commands, not
- just the current one, to match historic practice.
- + Make the user's EOF character an additional scroll character in ex.
- + Fix ex ^D scrolling to be the value of the scroll option, not half
- the screen.
- + Fix buffer execution to match historic practice -- bugs where the
- '*' command didn't work, and @<carriage-return> didn't work.
- + Fix doubled reporting of deleted lines in filters.
- + Rework the % ` / ? ( ) N n { and ^A commands to always cut into
- numeric buffers regardless of the location or length of the cut.
- This matches historic practice.
- + Fix the { command to check the current line if the cursor doesn't
- start on the first character of the line.
- + Do '!' expansion in the ex read command arguments, it's historic
- practice. In addition, it sets the last '!' command.
-1.27 -> 1.28 Wed Jul 27 21:29:18 1994
- + Add support for scrolling using the CS and SF/sf/SR/sr termcap
- strings to the 4BSD curses.
- + Rework of getkey() introduced a bug where command interrupt put
- nvi into an infinite loop.
- + Piping through a filter historically cut the replaced lines into
- the default buffer, although not the numeric ones.
- + Read of a filter and !! historically moved to the first nonblank
- of the resulting cursor line (most of the time).
- + Rework cursor motion flags, to support '!' as a motion command.
-1.26 -> 1.27 Tue Jul 26 10:27:58 1994
- + Add the meta option, to specify characters the shell will expand.
- + Fix the read command to match historic practice, the white space
- and bang characters weren't getting parsed correctly.
- + Change SIGALRM handler to save and restore errno.
- + Change SunOS include/compat.h to include <vfork.h> so that the
- ex/filter.c code works again.
- + Don't put lines deleted by the ex delete command into the numeric
- buffers, matching historic practice.
- + Fix; if appending to a buffer, default buffer historically only
- references the appended text, not the resulting text.
- + Support multiple, semi-colon separated search strings, and 'z'
- commands after search strings.
- + Make previous context mark setting match historic practice (see
- docs/internals/context).
- + Fix the set command to permit whitespace between the option and
- the question mark, fix question marks in general.
- + Fix bug where ex error messages could be accidentally preceded
- by a single space.
- + Fix bug where curses reorganization could lose screen specific
- mappings as soon as any screen exited.
- + Fix bug in paragraph code where invalid macros could be matched.
- Make paragraph motions stop at formfeed (^L) characters.
- + Change 'c' to match historic practice, it cut text into numeric
- buffers.
-1.25 -> 1.26 Tue Jul 19 17:46:24 1994
- + Ignore SIGWINCH if the screen size is unchanged; SunOS systems
- deliver one when a screen is uncovered.
- + Fix: don't permit a command with a motion component to wrap due
- to wrapscan and return to the original cursor position.
- + Fix: ^E wasn't beeping when reaching the bottom of the file.
- + Fix bg/fg bug where tmp file exiting caused a NULL dereference.
- + Rework file locking code to use fcntl(2) explicitly.
- + Fix bug in section code where invalid macros could be matched.
- + Fix bug where line number reset by vi's Q command.
- + Add explicit character mode designation to character mode buffers.
- + Add <sys/ioctl.h> include to sex/sex_window.c, needed by NET/2
- vintage systems.
- + Change to always flush a character during suspend, 4BSD curses
- has the optimization where it doesn't flush after a standend().
- + Fix bug on OSF1 where <curses.h> changes the values of VERASE,
- VKILL and VWERASE to incorrect ones.
- + Fix bug where optarg used incorrectly in main.c.
- + Block all signals when acting on a signal delivery.
- + Fix recovery bug where RCV_EMAIL could fire even if there wasn't
- a backing file; format recovery message.
-1.24 -> 1.25 Sun Jul 17 14:33:38 1994
- + Stop allowing keyboard suspends (^Z) in insert mode, it's hard
- to get autowrite correct, and it's not historic practice.
- + Fix z^, z+ to match historic practice.
- + Bug in message handling, "vi +35 non-existent_file" lost the
- status message because the "+35" pushed onto the stack erased
- it. For now, change so that messages aren't displayed if there
- are keys waiting -- may need to add a "don't-erase" bit to the
- character in the stack instead.
- + Bug in svi_msgflush(), where error messages could come out in
- normal video.
-1.23 -> 1.24 Sat Jul 16 18:30:18 1994
- + Fix core dump in exf.c, where editing a non-existent file and
- exiting could cause already free'd memory to be free'd.
- + Clean up numerous memory errors, courtesy of Purify.
- + Change process wait code to fail if wait fails, and not attempt
- to interpret the wait return information.
- + Open recovery and DB files for writing as well as reading, System
- V (fcntl) won't let you acquire LOCK_EX locks otherwise.
- + Fix substitute bug where could malloc 0 bytes (AIX breaks).
- + Permit the mapping of <carriage-return>, it's historic practice.
- + Historic vi didn't eat <blank> characters before the force
- flag, match historic practice.
- + Bug in ex argument parsing, corrected for literal characters
- twice.
- + Delete screen specific maps when the screen closes.
- + Move to the first non-<blank> in the line on startup; historic
- practice.
- + Change the ex visual command to move directly to a line if no
- trailing 'z' command.
- + Fix "[[" and "]]" to match historic practice (yet again...).
- + Fix "yb" and "y{" commands to update the cursor correctly.
- + Change "~<motion>" to match the yank cursor movement semantics
- exactly.
- + Move all of the curses related code into sex/svi -- major rework,
- but should help in future ports.
- + Fix bug in split code caused by new file naming code, where would
- drop core when a split screen exited.
- + Change svi_ex_write to do character display translation, so that
- messages with file names in them are displayed correctly.
- + Display the file name on split screens instead of a divider line.
- + Fix move bug, wasn't copying lines before putting them.
- + Fix bug were :n dropped core if no arguments supplied.
- + Don't quote characters in executed buffer: "ifoo<esc>" should leave
- insert mode after the buffer is executed.
- + Tagpop and tagpush should set the absolute mark in case only moving
- within a file.
- + Skip leading whitespace characters before tags and cursor word
- searches.
- + Fix bug in ex_global where re_conv() was allocating the temporary
- buffer and not freeing it.
-1.22 -> 1.23: Wed Jun 29 19:22:33 1994
- + New <sys/cdefs.h> required "inline" to change to "__inline"
- + Fix System V curses code for new ^Z support.
- + Fix off-by-one in the move code, avoid ":1,$mo$" with only one
- line in the buffer.
- + Line orientation of motion commands was remembered too long,
- i.e. '.' command could be incorrectly marked as line oriented.
- + Move file modification time into EXF, so it's shared across
- split screens.
- + Put the prev[ious] command back in, people complained.
- + Random fixes to next/prev semantics changed in 1.22.
- + Historically vi doesn't only move to the last address if there's
- ANYTHING after the addresses, e.g. ":3" moves to line 3, ":3|"
- prints line 3.
-1.21 -> 1.22: Mon Jun 27 11:01:41 1994
- + Make the line between split screens inverse video again.
- + Delete the prev[ious] command, it's not useful enough to keep.
- + Rework :args/file name handling from scratch -- MAJOR CHANGE,
- likely to introduce all sorts of new bugs.
- + Fix RE bug where no subexpressions in the pattern but there were
- subexpressions referenced in the replacement, e.g. "s/XXX/\1/g".
- + Change recovery to not leave unmodified files around after a
- crash, by using the owner 'x' bit on unmodified backup files.
- MAJOR CHANGE, the system recovery script has to change!
- + Change -r option to delete recovery.* files that reference non-
- existent vi.* files.
- + Rework recovery locking so that fcntl(2) locking will work.
- + Fix append (upper-case) buffers, broken by cut fixes.
- + Fix | to not set the absolute motion mark.
- + Read $HOME/.exrc file on startup if the effective user ID is
- root. This makes running vi while su(1)'d work correctly.
- + Use the full pathname of the file as the recovery name, not
- just the last component. Matches historic practice.
- + Keep marks in empty files from being destroyed.
- + Block all caught signals before calling the DB routines.
- + Make the line change report match historic practice (yanked
- lines were different than everything else).
- + Add section on multiple screens to the reference manual.
- + Display all messages at once, combine onto a single line if
- possible. Delete the trailing period from all messages.
-1.20 -> 1.21: Thu May 19 12:21:58 1994
- + Delete the -l flag from the recover mail.
- + Send the user email if ex command :preserve executed, this matches
- historic practice. Lots of changes to the preserve and recovery
- code, change preserve to snapshot files (again, historic practice).
- + Make buffers match historic practice: "add logically stores text
- into buffer a, buffer 1, and the unnamed buffer.
- + Print <tab> characters as ^I on the colon command line if the
- list option set.
- + Adjust ^F and ^B scroll values in the presence of split screens
- and small windows.
- + Break msg* routines out from util.c into msg.c, start thinking
- about message catalogs.
- + Add tildeop set option, based on stevie's option of the same name.
- Changes the ~ command into "[count] ~ motion", i.e. ~ takes a
- trailing motion.
- + Chose NOT to match historic practice on cursor positioning after
- consecutive undo commands on a single line; see vi/v_undo.c for
- the comment.
- + Add a one line cache so that multiple changes to the same line
- are only counted once (e.g. "dl35p" changes one line, not 35).
- + Rework signals some more. Block file sync signals in vi routines
- that interface to DB, so can sync the files at interrupt time.
- Write up all of the signal handling arguments, see signal.c.
-1.19 -> 1.20: Thu May 5 19:24:57 1994
- + Return ^Z to synchronous handling. See the dicussion in signal.c
- and svi_screen.c:svi_curses_init().
- + Fix bug where line change report was wrong in util.c:msg_rpt().
-1.18 -> 1.19: Thu May 5 12:59:51 1994
- + Block DSUSP so that ^Y isn't delivered at SIGTSTP.
- + Fix bug -- put into an empty file leaves the cursor at 1,0,
- not the first nonblank.
- + Fix bug were number of lines reported for the 'P' command was
- off-by-one.
- + Fix bug were 0^D wasn't being handled correctly.
- + Delete remnants of ^Z as a raw character.
- + Fix bug where if a map was an entire colon command, it may never
- have been displayed.
- + Final cursor position fixes for the vi T and t commands.
- + The ex :next command took an optional ex command as it's first
- argument similar to the :edit commands. Match historic practice.
-1.17 -> 1.18: Wed May 4 13:57:10 1994
- + Rework curses information in the PORT/Makefile's.
- + Minor fixes to ^Z asynchronous code.
-1.16 -> 1.17: Wed May 4 11:15:56 1994
- + Make ex comment handling match historic practice.
- + Make ^Z work asynchronously, we can no longer use the SIGTSTP
- handler in the curses library.
-1.15 -> 1.16: Mon May 2 19:42:07 1994
- + Make the 'p' and 'P' commands support counts, i.e. "Y10p" works.
- + Make characters that map to themselves as the first part of the
- mapping work, it's historic practice.
- + Fix bug where "s/./\& /" discarded the space in the replacement
- string.
- + Add support for up/down cursor arrows in text input mode, rework
- left/right support to match industry practice.
- + Fix bug were enough character remapping could corrupt memory.
- + Delete O_REMAPMAX in favor of setting interrupts after N mapped
- characters without a read, delete the map counter per character.
- MAJOR CHANGE. All of the interrupt signal handling has been
- reworked so that interrupts are always turned on instead of
- being turned on periodically, when an interruptible operation is
- pending.
- + Fix bug where vi wait() was interrupted by the recovery alarm.
- + Make +cmd's and initial commands execute with the current line
- set to the last line of the file. This is historic practice.
- + Change "lock failed" error message to a file status message.
- It always fails over NFS, and making all NFS files readonly
- isn't going to fly.
- + Use the historic line number format, but check for overflow.
- + Fix bug where vi command parser ignored buffers specified as
- part of the motion command.
- + Make [@*]buffer commands on character mode buffers match historic
- practice.
- + Fix bug where the cmap/chf entries of the tty structure weren't
- being cleared when new characters were read.
- + Fix bug where the default command motion flags were being set
- when the command was a motion component.
- + Fix wrapmargin bug; if appending characters, and wrapmargin breaks
- the line, an additional space is eaten.
-1.14 -> 1.15: Fri Apr 29 07:44:57 1994
- + Make the ex delete command work in any empty file.
- + Fix bug where 't' command placed the cursor on the character
- instead of to its left.
- + ^D and ^U didn't set the scroll option value historically.
- Note, this change means that any user set value (e.g. 15^D)
- will be lost when splitting the screen, since the split code
- now resets the scroll value regardless.
- + Fix the ( command to set the absolute movement mark.
- + Only use TIOCGWINSZ for window information if SIGWINCH signal
- caught.
- + Delete the -l flag, and make -r work for multiple arguments.
- Add the ex "recover[!] file" command.
- + Switch into ex terminal mode and use the sex routines when
- append/change/insert called from vi mode.
- + Make ^F and ^B match historic practice. This required a fairly
- extensive rework of the svi scrolling code.
- + Cursor positioning in H, M, L, G (first non-blank for 1G) wasn't
- being done correctly. Delete the SETLFNB flag. H, M, and L stay
- logical movements (SETNNB) and G always moves to the first nonblank.
- + System V uses "lines" and "cols", not "li" and "co", change as
- necessary. Check termcap function returns for errors.
- + Fix `<character> command to do start/end of line correction,
- and to set line mode if starting and stopping at column 0.
- + Fix bug in delete code where dropped core if deleted in character
- mode to an empty line. (Rework the delete code for efficiency.)
- + Give up on SunOS 4.1.X, and use "cc" instead of /usr/5bin/cc.
- + Protect ex_getline routine from interrupted system calls (if
- possible, set SA_RESTART on SIGALRM, too).
- + Fix leftright scrolling bug, when moving to a shorter line.
- + Do validity checking on the copy, move, t command target line
- numbers.
- + Change for System V % pattern broke trailing flags for empty
- replacement strings.
- + Fix bug when RCM flags retained in the saved dot structure.
- + Make the ex '=' command work for empty files.
- + Fix bug where special_key array was being free'd (it's no longer
- allocated).
- + Matches cut in line mode only if the starting cursor is at or
- before the first nonblank in its line, and the ending cursor is
- at or after the last nonblank in its line.
- + Add the :wn command, so you can write a file and switch to a new
- file in one command.
- + Allow only a single key as an argument to :viusage.
- + New movement code broke filter/paragraph operations in empty
- files ("!}date" in an empty file was dropping core).
-1.12 -> 1.14: Mon Apr 18 11:05:10 1994 (PUBLICLY AVAILABLE VERSION, 4.4BSD)
- + Fix FILE structure leakage in the ex filter code.
- + Rework suspend code for System V curses. Nvi has to do the
- the work, there's no way to get curses to do it right.
- + Revert SunOS 4.1.X ports to the distributed curses. There's
- a bug in Sun's implementation that we can't live with.
- + Quit immediately if row/column values are unreasonable.
- + Fix the function keys to match vi historic behavior.
- + Replace the echo/awk magic in the Makefile's with awk scripts.
-1.11 -> 1.12: Thu Apr 14 11:10:19 1994
- + Fix bug where only the first vi key was checked for validity.
- + Make 'R' continue to overwrite after a <carriage-return>.
- + Only display the "no recovery" message once.
- + Rework line backup code to restore the line to its previous
- condition.
- + Don't permit :q in a .exrc file or EXINIT variable.
- + Fix wrapscan option bug where forward searches become backward
- searches and do cursor correction accordingly.
- + Change "dd" to move the cursor to the first non-blank on the line.
- + Delete cursor attraction to the first non-blank, change non-blank
- motions to set the most attractive cursor position instead.
- + Fix 'r' substitute option to set the RE to the last RE, not the
- last substitute RE.
- + Fix 'c' and 'g' substitute options to always toggle, and fix
- edcompatible option to not reset them.
- + Display ex error messages in inverse video.
- + Fix errorbells option to match historic practice.
- + Delete fixed character display table in favor of table built based
- on the current locale.
- + Add ":set octal" option, that displays unknown characters as octal
- values instead of the default hexadecimal.
- + Make all command and text input modes interruptible.
- + Fix ex input mode to display error messages immediately, instead
- of waiting for the lines to be resolved.
- + Fix bug where vi calling append could overwrite the command.
- + Fix off-by-one in the ex print routine tab code.
- + Fix incorrect ^D test in vi text input routines.
- + Add autoindent support for ex text insert routines.
- + Add System V substitute command replacement pattern semantics,
- where '%' means the last replacement pattern.
- + Fix bug that \ didn't escape newlines in ex commands.
- + Regularize the names of special characters to CH_*.
- + Change hex insert character from ^Vx<hex_char> to ^X<hex_char>
- + Integrate System V style curses, so SunOS and Solaris ports can
- use the native curses implementation.
-1.10 -> 1.11: Thu Mar 24 16:07:45 EST 1994 (PUBLICLY AVAILABLE VERSION)
- + Change H, M, and L to set the absolute mark, historical practice.
- + Fix bug in stepping through multiple tags files.
- + Add "remapmax" option that turns off map counts so you can remap
- infinitely. If it's off, term_key() can be interrupted from the
- keyboard, which will cause the buffers to flush. I also dropped
- the default max number of remaps to 50. (Only Dave Hitz's TM
- macros and maze appear to go over that limit.)
- + Change :mkexrc to not dump w{300,1200,9600}, lisp options.
- + Fix backward search within a line bug.
- + Change all the includes of "pathnames.h" to use <>'s so that the
- PORT versions can use -I. to replace it with their own versions.
- + Make reads and writes interruptible. Rework code that enters and
- leaves ex for '!' and filter commands, rework all interrupt and
- timer code.
- + Fix core dump when user displayed option in .exrc file.
- + Fix bug where writing empty files didn't update the saved
- modification time.
- + Fix bug where /pattern/ addressing was always a backward search.
- + Fix bug triggered by autoindent of more than 32 characters, where
- nvi wasn't checking the right TEXT length.
- + Fix bug where joining only empty lines caused a core dump.
-1.09 -> 1.10: Sat Mar 19 15:40:29 EST 1994
- + Fix "set all" core dump.
-1.08 -> 1.09: Sat Mar 19 10:11:14 EST 1994
- + If the tag's file path is relative, and it doesn't exist, check
- relative to the tag file location.
- + Fix ~ command to free temporary buffer on error return.
- + Create vi.ref, a first cut at a reference document for vi.
- The manual page and the reference document only document the
- set options, so far.
- + Fix 1G bug not always going to the first non-blank.
- + Upgrade PORT/regex to release alpha3.4, from Henry Spencer.
- + Add MKS vi's "cdpath" option, supporting a cd search path.
- + Handle if search as a motion was discarded, i.e. "d/<erase>".
- + Change nvi to not create multiple recovery files if modifying
- a recovered file.
- + Decide to ignore that the cursor is before the '$' when inserting
- in list mode. It's too hard to fix.
-1.07 -> 1.08: Wed Mar 16 07:37:36 EST 1994
- + Leftright and big line scrolling fixes. This meant more changes
- to the screen display code, so there may be new problems.
- + Don't permit search-style addresses until a file has been read.
- + "c[Ww]" command incorrectly handled the "in whitespace" case.
- + Fix key space allocation bug triggered by cut/paste under SunOS.
- + Ex move command got the final cursor position wrong.
- + Delete "optimize option not implemented" message.
- + Make the literal-next character turn off mapping for the next
- character in text input mode.
-1.06 -> 1.07: Mon Mar 14 11:10:33 EST 1994
- + The "wire down" change in 1.05 broke ex command parsing, there
- wasn't a corresponding change to handle multiple K_VLNEXT chars.
- + Fix final position for vi's 't' command.
-1.05 -> 1.06: Sun Mar 13 16:12:52 EST 1994
- + Wire down ^D, ^H, ^W, and ^V, regardless of the user's termios
- values.
- + Add ^D as the ex scroll command.
- + Support ^Q as a literal-next character.
- + Rework abbreviations to be delimited by any !inword() character.
- + Add options description to the manual page.
- + Minor screen cache fix for svi_get.c.
- + Rework beautify option support to match historical practice.
- + Exit immediately if not reading from a tty and a command fails.
- + Default the SunOS 4.* ports to the distributed curses, not SMI's.
-1.04 -> 1.05: Thu Mar 24 16:07:45 EST 1994
- + Make cursor keys work in input mode.
- + Rework screen column code in vi curses screen. MAJOR CHANGE --
- after this, we'll be debugging curses screen presentation from
- scratch.
- + Explode include files in vi.h into the source files.
-1.03 -> 1.04: Sun Mar 6 14:14:16 EST 1994
- + Make the ex move command keep the marks on the moved lines.
- + Change resize semantics so you can set the screen size to a
- specific value. A couple of screen fixes for the resize code.
- + Fixes for foreground/background due to SIGWINCH.
- + Complete rework of all of vi's cursor movements. The underlying
- assumption in the old code was that the starting cursor position
- was part of the range of lines cut or deleted. The command
- "d[[" is an example where this isn't true. Change it so that all
- motion component commands set the final cursor position separately
- from the range, as it can't be done correctly later. This is a
- MAJOR CHANGE -- after this change, we'll be debugging the cursor
- positioning from scratch.
- + Rewrite the B, b, E, e commands to use vi's getc() interface
- instead of rolling their own.
- + Add a second MARK structure, LMARK, which is the larger mark
- needed by the logging and mark queue code. Everything else uses
- the reworked MARK structure, which is simply a line/column pair.
- + Rework cut/delete to not expect 1-past-the-end in the range, but
- to act on text to the end of the range, inclusive.
- + Sync on write's, to force NFS to flush.
-1.01 -> 1.03: Sun Jan 23 17:50:35 EST 1994 (PUBLICLY AVAILABLE VERSION)
- + Tag stack fixes, was returning to the tag, not the position from
- which the user tagged.
- + Only use from the cursor to the end of the word in cursor word
- searches and tags. (Matches historical vi behavior.)
- + Fix delete-last-line bug when line number option set.
- + Fix usage line for :split command.
- + If O_NUMBER set, long input lines would eventually fail, the column
- count for the second screen of long lines wasn't set correctly.
- + Fix for [[ reaching SOF with a column longer than the first line.
- + Fix for multiple error messages if no screen displayed.
- + Fix :read to set alternate file name as in historical practice.
- + Fix cut to rotate the numeric buffers if line mode flag set.
-1.00 -> 1.01: Wed Jan 12 13:37:18 EST 1994
- + Don't put cut items into numeric buffers if cutting less than
- parts of two lines.
-0.94 -> 1.00: Mon Jan 10 02:27:27 EST 1994
- + Read-ahead not there; BSD tty driver problem, SunOS curses
- problem.
- + Global command could error if it deleted the last line of
- the file.
- + Change '.' to only apply to the 'u' if entered immediately
- after the 'u' command. "1pu.u.u. is still broken, but I
- expect that it's going to be sacrificed for multiple undo.
- + If backward motion on a command, now move to the point; get
- yank cursor positioning correct.
- + Rework cut buffers to match historic practice -- yank/delete
- numeric buffers redone sensibly, ignoring historic practice.
-0.92 -> 0.93: Mon Dec 20 19:52:14 EST 1993
- + Christos Zoulas reimplemented the script windows using pty's,
- which means that they now work reasonably. The down side of
- this is that almost all ports other than 4.4BSD need to include
- two new files, login_tty.c and pty.c from the PORT/clib directory.
- I've added them to the Makefiles.
- + All calloc/malloc/realloc functions now cast their pointers, for
- SunOS -- there should be far fewer warning messages, during the
- build. The remaining messages are where CHAR_T's meet char *'s,
- i.e. where 8-bit clean meets strcmp.
- + The user's argument list handling has been reworked so that there
- is always a single consistent position for use by :next, :prev and
- :rewind.
- + All of the historical options are now at least accepted, although
- not all of them are implemented. (Edcompatible, hardtabs, lisp,
- optimize, redraw, and slowopen aren't implemented.)
- + The RE's have been reworked so that matches of length 0 are handled
- in the same way as vi used to handle them.
- + Several more mapping fixes and ex parser addressing fixes.
diff --git a/usr.bin/vi/docs/ev b/usr.bin/vi/docs/ev
deleted file mode 100644
index 144295a..0000000
--- a/usr.bin/vi/docs/ev
+++ /dev/null
@@ -1,55 +0,0 @@
-# @(#)ev 8.4 (Berkeley) 4/29/94
-
-Ev: Vi: Result:
-<CK> <CK> (Cursor keys). Move around the file.
-
-Meta key commands:
-^A<#> <#>G Goto line #.
-^A$ G Goto the end of the file.
-^A/ / Prompt and execute a forward search.
-^A: : Prompt and execute an ex command.
-^A? ? Prompt and execute a backward search.
-^Ac y'<c> Copy to mark in line mode (or copy the current line).
-^AC y`<c> Copy to mark in character mode.
-^Ad d'<c> Delete to mark in line mode (or delete the current line).
-^AD d`<c> Delete to mark in character mode.
-^Aj J Join lines.
-^Am m<c> Mark the current cursor position.
-^AN N Repeat search in the reverse direction.
-^An ^A Search for the word under the cursor.
-^Ar u Redo a command.
-^Au u Undo a command.
-
-Single key commands:
-^B ^B Page up a screen.
-^C ^C Interrupt long-running commands.
-^D ^D Page down a half-screen.
-^E $ End of line.
-^F ^F Page down a screen.
-^G ^G File status/information.
-^H X Delete the character to the left of the cursor.
-^I (TAB)
-^J j Cursor down one line.
-^K k Cursor up one line.
-^L ^L Redraw the screen.
-^M (CR) ^M In insert mode, split the line at the current cursor,
- creating a new line.
- In overwrite mode, cursor down one line.
-^N n Repeat previous search, in previous direction.
-^O (UNUSED)
-^P p Paste the cut text at the cursor position.
-^Q (XON/XOFF)
-^R (UNUSED)
-^S (XON/XOFF)
-^T D Truncate the line at the cursor position.
-^U ^U Page up a half-screen.
-^V<c> ^V<c> Insert/overwrite with a literal next character.
-^W w Move forward one whitespace separated word.
-^X x Delete the current character.
-^Y (UNUSED)
-^Z ^Z Suspend.
-
-New ex mode commands:
-
-^A:set ov[erwrite] Toggle "insert" mode, so that input keys overwrite
- the existing characters.
diff --git a/usr.bin/vi/docs/features b/usr.bin/vi/docs/features
deleted file mode 100644
index ed78564..0000000
--- a/usr.bin/vi/docs/features
+++ /dev/null
@@ -1,87 +0,0 @@
-List of things that should be added:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-+ X11 (Tk, Motif, Xaw) interface.
-+ Interpreted language (Perl5, Scheme, Tcl)
-+ Ports: Windows, Windows NT, MSDOS
-+ Message catalogs.
-+ Forms editing package; use RE's to verify field contents.
-+ Internationalization, including wide character support.
-+ Support for single line window editing, including full editing
- capability on the vi colon command line.
-+ Rob Pike's sam style RE's.
-
-List of suggested features:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-+ Filename completion. While on the subject of completion, it would be
- nice to have the completion mechanism found in tcsh version >= 6.03.
- For instance, the completion for the `:cd' command will be directories
- only. The completion for the `:set' command will be all options not
- set at that moment, and for `:set un' will be all options that are set
- at that moment. The completion for `:< count' will be the flags.
-
-+ Add a "push" command that would push a file on the tags stack.
- (Essentially make tags a special case of the stack, and make
- the stack more general purpose.)
-
-+ Make :script just run a command and edit the output, and :interactive,
- which allows interactive shell session, instead of just the current
- :script.
-
-+ Add versioning based on a "set version" variable, that would
- create backup copies when the file was written back, i.e. the
- ":w" and autowrite's would copy the original.
-
-+ Add tagging information to the man page so that users can display
- the part of the man page that discusses the command in which they're
- interested.
-
-+ Add a zone option so that you can declare that top/bottom few lines
- of the screen aren't filled except by accident, so that the text
- you ask for is always concentrated in the center of the screen.
-
-+ Add "set searchdir" for a list of directories to look in for
- files to edit. The semantic is that ":e foo" is replaced with
- the file name that is found, so there's no confusion as to
- which file is written.
-
-+ Change
- :di[splay] tags -> :tags
- :di[splay] screens -> :screens
- :di[splay] buffers -> :buffers
-
-+ A macro record function. Add the ability to record a sequence
- of keystrokes into a named buffer for later use. Handy when
- you're trying to build a semi-complex macro.
-
-+ The semantics of :split, :bg, and :fg aren't right. Someone needs to
- rethink how they should interact. The main problem arises when users
- want to get a window into a new file. Currently, the necessary sequence
- is ":split newfile|^W|:bg". It would be nice if you could simply
- background the current screen and edit a new one.
-
-+ An option to turn on a ``quarter plane'' model so that you can
- go as far to the right or down as you wish. The File or the
- current line is only extended if you actually put down a char at
- the new location. Very handy for ascii graphics and tables.
-
-+ Some way of replacing the command bindings. For this to work
- cleanly the notion of a command must be separate from that of a
- key. (Simulate the Rand editor?)
-
-+ Vertical splitting, so you can see files side by side.
-
-+ Tracking. Two or more files are associated so that when one file
- is scrolled up/down/left/right other files track by the same amount.
- Tracking may be constrained such that two files only track vertically
- or horizontally. This is relatively easy to implement.
-
-+ A status file so that the next time invocation of the editor returns
- to the same place, with the same number of windows etc. In case of
- change of the screen size, reasonable defaults are used. For each
- window size and location of the window, name of the file and position
- in it, any tab settings, any other settings for the window (such as
- insert/overwrite mode, auto indent etc). Last search RE and maybe
- direction. If a file does not exist the next time you invoke the
- editor, its window is left in the same place but with some default
- message.
diff --git a/usr.bin/vi/docs/internals/autowrite b/usr.bin/vi/docs/internals/autowrite
deleted file mode 100644
index 55cd13b..0000000
--- a/usr.bin/vi/docs/internals/autowrite
+++ /dev/null
@@ -1,88 +0,0 @@
-# @(#)autowrite 8.2 (Berkeley) 9/28/93
-
-Vi autowrite behavior, the fields with *'s are "don't cares".
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-Commands that are affected only by autowrite:
-
-Command File Autowrite? Action:
- modified?
------------------------------------------------
-^Z Y Y Write file and suspend.
-^Z Y N Suspend.
-^Z N * Suspend.
-
-# This behavior is NOT identical to :edit.
-^ Y Y Write file and jump.
-^ Y N Error.
-^ N * Jump.
-
-# The new nvi command ^T (:tagpop) behaves identically to ^].
-# This behavior is identical to :tag, :tagpop, and :tagpush with
-# force always set to N.
-^] Y Y Write file and jump.
-^] Y N Error.
-^] N * Jump.
-
-# There's no way to specify a force flag to the '!' command.
-:! Y Y Write file and execute.
-:! Y N Warn (if warn option) and execute.
-:! N * Execute.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-Commands that are affected by both autowrite and force:
-
-NOTE: the "force" flag is never passed on, i.e. the write
-to the file caused by the autowrite flag is never forced.
-
-Command File Autowrite? Force? Action:
- modified? (!)
--------------------------------------------------------
-# The first rule (YYY) is historic practice, but seems wrong.
-# In nvi, :next and :prev commands behave identically to :rewind.
-:next Y Y Y Write changes and jump.
-:next Y Y N Write changes and jump.
-:next Y N Y Abandon changes and jump.
-:next Y N N Error.
-:next N * * Jump.
-
-:rewind Y Y Y Abandon changes and jump.
-:rewind Y Y N Write changes and jump.
-:rewind Y N Y Abandon changes and jump.
-:rewind Y N N Error.
-:rewind N * * Jump.
-
-# The new nvi commands, :tagpop and :tagtop, behave identically to :tag.
-# Note, this behavior is the same as :rewind and friends, as well.
-:tag Y Y Y Abandon changes and jump.
-:tag Y Y N Write changes and jump.
-:tag Y N Y Abandon changes and jump.
-:tag Y N N Error.
-:tag N * * Jump.
-
-# The command :suspend behaves identically to :stop.
-:stop Y Y Y Suspend.
-:stop Y Y N Write changes and suspend.
-:stop Y N Y Suspend.
-:stop Y N N Suspend.
-:stop N * * Suspend.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-Commands that might be affected by autowrite, but aren't:
-
-Command File Autowrite? Force? Action:
- modified? (!)
--------------------------------------------------------
-#:ex, and :vi (executed while in vi mode) behave identically to :edit.
-:edit Y * Y Abandon changes and jump.
-:edit Y * N Error.
-:edit N * * Jump.
-
-:quit Y * Y Quit.
-:quit Y * N Error.
-:quit N * * Quit.
-
-:shell * * * Execute shell.
-
-:xit Y * * Write changes and exit.
-:xit N * * Exit.
diff --git a/usr.bin/vi/docs/internals/context b/usr.bin/vi/docs/internals/context
deleted file mode 100644
index 139a1c3..0000000
--- a/usr.bin/vi/docs/internals/context
+++ /dev/null
@@ -1,32 +0,0 @@
-# @(#)context 8.5 (Berkeley) 7/23/94
-
-In historic vi, the previous context mark was always set:
-
-ex address:
- any number, <question-mark>, <slash>, <dollar-sign>,
- <single-quote>, <backslash>
-
-ex commands: undo, "z.", global, vglobal
-
-vi commands: (, ), {, }, %, [[, ]], ^]
-
-nvi adds the vi command ^T to this list.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-In historic vi, the previous context mark was set if the
-line changed:
-
-vi commands: '<mark>, G, H, L, M, z
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-In historic vi, the previous context mark was set if the
-line or column changed:
-
-vi commands: `<mark>, /, ?, N, n
-
-nvi adds the vi command ^A to this list.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-In historic vi, the previous context mark was set in non-visual
-mode for ^R and ^L if the line changed, but I have yet to figure
-out how the line could change.
diff --git a/usr.bin/vi/docs/internals/gdb.script b/usr.bin/vi/docs/internals/gdb.script
deleted file mode 100644
index c875bf7..0000000
--- a/usr.bin/vi/docs/internals/gdb.script
+++ /dev/null
@@ -1,77 +0,0 @@
-# @(#)gdb.script 8.3 (Berkeley) 8/16/94
-
-# display the SVI screen map
-# usage dmap(sp)
-define dmap
- set $h = ((SVI_PRIVATE *)$arg0->svi_private)->h_smap
- set $t = ((SVI_PRIVATE *)$arg0->svi_private)->t_smap
- while ($h <= $t)
- printf "lno: %d; off %d ", (int)$h->lno, (int)$h->off
- if ($h->c_ecsize == 0)
- printf "flushed\n"
- else
- printf "\n\tsboff %d; scoff %d\n", \
- (int)$h->c_sboff, (int)$h->c_scoff
- printf "\teboff %d; eclen %d; ecsize %d\n", \
- (int)$h->c_eboff, (int)$h->c_eclen, \
- (int)$h->c_ecsize
- end
- set $h = $h + 1
- end
-end
-
-# display the tail of the SVI screen map
-define tmap
- set $h = ((SVI_PRIVATE *)$arg0->svi_private)->h_smap
- set $t = ((SVI_PRIVATE *)$arg0->svi_private)->t_smap
- while ($t >= $h)
- printf "lno: %d; off %d ", (int)$t->lno, (int)$t->off
- if ($t->c_ecsize == 0)
- printf "flushed\n"
- else
- printf "\n\tsboff %d; scoff %d\n", \
- (int)$t->c_sboff, (int)$t->c_scoff
- printf "\teboff %d; eclen %d; ecsize %d\n", \
- (int)$t->c_eboff, (int)$t->c_eclen, \
- (int)$t->c_ecsize
- end
- set $t = $t - 1
- end
-end
-
-# display the private structures
-define vip
- print *((VI_PRIVATE *)sp->vi_private)
-end
-define svp
- print *((SVI_PRIVATE *)sp->svi_private)
-end
-define exp
- print *((EX_PRIVATE *)sp->ex_private)
-end
-define sxp
- print *((SEX_PRIVATE *)sp->sex_private)
-end
-
-# display the marks
-define markp
- set $h = sp->ep->marks.next
- set $t = &sp->ep->marks
- while ($h != 0 && $h != $t)
- printf "key %c lno: %d cno: %d flags: %x\n", \
- ((MARK *)$h)->name, ((MARK *)$h)->lno, \
- ((MARK *)$h)->cno, ((MARK *)$h)->flags
- set $h = ((MARK *)$h)->next
- end
-end
-
-# display the tags
-define tagp
- set $h = sp->taghdr.next
- set $t = &sp->taghdr
- while ($h != 0 && $h != $t)
- printf "tag: %s lno %d cno %d\n", ((TAG *)$h)->frp->fname, \
- ((TAG *)$h)->lno, ((TAG *)$h)->cno
- set $h= ((TAG *)$h)->next
- end
-end
diff --git a/usr.bin/vi/docs/internals/input b/usr.bin/vi/docs/internals/input
deleted file mode 100644
index 9a7506e..0000000
--- a/usr.bin/vi/docs/internals/input
+++ /dev/null
@@ -1,350 +0,0 @@
-# @(#)input 5.5 (Berkeley) 7/2/94
-
-MAPS, EXECUTABLE BUFFERS AND INPUT IN EX/VI:
-
-The basic rule is that input in ex/vi is a stack. Every time a key which
-gets expanded is encountered, it is expanded and the expansion is treated
-as if it were input from the user. So, maps and executable buffers are
-simply pushed onto the stack from which keys are returned. The exception
-is that if the "remap" option is turned off, only a single map expansion
-is done. I intend to be fully backward compatible with this.
-
-Historically, if the mode of the editor changed (ex to vi or vice versa),
-any queued input was silently discarded. I don't see any reason to either
-support or not support this semantic. I intend to retain the queued input,
-mostly because it's simpler than throwing it away.
-
-Historically, neither the initial command on the command line (the + flag)
-or the +cmd associated with the ex and edit commands was subject to mapping.
-Also, while the +cmd appears to be subject to "@buffer" expansion, once
-expanded it doesn't appear to work correctly. I don't see any reason to
-either support or not support these semantics, so, for consistency, I intend
-to pass both the initial command and the command associated with ex and edit
-commands through the standard mapping and @ buffer expansion.
-
-One other difference between the historic ex/vi and nex/nvi is that nex
-displays the executed buffers as it executes them. This means that if
-the file is:
-
- set term=xterm
- set term=yterm
- set term=yterm
-
-the user will see the following during a typical edit session:
-
- nex testfile
- testfile: unmodified: line 3
- :1,$yank a
- :@a
- :set term=zterm
- :set term=yterm
- :set term=xterm
- :q!
-
-This seems like a feature and unlikely to break anything, so I don't
-intend to match historic practice in this area.
-
-The rest of this document is a set of conclusions as to how I believe
-the historic maps and @ buffers work. The summary is as follows:
-
-1: For buffers that are cut in "line mode", or buffers that are not cut
- in line mode but which contain portions of more than a single line, a
- trailing <newline> character appears in the input for each line in the
- buffer when it is executed. For buffers not cut in line mode and which
- contain portions of only a single line, no additional characters
- appear in the input.
-2: Executable buffers that execute other buffers don't load their
- contents until they execute them.
-3: Maps and executable buffers are copied when they are executed --
- they can be modified by the command but that does not change their
- actions.
-4: Historically, executable buffers are discarded if the editor
- switches between ex and vi modes.
-5: Executable buffers inside of map commands are expanded normally.
- Maps inside of executable buffers are expanded normally.
-6: If an error is encountered while executing a mapped command or buffer,
- the rest of the mapped command/buffer is discarded. No user input
- characters are discarded.
-7: Characters in executable buffers are remapped.
-8: Characters in executable buffers are not quoted.
-
-Individual test cases follow. Note, in the test cases, control characters
-are not literal and will have to be replaced to make the test cases work.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-1: For buffers that are cut in "line mode", or buffers that are not cut
- in line mode but which contain portions of more than a single line, a
- trailing <newline> character appears in the input for each line in the
- buffer when it is executed. For buffers not cut in line mode and which
- contain portions of only a single line, no additional characters
- appear in the input.
-
-=== test file ===
-3Gw
-w
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-=== end test file ===
-
- If the first line is loaded into 'a' and executed:
-
-1G"ayy@a
-
- The cursor ends up on the '2', a result of pushing "3Gw^J" onto
- the stack.
-
- If the first two lines are loaded into 'a' and executed:
-
-1G2"ayy@a
-
- The cursor ends up on the 'f' in "foo" in the fifth line of the
- file, a result of pushing "3Gw^Jw^J" onto the stack.
-
- If the first line is loaded into 'a', but not using line mode,
- and executed:
-
-1G"ay$@a
-
- The cursor ends up on the '1', a result of pushing "3Gw" onto
- the stack
-
- If the first two lines are loaded into 'a', but not using line mode,
- and executed:
-
-1G2"ay$@a
-
- The cursor ends up on the 'f' in "foo" in the fifth line of the
- file, a result of pushing "3Gw^Jw^J" onto the stack.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-2: Executable buffers that execute other buffers don't load their
- contents until they execute them.
-
-=== test file ===
-cwLOAD B^[
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-@a@b
-"byy
-=== end test file ===
-
- The command is loaded into 'e', and then executed. 'e' executes
- 'a', which loads 'b', then 'e' executes 'b'.
-
-5G"eyy6G"ayy1G@e
-
- The output should be:
-
-=== output file ===
-cwLOAD B^[
-LOAD B 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-@a@b
-"byy
-=== end output file ===
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-3: Maps and executable buffers are copied when they are executed --
- they can be modified by the command but that does not change their
- actions.
-
- Executable buffers:
-
-=== test file ===
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-@a@b
-"eyy
-cwEXECUTE B^[
-=== end test file ===
-
-4G"eyy5G"ayy6G"byy1G@eG"ep
-
- The command is loaded into 'e', and then executed. 'e' executes
- 'a', which loads 'e', then 'e' executes 'b' anyway.
-
- The output should be:
-
-=== output file ===
-line 1 foo bar baz
-EXECUTE B 2 foo bar baz
-line 3 foo bar baz
-@a@b
-"eyy
-cwEXECUTE B^[
-line 1 foo bar baz
-=== end output file ===
-
- Maps:
-
-=== test file ===
-Cine 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-=== end test file ===
-
- Entering the command ':map = :map = rB^V^MrA^M1G==' shows that
- the first time the '=' is entered the '=' map is set and the
- character is changed to 'A', the second time the character is
- changed to 'B'.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-4: Historically, executable buffers are discarded if the editor
- switches between ex and vi modes.
-
-=== test file ===
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-cwCHANGE^[Q:set
-set|visual|1Gwww
-=== end test file ===
-
-vi testfile
-4G"ayy@a
-
-ex testfile
-$p
-yank a
-@a
-
- In vi, the command is loaded into 'a' and then executed. The command
- subsequent to the 'Q' is (historically, silently) discarded.
-
- In ex, the command is loaded into 'a' and then executed. The command
- subsequent to the 'visual' is (historically, silently) discarded. The
- first set command is output by ex, although refreshing the screen usually
- causes it not to be seen.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-5: Executable buffers inside of map commands are expanded normally.
- Maps inside of executable buffers are expanded normally.
-
- Buffers inside of map commands:
-
-=== test file ===
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-cwREPLACE BY A^[
-=== end test file ===
-
-4G"ay$:map x @a
-1Gx
-
- The output should be:
-
-=== output file ===
-REPLACE BY A 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-cwREPLACE BY A^[
-=== end output file ===
-
- Maps commands inside of executable buffers:
-
-=== test file ===
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-X
-=== end test file ===
-
-:map X cwREPLACE BY XMAP^[
-4G"ay$1G@a
-
- The output should be:
-
-=== output file ===
-REPLACE BY XMAP 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-X
-=== end output file ===
-
- Here's a test that does both, repeatedly.
-
-=== test file ===
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-X
-Y
-cwREPLACED BY C^[
-blank line
-=== end test file ===
-
-:map x @a
-4G"ay$
-:map X @b
-5G"by$
-:map Y @c
-6G"cy$
-1Gx
-
- The output should be:
-
-=== output file ===
-REPLACED BY C 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-X
-Y
-cwREPLACED BY C^[
-blank line
-=== end output file ===
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-6: If an error is encountered while executing a mapped command or
- a buffer, the rest of the mapped command/buffer is discarded. No
- user input characters are discarded.
-
-=== test file ===
-line 1 foo bar baz
-line 2 foo bar baz
-line 3 foo bar baz
-:map = 10GcwREPLACMENT^V^[^[
-=== end test file ===
-
- The above mapping fails, however, if the 10G is changed to 1, 2,
- or 3G, it will succeed.
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-7: Characters in executable buffers are remapped.
-
-=== test file ===
-abcdefghijklmnnop
-ggg
-=== end test file ===
-
-:map g x
-2G"ay$1G@a
-
- The output should be:
-
-=== output file ===
-defghijklmnnop
-ggg
-=== end output file ===
-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-8: Characters in executable buffers are not quoted.
-
-=== test file ===
-iFOO^[
-
-=== end test file ===
-
-1G"ay$2G@a
-
- The output should be:
-
-=== output file ===
-iFOO^[
-FOO
-=== end output file ===
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
diff --git a/usr.bin/vi/docs/internals/quoting b/usr.bin/vi/docs/internals/quoting
deleted file mode 100644
index f20bd3f..0000000
--- a/usr.bin/vi/docs/internals/quoting
+++ /dev/null
@@ -1,219 +0,0 @@
-# @(#)quoting 5.4 (Berkeley) 8/20/93
-
-QUOTING IN EX/VI:
-
-There are two escape characters in historic ex/vi, ^V (or whatever
-character the user specified as their literal next character) and
-backslashes. There are two different areas in ex/vi where escaping
-is interesting: the command and text input modes, and within the ex
-commands themselves. In the examples below, ^V is used as the
-typical literal next character.
-
-1: Escaping characters in ex and vi command and text input modes.
- The set of characters that users might want to escape are as
- follows:
-
- vi text input mode (a, i, o, etc.):
-
- carriage return (^M)
- escape (^[)
- autoindent characters
- (^D, 0, ^, ^T)
- erase, word erase, and line erase
- (^H, ^W, ^U)
- newline (^J) (not historic practice)
- suspend (^Z) (not historic practice)
- repaint (^L) (not historic practice)
-
- vi command line (:colon commands):
-
- carriage return (^M)
- escape (^[)
- erase, word erase, and line erase
- (^H, ^W, ^U)
- newline (^J) (not historic practice)
- suspend (^Z) (not historic practice)
- repaint (^L) (not historic practice)
-
- ex text input mode (a, i, o, etc.):
-
- carriage return (^M)
- erase, word erase, and line erase
- (^H, ^W, ^U)
- newline (^J) (not historic practice)
-
- ex command line:
-
- carriage return (^M)
- erase, word erase, and line erase
- (^H, ^W, ^U)
- newline (^J) (not historic practice)
- suspend (^Z)
-
- I intend to follow historic practice for all of these cases, which
- was that ^V was the only way to escape any of these characters, and
- that whatever character followed the ^V was taken literally, i.e.
- ^V^V is a single ^V.
-
- The historic ex/vi disallowed the insertion of various control
- characters (^D, ^T, whatever) during various different modes, or,
- permitted the insertion of only a single one, or lots of other random
- behaviors (you can use ^D to enter a command in ex). I have
- regularized this behavior in nvi, there are no characters that cannot
- be entered or which have special meaning other than the ones listed
- above.
-
- One comment regarding the autoindent characters. In historic vi,
- if you entered "^V0^D" autoindent erasure was still triggered,
- although it wasn't if you entered "0^V^D". In nvi, if you escape
- either character, autoindent erasure is not triggered.
-
- This doesn't permit whitespace in command names, but that wasn't
- historic practice and doesn't seem worth doing.
-
- Fun facts to know and tell:
- The historic vi implementation for the 'r' command requires
- *three* ^V's to replace a single character with ^V.
-
-2: Ex commands:
-
- Ex commands are delimited by '|' or newline characters. Within
- the commands, whitespace characters delimit the arguments.
-
- I intend to treat ^V, followed by any character, as that literal
- character.
-
- This is historic behavior in vi, although there are special
- cases where it's impossible to escape a character, generally
- a whitespace character.
-
-3: Escaping characters in file names in ex commands:
-
- :cd [directory] (directory)
- :chdir [directory] (directory)
- :edit [+cmd] [file] (file)
- :ex [+cmd] [file] (file)
- :file [file] (file)
- :next [file ...] (file ...)
- :read [!cmd | file] (file)
- :source [file] (file)
- :write [!cmd | file] (file)
- :wq [file] (file)
- :xit [file] (file)
-
- I intend to treat a backslash in a file name, followed by any
- character, as that literal character.
-
- This is historic behavior in vi.
-
- In addition, since file names are also subject to word expansion,
- the rules for escape characters in section 3 of this document also
- apply. This is NOT historic behavior in vi, making it impossible
- to insert a whitespace, newline or carriage return character into
- a file name. This change could cause a problem if there were files
- with ^V's in their names, but I think that's unlikely.
-
-4: Escaping characters in non-file arguments in ex commands:
-
- :abbreviate word string (word, string)
-* :edit [+cmd] [file] (+cmd)
-* :ex [+cmd] [file] (+cmd)
- :k key (key)
- :map word string (word, string)
- :mark key (key)
-* :set [option ...] (option)
-* :tag string (string)
- :unabbreviate word (word)
- :unmap word (word)
-
- These commands use whitespace to delimit their arguments, and use
- ^V to escape those characters. The exceptions are starred in the
- above list, and are discussed below.
-
- In general, I intend to treat a ^V in any argument, followed by
- any character, as that literal character. This will permit
- editing of files name "foo|", for example, by using the string
- "foo\^V|", where the literal next character protects the pipe
- from the ex command parser and the backslash protects it from the
- shell expansion.
-
- This is backward compatible with historical vi, although there
- were a number of special cases where vi wasn't consistent.
-
-4.1: The edit/ex commands:
-
- The edit/ex commands are a special case because | symbols may
- occur in the "+cmd" field, for example:
-
- :edit +10|s/abc/ABC/ file.c
-
- In addition, the edit and ex commands have historically ignored
- literal next characters in the +cmd string, so that the following
- command won't work.
-
- :edit +10|s/X/^V / file.c
-
- I intend to handle the literal next character in edit/ex consistently
- with how it is handled in other commands.
-
- More fun facts to know and tell:
- The acid test for the ex/edit commands:
-
- date > file1; date > file2
- vi
- :edit +1|s/./XXX/|w file1| e file2|1 | s/./XXX/|wq
-
- No version of vi, of which I'm aware, handles it.
-
-4.2: The set command:
-
- The set command treats ^V's as literal characters, so the following
- command won't work. Backslashes do work in this case, though, so
- the second version of the command does work.
-
- set tags=tags_file1^V tags_file2
- set tags=tags_file1\ tags_file2
-
- I intend to continue permitting backslashes in set commands, but
- to also permit literal next characters to work as well. This is
- backward compatible, but will also make set consistent with the
- other commands. I think it's unlikely to break any historic
- .exrc's, given that there are probably very few files with ^V's
- in their name.
-
-4.3: The tag command:
-
- The tag command ignores ^V's and backslashes; there's no way to
- get a space into a tag name.
-
- I think this is a don't care, and I don't intend to fix it.
-
-5: Regular expressions:
-
- :global /pattern/ command
- :substitute /pattern/replace/
- :vglobal /pattern/ command
-
- I intend to treat a backslash in the pattern, followed by the
- delimiter character or a backslash, as that literal character.
-
- This is historic behavior in vi. It would get rid of a fairly
- hard-to-explain special case if we could just use the character
- immediately following the backslash in all cases, or, if we
- changed nvi to permit using the literal next character as a
- pattern escape character, but that would probably break historic
- scripts.
-
- There is an additional escaping issue for regular expressions.
- Within the pattern and replacement, the '|' character did not
- delimit ex commands. For example, the following is legal.
-
- :substitute /|/PIPE/|s/P/XXX/
-
- This is a special case that I will support.
-
-6: Ending anything with an escape character:
-
- In all of the above rules, an escape character (either ^V or a
- backslash) at the end of an argument or file name is not handled
- specially, but used as a literal character.
diff --git a/usr.bin/vi/docs/internals/structures b/usr.bin/vi/docs/internals/structures
deleted file mode 100644
index d49ab65..0000000
--- a/usr.bin/vi/docs/internals/structures
+++ /dev/null
@@ -1,61 +0,0 @@
-# @(#)structures 5.2 (Berkeley) 11/1/93
-
-There are three major data structures in this package. The first is a
-single global structure (named GS) which contains information common to
-all files and screens. It's really pretty tiny, and functions more as a
-single place to hang things than anything else.
-
-The second and third structures are the file structures (named EXF) and
-the screen structures (named SCR). They contain information theoretically
-unique to a screen or file, respectively. Each SCR structure has a set
-of functions which update the screen and/or return information about the
-screen from the underlying screen package.
-
-The GS structure contains linked lists SCR structures. The structures
-can also be classed by persistence. The GS structure never goes away
-and the SCR structure persists over instances of files.
-
-File names have different properties than files themselves, so the name
-information for a file is held in an FREF structure which is chained from
-the SCR structure.
-
-In general, functions are always passed an SCR structure and often an EXF
-structure as well. The SCR structure is necessary for any routine that
-wishes to talk to the screen, the EXF structure is necessary for any
-routine that wants to modify the file. The relationship between an SCR
-structure and its underlying EXF structure is not fixed, and although you
-can translate from an SCR to the underlying EXF, it is discouraged. If
-this becomes too onerous, I suspect I'll just stop passing around the EXF
-in the future.
-
-The naming of the structures is consistent across the program. (Macros
-even depend on it, so don't try and change it!) The global structure is
-"gp", the screen structure is "sp", and the file structure is "ep".
-
-A few other data structures:
-
-TEXT In nvi/cut.h. This structure describes a portion of a line,
- and is used by the input routines and as the "line" part of a
- cut buffer.
-
-CB In nvi/cut.h. A cut buffer. A cut buffer is a place to
- hang a list of TEXT structures.
-
-MARK In nvi/mark.h. A cursor position, consisting of a line number
- and a column number.
-
-MSG In nvi/msg.h. A chain of messages for the user.
-
-SEQ In nvi/seq.h. An abbreviation or a map entry.
-
-EXCMDARG
- In nvi/ex/excmd.h.stub. The structure that gets passed around
- to the functions that implement the ex commands. (The main
- ex command loop (see nvi/ex/ex.c) builds this up and then passes
- it to the ex functions.)
-
-VICMDARG
- In nvi/vi/vcmd.h. The structure that gets passed around to the
- functions that implement the vi commands. (The main vi command
- loop (see nvi/vi/vi.c) builds this up and then passes it to the
- vi functions.)
diff --git a/usr.bin/vi/docs/tutorial/vi.advanced b/usr.bin/vi/docs/tutorial/vi.advanced
deleted file mode 100644
index f757ad1..0000000
--- a/usr.bin/vi/docs/tutorial/vi.advanced
+++ /dev/null
@@ -1,1458 +0,0 @@
-Section 26: Index to the rest of the tutorial
-
-The remainder of the tutorial can be perused at your leisure. Simply find the
-topic of interest in the following list, and {/Section xx:/^M} to get to the
-appropriate section. (Remember that ^M means the return key)
-
-The material in the following sections is not necessarily in a bottom up
-order. It should be fairly obvious that if a section mentions something with
-which you are not familiar, say, buffers, you might {/buffer/^M} followed by
-several {n} to do a keyword search of the file for more details on that item.
-Another point to remember is that commands are surrounded by curly-braces and
-can therefore be found rather easily. To see where, say, the X command is
-used try {/{X}/^M}. Subsequent {n} will show you other places the command was
-used. We have tried to maintain the convention of placing the command letter
-surrounded by curly-braces on the section line where that command is
-mentioned.
-
-Finally, you should have enough 'savvy' at this point to be able to do your
-own experimentation with commands without too much hand-holding on the part of
-the tutorial. Experimentation is the best way to learn the effects of the
-commands.
-
- Section Topic - description
- ------- -------------------
-(Sections 1 through 25 are located in the file vi.beginner.)
- 1 introduction: {^F} {ZZ}
- 2 introduction (con't) and positioning: {^F} {^B}
- 3 introduction (con't) and positioning: {^F} {^B}
- 4 positioning: {^F} {^B} ^M (return key)
- 5 quitting: {:q!} ^M key
- 6 marking, cursor and screen positioning: {m} {G} {'} {z}
- 7 marking, cursor and screen positioning: {m} {G} {'} {z}
- 8 marking, cursor and screen positioning: {z} {m} {'}
- 9 marking and positioning: {m} {''}
- 10 line positioning: {^M} {-}
- 11 scrolling with {^M}
- 12 scrolling with {-} and screen adjustment {z}
- 13 notes on use of tutorial
- 14 other scrolling and postioning commands: {^E} {^Y} {^D} {^U}
- 15 searching: {/ .. /^M}
- 16 searching: {? .. ?^M} {n} (in search strings ^ $)
- 17 searching: \ and magic-characters in search strings
- 18 colon commands, exiting: {:} {ZZ}
- 19 screen positioning: {H} {M} {L}
- 20 character positioning: {w} {b} {0} {W} {B} {e} {E} {'} {`}
- 21 cursor positioning: {l} {k} {j} {h}
- 22 adding text: {i} {a} {I} {A} {o} {O} ^[ (escape key)
- 23 character manipulation: {f} {x} {X} {w} {l} {r} {R} {s} {S} {J}
- 24 undo: {u} {U}
- 25 review
-(The following sections are in this file.)
- 26 Index to the rest of the tutorial ******** YOU ARE HERE *******
- 27 discussion of repeat counts and the repeat command: {.}
- 28 more on low-level character motions: {t} {T} {|}
- 29 advanced correction operators: {d} {c}
- 30 updating the screen: {^R}
- 31 text buffers: {"}
- 32 rearranging and duplicating text: {p} {P} {y} {Y}
- 33 recovering lost lines
- 34 advanced file manipulation with vi
- 34.1 more than one file at a time: {:n}
- 34.2 reading files and command output: {:r}
- 34.3 invoking vi from within vi: {:e} {:vi}
- 34.4 escaping to a shell: {:sh} {:!}
- 34.5 writing parts of a file: {:w}
- 34.6 filtering portions of text: {!}
- 35 advanced searching: magic patterns
- 36 advanced substitution: {:s}
- 37 advanced line addressing: {:p} {:g} {:v}
- 38 higher level text objects and nroff: ( ) { } [[ ]]
- 39 more about inserting text
- 40 more on operators: {d} {c} {<} {>} {!} {=} {y}
- 41 abbreviations: {:ab}
- 42 vi's relationship with the ex editor: {:}
- 43 vi on hardcopy terminals and dumb terminals: open mode
- 44 options: {:set} {setenv EXINIT}
- 44.1 autoindent
- 44.2 autoprint
- 44.3 autowrite
- 44.4 beautify
- 44.5 directory
- 44.6 edcompatible
- 44.7 errorbells
- 44.8 hardtabs
- 44.9 ignorecase
- 44.10 lisp
- 44.11 list
- 44.12 magic
- 44.13 mesg
- 44.14 number
- 44.15 open
- 44.16 optimize
- 44.17 paragraphs
- 44.18 prompt
- 44.19 readonly
- 44.20 redraw
- 44.21 remap
- 44.22 report
- 44.23 scroll
- 44.24 sections
- 44.25 shell
- 44.26 shiftwidth
- 44.27 showmatch
- 44.28 slowopen
- 44.29 tabstop
- 44.30 tags
- 44.31 taglength
- 44.32 term
- 44.33 terse
- 44.34 timeout
- 44.35 ttytype
- 44.36 warn
- 44.37 window
- 44.38 wrapscan
- 44.39 wrapmargin
- 44.40 writeany
- 44.41 w300, w1200, w9600
-
-Section 27: repetition counts and the repeat command {.}
-
-Most vi commands will use a preceding count to affect their behavior in some
-way. We have already seen how {3x} deletes three characters, and {22G} moves
-us to line 22 of the file. For almost all of the commands, one can survive by
-thinking of these leading numbers as a 'repeat count' specifying that the
-command is to be repeated so many number of times.
-
-Other commands use the repeat count slightly differently, like the {G} command
-which use it as a line number.
-
-For example:
-
-{3^D} means scroll down in the file three lines. Subsequent {^D} OR {^U} will
-scroll only three lines in their respective directions!
-
-{3z^M} says put line three of the file at the top of the screen, while {3z.}
-says put line three as close to the middle of the screen as possible.
-
-{50|} moves the cursor to column fifty in the current line.
-
-{3^F} says move forward 3 screenfulls. This is a repetition count. The
-documents advertise that {3^B} should move BACK three screenfulls, but I
-can't get it to work.
-
-Position the cursor on some text and try {3r.}. This replaces three characters
-with '...'. However, {3s.....^[} is the same as {3xi.....^[}.
-
-Try {10a+----^[}.
-
-A very useful instance of a repetition count is one given to the '.' command,
-which repeats the last 'change' command. If you {dw} and then {3.}, you will
-delete first one and then three words. You can then delete two more words with
-{2.}. If you {3dw}, you will delete three words. A subsequent {.} will delete
-three more words. But a subsequent {2.} will delete only two words, not three
-times two words.
-
-Caveat: The author has noticed that any repetition count with {^B} will NOT
-work: indeed, if you are at the end of your file and try {3^B} sufficiently
-often, the editor will hang you in an infinite loop. Please don't try it:
-take my word for it.
-
-Section 28: {t} {T} {|}
-
-Position the cursor on line 13 below:
-
-Line 13: Four score and seven years ago, our forefathers brought ...
-
-Note that {fv} moves the cursor on/over the 'v' in 'seven'. Do a {0} to return
-to the beginning of the line and try a {tv}. The cursor is now on/over the
-first 'e' in 'seven'. The {f} command finds the next occurrence of the
-specified letter and moves the cursor to it. The {t} command finds the
-specified letter and moves the cursor to the character immediately preceding
-it. {T} searches backwards, as does {F}.
-
-Now try {60|}: the cursor is now on the 'o' in 'brought', which is the
-sixtieth character on the line.
-
-Section 29: {d} {c}
-
-Due to their complexity we have delayed discussion of two of the most powerful
-operators in vi until now. Effective use of these operators requires more
-explanation than was deemed appropriate for the first half of the tutorial.
-
-{d} and {c} are called operators instead of commands because they consist of
-three parts: a count specification or a buffer specification (see section
-#BUFFERS), the {d} or {c}, and the object or range description. We will not
-discuss buffers at this stage, but will limit ourselves to count
-specifications. Examples speak louder than words: position the cursor at the
-beginning of line 14:
-
-Line 14: Euclid alone has looked on beauty bear.
-
-Obviously, there is something wrong with this quotation. Type {2fb} to
-position the cursor on the 'b' of 'bear'. Now, type {cwbare^[}
-and observe the results. The {cw} specifies that the change command {c} is to
-operate on a word object. More accurately, it specifies that the range of the
-change command includes the next word.
-
-Position the cursor on the period in Line 14. (one way is to use {f.})
-Now, type {cbbeast^[}. This specifies the range of the change command to be the
-previous word (the 'b' reminiscent of the {b} command). If we had wished to
-delete the word rather than change it, we would have used the {d} operator,
-rather than the {c} operator.
-
-Position the cursor at the beginning of the line with {0}. Type
-{d/look/^M}. The search string specified the range of the delete.
-Everything UP TO the word 'looking' was deleted from the line.
-
-In general, almost any command that would move the cursor will specify a range
-for these commands. The most confusing exception to this rule is when {dd} or
-{cc} is entered: they refer to the whole line. Following is a summary of the
-suffixes (suffices? suffici?) and the ranges they specify:
-
- suffix will delete{d}/change{c}
- ------ ------------------------
- ^[ cancels the command
- w the word to the right of the cursor
- W ditto, but ignoring punctuation
- b the word to the left of the cursor
- B ditto, but ignoring punctuation
- e see below.
- E ditto
- (space) a character
- $ to the end of the line
- ^ to the beginning of the line
- / .. / up to, but not including, the string
- ? .. ? back to and including the string
- fc up to and including the occurrence of c
- Fc back to and including the occurrence of c
- tc up to but not including the occurrence of c
- Tc back to but not including the occurrence of c
- ^M TWO lines (that's right: two)
- (number)^M that many lines plus one
- (number)G up to and including line (number)
- ( the previous sentence if you are at the beginning of
- the current sentence, or the current sentence up to where
- you are if you are not at the beginning of the current
- sentence. Here, 'sentence' refers to the intuitive
- notion of an English sentence, ending with '!', '?',
- or '.' and followed by an end of line or two spaces.
- ) the rest of the current sentence
- { analogous to '(', but in reference to paragraphs:
- sections of text surrounded by blank lines
- } analogous to ')', but in reference to paragraphs
- [[ analogous to '(', but in reference to sections
- ]] analogous to ')', but in reference to sections
- H the first line on the screen
- M the middle line on the screen
- L the last line on the screen
- 3L through the third line from the bottom of the screen
- ^F forward a screenful
- ^B backward a screenful
- :
- : etc. etc. etc.
-
-This list is not exhaustive, but it should be sufficient to get the idea
-across: after the {c} or {d} operator, you can specify a range with another
-move-the-cursor command, and that is the region of text over which the command
-will be effective.
-
-Section 30: updating the screen {^R}
-
-Vi tries to be very intelligent about the type of terminal you are working on
-and tries to use the in-terminal computing power (if any) of your terminal.
-Also if the terminal is running at a low baud rate (say 1200 or below), vi sets
-various parameters to make things easier for you. For example, if you were
-running on a 300 baud terminal (that's 30 characters per second transmission
-rate) not all 24 lines of the screen would be used by vi. In addition, there
-is a large portion of the editor keeping track of what your screen currently
-looks like, and what it would look like after a command has been executed. Vi
-then compares the two, and updates only those portions of the screen that have
-changed.
-
-Furthermore, some of you may have noticed (it depends on your terminal) that
-deleting lines or changing large portions of text may leave some lines on the
-screen looking like:
-@
-meaning that this line of the screen does not correspond to any line in your
-file. It would cost more to update the line than to leave it blank for the
-moment. If you would like to see your screen fully up-to-date with the
-contents of your file, type {^R}.
-
-To see it in action, delete several lines with {5dd}, type {^R}, and then type
-{u} to get the lines back.
-
-Here is as good a place as any to mention that if the editor is displaying the
-end of your file, there may be lines on the screen that look like:
-~
-indicating that that screen line would not be affected by {^R}. These lines
-simply indicate the end of the file.
-
-Section 31: text buffers {"}
-
-Vi gives you the ability to store text away in "buffers". This feature is very
-convenient for moving text around in your file. There are a total of thirty-
-five buffers available in vi. There is the "unnamed" buffer that is used by all
-commands that delete text, including the change operator {c}, the substitute
-and replace commands {s} and {r}, as well as the delete operator {d} and delete
-commands {x} and {X}. This buffer is filled each time any of these commands
-are used. However, the undo command {u} has no effect on the unnamed buffer.
-
-There are twenty-six buffers named 'a' through 'z' which are available for the
-user. If the name of the buffer is capitalized, then the buffer is not
-overwritten but appended to. For example, the command {"qdd} will delete one
-line and store that line in the 'q' buffer, destroying the previous contents of
-the buffer. However, {"Qdd} will delete one line of text and append that line
-to the current contents of the 'q' buffer.
-
-Finally, there are nine buffers named '1' through '9' in which the last nine
-deletes are stored. Buffer 1 is the default buffer for the modify commands and
-is sometimes called the unnamed buffer.
-
-To reference a specific buffer, use the double-quote command {"} followed by
-the name of the buffer. The next two sections show how buffers can be used to
-advantage.
-
-Section 32: rearranging and duplicating text: {y} {Y} {p} {P}
-
-Position yourself on line 15 below and {z^M}:
-
-Line 15: A tree as lovely as a poem ...
-Line 16: I think that I shall never see
-
-Type {dd}. Line 15 has disappeared and been replaced with the empty line (one
-with the single character @ on it) or (again depending on your terminal) Line
-16 has moved up and taken its place. We could recover Line 15 with an undo
-{u} but that would simply return it to its original location. Obviously, the
-two lines are reversed, so we want to put line 15 AFTER line 16. This is
-simply done with the put command {p}, which you should type now. What has
-happened is that {dd} put Line 15 into the unnamed buffer, and the {p} command
-retrieved the line from the unnamed buffer.
-
-Now type {u} and observe that Line 15 disappears again (the put was undone
-without affecting the unnamed buffer). Type {P} and see that the capital {P}
-puts the line BEFORE the cursor.
-
-To get Line 15 where it belongs again type {dd}{p}.
-
-Also in Line 15 note that the words 'tree' and 'poem' are reversed. Using the
-unnamed buffer again: {ft}{dw}{ma}{fp}{P}{w}{dw}{`aP} will set things aright
-(note the use of the reverse quote).
-
-The put commands {p} and {P} do not affect the contents of the buffer.
-Therefore, multiple {p} or {P} will put multiple copies of the unnamed buffer
-into your file.
-
-Experiment with {d} and {p} on words, paragraphs, etc. Whatever {d}
-deletes, {p} can put.
-
-Position the cursor on Line 17 and {z^M}:
-
-Line 17: interest apple cat elephant boy dog girl hay farmer
-
-Our task is to alphabetize the words on line 17. With the named buffers (and a
-contrived example) it is quite easy:
-
-{"idw}{"adw}{"cdw}{"edw}{"bdw}{"ddw}{"gdw}{"hdw}{"fdw}
-
-stores each of the words in the named buffer corresponding to the first letter
-of each of the words ('interest' goes in buffer "i, 'apple' goes in buffer "a,
-etc.). Now to put the words in order type:
-
-{"ap$}{"bp$}{"cp$}{"dp$}{"ep$}{"fp$}{"gp$}{"hp$}{"ip$}
-
-Notice that, because 'farmer' was at the end of the line, {dw} did not include
-a space after it, and that, therefore, there is no space between 'farmer' and
-'girl'. This is corrected with {Fg}{i ^[}.
-
-This example could have been done just as easily with lines as with
-words.
-
-You do not have to delete the text in order to put it into a buffer. If all
-you wish to do is to copy the text somewhere else, don't use {d}, rather use
-the yank commands {y} or {Y}. {y} is like {d} and {c} - an operator rather
-than a command. It, too, takes a buffer specification and a range
-specification. Therefore, instead of {dw}{P} to load the unnamed buffer with a
-word without deleting the word, use {yw} (yank a word).
-
-{Y} is designed yank lines, and not arbitrary ranges. That is, {Y} is
-equivalent to {yy} (remember that operators doubled means the current line),
-and {3Y} is equivalent to {3yy}.
-
-If the text you yank or modify forms a part of a line, or is an object such as
-a sentence which partially spans more than one line, then when you put the text
-back, it will be placed after the cursor (or before if you use {P}). If the
-yanked text forms whole lines, they will be put back as whole lines, without
-changing the current line. In this case, the put acts much like the {o} or {O}
-command.
-
-The named buffers "a through "z are not affected by changing edit files.
-However, the unnamed buffer is lost when you change files, so to move text from
-one file to another you should use a named buffer.
-
-Section 33: recovering lost lines
-
-Vi also keeps track of the last nine deletes, whether you ask for it or not.
-This is very convenient if you would like to recover some text that was
-accidentally deleted or modified. Position the cursor on line 18 following,
-and {z^M}.
-
-
-Line 18: line 1
-Line 19: line 2
-Line 20: line 3
-Line 21: line 4
-Line 22: line 5
-Line 23: line 6
-Line 24: line 7
-Line 25: line 8
-Line 26: line 9
-Type {dd} nine times: now don't cheat with {9dd}! That is totally different.
-
-The command {"1p} will retrieve the last delete. Furthermore, when the
-numbered buffers are used, the repeat-command command {.} will increment the
-buffer numbers before executing, so that subsequent {.} will recover all nine
-of the deleted lines, albeit in reverse order. If you would like to review the
-last nine deletes without affecting the buffers or your file, do an undo {u}
-after each put {p} and {.}:
-
-{"1p}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}
-
-will show you all the buffers and leave them and your file intact.
-
-If you had cheated above and deleted the nine lines with {9dd}, all nine lines
-would have been stored in both the unnamed buffer and in buffer number 1.
-(Obviously, buffer number 1 IS the unnamed buffer and is just the default
-buffer for the modify commands.)
-
-Section 34: advanced file manipulation: {:r} {:e} {:n} {:w} {!} {:!}
-
-We've already looked at writing out the file you are editing with the
-{:w} command. Now let's look at some other vi commands to make editing
-more efficient.
-
-Section 34.1: more than one file at a time {:n} {:args}
-
-Many times you will want to edit more than one file in an editing session.
-Instead of entering vi and editing the first file, exiting, entering vi and
-editing the second, etc., vi will allow you to specify ALL files that you wish
-to edit on the invocation line. Therefore, if you wanted to edit file1 and
-file2:
-
-% vi file1 file2
-
-will set up file1 for editing. When you are done editing file one, write it
-out {:w^M} and then type {:n^M} to get the next file on the list. On large
-programming projects with many source files, it is often convenient just to
-specify all source files with, say:
-
-% vi *.c
-
-If {:n^M} brings in a file that does not need any editing, another {:n^M}
-will bring in the next file.
-
-If you have made changes to the first file, but decide to discard these changes
-and proceed to the next file, {:n!^M} forces the editor to discard the current
-contents of the editor.
-
-You can specify a new list of files after {:n}; e.g., {:n f1 f2 f3^M}. This
-will replace the current list of files (if any).
-
-You can see the current list of files being edited with {:args^M}.
-
-Section 34.2: reading files and command output: {:r}
-
-Typing {:r fname^M} will read the contents of file fname into the editor and
-put the contents AFTER the cursor line.
-
-Typing {:r !cmd^M} will read the output of the command cmd and place that
-output after the cursor line.
-
-Section 34.3: invoking vi from within vi: {:e} {:vi}
-
-To edit another file not mentioned on the invocation line, type {:e filename^M}
-or {:vi filename^M}. If you wish to discard the changes to the current file,
-use the exclamation point after the command, e.g. {:e! filename^M}.
-
-Section 34.4: escaping to a shell: {:sh} {:!} {^Z}
-
-Occasionally, it is useful to interrupt the current editing session to perform
-a UNIX task. However, there is no need to write the current file out, exit
-the editor, perform the task, and then reinvoke the editor on the same file.
-One thing to do is to spin off another process. If there are several UNIX
-commands you will need to execute, simply create another shell with {:sh^M}.
-At this point, the editor is put to sleep and will be reawakened when you log
-out of the shell.
-
-If it is a single command that you want to execute, type {:!cmd^M}, where cmd
-is the command that you wish to run. The output of the command will come to
-the terminal as normal, and will not be made part of your file. The message
-"[Hit return to continue]" will be displayed by vi after the command is
-finished. Hitting return will then repaint the screen. Typing another
-{:!cmd^M} at this point is also acceptable.
-
-However, there is a quicker, easier way: type {^Z}. Now this is a little
-tricky, but hang in there. When you logged into UNIX, the first program you
-began communicating with was a program that is called a "shell" (i.e. it 'lays
-over' the operating system protecting you from it, sort of like a considerate
-porcupine). When you got your first prompt on the terminal (probably a '%'
-character) this was the shell telling you to type your first command. When
-you typed {vi filename} for some file, the shell did not go away, it just went
-to sleep. The shell is now the parent of vi. When you type {^Z} the editor
-goes to sleep, the shell wakes up and says "you rang?" in the form of another
-prompt (probably '%'). At this point you are talking to the shell again and
-you can do anything that you could before including edit another file! (The
-only thing you can't do is log out: you will get the message "There are
-stopped jobs.")
-
-When your business with the shell is done, type {fg} for 'foreground' and the
-last process which you ^Z'd out of will be reawakened and the shell will go
-back to sleep. I will refer you to the documentation for the Berkeley shell
-'csh' for more information on this useful capability.
-
-Section 34.5: writing parts of a file: {:w}
-
-The {:w} command will accept a range specifier that will then write only a
-selected range of lines to a file. To write this section to a file, position
-the cursor on the section line (e.g. {/^Section 34.5:/^M}) and {z^M}. Now type
-{^G} to find out the line number (it will be something like "line 513"). Now
-{/^Section 34.6:/-1^M} to find the last line of this section, and {^G} to find
-its line number (it will be something like 542). To write out this section of
-text by itself to a separate file which we will call "sepfile", type
-{:510,542w sepfile^M}. If sepfile already exists, you will have to use the
-exclamation point: {:1147,1168w! sepfile^M} or write to a different, non-
-existent file.
-
-{:!cat sepfile^M} will display the file just written, and it should be the
-contents of this section.
-
-There is an alternate method of determining the line numbers for the write.
-{:set number^M} will repaint the screen with each line numbered. When the file
-is written and the numbers no longer needed, {:set nonumber^M} will remove the
-numbers, and {^R} will adjust the screen.
-
-Or, if you remember your earlier lessons about marking lines of text,
-mark the beginning and ending lines. Suppose we had used {ma} to mark the
-first line of the section and {mb} to mark the last. Then the command
-{:'a,'bw sepfile^M} will write the section into "sepfile". In general,
-you can replace a line number with the 'name' of a marked line (a single-quote
-followed by the letter used to mark the line)
-
-
-Section 34.6: filtering portions of text: {!}
-
-{!} is an operator like {c} and {d}. That is, it consists of a repetition
-count, {!}, and a range specifier. Once the {!} operator is entered in its
-entirety, a prompt will be given at the bottom of the screen for a UNIX
-command. The text specified by the {!} operator is then deleted and
-passed/filtered/piped to the UNIX command you type. The output of the UNIX
-command is then placed in your file. For example, place the cursor at the
-beginning of the following line and {z^M}:
-
-ls -l vi.tutorial
-********* marks the bottom of the output from the ls command **********
-
-Now type {!!csh^M}. The line will be replaced with the output from the ls
-command. The {u} command works on {!}, also.
-
-Here is an extended exercise to display some of these capabilities. When this
-tutorial was prepared, certain auxiliary programs were created to aid in its
-development. Of major concern was the formatting of sections of the tutorial
-to fit on a single screen, particularly the first few sections. What was
-needed was a vi command that would 'format' a paragraph; that is, fill out
-lines with as many words as would fit in eighty columns. There is no such vi
-command. Therefore, another method had to be found.
-
-Of course, nroff was designed to do text formatting. However, it produces a
-'page'; meaning that there may be many blank lines at the end of a formatted
-paragraph from nroff. The awk program was used to strip these blank lines from
-the output from nroff. Below are the two files used for this purpose: I refer
-you to documentation on nroff and awk for a full explanation of their function.
-Position the cursor on the next line and {z^M}.
-
-******** contents of file f **********
-#
-nroff -i form.mac | awk "length != 0 { print }"
-***** contents of file form.mac ******
-.na
-.nh
-.ll 79
-.ec 
-.c2 
-.cc 
-**************************************
-
-Determine the line numbers of the two lines of file f. They should be
-something like 574 and 575, although you better double check: this file is
-under constant revision and the line numbers may change inadvertently. Then
-{:574,575w f^M}. Do the same for the lines of file form.mac. They will be
-approximately 577 and 582. Then {:577,582w form.mac^M}. File f must have
-execute privileges as a shell file: {:!chmod 744 f^M}.
-
-Observe that this paragraph is
-rather ratty in appearance. With our newly created files we can
-clean it up dramatically. Position the cursor at the beginning
-of this paragraph and type the following sequence of
-characters
-(note that we must abandon temporarily our convention
-of curly braces since the command itself contains a curly brace - we
-will use square brackets for the nonce): [!}f^M].
-
-Here is a brief explanation of what has happened. By typing [!}f^M] we
-specified that the paragraph (all text between the cursor and the first blank
-line) will be removed from the edit file and piped to a UNIX program called
-"f". This is a shell command file that we have created. This shell file runs
-nroff, pipes its output to awk to remove blank lines, and the output from awk
-is then read back into our file in the place of the old, ratty paragraph. The
-file form.mac is a list of commands to nroff to get it to produce paragraphs
-to our taste (the right margin is not justified, the line is 79 characters
-long, words are not hyphenated, and three nroff characters are renamed to
-avoid conflict: note that in this file, the {^G} you see there is vi's display
-of the control-G character, and not the two separate characters ^ up-arrow and
-G upper-case g).
-
-This example was created before the existence of the fmt program. I now type
-[!}fmt^M] to get the same effect much faster. Actually, I don't type those
-six keys each time: I have an abbreviation (which see).
-
-Section 35: searching with magic patterns
-
-The documentation available for "magic patterns" (i.e. regular expressions) is
-very scanty. The following should explain this possibly very confusing feature
-of the editor. This section assumes that the magic option is on. To make
-sure, you might want to type {:set magic^M}.
-
-By "magic pattern" we mean a general description of a piece of text that the
-editor attempts to find during a search. Most search patterns consist of
-strings of characters that must be matched exactly, e.g. {/card/^M} searches
-for a specific string of four characters. Let us suppose that you have
-discovered that you consistently have mistyped this simple word as either ccrd
-or czrd (this is not so far-fetched for touch typists). You could {/ccrd/^M}
-and {n} until there are no more of this spelling, followed by {/czrd/^M} and
-{n} until there are no more of these. Or you could {/c.rd/^M} and catch all of
-them on the first pass. Try typing {/c.rd/^M} followed by several {n} and
-observe the effect.
-
-Line 27: card cord curd ceard
-
-When '.' is used in a search string, it has the effect of matching any single
-character.
-
-The character '^' (up-arrow) used at the beginning of a search string means
-the beginning of the line. {/^Line 27/^M} will find the example line above,
-while {/Line 27/^M} will find an occurrence of this string anywhere in the
-line.
-
-Similarly, {/ the$/^M} will find all occurrences of the word 'the' occurring
-at the end of a line. There are several of them in this file.
-
-Note that {:set nomagic^M} will turn off the special meaning of these magic
-characters EXCEPT for '^' and '$' which retain their special meanings at the
-beginning and end of a search string. Within the search string they hold no
-special meaning. Try {/\/ the$\//^M} and note that the dollar-sign is not the
-last character in the search string. Let the dollar-sign be the last
-character in the search string, as in {/\/ the$/^M} and observe the result.
-
-Observe the result of {/back.*file/^M}. This command, followed by sufficient
-{n}, will show you all lines in the file that contain both the words 'back'
-and 'file' on the same line. The '*' magic character specifies that the
-previous regular expression (the '.' in our example) is to be repeatedly
-matched zero or more times. In our example we specified that the words 'back'
-and 'file' must appear on the same line (they may be parts of words such as
-'backwards' or 'workfile') separated by any number (including zero) of
-characters.
-
-We could have specified that 'back' and 'file' are to be words by themselves by
-using the magic sequences '\<' or '\>'. E.g. {/\<back\>.*\<file\>/^M}. The
-sequence '\<' specifies that this point of the search string must match the
-beginning of a word, while '\>' specifies a match at the end of a word. By
-surrounding a string with these characters we have specified that they must be
-words.
-
-To find all words that begin with an 'l' or a 'w', followed by an 'a' or an
-'e', and ending in 'ing', try {/\<[lw][ea][a-z]*ing\>/^M}. This will match
-words like 'learning', 'warning', and 'leading'. The '[..]' notation matches
-exactly ONE character. The character matched will be one of the characters
-enclosed in the square brackets. The characters may be specified individually
-as in [abcd] or a '-' may be used to specify a range of characters as in [a-d].
-That is, [az] will match the letter 'a' OR the letter 'z', while [a-z] will
-match any of the lower case letters from 'a' through 'z'. If you would like to
-match either an 'a', a '-', or a 'z', then the '-' must be escaped: [a\-z] will
-match ONE of the three characters 'a', '-', or 'z'.
-
-If you wish to find all Capitalized words, try {/\<[A-Z][a-z]*\>/^M}. The
-following will find all character sequences that do NOT begin with an
-uncapitalized letter by applying a special meaning to the '^' character in
-square brackets: {/\<[^a-z][a-z]*\>/^M}. When '^' is the first character of a
-square-bracket expression, it specifies "all but these characters". (No
-one claimed vi was consistent.)
-
-To find all variable names (the first character is alphabetic, the remaining
-characters are alphanumeric): try {/\<[A-Za-z][A-Za-z0-9]*\>/^M}.
-
-In summary, here are the primitives for building regular expressions:
-
- ^ at beginning of pattern, matches beginning of line
- $ at end of pattern, matches end of line
- . matches any single character
- \< matches the beginning of a word
- \> matches the end of a word
- [str] matches any single character in str
- [^str] matches any single character NOT in str
- [x-y] matches any character in the ASCII range between x and y
- * matches any number (including zero) of the preceding pattern
-
-Section 36: advanced substitution: {:s}
-
-The straightforward colon-substitute command looks like the substitute
-command of most line-oriented editors. Indeed, vi is nothing more than a
-superstructure on the line-oriented editor ex and the colon commands are
-simply a way of accessing commands within ex (see section #EX). This gives us
-a lot of global file processing not usually found in visual oriented editors.
-
-The colon-substitute command looks like: {:s/ .. / .. /^M} and will find the
-pattern specified after the first slash (this is called the search pattern),
-and replace it with the pattern specified after the second slash (called,
-obviously enough, the replacement pattern). E.g. position the cursor on line
-28 below and {:s/esample/example/^M}:
-
-Line 28: This is an esample.
-
-The {u} and {U} commands work for {:s}. The first pattern (the search pattern)
-may be a regular expression just as for the search command (after all, it IS a
-search, albeit limited to the current line). Do an {u} on the above line, and
-try the following substitute, which will do almost the same thing:
-{:s/s[^ ]/x/^M}.
-Better undo it with {u}. The first pattern {s[^ ]} matches an 's'
-NOT followed by a blank: the search therefore ignores the 's'es in 'This' and
-'is'. However, the character matched by {[^ ]} must appear in the replacement
-pattern. But, in general, we do not know what that character is! (In this
-particular example we obviously do, but more complicated examples will follow.)
-Therefore, vi (really ex) has a duplication mechanism to copy patterns matched
-in the search string into the replacement string. Line 29 below is a copy of
-line 28 above so you can adjust your screen.
-
-Line 29: This is an esample.
-
-In general, you can nest parts of the search pattern in \( .. \) and refer to
-it in the replacement pattern as \n, where n is a digit. The problem outlined
-in the previous paragraph is solved with {:s/s\([^ ]\)/x\1/^M}: try it. Here
-\1 refers to the first pattern grouping \( .. \) in the search string.
-
-Obviously, for a single line, this is rather tedious. Where it becomes
-powerful, if not necessary, is in colon-substitutes that cover a range of
-lines. (See the next section for a particularly comprehensive example.)
-
-If the entire character sequence matched by the search pattern is needed in
-the replacement pattern, then the unescaped character '&' can be used. On
-Line 29 above, try {:s/an e.ample/not &/^M}. If another line is to have the
-word 'not' prepended to a pattern, then '~' can save you from re-typing the
-replacement pattern. E.g. {:s/some pattern/~/^M} after the previous example
-would be equivalent to {:s/some pattern/not &/^M}.
-
-One other useful replacement pattern allows you to change the case of
-individual letters. The sequences {\u} and {\l} cause the immediately
-following character in the replacement to be converted to upper- or lower-case,
-respectively, if this character is a letter. The sequences {\U} and {\L} turn
-such conversion on, either until {\E} or {\e} is encountered, or until the end
-of the replacement pattern.
-
-For example, position the cursor on a line: pick a line, any line. Type
-{:s/.*/\U&/^M} and observe the result. You can undo it with {u}.
-
-The search pattern may actually match more than once on a single line.
-However, only the first pattern is substituted. If you would like ALL
-patterns matched on the line to be substituted, append a 'g' after the
-replacement pattern: {:s/123/456/g^M} will substitute EVERY occurrence
-on the line of 123 with 456.
-
-Section 37: advanced line addressing: {:p} {:g} {:v}
-
-Ex (available through the colon command in vi) offers several methods for
-specifying the lines on which a set of commands will act. For example, if you
-would like to see lines 50 through 100 of your file: {:50,100p^M} will display
-them, wait for you to [Hit return to continue], and leave you on line 100.
-Obviously, it would be easier just to do {100G} from within vi. But
-what if you would like to make changes to just those lines? Then the
-addressing is important and powerful.
-
-Line 30: This is a text.
-Line 31: Here is another text.
-Line 32: One more text line.
-
-The lines above contain a typing error that the author of this tutorial tends
-to make every time he attempts to type the word 'test'. To change all of these
-'text's into 'test's, try the following:
-{:/^Line 30/,/^Line 32/s/text/test/^M}. This finds the beginning and end of
-the portion of text to be changed, and limits the substitution to each of the
-lines in that range. The {u} command applies to ALL of the substitutions as
-a group.
-
-This provides a mechanism for powerful text manipulations.
-And very complicated examples.
-
-Line 33: This test is a.
-Line 34: Here test is another.
-Line 35: One line more test.
-
-The above three lines have the second word out of order. The following command
-string will put things right. Be very careful when typing this: it is very
-long, full of special characters, and easy to mess up. You may want to
-consider reading the following section to understand it before trying the
-experiment. Don't worry about messing up the rest of the file, though: the
-address range is specified.
-
-{:/^Line 33/,/^Line 35/s/\([^:]*\): \([^ ]*\) \([^ ]*\) \([^.]*\)/\1: \2 \4 \3/^M}
-
-There are several things to note about this command string. First of all, the
-range of the substitute was limited by the address specification {/^Line
-33/,/^Line 35/^M}. It might have been simpler to do {:set number^M} to see the
-line numbers directly, and then, in place of the two searches, typed
-the line numbers, e.g. {1396,1398}. Or to mark the lines with {ma} and {mb}
-and use {'a,'b}.
-
-Then follows the substitute pattern itself. To make it easier to understand
-what the substitute is doing, the command is duplicated below with the various
-patterns named for easier reference:
-
- s/\([^:]*\): \([^ ]*\) \([^ ]*\) \([^.]*\)/\1: \2 \4 \3/
- |--\1---| |--\2---| |--\3---| |--\4---|
- |--------search pattern------------------|-replacement|
- |--pattern---|
-
-In overview, the substitute looks for a particular pattern made up of
-sub-patterns, which are named \1, \2, \3, and \4. These patterns are specified
-by stating what they are NOT. Pattern \1 is the sequence of characters that
-are NOT colons: in the search string, {[^:]} will match exactly one character
-that is not a colon, while appending the asterisk {[^:]*} specifies that the
-'not a colon' pattern is to be repeated until no longer satisfied, and
-{\([^:]*\)} then gives the pattern its name, in this case \1. Outside of the
-specification of \1 comes {: }, specifying that the next two characters must be
-a colon followed by a blank.
-
-Patterns \2 and \3 are similar, specifying character sequences that are
-not blanks. Pattern \4 matches up to the period at the end of the line.
-
-The replacement pattern then consists of specifying the new order of the
-patterns.
-
-This is a particularly complicated example, perhaps the most complicated
-in this tutorial/reference. For our small examples, it is obviously
-tedious and error prone. For large files, however, it may be the most
-efficient way to make the desired modifications.
-
-(The reader is advised to look at the documentation for awk. This tool is very
-powerful and slightly simpler to use than vi for this kind of file
-manipulation. But, it is another command language to learn.)
-
-Many times, you will not want to operate on every line in a certain
-range. Rather you will want to make changes on lines that satisfy
-certain patterns; e.g. for every line that has the string 'NPS' on it,
-change 'NPS' to 'Naval Postgraduate School'. The {:g} addressing
-command was designed for this purpose. The example of this paragraph
-could be typed as {:g/NPS/s//Naval Postgraduate School/^M}.
-
-The general format of the command is {:g/(pattern)/cmds^M} and it
-works in the following way: all lines that match the pattern
-following the {:g} are 'tagged' in a special way. Then each of these
-lines have the commands following the pattern executed over them.
-
-Line 36: ABC rhino george farmer Dick jester lest
-Line 37: george farmer rhino lest jester ABC
-Line 38: rhino lest george Dick farmer ABC jester
-
-Type:
-
-{:g/^Line.*ABC/s/Dick/Harry Binswanger/|s/george farmer/gentleman george/p^M}
-
-There are several things of note here. First, lines 36, 37, and 38 above are
-tagged by the {:g}. Type {:g/^Line.*ABC/p^M} to verify this. Second, there
-are two substitutes on the same line separated by '|'. In general, any colon
-commands can be strung together with '|'. Third, both substitutes operate on
-all three lines, even though the first stubstitute works on only two of the
-lines (36 and 38). Fourth, the second substitute works on only two lines (36
-and 37) and those are the two lines printed by the trailing 'p'.
-
-The {:v} command works similarly to the {:g} command, except that the sense of
-the test for 'tagging' the lines is reversed: all lines NOT matching the search
-pattern are tagged and operated on by the commands.
-
-Using {^V} to quote carriage return (see section 39) can be used in global
-substitutions to split two lines. For example, the command
-{:g/\. /s//.^V^M/g^M} will change your file so that each sentence is on a
-separate line. (Note that we have to 'escape' the '.', because '.' by itself
-matches any character. Our command says to find any line which contains a
-period followed by 2 spaces, and inserts a carriage return after the period.)
-
-Caveat: In some of the documentation for ex and vi you may find the
-comment to the effect that {\^M} can be used between commands following
-{:g}. The author of this tutorial has never gotten this to work and has
-crashed the editor trying.
-
-Section 38: higher level text objects and nroff: {(} {)} [{] [}] {[[} {]]}
-
-(Note: this section may be a little confusing because of our command
-notation. Using curly braces to surround command strings works fine as
-long as the command string does not contain any curly braces itself.
-However, the curly braces are legitimate commands in vi. Therefore, for
-any command sequence that contains curly braces, we will surround that
-sequence with SQUARE braces, as on the previous Section line.)
-
-In working with a document, particularly if using the text formatting
-programs nroff or troff, it is often advantageous to work in terms of
-sentences, paragraphs, and sections. The operations {(} and {)} move to
-the beginning of the previous and next sentences, respectively. Thus
-the command {d)} will delete the rest of the current sentence; likewise
-{d(} will delete the previous sentence if you are at the beginning of
-the current sentence, or, if you are not at the beginning of a sentence,
-it will delete the current sentence from the beginning
-up to where you are.
-
-A sentence is defined to end at a '.', '!', or '?' which is followed
-by either the end of a line, or by two spaces. Any number of closing
-')', ']', '"', and ''' characters may appear after the '.', '!', or '?'
-before the spaces or end of line. Therefore, the {(} and {)} commands
-would recognize only one sentence in the following line, but two
-sentences on the second following line.
-
-Line 39: This is one sentence. Even though it looks like two.
-Line 40: This is two sentences. Because it has two spaces after the '.'.
-
-The operations [{] and [}] move over paragraphs and the operations {[[}
-and {]]} move over sections.
-
-A paragraph begins after each empty line, and also at each of a set of nroff
-paragraph macros. A section begins after each line with a form-feed ^L in the
-first column, and at each of a set of nroff section macros. When preparing a
-text file as input to nroff, you will probably be using a set of nroff macros
-to make the formatting specifications easier, or more to your taste. These
-macros are invoked by beginning a line with a period followed by the one or two
-letter macro name. Vi has been programmed to recognize these nroff macros, and
-if it doesn't recognize your particular macro you can use the {:set paragraphs}
-or {:set sections} commands so that it will.
-
-Section 39: more about inserting text
-
-There are a number of characters which you can use to make correnctions
-during input mode. These are summarized in the following table.
-
- ^H deletes the last input character
- ^W deletes the last input word
- (erase) same as ^H; each terminal can define its own erase character;
- for some it is ^H, for others it is the DELETE key, and for
- others it is '@'.
- (kill) deletes the input on this line; each terminal can define its
- own line-kill character; for some it is ^U, for others it is
- '@'; you will need to experiment on your terminal to find
- out what your line-kill and erase characters are.
- \ escapes a following ^H, (kill), and (erase) characters: i.e.
- this is how to put these characters in your file.
- ^[ escape key; ends insertion mode
- ^? the delete key; interrupts an insertion, terminating it
- abnormally.
- ^M the return key; starts a new line.
- ^D backtabs over the indentation set by the autoindent option
- 0^D backtabs over all indentation back to the beginning of the line
- ^^D (up-arrow followed by control-d)same as 0^D, except the indentation
- will be restored at the beginning of the next line.
- ^V quotes the next non-printing character into the file
-
-If you wish to type in your erase or kill character (say # or @ or ^U) then you
-must precede it with a \, just as you would do at the normal system command
-level. A more general way of typing non-printing characters into the file is
-to precede them with a ^V. The ^V echoes as a ^ character on which the cursor
-rests. This indicates that the editor expects you to type a control character
-and it will be inserted into the file at that point. There are a few
-exceptions to note. The implementation of the editor does not allow the null
-character ^@ to appear in files. Also the linefeed character ^J is used by the
-editor to separate lines in the file, so it cannot appear in the middle of a
-line. (Trying to insert a ^M into a file, or putting it in the replacement
-part of a substitution string will result in the matched line being split in
-two. This, in effect, is how to split lines by using a substitution.) You can
-insert any other character, however, if you wait for the editor to echo the ^
-before you type the character. In fact, the editor will treat a following
-letter as a request for the corresponding control character. This is the only
-way to type ^S or ^Q, since the system normally uses them to suspend and resume
-output and never gives them to the editor to process.
-
-If you are using the autoindent option you can backtab over the indent which it
-supplies by typing a ^D. This backs up to the boundary specified by the
-shiftwidth option. This only works immediately after the supplied autoindent.
-
-When you are using the autoindent option you may wish to place a label at the
-left margin of a line. The way to do this easily is to type ^ (up-arrow) and
-then ^D. The editor will move the cursor to the left margin for one line, and
-restore the previous indent on the next. You can also type a 0 followed
-immediately by a ^D if you wish to kill all indentation and not have it resume
-on the next line.
-
-Section 40: more on operators: {d} {c} {<} {>} {!} {=} {y}
-
-Below is a non-exhaustive list of commands that can follow the operators
-to affect the range over which the operators will work. However, note
-that the operators {<}, {>}, {!}, and {=} do not operate on any object
-less than a line. Try {!w} and you will get a beep. To get the
-operator to work on just the current line, double it. E.g. {<<}.
-
- suffix will operate on
- ------ ------------------------
- ^[ cancels the command
- w the word to the right of the cursor
- W ditto, but ignoring punctuation
- b the word to the left of the cursor
- B ditto, but ignoring punctuation
- e see below.
- E ditto
- (space) a character
- $ to the end of the line
- ^ to the beginning of the line
- / .. / up to, but not including, the string
- ? .. ? back to and including the string
- fc up to and including the occurrence of c
- Fc back to and including the occurrence of c
- tc up to but not including the occurrence of c
- Tc back to but not including the occurrence of c
- ^M TWO lines (that's right: two)
- (number)^M that many lines plus one
- (number)G up to and including line (number)
- ( the previous sentence if you are at the beginning of
- the current sentence, or the current sentence up to where
- you are if you are not at the beginning of the current
- sentence. Here, 'sentence' refers to the intuitive
- notion of an English sentence, ending with '!', '?',
- or '.' and followed by an end of line or two spaces.
- ) the rest of the current sentence
- { analogous to '(', but in reference to paragraphs:
- sections of text surrounded by blank lines
- } analogous to ')', but in reference to paragraphs
- [[ analogous to '(', but in reference to sections
- ]] analogous to ')', but in reference to sections
- H the first line on the screen
- M the middle line on the screen
- L the last line on the screen
- 3L through the third line from the bottom of the screen
- ^F forward a screenful
- ^B backward a screenful
- :
- : etc. etc. etc.
-
-This list is not exhaustive, but it should be sufficient to get the idea
-across: after the operator, you can specify a range with a move-the-cursor
-command, and that is the region of text over which the operator will be
-effective.
-
-Section 41: abbreviations: {:ab}
-
-When typing large documents you may find yourself typing a large phrase
-over and over. Vi gives you the ability to specify an abbreviation for
-a long string such that typing the abbreviation will automatically
-expand into the longer phrase.
-
-Type {:ab nps Naval Postgraduate School^M}. Now type:
-
-{iThis is to show off the nps's UNIX editor.^M^[}
-
-Section 42: vi's relationship with the ex editor: {:}
-
-Vi is actually one mode of editing within the editor ex. When you are
-running vi you can escape to the line oriented editor of ex by giving
-the command {Q}. All of the colon-commands which were introduced above
-are available in ex. Likewise, most ex commands can be invoked from vi
-using {:}.
-
-In rare instances, an internal error may occur in vi. In this case you
-will get a diagnostic and will be left in the command mode of ex. You can
-then save your work and quit if you wish by giving the command {x} after
-the colon prompt of ex. Or you can reenter vi (if you are brave) by
-giving ex the command {vi}.
-
-Section 43: vi on hardcopy terminals and dumb terminals: open mode
-
-(The author has not checked the following documentation for accuracy. It is
-abstracted from the Introduction to Vi Editing document.)
-
-If you are on a hardcopy terminal or a terminal which does not have a cursor
-which can move off the bottom line, you can still use the command set of vi,
-but in a different mode. When you give the vi command to UNIX, the editor will
-tell you that it is using open mode. This name comes from the open command in
-ex, which is used to get into the same mode.
-
-The only difference between visual mode (normal vi) and open mode is the way in
-which the text is displayed.
-
-In open mode the editor uses a single line window into the file, and moving
-backward and forward in the file causes new lines to be displayed, always below
-the current line. Two commands of vi work differently in open: {z} and {^R}.
-The {z} command does not take parameters, but rather draws a window of context
-around the current line and then returns you to the current line.
-
-If you are on a hardcopy terminal, the {^R} command will retype the current
-line. On such terminals, the editor normally uses two lines to represent the
-current line. The first line is a copy of the line as you started to edit it,
-and you work on the line below this line. When you delete characters, the
-editor types a number of \'s to show you the characters which are deleted. The
-editor also reprints the current line soon after such changes so that you can
-see what the line looks like again.
-
-It is sometimes useful to use this mode on very slow terminals which can
-support vi in the full screen mode. You can do this by entering ex and using
-an {open} command.
-
-*********************************************************************
-Section 44: options: {:set} {setenv EXINIT}
-
-You will discover options as you need them. Do not worry about them very much
-on the first pass through this document. My advice is to glance through them,
-noting the ones that look interesting, ignoring the ones you don't understand,
-and try re-scanning them in a couple of weeks.
-
-If you decide that you have a favorite set of options and would like to change
-the default values for the editor, place a {setenv EXINIT} command in your
-.login file. When you are given an account under UNIX your directory has
-placed in it a file that is executed each time you log in. If one of the
-commands in this file sets the environment variable EXINIT to a string of vi
-commands, you can have many things done for you each time you invoke vi. For
-example, if you decide that you don't like tabstops placed every eight columns
-but prefer every four columns, and that you wish the editor to insert linefeeds
-for you when your typing gets you close to column 72, and you want
-autoindentation, then include the following line in your .login file:
-
-setenv EXINIT='set tabstop=4 wrapmargin=8 autoindent'
-
-or equivalently
-
-setenv EXINIT='se ts=4 wm=8 ai'
-
-Each time you bring up vi, this command will be executed and the options set.
-
-There are forty options in the vi/ex editor that the user can set for his/her
-own convenience. They are described in more detail in individual sections
-below. The section line will show the full spelling of the option name, the
-abbreviation, and the default value of the option. The text itself
-comes from the ex reference manual and is not the epitome of clarity.
-
-Section 44.1: {autoindent}, {ai} default: noai
-
-Can be used to ease the preparation of structured program text. At the
-beginning of each append, change or insert command or when a new line is opened
-or created by an append, change, insert, or substitute operation within open or
-visual mode, ex looks at the line being appended after, the first line changed
-or the line inserted before and calculates the amount of white space at the
-start of the line. It then aligns the cursor at the level of indentation so
-determined.
-
-If the user then types lines of text in, they will continue to be justified at
-the displayed indenting level. If more white space is typed at the beginning
-of a line, the following line will start aligned with the first non-white
-character of the previous line. To back the cursor up to the preceding tab
-stop one can hit {^D}. The tab stops going backwards are defined at multiples
-of the shiftwidth option. You cannot backspace over the indent, except by
-sending an end-of-file with a {^D}. A line with no characters added to it
-turns into a completely blank line (the white space provided for the autoindent
-is discarded). Also specially processed in this mode are lines beginning with
-an up-arrow `^' and immediately followed by a {^D}. This causes the input to
-be repositioned at the beginning of the line, but retaining the previous indent
-for the next line. Similarly, a `0' followed by a {^D} repositions at the
-beginning but without retaining the previous indent. Autoindent doesn't happen
-in global commands or when the input is not a terminal.
-
-Section 44.2: {autoprint}, {ap} default: ap
-
-Causes the current line to be printed after each delete, copy, join, move,
-substitute, t, undo or shift command. This has the same effect as supplying a
-trailing `p' to each such command. Autoprint is suppressed in globals, and
-only applies to the last of many commands on a line.
-
-Section 44.3: {autowrite}, {aw} default: noaw
-
-Causes the contents of the buffer to be written to the current file if you have
-modified it and give a next, rewind, stop, tag, or {!} command, or a control-
-up-arrow {^^} (switch files) or {^]} (tag goto) command in visual. Note, that
-the edit and ex commands do not autowrite. In each case, there is an
-equivalent way of switching when autowrite is set to avoid the autowrite
-({edit} for next, rewind! for rewind, stop! for stop, tag! for tag, shell
-for {!}, and {:e #} and a {:ta!} command from within visual).
-
-Section 44.4: {beautify}, {bf} default: nobeautify
-
-Causes all control characters except tab ^I, newline ^M and form-feed ^L to be
-discarded from the input. A complaint is registered the first time a backspace
-character is discarded. Beautify does not apply to command input.
-
-Section 44.5: {directory}, {dir} default: dir=/tmp
-
-Specifies the directory in which ex places its buffer file. If this directory
-in not writable, then the editor will exit abruptly when it fails to be able to
-create its buffer there.
-
-Section 44.6: {edcompatible} default: noedcompatible
-
-Causes the presence or absence of g and c suffixes on substitute commands to be
-remembered, and to be toggled by repeating the suffices. The suffix r makes
-the substitution be as in the {~} command, instead of like {&}.
-
-[Author's note: this should not concern users of vi.]
-
-Section 44.7: {errorbells}, {eb} default: noeb
-
-Error messages are preceded by a bell. However, bell ringing in open and
-visual modes on errors is not suppressed by setting noeb. If possible the
-editor always places the error message in a standout mode of the terminal (such
-as inverse video) instead of ringing the bell.
-
-Section 44.8: {hardtabs}, {ht} default: ht=8
-
-Gives the boundaries on which terminal hardware tabs are set (or on which the
-system expands tabs).
-
-Section 44.9: {ignorecase}, {ic} default: noic
-
-All upper case characters in the text are mapped to lower case in regular
-expression matching. In addition, all upper case characters in regular
-expressions are mapped to lower case except in character class specifications
-(that is, character in square brackets).
-
-Section 44.10: {lisp} default: nolisp
-
-Autoindent indents appropriately for lisp code, and the {(}, {)}, [{], [}],
-{[[}, and {]]} commands in open and visual modes are modified in a
-striaghtforward, intuitive fashion to have meaning for lisp.
-
-[Author's note: but don't ask me to define them precisely.]
-
-Section 44.11: {list} default: nolist
-
-All printed lines will be displayed (more) unambiguously, showing tabs as ^I
-and end-of-lines with `$'. This is the same as in the ex command {list}.
-
-Section 44.12: {magic} default: magic for {ex} and {vi}, nomagic for edit.
-
-If nomagic is set, the number of regular expression metacharacters is greatly
-reduced, with only up-arrow `^' and `$' having special effects. In addition
-the metacharacters `~' and `&' of the replacement pattern are treated as normal
-characters. All the normal metacharacters may be made magic when nomagic is
-set by preceding them with a `\'.
-
-[Author's note: In other words, if magic is set a back-slant turns the magic
-off for the following character, and if nomagic is set a back-slant turns the
-magic ON for the following character. And, no, we are not playing Dungeons and
-Dragons, although I think the writers of these option notes must have played it
-all the time.]
-
-Section 44.13: {mesg} default: mesg
-
-Causes write permission to be turned off to the terminal while you are in
-visual mode, if nomesg is set.
-
-[Author's note: I don't know if anyone could have made any one sentence
-paragraph more confusing than this one. What it says is: mesg allows people to
-write to you even if you are in visual or open mode; nomesg locks your terminal
-so they can't write to you and mess up your screen.]
-
-Section 44.14: {number, nu} default: nonumber
-
-Causes all output lines to be printed with their line numbers. In addition
-each input line will be prompted with its line number.
-
-Section 44.15: {open} default: open
-
-If {noopen}, the commands open and visual are not permitted. This is set for
-edit to prevent confusion resulting from accidental entry to open or visual
-mode.
-
-[Author's note: As you may have guessed by now, there are actually three
-editors available under Berkeley UNIX that are in reality the same
-program, ex, with different options set: ex itself, vi, and edit.]
-
-Section 44.16: {optimize, opt} default: optimize
-
-Throughput of text is expedited by setting the terminal to not do automatic
-carriage returns when printing more than one (logical) line of output, greatly
-speeding output on terminals without addressable cursors when text with leading
-white space is printed.
-
-[Author's note: I still don't know what this option does.]
-
-Section 44.17: {paragraphs, para} default: para=IPLPPPQPP LIbp
-
-Specifies the paragraphs for the [{] and [}] operations in open and visual.
-The pairs of characters in the option's value are the names of the nroff macros
-which start paragraphs.
-
-Section 44.18: {prompt} default: prompt
-
-Command mode input is prompted for with a `:'.
-
-[Author's note: Doesn't seem to have any effect on vi.]
-
-Section 44.19: {readonly}, {ro} default: noro, unless invoked with -R
- or insufficient privileges on file
-
-This option allows you to guarantee that you won't clobber your file by
-accident. You can set the option and writes will fail unless you use an `!'
-after the write. Commands such as {x}, {ZZ}, the autowrite option, and in
-general anything that writes is affected. This option is turned on if you
-invoke the editor with the -R flag.
-
-Section 44.20: {redraw} default: noredraw
-
-The editor simulates (using great amounts of output), an intelligent terminal
-on a dumb terminal (e.g. during insertions in visual the characters to the
-right of the cursor position are refreshed as each input character is typed).
-Useful only at very high baud rates, and should be used only if the system is
-not heavily loaded: you will notice the performance degradation yourself.
-
-Section 44.21: {remap} default: remap
-
-If on, macros are repeatedly tried until they are unchanged. For example, if o
-is mapped to O, and O is mapped to I, then if remap is set, o will map to I,
-but if noremap is set, it will map to O .
-
-Section 44.22: {report} default: report=5 for ex and vi, 2 for edit
-
-Specifies a threshold for feedback from commands. Any command which modifies
-more than the specified number of lines will provide feedback as to the scope
-of its changes. For commands such as global, open, undo, and visual which have
-potentially more far reaching scope, the net change in the number of lines in
-the buffer is presented at the end of the command, subject to this same
-threshold. Thus notification is suppressed during a global command on the
-individual commands performed.
-
-Section 44.23: {scroll} default: scroll=1/2 window
-
-Determines the number of logical lines scrolled when a {^D} is received from a
-terminal in command mode, and determines the number of lines printed by a
-command mode z command (double the value of scroll).
-
-[Author's note: Doesn't seem to affect {^D} and {z} in visual (vi) mode.]
-
-Section 44.24: sections {sections} default: sections=SHNHH HU
-
-Specifies the section macros from nroff for the {[[} and {]]} operations in
-open and visual. The pairs of characters in the options's value are the names
-of the macros which start paragraphs.
-
-Section 44.25: {shell}, {sh} default: sh=/bin/sh
-
-Gives the path name of the shell forked for the shell escape command `!', and
-by the shell command. The default is taken from SHELL in the environment, if
-present.
-
-[Editor's note: I would suggest that you place the following line in
-your .login file:
-setenv SHELL '/bin/csh'
-]
-
-Section 44.26: {shiftwidth}, {sw} default: sw=8
-
-Used in reverse tabbing with {^D} when using autoindent to append text, and
-used by the shift commands. Should probably be the same value as the tabstop
-option.
-
-Section 44.27: {showmatch}, {sm} default: nosm
-
-In open and visual mode, when a `)' or `}' is typed, if the matching `(' or `{'
-is on the screen, move the cursor to it for one second. Extremely useful with
-complicated nested expressions, or with lisp.
-
-Section 44.28: {slowopen}, {slow} default: terminal dependent
-
-Affects the display algorithm used in visual mode, holding off display updating
-during input of new text to improve throughput when the terminal in use is both
-slow and unintelligent. See "An Introduction to Display Editing with Vi" for
-more details.
-
-Section 44.29: {tabstop}, {ts} default: ts=8
-
-The editor expands tabs ^I to tabstop boundaries in the display.
-
-Section 44.30: {taglength}, {tl} default: tl=0
-
-Tags are not significant beyond this many characters.
-A value of zero (the default) means that all characters are significant.
-
-Section 44.31: {tags} default: tags=tags /usr/lib/tags
-
-A path of files to be used as tag files for the tag command. A requested tag
-is searched for in the specified files, sequentially. By default files called
-tags are searched for in the current directory and in /usr/lib (a master file
-for the entire system).
-
-[Author's note: The author of this tutorial has never used this option, nor
-seen it used. I'm not even sure I know what they are talking about.]
-
-Section 44.32: {term} default: from environment variable TERM
-
-The terminal type of the output device.
-
-Section 44.33: {terse} default: noterse
-
-Shorter error diagnostics are produced for the experienced user.
-
-Section 44.34: {timeout} default: timeout
-
-Causes macros to time out after one second. Turn it off and they will
-wait forever. This is useful if you want multi-character macros, but if
-your terminal sends escape sequences for arrow keys, it will be
-necessary to hit escape twice to get a beep.
-
-[Editor's note: Another paragraph which requires a cryptographer.]
-
-Section 44.35: ttytype
-
-[Editor's note: I have found no documentation for this option at all.]
-
-Section 44.36: {warn} default: warn
-
-Warn if there has been `[No write since last change]' before a `!' command
-escape.
-
-Section 44.37: {window} default: window=speed dependent
-
-The number of lines in a text window in the visual command. The default is 8
-at slow speeds (600 baud or less), 16 at medium speed (1200 baud), and the full
-screen (minus one line) at higher speeds.
-
-Section 44.38: {wrapscan}, {ws} default: ws
-
-Searches using the regular expressions in addressing will wrap around past the
-end of the file.
-
-Section 44.39: {wrapmargin}, {wm} default: wm=0
-
-Defines a margin for automatic wrapover of text during input in open and visual
-modes. The numeric value is the number of columns from the right edge of the
-screen around which vi looks for a convenient place to insert a new-line
-character (wm=0 is OFF). This is very convenient for touch typists.
-Wrapmargin behaves much like fill/nojustify mode does in nroff.
-
-Section 44.40: {writeany}, {wa} default: nowa
-
-Inhibit the checks normally made before write commands, allowing a write to any
-file which the system protection mechanism will allow.
-
-Section 44.41: {w300}, {w1200}, {w9600} defaults: w300=8
- w1200=16
- w9600=full screen minus one
-
-These are not true options but set the default size of the window for when the
-speed is slow (300), medium (1200), or high (9600), respectively. They are
-suitable for an EXINIT and make it easy to change the 8/16/full screen rule.
-
-Section 45: Limitations
-
-Here are some editor limits that the user is likely to encounter:
- 1024 characters per line
- 256 characters per global command list
- 128 characters per file name
- 128 characters in the previous inserted and deleted text in open or
- visual
- 100 characters in a shell escape command
- 63 characters in a string valued option
- 30 characters in a tag name
- 250000 lines in the file (this is silently enforced).
-
-The visual implementation limits the number of macros defined with map to 32,
-and the total number of characters in macros to be less than 512.
-
-[Editor's note: these limits may not apply to versions after 4.1BSD.]
diff --git a/usr.bin/vi/docs/tutorial/vi.beginner b/usr.bin/vi/docs/tutorial/vi.beginner
deleted file mode 100644
index 3bf35ac..0000000
--- a/usr.bin/vi/docs/tutorial/vi.beginner
+++ /dev/null
@@ -1,741 +0,0 @@
-Section 1: {^F} {ZZ}
-
-To get out of this tutorial, type: ZZ (two capital Z's).
-
-Learning a new computer system implies learning a new text editor. These
-tutorial lessons were created by Dain Samples to help you come to grips with
-UC Berkeley's screen oriented editor called vi (for VIsual). This tutorial
-uses the vi editor itself as the means of presentation.
-
-For best use of this tutorial, read all of a screen before performing any of
-the indicated actions. This tutorial (or, at least, the first half of it) has
-been designed to systematically present the vi commands IF THE INSTRUCTIONS
-ARE FOLLOWED! If you are too adventuresome, you may find yourself lost. If
-you ever find yourself stuck, remember the first line of this section.
-
-OK, now find the control key on your keyboard; it usually has CTL or CTRL
-written on its upper surface. Your first assignment is to hold the control
-key down while you press the 'F' key on your keyboard. Please do so now.
-
-
-
-Section 2: {^F} {^B}
-Many of vi's commands use the control key and some other key in combination,
-as with the control and the 'F' key above. This is abbreviated CTL-F, or ^F.
-
-As you have probably guessed by now, ^F (CTL-F) moves you forward a fixed
-number of lines in the file. Throughout the remainder of the tutorial when
-you are ready to advance to the next section of text, hit ^F.
-
-The opposite command is ^B. Just for fun, you might want to try a ^B to see
-the previous section again. Be sure to do a ^F to return you here.
-
-Determine what the cursor looks like on your screen. Whatever it is (a box,
-an underscore, blinking, flashing, inverse, etc.) it should now be positioned
-in the upper left-hand corner of your screen under or on the S of Section.
-Become familiar with your cursor: to use vi correctly it is important to
-always know where the cursor is.
-
-Did you notice that when you do a ^F the cursor is left at the top of the
-screen, and a ^B leaves the cursor near the bottom of the screen? Try the two
-commands ^B^F again. And now do another ^F to see the next section.
-
-Section 3: {^F} {^B}
-You now have two basic commands for examining a file, both forwards (^F) and
-backwards (^B).
-
-Note that these are vi text editing commands: they are not commands for the
-tutorial. Indeed, this tutorial is nothing but a text file which you are now
-editing. Everything you do and learn in this tutorial will be applicable to
-editing text files.
-
-Therefore, when you are editing a file and are ready to see more of the text,
-entering ^F will get you to the next section of the file. Entering ^B will
-show you the previous section.
-
-Time for you to do another ^F.
-
-
-
-
-
-
-
-Section 4: {^F} {^B} {^M} (return key)
-We will adopt the notation of putting commands in curly braces so we can write
-them unambiguously. For example, if you are to type the command sequence
-"control B control F" (as we asked you to do above) it would appear as {^B^F}.
-This allows clear delineation of the command strings from the text. Remember
-that the curly braces are NOT part of the command string you are to type. Do
-NOT type the curly braces.
-
-Sometimes, the command string in the curly braces will be rather long, and may
-be such that the first couple of characters of the command will erase from
-the screen the string you are trying to read and type. It is suggested that
-you write down the longer commands BEFORE you type them so you won't forget
-them once they disappear.
-
-Now locate the return key on your keyboard: it is usually marked 'RETURN',
-indicate hitting the return key. In fact, the control-M key sequence is
-exactly the same as if you hit the return key, and vice versa.
-
-Now type {^F}.
-
-
-Section 5: {:q!} {ZZ} {^M} (return key)
-Recognize that this tutorial is nothing more than a text file that you
-are editing. This means that if you do something wrong, it is possible
-for you to destroy the information in this file. Don't worry. If this
-happens, type {ZZ} (two capital Z's) or {:q!^M} to leave the tutorial.
-Restart the tutorial. Once in the tutorial, you can then page forward
-with {^F} until you are back to where you want to be. (There are
-easier ways to do this, some of which will be discussed later, but this
-is the most straightforward.)
-
-You may want to write these commands down in a convenient place for quick
-reference: {:q!^M} and {ZZ}
-
-We will assume that you now know to do a {^F} to advance the file
-
-
-
-
-
-
-
-Section 6: {m} {G} {'} {z}
-Now that you know how to get around in the file via ^F and ^B let's look at
-other ways of examining a text file. Sometimes it is necessary, in the midst
-of editing a file, to examine another part of the file. You are then faced
-with the problem of remembering your place in the file, looking at the other
-text, and then getting back to your original location. Vi has a 'mark'
-command, m. Type {mp}. You have just 'marked' your current location in the
-file and given it the name 'p'. The command string below will do three
-things: position you at the beginning of the file (line 1), then return you to
-the location 'p' that you just marked with the 'm' command, and, since the
-screen will not look exactly the same as it does right now, the 'z' command
-will reposition the screen. (You may want to write the string down before
-typing it: once you type {1G} it will no longer be on the screen.)
-
-So now type {1G'pz^M} - a one followed by a capital G, followed by the quote
-mark, followed by a lower case 'p', then a lower case 'z', then a return
-(which is the same as a ^M). The {1G} moves you to line 1, i.e. the beginning
-of the file. The {'p} moves you to the location you marked with {mp}. The
-{z^M} command will repaint the screen putting the cursor at the top of the
-screen. (Now {^F}.)
-
-Section 7: {m} {G} {'} {z}
-Let's look at some variations on those commands. If you wanted to look at
-line 22 in the file and return to this location you could type {mp22G'p}. Do
-so now, observing that {22G} puts your cursor at the beginning of section 2 in
-the middle of the screen.
-
-Also note that, without the {z^M} command, the line with 'Section 7' on it is
-now in the MIDDLE of the screen, and not at the top. Our cursor is on the
-correct line (where we did the {mp} command) but the line is not where we
-might like it to be on the screen. That is the function of the {z^M} command.
-(Remember, ^M is the same as the 'return' key on your keyboard.) Type {z^M}
-now and observe the effect.
-
-As you can see, the 'Section 7' line is now at the top of the screen with the
-cursor happily under the capital S. If you would like the cursor line (i.e.
-the line which the cursor is on) in the middle of the screen again, you would
-type {z.}. If you wanted the cursor line to be at the BOTTOM of the screen,
-type {z-}. Try typing {z-z.z^M} and watch what happens.
-
-{^F}
-
-Section 8: {z} {m} {'}
-
-Note that the z command does not change the position of our cursor in the file
-itself, it simply moves the cursor around on the screen by moving the contents
-of the file around on the screen. The cursor stays on the same line of the
-file when using the z command.
-
-This brings up an important point. There are two questions that the users of
-vi continually need to know the answer to: "Where am I in the file?" and
-"Where am I on the screen?" The cursor on your terminal shows the answer to
-both questions. Some commands will move you around in the file, usually
-changing the location of the cursor on the screen as well. Other commands
-move the cursor around on the screen without changing your location in the
-file.
-
-Now type {ma}. Your location in the file has been given the name 'a'. If you
-type {'p'a} you will see the previous location we marked in section 7, and
-then will be returned to the current location. (You will want to do a {z^M}
-to repaint the screen afterwards.) Try it.
-{^F}
-
-Section 9: {m} {''}
-Now we can move about in our file pretty freely. By using the {m} command we
-can give the current cursor position a lower-case-character name, like 'p',
-'a', 'e', 'm', or 'b'. Using the {G} command preceded by a line number we can
-look at any line in the file we like. Using the single quote command {'}
-followed by a character used in an {m} command, we can return to any location
-in the file we have marked.
-
-However, try {m3}, or {mM}. You should hear a beep, or bell. Only lower-case
-letters are acceptable to the {m} and {'} commands: numbers, upper-case
-letters, and special characters are not acceptable.
-
-If you type the {'} command with a character that is lower-case alphabetic but
-that has not been used in an {m} command, or for which the 'marked' text has
-been deleted, you will also get a beep. Try {'i}. You should get a beep
-because the command {mi} has never been issued. (Unless you've been
-experimenting.)
-
-The command {''} attempts to return you to the location at which you last
-modified some part of your file. However, my experience has been that it is
-difficult to predict exactly where you will end up.
-Section 10: {^M} {-}
-Now do {ma}, marking your position at the top of the screen. Now hit {^M} (or
-return) until the cursor is right ...
-* <- here, over/under the asterisk. Now
-type {mb'a'b} and watch the cursor move from the asterisk to the top of the
-screen and back again.
-
-The {^M} command moves the cursor to the beginning of the next line. Now type
-{^M} until the cursor is right ...
-* <- here. The command to move the cursor to the beginning of the
-previous line is {-}. Practice moving the cursor around on the screen by using
-{^M} and {-}. BE CAREFUL to not move the cursor OFF the screen just yet. If
-you do, type {'az^M}.
-
-Now we can move to any line within the screen. Practice moving around in the
-file using the {^F}, {^B}, {-}, {^M}, {z}, and {'} commands. When you are
-fairly confident that you can get to where you need to be in the file, and
-position the cursor on the screen where you want it type {'az^M^F} (which, of
-course, moves you back to the beginning of this section, repositions the
-cursor at the top of the screen, and advances you to the next section).
-
-Section 11: scrolling: {^M}
-The cursor should now be on the S of 'Section 11', and this should be on the
-first line of the screen. If it is not, do {^M} or {-} as appropriate to put
-the cursor on the section line, and type {z^M}.
-
-Type {mc} to mark your place.
-
-Now type {^M} until the cursor is on the last line of this screen. Now do one
-more {^M} and observe the result. This is called scrolling. When you
-attempted to move to a line not displayed on the screen, the line at the top of
-the screen was 'scrolled off', and a line at the bottom of the screen was
-'scrolled on'. The top line with 'Section 11' should no longer be visible.
-
-Now type {'cz^M} to reset the screen and type {^F} for the next section.
-
-
-
-
-
-
-
-Section 12: {-} {z}
-
-The {-} command moves the cursor to the previous line in the file. Now type
-{-}, which attempts to move the cursor to the previous line in this file.
-However, that line is not on the screen. The resulting action will depend on
-your terminal. (Do a {^Mz^M} to reposition the file). On intelligent
-terminals (e.g. VT100s, Z19s, Concept 100s), a top line is 'scrolled on' and
-the bottom line is 'scrolled off'. Other terminals, however, may not have
-this 'reverse scrolling' feature. They will simply repaint the screen with
-the cursor line in the middle of the screen. On such terminals it is
-necessary to type {z^M} to get the cursor line back to the top of the screen.
-
-
-
-
-
-
-
-
-
-
-Section 13:
-Up until this point, the tutorial has always tried to make sure that the first
-line of each screen has on it the section number and a list of the commands
-covered in that section. This will no longer be strictly maintained. If you
-want the section line at the top of the screen, you now know enough commands to
-do it easily: do {^M} or {-} until the cursor is on the section line and
-then {z^M}. Also, from this point on, it may not be the case that a {^F} will
-put you at the beginning of the next section. Therefore, be aware of where you
-are in the file as we look at other commands. You may have to find your way
-back to a particular section without any help from the tutorial. If you do not
-feel comfortable with this, then it is suggested that you practice moving from
-section 1 to section 13, back and forth, using {^M}, {-}, {^F}, and {^B}
-commands for a while.
-
-Also make liberal use of the mark command {m}: if, for example, you make a
-habit of using {mz} to mark your current location in the file, then you will
-always be able to return to that location with {'z} if the editor does
-something strange and you have no idea where you are or what happened.
-
-And finally, the proscription against experimentation is hereby lifted: play
-with the editor. Feel free to try out variations on the commands and move
-around in the file. By this time you should be able to recover from any gross
-errors.
-
-Section 14: {^E} {^Y} {^D} {^U}
-Let us now look at a few other commands for moving around in the file, and
-moving the file around on the screen. Note that the commands we have already
-looked at are sufficient: you really don't need any more commands for looking
-in a file. The following commands are not absolutely necessary. However,
-they can make editing more convenient, and you should take note of their
-existence. But it would be perfectly valid to decide to ignore them on this
-first pass: you can learn them later when you see a need for them, if you ever
-do.
-
-First, let's clear up some potentially confusing language. In at least one
-place in the official document ('An Introduction to Display Editing with Vi'
-by William Joy, and Mark Horton, September 1980), the expression "to scroll
-down text" means that the cursor is moved down in your file. However, note
-that this may result in the text on the screen moving UP. This use of the
-word 'scroll' refers to the action of the cursor within the file. However,
-another legitimate use of the word refers to the action of the text on the
-screen. That is, if the lines on your screen move up toward the top of the
-screen, this would be 'scrolling the screen up'. If the lines move down
-toward the bottom of the screen, this would be refered to as scrolling down.
-
-I have tried to maintain the following jargon: 'scrolling' refers to what the
-text does on the screen, not to what the cursor does within the file. For the
-latter I will refer to the cursor 'moving', or to 'moving the cursor'. I
-realize that this is not necessarily consistent with Joy and Horton, but they
-were wrong.
-
-{^E} scrolls the whole screen up one line, keeping the cursor on the same line,
-if possible. However, if the cursor line is the first line on the screen, then
-the cursor is moved to the next line in the file. Try typing {^E}.
-
-{^Y} scrolls the screen down one line, keeping the cursor on the same line, if
-possible. However, if the cursor line is the last line on the screen, then the
-cursor is moved to the previous line in the file. Try it.
-
-{^D} moves the cursor down into the file, scrolling the screen up.
-
-{^U} moves the cursor up into the file, also scrolling the screen if the
-terminal you are on has the reverse scroll capability. Otherwise the
-screen is repainted.
-
-Note that {^E} and {^Y} move the cursor on the screen while trying to keep the
-cursor at the same place in the file (if possible: however, the cursor can
-never move off screen), while {^D} and {^U} keep the cursor at the same place
-on the screen while moving the cursor within the file.
-
-Section 15: {/ .. /^M}
-
-Another way to position yourself in the file is by giving the editor a string
-to search for. Type the following: {/Here 1/^M} and the cursor should end up
-right ...........................here ^. Now type {/Section 15:/^M} and the
-cursor will end up over/on .....................here ^. Now type {//^M} and
-observe that the cursor is now over the capital S five lines above this line.
-Typing {//^M} several more times will bounce the cursor back and forth between
-the two occurrences of the string. In other words, when you type a string
-between the two slashes, it is searched for. Typing the slashes with nothing
-between them acts as if you had typed the previous string again.
-
-Observe that the string you type between the two slashes is entered on the
-bottom line of the screen. Now type {/Search for x /^M} except replace the 'x'
-in the string with some other character, say 'b'. The message "Pattern not
-found" should appear on the bottom of the screen. If you hadn't replaced the
-'x', then you would have found the string. Try it.
-
-Section 16: {? .. ?^M} {n} (search strings: ^ $)
-
-When you surround the sought-for string with slashes as in {/Search/}, the
-file is searched beginning from your current position in the file. If the
-string is not found by the end of the file, searching is restarted at the
-beginning of the file. However, if you do want the search to find the
-PREVIOUS rather than the NEXT occurrence of the string, surround the string
-with question marks instead of slash marks.
-
-Below are several occurrences of the same string.
-Here 2 Here 2 Here 2
- Here 2 Here 2.
-Observe the effect of the following search commands (try them in the
-sequence shown):
-{/Here 2/^M} {//^M} {??^M}
-{/^Here 2/^M} {//^M} {??^M}
-{/Here 2$/^M} {//^M} {??^M}
-
-The first command looks for the next occurrence of the string 'Here 2'.
-However the second line of commands looks for an occurrence of 'Here 2' that
-is at the beginning of the line. When the up-arrow is the first character of
-a search string it stands for the beginning of the line. When the dollar-sign
-is the last character of the search string it stands for the end of the line.
-Therefore, the third line of commands searches for the string only when it is
-at the end of the line. Since there is only one place the string begins a
-line, and only one place the string ends the line, subsequent {//^M} and
-{??^M} will find those same strings over and over.
-
-The {n} command will find the next occurrence of the / or ? search
-string. Try {/Here 2/^M} followed by several {n} and observe the
-effect. Then try {??^M} followed by several {n}. The {n} command
-remembers the direction of the last search. It is just a way to save a
-few keystrokes.
-
-Section 17: \ and magic-characters in search strings
-
-Now type {/Here 3$/^M}. You might expect the cursor to end up
-right......^ here. However, you will get "Pattern not found" at the bottom of
-the screen. Remember that the dollar-sign stands for the end of the line.
-Somehow, you must tell vi that you do not want the end of the line, but a
-dollar-sign. In other words, you must take away the special meaning that the
-dollar-sign has for the search mechanism. You do this (for any special
-character, including the up-arrow ^) by putting a back-slash ('\', not '/') in
-front of the character.
-
-Now try {/Here 3\$/^M} and you should end up nine lines above this one. Try
-{//^M} and note that it returns you to the same place, and not to the first
-line of this paragraph: the back-slash character is not part of the search
-string and will not be found. To find the string in the first line of this
-paragraph, type {/Here 3\\\$/^M}. There are three back-slashes: the first takes
-away the special meaning from the second, and the third takes away the special
-meaning from the dollar-sign.
-
-Following is a list of the characters that have special meanings in search
-strings. If you wish to find a string containing one of these characters, you
-will have to be precede the character with a backslash. These characters are
-called magic characters because of the fun and games you can have with them
-and they can have with you, if you aren't aware of what they do.
-
- ^ - (up-arrow) beginning of a line
- $ - (dollar-sign) end of a line
- . - (period) matches any character
- \ - (backslant) the escape character itself
- [ - (square bracket) for finding patterns (see section #SEARCH)
- ] - (square bracket) ditto
- * - (asterisk) ditto
-
-Without trying to explain it here, note that {:set nomagic^M} turns off the
-special meanings of all but the ^ up-arrow, $ dollar-sign, and backslash
-characters.
-
-Section 18: {: (colon commands)} {ZZ}
-
-In this section we will discuss getting into and out of the editor in more
-detail. If you are editing a file and wish to save the results the command
-sequence {:w^M} writes the current contents of the file out to disk, using the
-file name you used when you invoked the editor. That is, if you are at the
-command level in Unix, and you invoke vi with {vi foo} where foo is the name
-of the file you wish to edit, then foo is the name of the file used by the
-{:w^M} command.
-
-If you are done, the write and quit commands can be combined into a single
-command {:wq^M}. An even simpler way is the command {ZZ} (two capital Z's).
-
-If, for some reason, you wish to exit without saving any changes you have made,
-{:q!^M} does the trick. If you have not made any changes, the exclamation
-point is not necessary: {:q^M}. Vi is pretty good about not letting you
-get out without warning you that you haven't saved your file.
-
-We have mentioned before that you are currently in the vi editor, editing a
-file. If you wish to start the tutorial over from the very beginning, you
-could {ZZ}, and then type {vi.tut beginner} in response to the Unix prompt.
-This will create a fresh copy of this file for you, which might be necessary
-if you accidentally destroyed the copy you were working with. Just do a
-search for the last section you were in: e.g. {/Section 18:/^Mz^M}.
-
-Section 19: {H} {M} {L}
-
-Here are a few more commands that will move you around on the screen. Again,
-they are not absolutely necessary, but they can make screen positioning easier:
-
-{H} - puts the cursor at the top of the screen (the 'home' position)
-
-{M} - puts the cursor in the middle of the screen
-
-{L} - puts the cursor at the bottom of the screen.
-
-Try typing {HML} and watch the cursor.
-
-Try typing {5HM5L} and note that 5H puts you five lines from the top of the
-screen, and 5L puts you five lines from the bottom of the screen.
-
-Section 20: {w} {b} {0} {W} {B} {e} {E} {'} {`}
-
-Up to this point we have concentrated on positioning in the file, and
-positioning on the screen. Now let's look at positioning in a line. Put the
-cursor at the beginning of the following line and type {z^M}:
-
-This is a test line: your cursor should initially be at its beginning.
-
-The test line should now be at the top of your screen. Type {w} several times.
-Note that it moves you forward to the beginning of the next word. Now type
-{b} (back to the beginning of the word) several times till you are at the
-beginning of the line. (If you accidentally type too many {b}, type {w} until
-you are on the beginning of the line again.) Type {wwwww} (five w's) and note
-that the cursor is now on the colon in the sentence. The lower-case w command
-moves you forward one word, paying attention to certain characters such as
-colon and period as delimiters and counting them as words themselves. Now
-type {0} (zero, not o 'oh'): this moves you to the beginning of the current
-line. Now type {5w} and notice that this has the effect of repeating {w} five
-times and that you are now back on the colon. Type {0} (zero) again. To
-ignore the delimiters and to move to the beginning of the next word using only
-blanks, tabs and carriage-returns (these are called white-space characters) to
-delimit the words, use the {W} command: upper-case W. {B} takes you back a
-word using white-space characters as word delimiters.
-
-Note that the commands {wbWB} do not stop at the beginning or end of a line:
-they will continue to the next word on the next line in the direction specified
-(a blank line counts as a word).
-
-If you are interested in the END of the word, and not the BEGINNING, then use
-the {e} and {E} commands. These commands only move forward and there are no
-corresponding 'reverse search' commands for the end of a word.
-
-Also, we have been using the {'} command to move the cursor to a position that
-we have previously marked with the {m} command. However, position the cursor
-in the middle of a line (any line, just pick one) and type {mk}, marking that
-position with the letter k. Now type a few returns {^M} and type {'k}.
-Observe that the cursor is now at the beginning of the line that you marked.
-Now try {`k}: note that this is the reverse apostrophe, or back-quote, or grave
-accent, or whatever you want to call it. Also note that it moves you to the
-character that was marked, not just to the line that was marked.
-
-In addition, the {``} command works just like the {''} command except that you
-are taken to the exact character, not just to the line. (I'm still not
-sure which exact character, just as I'm still not sure which line.)
-
-Section 21: {l} {k} {j} {h}
-
-There are several commands to move around on the screen on a character by
-character basis:
-
-l - moves the cursor one character to the RIGHT
-k - moves the cursor UP one line
-j - moves the cursor DOWN one line
-h - moves the cursor one character to the LEFT
-
-Section 22: {i} {a} {I} {A} {o} {O} ^[ (escape key)
-
-For this and following sections you will need to use the ESCAPE key on your
-terminal. It is usually marked ESC. Since the escape key is the same as
-typing {^[} we will use ^[ for the escape key.
-
-Probably the most often used command in an editor is the insert command. Below
-are two lines of text, the first correct, the second incorrect. Position your
-cursor at the beginning of Line 1 and type {z^M}.
-
-Line 1: This is an example of the insert command.
-Line 2: This is an of the insert command.
-
-To make line 2 look like line 1, we are going to insert the characters
-'example ' before the word 'of'. So, now move the cursor so that it is
-positioned on the 'o' of 'of'. (You can do this by typing {^M} to move
-to the beginning of line 2, followed by {6w} or {wwwwww} to position the cursor
-on the word 'of'.)
-
-Now carefully type the following string and observe the effects:
- {iexample ^[} (remember: ^[ is the escape key)}
-The {i} begins the insert mode, and 'example ' is inserted into the line:
-be sure to notice the blank in 'example '. The ^[ ends insertion mode,
-and the line is updated to include the new string. Line 1 should look exactly
-like Line 2.
-
-Move the cursor to the beginning of Line 3 below and type {z^M}:
-
-Line 3: These lines are examples for the 'a' command.
-Line 4: These line are examples for the '
-
-We will change line four to look like line three by using the append command.
-We need to append an 's' to the word 'line'. Position the cursor on the 'e'
-of 'line'. You can do this in several ways, one way is the following:
-First, type {/line /^M}. This puts us on the word 'line' in Line 4
-(the blank in the search string is important!). Next, type {e}. The 'e' puts
-us at the end of the word. Now, type {as^[ (^[ is the escape character)}.
-The 'a' puts us in insert mode, AFTER the current character. We appended the
-'s', and the escape ^[ ended the insert mode.
-
-The difference between {i} (insert) and {a} (append) is that {i} begins
-inserting text BEFORE the cursor, and {a} begins inserting AFTER the cursor.
-
-Now type {Aa' command.^[}. The cursor is moved to the end of the line and the
-string following {A} is inserted into the text. Line 4 should now look like
-line 3.
-
-Just as {A} moves you to the end of the line to begin inserting, {I} would
-begin inserting at the FRONT of the line.
-
-To begin the insertion of a line after the cursor line, type {o}. To insert a
-line before the cursor line, type {O}. In other words {o123^[} is equivalent
-to {A^M123^[}, and {O123^[} is equivalent to {I123^M^[}. The text after the
-{o} or {O} is ended with an escape ^[.
-
-This paragraph contains information that is terminal dependent: you will just
-have to experiment to discover what your terminal does. Once in the insert
-mode, if you make a mistake in the typing, ^H will delete the previous
-character up to the beginning of the current insertion. ^W will delete the
-previous word, and one of ^U, @, or ^X will delete the current line (up to the
-beginning of the current insertion). You will need to experiment with ^U, @,
-and ^X to determine which works for your terminal.
-
-Section 23: {f} {x} {X} {w} {l} {r} {R} {s} {S} {J}
-
-Position the cursor at the beginning of line 5 and {z^M}:
-
-Line 5: The line as it should be.
-Line 6: The line as it shouldn't be.
-
-To make Line 6 like Line 5, we have to delete the 'n', the apostrophe, and the
-'t'. There are several ways to position ourselves at the 'n'. Choose
-whichever one suits your fancy:
-
-{/n't/^M}
-{^M7w6l} or {^M7w6 } (note the space)
-{^M3fn} (finds the 3rd 'n' on the line)
-
-Now {xxx} will delete the three characters, as will {3x}.
-
-Note that {X} deletes the character just BEFORE the cursor, as opposed
-to the character AT the cursor.
-
-Position the cursor at line 7 and {z^M}:
-
-Line 7: The line as it would be.
-Line 8: The line as it could be.
-
-To change line 8 into line 7 we need to change the 'c' in 'could' into a 'w'.
-The 'r' (replace) command was designed for this. Typing {rc} is the same as
-typing {xic^[} (i.e. delete the 'bad' character and insert the correct
-new character). Therefore, assuming that you have positioned the cursor on the
-'c' of 'could', the easiest way to change 'could' into 'would' is {rw}.
-
-If you would like to now change the 'would' into 'should', use the substitute
-command, 's': {ssh^[}. The difference between 'r' and 's' is that 'r'
-(replace) replaces the current character with another character, while 's'
-(substitute) substitutes the current character with a string, ended with an
-escape.
-
-The capital letter version of replace {R} replaces each character by a
-character one at a time until you type an escape, ^[. The 'S' command
-substitutes the whole line.
-
-Position your cursor at the beginning of line 9 and {z^M}.
-
-Line 9: Love is a many splendored thing.
-Line 10: Love is a most splendored thing.
-
-To change line 10 into line 9, position the cursor at the beginning of 'most',
-and type {Rmany^[}.
-
-You may have noticed that, when inserting text, a new line is formed by typing
-{^M}. When changing, replacing, or substituting text you can make a new line
-by typing {^M}. However, neither {x} nor {X} will remove ^M to make two lines
-into one line. To do this, position the cursor on the first of the two lines
-you wish to make into a single line and type {J} (uppercase J for 'Join').
-
-Section 24: {u} {U}
-
-Finally, before we review, let's look at the undo command. Position
-your cursor on line 11 below and {z^M}.
-
-Line 11: The quick brown fox jumped over the lazy hound dog.
-Line 12: the qwick black dog dumped over the laxy poune fox.
-
-Type the following set of commands, and observe carefully the effect of each
-of the commands:
-
-{/^Line 12:/^M} {ft} {rT} {fw} {ru} {w} {Rbrown fox^[} {w} {rj}
-{fx} {rz} {w} {Rhound dog^[}
-
-Line 12 now matches line 11. Now type {U} - capital 'U'. And line 12 now
-looks like it did before you typed in the command strings. Now type:
-
-{ft} {rT} {fw} {ru} {^M} {^M}
-
-and then type {u}: the cursor jumps back to the line containing the second
-change you made and 'undoes' it. That is, {U} 'undoes' all the changes on the
-line, and {u} 'undoes' only the last change. Type {u} several times and
-observe what happens: {u} can undo a previous {u}!
-
-Caveat: {U} only works as long as the cursor is still on the line. Move the
-cursor off the line and {U} will have no effect, except to possibly beep at
-you. However, {u} will undo the last change, no matter where it occurred.
-
-Section 25: review
-
-At this point, you have all the commands you need in order to make use of vi.
-The remainder of this tutorial will discuss variations on these commands as
-well as introduce new commands that make the job of editing more efficient.
-Here is a brief review of the basic commands we have covered. They are listed
-in the order of increasing complexity and/or decreasing necessity (to say that
-a command is less necessary is not to say that it is less useful!). These
-commands allow you to comfortably edit any text file. There are other
-commands that will make life easier but will require extra time to learn,
-obviously. You may want to consider setting this tutorial aside for several
-weeks and returning to it later after gaining experience with vi and getting
-comfortable with it. The convenience of some of the more exotic commands may
-then be apparent and worth the extra investment of time and effort
-required to master them.
-
-to get into the editor from Unix: {vi filename}
-to exit the editor
- saving all changes {ZZ} or {:wq^M}
- throwing away all changes {:q!^M}
- when no changes have been made {:q^M}
-save a file without exiting the editor {:w^M}
-write the file into another file {:w filename^M}
-insert text
- before the cursor {i ...text... ^[}
- at the beginning of the line {I ...text... ^[}
- after the cursor (append) {a ...text... ^[}
- at the end of the line {A ...text... ^[}
- after the current line {o ...text... ^[}
- before the current line {O ...text... ^[}
-delete the character ...
- under the cursor {x}
- to the left of the cursor {X}
-delete n characters {nx} or {nX} (for n a number)
-make two lines into one line (Join) {J}
-find a string in the file ...
- searching forward {/ ...string... /^M}
- searching backwards {? ...string... ?^M}
-repeat the last search command {n}
-repeat the last search command in the
- opposite direction {N}
-find the character c on this line ...
- searching forward {fc}
- searching backward {Fc}
-repeat the last 'find character' command {;}
-replace a character with character x {rx}
-substitute a single character with text {s ...text... ^[}
-substitute n characters with text {ns ...text... ^[}
-replace characters one-by-one with text {R ...text... ^[}
-undo all changes to the current line {U}
-undo the last single change {u}
-move forward in the file a "screenful" {^F}
-move back in the file a "screenful" {^B}
-move forward in the file one line {^M} or {+}
-move backward in the file one line {-}
-move to the beginning of the line {0}
-move to the end of the line {$}
-move forward one word {w}
-move forward one word, ignoring punctuation {W}
-move forward to the end of the next word {e}
-to the end of the word, ignoring punctuation{E}
-move backward one word {b}
-move back one word, ignoring punctuation {B}
-return to the last line modified {''}
-scroll a line onto the top of the screen {^Y}
-scroll a line onto the bottom of the screen {^E}
-move "up" in the file a half-screen {^U}
-move "down" in the file a half-screen {^D}
-move the cursor to the top screen line {H}
-move the cursor to the bottom screen line {L}
-move the cursor to the middle line {M}
-move LEFT one character position {h} or {^H}
-move RIGHT one character position {l} or { }
-move UP in the same column {k} or {^P}
-move DOWN in the same column {j} or {^N}
-mark the current position, name it x {mx}
-move to the line marked/named x {'x}
-move to the character position named x {`x}
-move to the beginning of the file {1G}
-move to the end of the file {G}
-move to line 23 in the file {23G}
-repaint the screen with the cursor line
- at the top of the screen {z^M}
- in the middle of the screen {z.}
- at the bottom of the screen {z-}
-
-More information on vi can be found in the file vi.advanced, which you can
-peruse at your leisure. From UNIX, type {vi.tut advanced^M}.
diff --git a/usr.bin/vi/docs/tutorial/vi.tut.csh b/usr.bin/vi/docs/tutorial/vi.tut.csh
deleted file mode 100755
index 01554bc..0000000
--- a/usr.bin/vi/docs/tutorial/vi.tut.csh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/csh -f
-#
-# This makes the user's EXINIT variable set to the 'correct' things.
-# I don't know what will happen if they also have a .exrc file!
-#
-# XXX
-# Make sure that user is using a 24 line window!!!
-#
-if ($1 != "beginner" && $1 != "advanced") then
- echo Usage: $0 beginner or $0 advanced
- exit
-endif
-
-if ($?EXINIT) then
- set oexinit="$EXINIT"
- setenv EXINIT 'se ts=4 wm=8 sw=4'
-endif
-
-vi vi.{$1}
-
-onintr:
- if ($?oexinit) then
- setenv EXINIT "$oexinit"
-endif
diff --git a/usr.bin/vi/ex/ex.c b/usr.bin/vi/ex/ex.c
deleted file mode 100644
index 66dddb0..0000000
--- a/usr.bin/vi/ex/ex.c
+++ /dev/null
@@ -1,1866 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex.c 8.157 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-static void badlno __P((SCR *, recno_t));
-static __inline EXCMDLIST const *
- ex_comm_search __P((char *, size_t));
-static int ep_line __P((SCR *, EXF *, MARK *, char **, size_t *, int *));
-static int ep_range __P((SCR *, EXF *, EXCMDARG *, char **, size_t *));
-
-/*
- * ex --
- * Read an ex command and execute it.
- */
-int
-ex(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- enum input irval;
- TEXT *tp;
- u_int flags, saved_mode;
- int eval;
-
- if (ex_init(sp, ep))
- return (1);
-
- if (sp->s_refresh(sp, ep))
- return (ex_end(sp));
-
- /* If reading from a file, messages should have line info. */
- if (!F_ISSET(sp->gp, G_STDIN_TTY)) {
- sp->if_lno = 1;
- sp->if_name = strdup("input");
- }
-
- /*
- * !!!
- * Historically, the beautify option applies to ex command input read
- * from a file. In addition, the first time a ^H was discarded from
- * the input, a message "^H discarded" was displayed. We don't bother.
- */
- LF_INIT(TXT_BACKSLASH | TXT_CNTRLD | TXT_CR | TXT_EXSUSPEND);
-
- for (eval = 0;; ++sp->if_lno) {
- /* Set the flags that the user can change. */
- if (O_ISSET(sp, O_BEAUTIFY))
- LF_SET(TXT_BEAUTIFY);
- else
- LF_CLR(TXT_BEAUTIFY);
- if (O_ISSET(sp, O_PROMPT))
- LF_SET(TXT_PROMPT);
- else
- LF_CLR(TXT_PROMPT);
-
- /*
- * Get the next command. Interrupt flag manipulation is
- * safe because ex_icmd clears them all.
- */
- CLR_INTERRUPT(sp);
- F_SET(sp, S_INTERRUPTIBLE);
- irval = sp->s_get(sp, ep, sp->tiqp, ':', flags);
- if (INTERRUPTED(sp)) {
- (void)fputc('\n', stdout);
- (void)fflush(stdout);
- goto refresh;
- }
- switch (irval) {
- case INP_OK:
- break;
- case INP_EOF:
- case INP_ERR:
- F_SET(sp, S_EXIT_FORCE);
- /* FALLTHROUGH */
- case INP_INTR:
- goto ret;
- }
-
- /*
- * If the user entered a carriage return, send ex_cmd()
- * a separator -- it discards single newlines.
- */
- tp = sp->tiqp->cqh_first;
- if (tp->len == 0) {
- tp->len = 1;
- tp->lb[0] = ' ';
- }
-
- saved_mode = F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE);
- if (ex_icmd(sp, ep,
- tp->lb, tp->len, 1) && !F_ISSET(sp->gp, G_STDIN_TTY))
- F_SET(sp, S_EXIT_FORCE);
- (void)msg_rpt(sp, 0);
- if (saved_mode != F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE))
- break;
-
-refresh: if (sp->s_refresh(sp, ep)) {
- eval = 1;
- break;
- }
- }
-ret: if (sp->if_name != NULL) {
- FREE(sp->if_name, strlen(sp->if_name) + 1);
- sp->if_name = NULL;
- }
- return (ex_end(sp) || eval);
-}
-
-/*
- * ex_cfile --
- * Execute ex commands from a file.
- */
-int
-ex_cfile(sp, ep, filename, needsep)
- SCR *sp;
- EXF *ep;
- char *filename;
- int needsep;
-{
- struct stat sb;
- int fd, len, rval;
- char *bp;
-
- bp = NULL;
- if ((fd = open(filename, O_RDONLY, 0)) < 0 || fstat(fd, &sb))
- goto err;
-
- /*
- * XXX
- * We'd like to test if the file is too big to malloc. Since we don't
- * know what size or type off_t's or size_t's are, what the largest
- * unsigned integral type is, or what random insanity the local C
- * compiler will perpetrate, doing the comparison in a portable way
- * is flatly impossible. Hope that malloc fails if the file is too
- * large.
- */
- MALLOC(sp, bp, char *, (size_t)sb.st_size + 1);
- if (bp == NULL)
- goto err;
-
- len = read(fd, bp, (int)sb.st_size);
- if (len == -1 || len != sb.st_size) {
- if (len != sb.st_size)
- errno = EIO;
-err: rval = 1;
- msgq(sp, M_SYSERR, filename);
- } else {
- bp[sb.st_size] = '\0'; /* XXX */
-
- /*
- * Run the command. Messages include file/line information,
- * but we don't care if we can't get space.
- */
- sp->if_lno = 1;
- sp->if_name = strdup(filename);
- F_SET(sp, S_VLITONLY);
- rval = ex_icmd(sp, ep, bp, len, needsep);
- F_CLR(sp, S_VLITONLY);
- free(sp->if_name);
- sp->if_name = NULL;
- }
-
- /*
- * !!!
- * THE UNDERLYING EXF MAY HAVE CHANGED.
- */
- if (bp != NULL)
- FREE(bp, sb.st_size);
- if (fd >= 0)
- (void)close(fd);
- return (rval);
-}
-
-/*
- * ex_icmd --
- * Call ex_cmd() after turning off interruptible bits.
- */
-int
-ex_icmd(sp, ep, cmd, len, needsep)
- SCR *sp;
- EXF *ep;
- char *cmd;
- size_t len;
- int needsep;
-{
- /*
- * Ex goes through here for each vi :colon command and for each ex
- * command, however, globally executed commands don't go through
- * here, instead, they call ex_cmd directly. So, reset all of the
- * interruptible flags now.
- *
- * !!!
- * Previous versions of nvi cleared mapped characters on error. This
- * feature was removed when users complained that it wasn't historic
- * practice.
- */
- CLR_INTERRUPT(sp);
- return (ex_cmd(sp, ep, cmd, len, needsep));
-}
-
-/* Special command structure for :s as a repeat substitution command. */
-static EXCMDLIST const cmd_subagain =
- {"s", ex_subagain, E_ADDR2|E_NORC,
- "s",
- "[line [,line]] s [cgr] [count] [#lp]",
- "repeat the last subsitution"};
-
-/* Special command structure for :d[flags]. */
-static EXCMDLIST const cmd_del2 =
- {"delete", ex_delete, E_ADDR2|E_AUTOPRINT|E_NORC,
- "1bca1",
- "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
- "delete lines from the file"};
-
-/*
- * ex_cmd --
- * Parse and execute a string containing ex commands.
- */
-int
-ex_cmd(sp, ep, cmd, cmdlen, needsep)
- SCR *sp;
- EXF *ep;
- char *cmd;
- size_t cmdlen;
- int needsep;
-{
- enum { NOTSET, NEEDSEP_N, NEEDSEP_NR, NONE } sep;
- EX_PRIVATE *exp;
- EXCMDARG exc;
- EXCMDLIST const *cp;
- MARK cur;
- recno_t lno, num;
- size_t arg1_len, len, save_cmdlen;
- long flagoff;
- u_int saved_mode;
- int blank, ch, cnt, delim, flags, namelen, nl;
- int optnum, uselastcmd, tmp, vi_address;
- char *arg1, *save_cmd, *p, *s, *t;
-
- /* Init. */
- nl = 0;
- sep = needsep ? NOTSET : NONE;
-loop: if (nl) {
- nl = 0;
- ++sp->if_lno;
- }
- arg1 = NULL;
- save_cmdlen = 0;
-
- /* It's possible that we've been interrupted during a command. */
- if (INTERRUPTED(sp))
- return (0);
-
- /* Skip <blank>s, empty lines. */
- for (blank = 0; cmdlen > 0; ++cmd, --cmdlen)
- if ((ch = *cmd) == '\n')
- ++sp->if_lno;
- else if (isblank(ch))
- blank = 1;
- else
- break;
-
- /*
- * !!!
- * Permit extra colons at the start of the line. Historically,
- * ex/vi allowed a single extra one. It's simpler not to count.
- * The stripping is done here because, historically, any command
- * could have preceding colons, e.g. ":g/pattern/:p" worked.
- */
- if (cmdlen != 0 && ch == ':') {
- if (sep == NOTSET)
- sep = NEEDSEP_N;
- while (--cmdlen > 0 && (ch = *++cmd) == ':');
- }
-
- /*
- * Command lines that start with a double-quote are comments.
- *
- * !!!
- * Historically, there was no escape or delimiter for a comment,
- * e.g. :"foo|set was a single comment and nothing was output.
- * Since nvi permits users to escape <newline> characters into
- * command lines, we have to check for that case.
- */
- if (cmdlen != 0 && ch == '"') {
- while (--cmdlen > 0 && *++cmd != '\n');
- if (*cmd == '\n') {
- nl = 1;
- ++cmd;
- --cmdlen;
- }
- goto loop;
- }
-
- /* Skip whitespace. */
- for (; cmdlen > 0; ++cmd, --cmdlen) {
- ch = *cmd;
- if (!isblank(ch))
- break;
- }
-
- /*
- * The last point at which an empty line can mean do nothing.
- *
- * !!!
- * Historically, in ex mode, lines containing only <blank> characters
- * were the same as a single <carriage-return>, i.e. a default command.
- * In vi mode, they were ignored.
- *
- * In .exrc files this was a serious annoyance, as vi kept trying to
- * treat them as print commands. We ignore backward compatibility in
- * this case, and discard lines containing only <blank> characters from
- * .exrc files.
- */
- if (cmdlen == 0 && (!IN_EX_MODE(sp) || ep == NULL || !blank))
- return (0);
-
- /* Initialize the structure passed to underlying functions. */
- memset(&exc, 0, sizeof(EXCMDARG));
- exp = EXP(sp);
- if (argv_init(sp, ep, &exc))
- goto err;
-
- /*
- * Check to see if this is a command for which we may want to output
- * a \r separator instead of a \n. (The command :1<CR> puts out a \n,
- * but the command :<CR> puts out a \r.) If the line is empty except
- * for <blank>s, <carriage-return> or <eof>, we'll probably want to
- * output \r. I don't think there's any way to get <blank> characters
- * *after* the command character, but this is the ex parser, and I've
- * been wrong before.
- */
- if (sep == NOTSET)
- sep = cmdlen == 0 || cmdlen == 1 && cmd[0] == '\004' ?
- NEEDSEP_NR : NEEDSEP_N;
-
- /* Parse command addresses. */
- if (ep_range(sp, ep, &exc, &cmd, &cmdlen))
- goto err;
-
- /* Skip whitespace. */
- for (; cmdlen > 0; ++cmd, --cmdlen) {
- ch = *cmd;
- if (!isblank(ch))
- break;
- }
-
- /*
- * If no command, ex does the last specified of p, l, or #, and vi
- * moves to the line. Otherwise, determine the length of the command
- * name by looking for the first non-alphabetic character. (There
- * are a few non-alphabetic characters in command names, but they're
- * all single character commands.) This isn't a great test, because
- * it means that, for the command ":e +cut.c file", we'll report that
- * the command "cut" wasn't known. However, it makes ":e+35 file" work
- * correctly.
- *
- * !!!
- * Historically, lines with multiple adjacent (or <blank> separated)
- * command separators were very strange. For example, the command
- * |||<carriage-return>, when the cursor was on line 1, displayed
- * lines 2, 3 and 5 of the file. In addition, the command " | "
- * would only display the line after the next line, instead of the
- * next two lines. No ideas why. It worked reasonably when executed
- * from vi mode, and displayed lines 2, 3, and 4, so we do a default
- * command for each separator.
- */
-#define SINGLE_CHAR_COMMANDS "\004!#&*<=>@~"
- if (cmdlen != 0 && cmd[0] != '|' && cmd[0] != '\n') {
- if (strchr(SINGLE_CHAR_COMMANDS, *cmd)) {
- p = cmd;
- ++cmd;
- --cmdlen;
- namelen = 1;
- } else {
- for (p = cmd; cmdlen > 0; --cmdlen, ++cmd)
- if (!isalpha(*cmd))
- break;
- if ((namelen = cmd - p) == 0) {
- msgq(sp, M_ERR, "Unknown command name");
- goto err;
- }
- }
-
- /*
- * !!!
- * Historic vi permitted flags to immediately follow any
- * subset of the 'delete' command, but then did not permit
- * further arguments (flag, buffer, count). Make it work.
- * Permit further arguments for the few shreds of dignity
- * it offers.
- *
- * !!!
- * Note, adding commands that start with 'd', and match
- * "delete" up to a l, p, +, - or # character can break
- * this code.
- */
- if (p[0] == 'd') {
- for (s = p,
- t = cmds[C_DELETE].name; *s == *t; ++s, ++t);
- if (s[0] == 'l' || s[0] == 'p' ||
- s[0] == '+' || s[0] == '-' || s[0] == '#') {
- len = (cmd - p) - (s - p);
- cmd -= len;
- cmdlen += len;
- cp = &cmd_del2;
- goto skip;
- }
- }
-
- /*
- * Search the table for the command.
- *
- * !!!
- * Historic vi permitted the mark to immediately follow the
- * 'k' in the 'k' command. Make it work.
- *
- * !!!
- * Historic vi permitted pretty much anything to follow the
- * substitute command, e.g. "s/e/E/|s|sgc3p" was fine. Make
- * the command "sgc" work.
- */
- if ((cp = ex_comm_search(p, namelen)) == NULL)
- switch (p[0]) {
- case 's':
- cmd -= namelen - 1;
- cmdlen += namelen - 1;
- cp = &cmd_subagain;
- break;
- case 'k':
- if (p[1] && !p[2]) {
- cmd -= namelen - 1;
- cmdlen += namelen - 1;
- cp = &cmds[C_K];
- break;
- }
- /* FALLTHROUGH */
- default:
- msgq(sp, M_ERR,
- "The %.*s command is unknown", namelen, p);
- goto err;
- }
-
- /* Some commands are either not implemented or turned off. */
-skip: if (F_ISSET(cp, E_NOPERM)) {
- msgq(sp, M_ERR,
- "The %s command is not currently supported",
- cp->name);
- goto err;
- }
-
- /* Some commands aren't okay in globals. */
- if (F_ISSET(sp, S_GLOBAL) && F_ISSET(cp, E_NOGLOBAL)) {
- msgq(sp, M_ERR,
- "The %s command can't be used as part of a global command",
- cp->name);
- goto err;
- }
-
- /*
- * Multiple < and > characters; another "feature". Note,
- * The string passed to the underlying function may not be
- * nul terminated in this case.
- */
- if ((cp == &cmds[C_SHIFTL] && *p == '<') ||
- (cp == &cmds[C_SHIFTR] && *p == '>')) {
- for (ch = *p; cmdlen > 0; --cmdlen, ++cmd)
- if (*cmd != ch)
- break;
- if (argv_exp0(sp, ep, &exc, p, cmd - p))
- goto err;
- }
-
- /*
- * The visual command has a different syntax when called
- * from ex than when called from a vi colon command. FMH.
- */
- if (cp == &cmds[C_VISUAL_EX] && IN_VI_MODE(sp))
- cp = &cmds[C_VISUAL_VI];
-
- /* Set the format style flags for the next command. */
- if (cp == &cmds[C_HASH])
- exp->fdef = E_F_HASH;
- else if (cp == &cmds[C_LIST])
- exp->fdef = E_F_LIST;
- else if (cp == &cmds[C_PRINT])
- exp->fdef = E_F_PRINT;
- uselastcmd = 0;
- } else {
- /* Print is the default command. */
- cp = &cmds[C_PRINT];
-
- /* Set the saved format flags. */
- F_SET(&exc, exp->fdef);
-
- /*
- * !!!
- * If no address was specified, and it's not a global command,
- * we up the address by one. (I have not an idea why global
- * commands are exempted, but it's (ahem) historic practice.
- */
- if (exc.addrcnt == 0 && !F_ISSET(sp, S_GLOBAL)) {
- exc.addrcnt = 1;
- exc.addr1.lno = sp->lno + 1;
- exc.addr1.cno = sp->cno;
- }
-
- uselastcmd = 1;
- }
-
- /*
- * !!!
- * Historically, the number option applied to both ex and vi. One
- * strangeness was that ex didn't switch display formats until a
- * command was entered, e.g. <CR>'s after the set didn't change to
- * the new format, but :1p would.
- */
- if (O_ISSET(sp, O_NUMBER)) {
- optnum = 1;
- F_SET(&exc, E_F_HASH);
- } else
- optnum = 0;
-
- /* Initialize local flags to the command flags. */
- LF_INIT(cp->flags);
-
- /*
- * File state must be checked throughout this code, because it is
- * called when reading the .exrc file and similar things. There's
- * this little chicken and egg problem -- if we read the file first,
- * we won't know how to display it. If we read/set the exrc stuff
- * first, we can't allow any command that requires file state. We
- * don't have a "reading an rc" bit, because we want the commands
- * to work when the user source's the rc file later. Historic vi
- * generally took the easy way out and dropped core.
- */
- if (LF_ISSET(E_NORC) && ep == NULL) {
- msgq(sp, M_ERR,
- "The %s command requires that a file have already been read in",
- cp->name);
- goto err;
- }
-
- /*
- * There are three normal termination cases for an ex command. They
- * are the end of the string (cmdlen), or unescaped (by literal next
- * characters) newline or '|' characters. As we're past any addresses,
- * we can now determine how long the command is, so we don't have to
- * look for all the possible terminations. There are three exciting
- * special cases:
- *
- * 1: The bang, global, vglobal and the filter versions of the read and
- * write commands are delimited by newlines (they can contain shell
- * pipes).
- * 2: The ex, edit, next and visual in vi mode commands all take ex
- * commands as their first arguments.
- * 3: The substitute command takes an RE as its first argument, and
- * wants it to be specially delimited.
- *
- * Historically, '|' characters in the first argument of the ex, edit,
- * next, vi visual, and substitute commands didn't delimit the command.
- * And, in the filter cases for read and write, and the bang, global
- * and vglobal commands, they did not delimit the command at all.
- *
- * For example, the following commands were legal:
- *
- * :edit +25|s/abc/ABC/ file.c
- * :substitute s/|/PIPE/
- * :read !spell % | columnate
- * :global/pattern/p|l
- *
- * It's not quite as simple as it sounds, however. The command:
- *
- * :substitute s/a/b/|s/c/d|set
- *
- * was also legal, i.e. the historic ex parser (using the word loosely,
- * since "parser" implies some regularity) delimited the RE's based on
- * its delimiter and not anything so irretrievably vulgar as a command
- * syntax.
- *
- * One thing that makes this easier is that we can ignore most of the
- * command termination conditions for the commands that want to take
- * the command up to the next newline. None of them are legal in .exrc
- * files, so if we're here, we only dealing with a single line, and we
- * can just eat it.
- *
- * Anyhow, the following code makes this all work. First, for the
- * special cases we move past their special argument(s). Then, we
- * do normal command processing on whatever is left. Barf-O-Rama.
- */
- arg1_len = 0;
- save_cmd = cmd;
- if (cp == &cmds[C_EDIT] || cp == &cmds[C_EX] ||
- cp == &cmds[C_NEXT] || cp == &cmds[C_VISUAL_VI]) {
- /*
- * Move to the next non-whitespace character. A '!'
- * immediately following the command is eaten as a
- * force flag.
- */
- if (cmdlen > 0 && *cmd == '!') {
- ++cmd;
- --cmdlen;
- F_SET(&exc, E_FORCE);
-
- /* Reset, don't reparse. */
- save_cmd = cmd;
- }
- for (tmp = 0; cmdlen > 0; --cmdlen, ++cmd)
- if (!isblank(*cmd))
- break;
- /*
- * QUOTING NOTE:
- *
- * The historic implementation ignored all escape characters
- * so there was no way to put a space or newline into the +cmd
- * field. We do a simplistic job of fixing it by moving to the
- * first whitespace character that isn't escaped by a literal
- * next character. The literal next characters are stripped
- * as they're no longer useful.
- */
- if (cmdlen > 0 && *cmd == '+') {
- ++cmd;
- --cmdlen;
- for (arg1 = p = cmd; cmdlen > 0; --cmdlen, ++cmd) {
- ch = *cmd;
- if (IS_ESCAPE(sp, ch) && cmdlen > 1) {
- --cmdlen;
- ch = *++cmd;
- } else if (isblank(ch))
- break;
- *p++ = ch;
- }
- arg1_len = cmd - arg1;
-
- /* Reset, so the first argument isn't reparsed. */
- save_cmd = cmd;
- }
- } else if (cp == &cmds[C_BANG] ||
- cp == &cmds[C_GLOBAL] || cp == &cmds[C_VGLOBAL]) {
- cmd += cmdlen;
- cmdlen = 0;
- } else if (cp == &cmds[C_READ] || cp == &cmds[C_WRITE]) {
- /*
- * Move to the next character. If it's a '!', it's a filter
- * command and we want to eat it all, otherwise, we're done.
- */
- for (; cmdlen > 0; --cmdlen, ++cmd) {
- ch = *cmd;
- if (!isblank(ch))
- break;
- }
- if (cmdlen > 0 && ch == '!') {
- cmd += cmdlen;
- cmdlen = 0;
- }
- } else if (cp == &cmds[C_SUBSTITUTE]) {
- /*
- * Move to the next non-whitespace character, we'll use it as
- * the delimiter. If the character isn't an alphanumeric or
- * a '|', it's the delimiter, so parse it. Otherwise, we're
- * into something like ":s g", so use the special substitute
- * command.
- */
- for (; cmdlen > 0; --cmdlen, ++cmd)
- if (!isblank(cmd[0]))
- break;
-
- if (isalnum(cmd[0]) || cmd[0] == '|')
- cp = &cmd_subagain;
- else if (cmdlen > 0) {
- /*
- * QUOTING NOTE:
- *
- * Backslashes quote delimiter characters for RE's.
- * The backslashes are NOT removed since they'll be
- * used by the RE code. Move to the third delimiter
- * that's not escaped (or the end of the command).
- */
- delim = *cmd;
- ++cmd;
- --cmdlen;
- for (cnt = 2; cmdlen > 0 && cnt; --cmdlen, ++cmd)
- if (cmd[0] == '\\' && cmdlen > 1) {
- ++cmd;
- --cmdlen;
- } else if (cmd[0] == delim)
- --cnt;
- }
- }
- /*
- * Use normal quoting and termination rules to find the end of this
- * command.
- *
- * QUOTING NOTE:
- *
- * Historically, vi permitted ^V's to escape <newline>'s in the .exrc
- * file. It was almost certainly a bug, but that's what bug-for-bug
- * compatibility means, Grasshopper. Also, ^V's escape the command
- * delimiters. Literal next quote characters in front of the newlines,
- * '|' characters or literal next characters are stripped as as they're
- * no longer useful.
- */
- vi_address = cmdlen != 0 && cmd[0] != '\n';
- for (p = cmd, cnt = 0; cmdlen > 0; --cmdlen, ++cmd) {
- ch = cmd[0];
- if (IS_ESCAPE(sp, ch) && cmdlen > 1) {
- tmp = cmd[1];
- if (tmp == '\n' || tmp == '|') {
- if (tmp == '\n')
- ++sp->if_lno;
- --cmdlen;
- ++cmd;
- ++cnt;
- ch = tmp;
- }
- } else if (ch == '\n' || ch == '|') {
- if (ch == '\n')
- nl = 1;
- --cmdlen;
- break;
- }
- *p++ = ch;
- }
-
- /*
- * Save off the next command information, go back to the
- * original start of the command.
- */
- p = cmd + 1;
- cmd = save_cmd;
- save_cmd = p;
- save_cmdlen = cmdlen;
- cmdlen = ((save_cmd - cmd) - 1) - cnt;
-
- /*
- * !!!
- * The "set tags" command historically used a backslash, not the
- * user's literal next character, to escape whitespace. Handle
- * it here instead of complicating the argv_exp3() code. Note,
- * this isn't a particularly complex trap, and if backslashes were
- * legal in set commands, this would have to be much more complicated.
- */
- if (cp == &cmds[C_SET])
- for (p = cmd, len = cmdlen; len > 0; --len, ++p)
- if (*p == '\\')
- *p = CH_LITERAL;
-
- /*
- * Set the default addresses. It's an error to specify an address for
- * a command that doesn't take them. If two addresses are specified
- * for a command that only takes one, lose the first one. Two special
- * cases here, some commands take 0 or 2 addresses. For most of them
- * (the E_ADDR2_ALL flag), 0 defaults to the entire file. For one
- * (the `!' command, the E_ADDR2_NONE flag), 0 defaults to no lines.
- *
- * Also, if the file is empty, some commands want to use an address of
- * 0, i.e. the entire file is 0 to 0, and the default first address is
- * 0. Otherwise, an entire file is 1 to N and the default line is 1.
- * Note, we also add the E_ZERO flag to the command flags, for the case
- * where the 0 address is only valid if it's a default address.
- *
- * Also, set a flag if we set the default addresses. Some commands
- * (ex: z) care if the user specified an address of if we just used
- * the current cursor.
- */
- switch (LF_ISSET(E_ADDR1|E_ADDR2|E_ADDR2_ALL|E_ADDR2_NONE)) {
- case E_ADDR1: /* One address: */
- switch (exc.addrcnt) {
- case 0: /* Default cursor/empty file. */
- exc.addrcnt = 1;
- F_SET(&exc, E_ADDRDEF);
- if (LF_ISSET(E_ZERODEF)) {
- if (file_lline(sp, ep, &lno))
- goto err;
- if (lno == 0) {
- exc.addr1.lno = 0;
- LF_SET(E_ZERO);
- } else
- exc.addr1.lno = sp->lno;
- } else
- exc.addr1.lno = sp->lno;
- exc.addr1.cno = sp->cno;
- break;
- case 1:
- break;
- case 2: /* Lose the first address. */
- exc.addrcnt = 1;
- exc.addr1 = exc.addr2;
- }
- break;
- case E_ADDR2_NONE: /* Zero/two addresses: */
- if (exc.addrcnt == 0) /* Default to nothing. */
- break;
- goto two;
- case E_ADDR2_ALL: /* Zero/two addresses: */
- if (exc.addrcnt == 0) { /* Default entire/empty file. */
- exc.addrcnt = 2;
- F_SET(&exc, E_ADDRDEF);
- if (file_lline(sp, ep, &exc.addr2.lno))
- goto err;
- if (LF_ISSET(E_ZERODEF) && exc.addr2.lno == 0) {
- exc.addr1.lno = 0;
- LF_SET(E_ZERO);
- } else
- exc.addr1.lno = 1;
- exc.addr1.cno = exc.addr2.cno = 0;
- F_SET(&exc, E_ADDR2_ALL);
- break;
- }
- /* FALLTHROUGH */
- case E_ADDR2: /* Two addresses: */
-two: switch (exc.addrcnt) {
- case 0: /* Default cursor/empty file. */
- exc.addrcnt = 2;
- F_SET(&exc, E_ADDRDEF);
- if (LF_ISSET(E_ZERODEF) && sp->lno == 1) {
- if (file_lline(sp, ep, &lno))
- goto err;
- if (lno == 0) {
- exc.addr1.lno = exc.addr2.lno = 0;
- LF_SET(E_ZERO);
- } else
- exc.addr1.lno = exc.addr2.lno = sp->lno;
- } else
- exc.addr1.lno = exc.addr2.lno = sp->lno;
- exc.addr1.cno = exc.addr2.cno = sp->cno;
- break;
- case 1: /* Default to first address. */
- exc.addrcnt = 2;
- exc.addr2 = exc.addr1;
- break;
- case 2:
- break;
- }
- break;
- default:
- if (exc.addrcnt) /* Error. */
- goto usage;
- }
-
- /*
- * !!!
- * The ^D scroll command historically scrolled the value of the scroll
- * option or to EOF. It was an error if the cursor was already at EOF.
- * (Leading addresses were permitted, but were then ignored.)
- */
- if (cp == &cmds[C_SCROLL]) {
- exc.addrcnt = 2;
- exc.addr1.lno = sp->lno + 1;
- exc.addr2.lno = sp->lno + O_VAL(sp, O_SCROLL);
- exc.addr1.cno = exc.addr2.cno = sp->cno;
- if (file_lline(sp, ep, &lno))
- goto err;
- if (lno != 0 && lno > sp->lno && exc.addr2.lno > lno)
- exc.addr2.lno = lno;
- }
-
- flagoff = 0;
- for (p = cp->syntax; *p != '\0'; ++p) {
- /*
- * The force flag is sensitive to leading whitespace, i.e.
- * "next !" is different from "next!". Handle it before
- * skipping leading <blank>s.
- */
- if (*p == '!') {
- if (cmdlen > 0 && *cmd == '!') {
- ++cmd;
- --cmdlen;
- F_SET(&exc, E_FORCE);
- }
- continue;
- }
-
- /* Skip leading <blank>s. */
- for (; cmdlen > 0; --cmdlen, ++cmd)
- if (!isblank(*cmd))
- break;
-
- /*
- * Quit when reach the end of the command, unless it's a
- * command that does its own parsing, in which case we want
- * to build a reasonable argv for it. This code guarantees
- * that there will be an argv when the function gets called,
- * so the correct test is for a length of 0, not for the
- * argc > 0. Since '!' can precede commands that do their
- * own parsing, we have to have already handled it.
- */
- if (cmdlen == 0 && *p != 'S' && *p != 's')
- break;
-
- switch (*p) {
- case '1': /* +, -, #, l, p */
- /*
- * !!!
- * Historically, some flags were ignored depending
- * on where they occurred in the command line. For
- * example, in the command, ":3+++p--#", historic vi
- * acted on the '#' flag, but ignored the '-' flags.
- * It's unambiguous what the flags mean, so we just
- * handle them regardless of the stupidity of their
- * location.
- */
- for (; cmdlen; --cmdlen, ++cmd)
- switch (*cmd) {
- case '+':
- ++flagoff;
- break;
- case '-':
- --flagoff;
- break;
- case '#':
- optnum = 0;
- F_SET(&exc, E_F_HASH);
- exp->fdef |= E_F_HASH;
- break;
- case 'l':
- F_SET(&exc, E_F_LIST);
- exp->fdef |= E_F_LIST;
- break;
- case 'p':
- F_SET(&exc, E_F_PRINT);
- exp->fdef |= E_F_PRINT;
- break;
- default:
- goto end1;
- }
-end1: break;
- case '2': /* -, ., +, ^ */
- case '3': /* -, ., +, ^, = */
- for (; cmdlen; --cmdlen, ++cmd)
- switch (*cmd) {
- case '-':
- F_SET(&exc, E_F_DASH);
- break;
- case '.':
- F_SET(&exc, E_F_DOT);
- break;
- case '+':
- F_SET(&exc, E_F_PLUS);
- break;
- case '^':
- F_SET(&exc, E_F_CARAT);
- break;
- case '=':
- if (*p == '3') {
- F_SET(&exc, E_F_EQUAL);
- break;
- }
- /* FALLTHROUGH */
- default:
- goto end2;
- }
-end2: break;
- case 'b': /* buffer */
- /*
- * !!!
- * Historically, "d #" was a delete with a flag, not a
- * delete into the '#' buffer. If the current command
- * permits a flag, don't use one as a buffer. However,
- * the 'l' and 'p' flags were legal buffer names in the
- * historic ex, and were used as buffers, not flags.
- */
- if ((cmd[0] == '+' || cmd[0] == '-' || cmd[0] == '#') &&
- strchr(p, '1') != NULL)
- break;
- /*
- * !!!
- * Digits can't be buffer names in ex commands, or the
- * command "d2" would be a delete into buffer '2', and
- * not a two-line deletion.
- */
- if (!isdigit(cmd[0])) {
- exc.buffer = *cmd;
- ++cmd;
- --cmdlen;
- F_SET(&exc, E_BUFFER);
- }
- break;
- case 'c': /* count [01+a] */
- ++p;
- /* Validate any signed value. */
- if (!isdigit(*cmd) &&
- (*p != '+' || (*cmd != '+' && *cmd != '-')))
- break;
- /* If a signed value, set appropriate flags. */
- if (*cmd == '-')
- F_SET(&exc, E_COUNT_NEG);
- else if (*cmd == '+')
- F_SET(&exc, E_COUNT_POS);
-/* 8-bit XXX */ if ((lno = strtol(cmd, &t, 10)) == 0 && *p != '0') {
- msgq(sp, M_ERR, "Count may not be zero");
- goto err;
- }
- cmdlen -= (t - cmd);
- cmd = t;
- /*
- * Count as address offsets occur in commands taking
- * two addresses. Historic vi practice was to use
- * the count as an offset from the *second* address.
- *
- * Set a count flag; some underlying commands (see
- * join) do different things with counts than with
- * line addresses.
- */
- if (*p == 'a') {
- exc.addr1 = exc.addr2;
- exc.addr2.lno = exc.addr1.lno + lno - 1;
- } else
- exc.count = lno;
- F_SET(&exc, E_COUNT);
- break;
- case 'f': /* file */
- if (argv_exp2(sp, ep,
- &exc, cmd, cmdlen, cp == &cmds[C_BANG]))
- goto err;
- goto countchk;
- case 'l': /* line */
- if (ep_line(sp, ep, &cur, &cmd, &cmdlen, &tmp))
- goto err;
- /* Line specifications are always required. */
- if (!tmp) {
- msgq(sp, M_ERR,
- "%s: bad line specification", cmd);
- goto err;
- }
- /* The line must exist for these commands. */
- if (file_lline(sp, ep, &lno))
- goto err;
- if (cur.lno > lno) {
- badlno(sp, lno);
- goto err;
- }
- exc.lineno = cur.lno;
- break;
- case 'S': /* string, file exp. */
- if (argv_exp1(sp, ep,
- &exc, cmd, cmdlen, cp == &cmds[C_BANG]))
- goto err;
- goto addr2;
- case 's': /* string */
- if (argv_exp0(sp, ep, &exc, cmd, cmdlen))
- goto err;
- goto addr2;
- case 'W': /* word string */
- /*
- * QUOTING NOTE:
- *
- * Literal next characters escape the following
- * character. Quoting characters are stripped
- * here since they are no longer useful.
- *
- * First there was the word.
- */
- for (p = t = cmd; cmdlen > 0; --cmdlen, ++cmd) {
- ch = *cmd;
- if (IS_ESCAPE(sp, ch) && cmdlen > 1) {
- --cmdlen;
- *p++ = *++cmd;
- } else if (isblank(ch)) {
- ++cmd;
- --cmdlen;
- break;
- } else
- *p++ = ch;
- }
- if (argv_exp0(sp, ep, &exc, t, p - t))
- goto err;
-
- /* Delete intervening whitespace. */
- for (; cmdlen > 0; --cmdlen, ++cmd) {
- ch = *cmd;
- if (!isblank(ch))
- break;
- }
- if (cmdlen == 0)
- goto usage;
-
- /* Followed by the string. */
- for (p = t = cmd; cmdlen > 0; --cmdlen, ++cmd, ++p) {
- ch = *cmd;
- if (IS_ESCAPE(sp, ch) && cmdlen > 1) {
- --cmdlen;
- *p = *++cmd;
- } else
- *p = ch;
- }
- if (argv_exp0(sp, ep, &exc, t, p - t))
- goto err;
- goto addr2;
- case 'w': /* word */
- if (argv_exp3(sp, ep, &exc, cmd, cmdlen))
- goto err;
-countchk: if (*++p != 'N') { /* N */
- /*
- * If a number is specified, must either be
- * 0 or that number, if optional, and that
- * number, if required.
- */
- num = *p - '0';
- if ((*++p != 'o' || exp->argsoff != 0) &&
- exp->argsoff != num)
- goto usage;
- }
- goto addr2;
- default:
- msgq(sp, M_ERR,
- "Internal syntax table error (%s: %c)",
- cp->name, *p);
- }
- }
-
- /* Skip trailing whitespace. */
- for (; cmdlen; --cmdlen) {
- ch = *cmd++;
- if (!isblank(ch))
- break;
- }
-
- /*
- * There shouldn't be anything left, and no more required
- * fields, i.e neither 'l' or 'r' in the syntax string.
- */
- if (cmdlen || strpbrk(p, "lr")) {
-usage: msgq(sp, M_ERR, "Usage: %s", cp->usage);
- goto err;
- }
-
- /* Verify that the addresses are legal. */
-addr2: switch (exc.addrcnt) {
- case 2:
- if (file_lline(sp, ep, &lno))
- goto err;
- /*
- * Historic ex/vi permitted commands with counts to go past
- * EOF. So, for example, if the file only had 5 lines, the
- * ex command "1,6>" would fail, but the command ">300"
- * would succeed. Since we don't want to have to make all
- * of the underlying commands handle random line numbers,
- * fix it here.
- */
- if (exc.addr2.lno > lno)
- if (F_ISSET(&exc, E_COUNT))
- exc.addr2.lno = lno;
- else {
- badlno(sp, lno);
- goto err;
- }
- /* FALLTHROUGH */
- case 1:
- num = exc.addr1.lno;
- /*
- * If it's a "default vi command", zero is okay. Historic
- * vi allowed this, note, it's also the hack that allows
- * "vi +100 nonexistent_file" to work.
- */
- if (num == 0 && (IN_EX_MODE(sp) || uselastcmd != 1) &&
- !LF_ISSET(E_ZERO)) {
- msgq(sp, M_ERR,
- "The %s command doesn't permit an address of 0",
- cp->name);
- goto err;
- }
- if (file_lline(sp, ep, &lno))
- goto err;
- if (num > lno) {
- badlno(sp, lno);
- goto err;
- }
- break;
- }
-
- /*
- * If doing a default command and there's nothing left on the line,
- * vi just moves to the line. For example, ":3" and ":'a,'b" just
- * move to line 3 and line 'b, respectively, but ":3|" prints line 3.
- *
- * !!!
- * This is done before the absolute mark gets set; historically,
- * "/a/,/b/" did NOT set vi's absolute mark, but "/a/,/b/d" did.
- */
- if (IN_VI_MODE(sp) && uselastcmd && vi_address == 0) {
- switch (exc.addrcnt) {
- case 2:
- sp->lno = exc.addr2.lno ? exc.addr2.lno : 1;
- sp->cno = exc.addr2.cno;
- break;
- case 1:
- sp->lno = exc.addr1.lno ? exc.addr1.lno : 1;
- sp->cno = exc.addr1.cno;
- break;
- }
- cmd = save_cmd;
- cmdlen = save_cmdlen;
- goto loop;
- }
-
- /*
- * Set the absolute mark -- we have to set it for vi here, in case
- * it's a compound command, e.g. ":5p|6" should set the absolute
- * mark for vi.
- */
- if (F_ISSET(exp, EX_ABSMARK)) {
- cur.lno = sp->lno;
- cur.cno = sp->cno;
- F_CLR(exp, EX_ABSMARK);
- if (mark_set(sp, ep, ABSMARK1, &cur, 1))
- goto err;
- }
-
- /* Final setup for the command. */
- exc.cmd = cp;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "ex_cmd: %s", exc.cmd->name);
- if (exc.addrcnt > 0) {
- TRACE(sp, "\taddr1 %d", exc.addr1.lno);
- if (exc.addrcnt > 1)
- TRACE(sp, " addr2: %d", exc.addr2.lno);
- TRACE(sp, "\n");
- }
- if (exc.lineno)
- TRACE(sp, "\tlineno %d", exc.lineno);
- if (exc.flags)
- TRACE(sp, "\tflags %0x", exc.flags);
- if (F_ISSET(&exc, E_BUFFER))
- TRACE(sp, "\tbuffer %c", exc.buffer);
- TRACE(sp, "\n");
- if (exc.argc) {
- for (cnt = 0; cnt < exc.argc; ++cnt)
- TRACE(sp, "\targ %d: {%s}", cnt, exc.argv[cnt]);
- TRACE(sp, "\n");
- }
-#endif
- /* Clear autoprint flag. */
- F_CLR(exp, EX_AUTOPRINT);
-
- /* Increment the command count if not called from vi. */
- if (IN_EX_MODE(sp))
- ++sp->ccnt;
-
- /*
- * If file state available, and not doing a global command,
- * log the start of an action.
- */
- if (ep != NULL && !F_ISSET(sp, S_GLOBAL))
- (void)log_cursor(sp, ep);
-
- /*
- * !!!
- * There are two special commands for the purposes of this code: the
- * default command (<carriage-return>) or the scrolling commands (^D
- * and <EOF>) as the first non-<blank> characters in the line.
- *
- * If this is the first command in the command line, we received the
- * command from the ex command loop and we're talking to a tty, and
- * and there's nothing else on the command line, and it's one of the
- * special commands, we erase the prompt character with a '\r'. Else,
- * we put out a newline character to separate the command from the
- * output from the command. It's OK if vi calls us -- we won't be in
- * ex mode so we'll do nothing.
- *
- * !!!
- * Historically, ex only put out a \r, so, if the displayed line was
- * only a single character long, and <eof> was represented as ^D, the
- * output wouldn't overwrite the user's input. Sex currently doesn't
- * display the <eof> character if it's going to be the scroll command,
- * i.e. if it's the first non-<blank> character in the line. If sex
- * is changed to run in cooked mode, i.e. <eof> is displayed, this code
- * will have to overwrite it. We also don't treat lines with extra
- * prompt characters as empty -- it's not worth the effort since we'd
- * have to overwrite some indeterminate number of columns with spaces
- * to clean up. For now, put out enough spaces to overwrite the prompt.
- */
- if (sep != NONE) {
- if (ep != NULL &&
- IN_EX_MODE(sp) && F_ISSET(sp->gp, G_STDIN_TTY))
- if (sep == NEEDSEP_NR &&
- (uselastcmd || cp == &cmds[C_SCROLL])) {
- (void)putchar('\r');
- for (len = KEY_LEN(sp, PROMPTCHAR); len--;)
- (void)putchar(' ');
- (void)putchar('\r');
- } else
- (void)putchar('\n');
- sep = NONE;
- }
-
- /* Save the current mode. */
- saved_mode = F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE);
-
- /* Do the command. */
- if (cp->fn(sp, ep, &exc))
- goto err;
-
-#ifdef DEBUG
- /* Make sure no function left the temporary space locked. */
- if (F_ISSET(sp->gp, G_TMP_INUSE)) {
- F_CLR(sp->gp, G_TMP_INUSE);
- msgq(sp, M_ERR, "Error: ex: temporary buffer not released");
- goto err;
- }
-#endif
- if (saved_mode != F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE)) {
- /*
- * Only here if the mode of the underlying file changed, e.g.
- * the user switched files or is exiting. Two things that we
- * might have to save: first, any "+cmd" field set up for an
- * ex/edit command will have to be saved for later, also, any
- * part of the current ex command that hasn't been executed
- * yet. For example:
- *
- * :edit +25 file.c|s/abc/ABC/|1
- *
- * !!!
- * The historic vi just hung, of course; nvi handles it by
- * pushing the keys onto the tty queue. Since the commands
- * are intended as ex commands, add additional characters
- * to make it all work if we're switching modes to vi. Also,
- * + commands were oriented to the last line in the file,
- * historically, make the cursor start out there.
- *
- * For the fun of it, if you want to see if a vi clone got the
- * ex argument parsing right, try:
- *
- * echo 'foo|bar' > file1; echo 'foo/bar' > file2;
- * vi
- * :edit +1|s/|/PIPE/|w file1| e file2|1 | s/\//SLASH/|wq
- */
- if (arg1_len == 0 && save_cmdlen == 0)
- return (0);
- if (term_push(sp, "\n", 1, 0))
- goto err;
- if (save_cmdlen != 0)
- if (term_push(sp, save_cmd, save_cmdlen, 0))
- goto err;
- if (arg1 != NULL) {
- if (IN_VI_MODE(sp) && save_cmdlen != 0 &&
- term_push(sp, "|", 1, 0))
- goto err;
- if (term_push(sp, arg1, arg1_len, 0))
- goto err;
- if (file_lline(sp, ep, &sp->frp->lno))
- goto err;
- F_SET(sp->frp, FR_CURSORSET);
- }
- if (IN_VI_MODE(sp) && term_push(sp, ":", 1, 0))
- goto err;
- return (0);
- }
-
- /*
- * Integrate any offset parsed by the underlying command, and make
- * sure the referenced line exists.
- *
- * XXX
- * May not match historic practice (I've never been able to completely
- * figure it out.) For example, the '=' command from vi mode often
- * got the offset wrong, and complained it was too large, but didn't
- * seem to have a problem with the cursor. If anyone complains, ask
- * them how it's supposed to work, they probably know.
- */
- if (ep != NULL && (flagoff += exc.flagoff)) {
- if (flagoff < 0) {
- if (sp->lno <= -flagoff) {
- msgq(sp, M_ERR, "Flag offset before line 1");
- goto err;
- }
- } else {
- if (file_lline(sp, ep, &lno))
- goto err;
- if (sp->lno + flagoff > lno) {
- msgq(sp, M_ERR, "Flag offset past end-of-file");
- goto err;
- }
- }
- sp->lno += flagoff;
- }
-
- /*
- * If the command was successful and we're in ex command mode, we
- * may want to display a line. Make sure there's a line to display.
- */
- if (ep != NULL &&
- IN_EX_MODE(sp) && !F_ISSET(sp, S_GLOBAL) && sp->lno != 0) {
- /*
- * The print commands have already handled the `print' flags.
- * If so, clear them.
- */
- if (LF_ISSET(E_F_PRCLEAR))
- F_CLR(&exc, E_F_HASH | E_F_LIST | E_F_PRINT);
-
- /* If hash only set because of the number option, discard it. */
- if (optnum)
- F_CLR(&exc, E_F_HASH);
-
- /*
- * If there was an explicit flag to display the new cursor
- * line, or we're in ex mode, autoprint is set, and a change
- * was made, display the line. If any print flags set use
- * them, otherwise default to print.
- */
- LF_INIT(F_ISSET(&exc, E_F_HASH | E_F_LIST | E_F_PRINT));
- if (!LF_ISSET(E_F_HASH | E_F_LIST | E_F_PRINT) &&
- O_ISSET(sp, O_AUTOPRINT) &&
- (F_ISSET(exp, EX_AUTOPRINT) || F_ISSET(cp, E_AUTOPRINT)))
- LF_INIT(E_F_PRINT);
-
- if (LF_ISSET(E_F_HASH | E_F_LIST | E_F_PRINT)) {
- memset(&exc, 0, sizeof(EXCMDARG));
- exc.addrcnt = 2;
- exc.addr1.lno = exc.addr2.lno = sp->lno;
- exc.addr1.cno = exc.addr2.cno = sp->cno;
- (void)ex_print(sp, ep, &exc.addr1, &exc.addr2, flags);
- }
- }
-
- cmd = save_cmd;
- cmdlen = save_cmdlen;
- goto loop;
- /* NOTREACHED */
-
- /*
- * If we haven't put out a separator line, do it now. For more
- * detailed comments, see above.
- */
-err: if (sep != NONE &&
- ep != NULL && IN_EX_MODE(sp) && F_ISSET(sp->gp, G_STDIN_TTY))
- (void)fputc('\n', stdout);
- /*
- * On error, we discard any keys we have left, as well as any keys
- * that were mapped. The test of save_cmdlen isn't necessarily
- * correct. If we fail early enough we don't know if the entire
- * string was a single command or not. Try and guess, it's useful
- * to know if part of the command was discarded.
- */
- if (save_cmdlen == 0)
- for (; cmdlen; --cmdlen) {
- ch = *cmd++;
- if (IS_ESCAPE(sp, ch) && cmdlen > 1) {
- --cmdlen;
- ++cmd;
- } else if (ch == '\n' || ch == '|') {
- if (cmdlen > 1)
- save_cmdlen = 1;
- break;
- }
- }
- if (save_cmdlen != 0)
- msgq(sp, M_ERR,
- "Ex command failed: remaining command input discarded");
- /*
- * !!!
- * Previous versions of nvi cleared mapped characters on error. This
- * feature was removed when users complained that it wasn't historic
- * practice.
- */
- return (1);
-}
-
-/*
- * ep_range --
- * Get a line range for ex commands.
- */
-static int
-ep_range(sp, ep, excp, cmdp, cmdlenp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *excp;
- char **cmdp;
- size_t *cmdlenp;
-{
- MARK cur, savecursor;
- size_t cmdlen;
- int savecursor_set, tmp;
- char *cmd;
-
- /* Percent character is all lines in the file. */
- cmd = *cmdp;
- cmdlen = *cmdlenp;
- if (*cmd == '%') {
- excp->addr1.lno = 1;
- if (file_lline(sp, ep, &excp->addr2.lno))
- return (1);
-
- /* If an empty file, then the first line is 0, not 1. */
- if (excp->addr2.lno == 0)
- excp->addr1.lno = 0;
- excp->addr1.cno = excp->addr2.cno = 0;
- excp->addrcnt = 2;
-
- ++*cmdp;
- --*cmdlenp;
- return (0);
- }
-
- /* Parse comma or semi-colon delimited line specs. */
- for (savecursor_set = 0, excp->addrcnt = 0; cmdlen > 0;)
- switch (*cmd) {
- case ';': /* Semi-colon delimiter. */
- /*
- * Comma delimiters delimit; semi-colon delimiters
- * change the current address for the 2nd address
- * to be the first address. Trailing or multiple
- * delimiters are discarded.
- */
- if (excp->addrcnt == 0)
- goto done;
- if (!savecursor_set) {
- savecursor.lno = sp->lno;
- savecursor.cno = sp->cno;
- sp->lno = excp->addr1.lno;
- sp->cno = excp->addr1.cno;
- savecursor_set = 1;
- }
- ++cmd;
- --cmdlen;
- break;
- case ',': /* Comma delimiter. */
- /* If no addresses yet, defaults to ".". */
- if (excp->addrcnt == 0) {
- excp->addr1.lno = sp->lno;
- excp->addr1.cno = sp->cno;
- excp->addrcnt = 1;
- }
- /* FALLTHROUGH */
- case ' ': /* Whitespace. */
- case '\t': /* Whitespace. */
- ++cmd;
- --cmdlen;
- break;
- default:
- if (ep_line(sp, ep, &cur, &cmd, &cmdlen, &tmp))
- return (1);
- if (!tmp)
- goto done;
-
- /*
- * Extra addresses are discarded, starting with
- * the first.
- */
- switch (excp->addrcnt) {
- case 0:
- excp->addr1 = cur;
- excp->addrcnt = 1;
- break;
- case 1:
- excp->addr2 = cur;
- excp->addrcnt = 2;
- break;
- case 2:
- excp->addr1 = excp->addr2;
- excp->addr2 = cur;
- break;
- }
- break;
- }
-
- /*
- * XXX
- * This is probably not the right behavior for savecursor --
- * need to figure out what the historical ex did for ";,;,;5p"
- * or similar stupidity.
- */
-done: if (savecursor_set) {
- sp->lno = savecursor.lno;
- sp->cno = savecursor.cno;
- }
- if (excp->addrcnt == 2 && excp->addr2.lno < excp->addr1.lno) {
- msgq(sp, M_ERR,
- "The second address is smaller than the first");
- return (1);
- }
- *cmdp = cmd;
- *cmdlenp = cmdlen;
- return (0);
-}
-
-/*
- * Get a single line address specifier.
- *
- * The way the "previous context" mark worked was that any "non-relative"
- * motion set it. While ex/vi wasn't totally consistent about this, ANY
- * numeric address, search pattern, '$', or mark reference in an address
- * was considered non-relative, and set the value. Which should explain
- * why we're hacking marks down here. The problem was that the mark was
- * only set if the command was called, i.e. we have to set a flag and test
- * it later.
- *
- * XXX
- * This is not exactly historic practice, although it's fairly close.
- */
-static int
-ep_line(sp, ep, cur, cmdp, cmdlenp, addr_found)
- SCR *sp;
- EXF *ep;
- MARK *cur;
- char **cmdp;
- size_t *cmdlenp;
- int *addr_found;
-{
- EX_PRIVATE *exp;
- MARK m;
- long total;
- u_int flags;
- size_t cmdlen;
- int (*sf) __P((SCR *, EXF *, MARK *, MARK *, char *, char **, u_int *));
- char *cmd, *endp;
-
- exp = EXP(sp);
- *addr_found = 0;
-
- cmd = *cmdp;
- cmdlen = *cmdlenp;
- switch (*cmd) {
- case '$': /* Last line in the file. */
- *addr_found = 1;
- F_SET(exp, EX_ABSMARK);
-
- cur->cno = 0;
- if (file_lline(sp, ep, &cur->lno))
- return (1);
- ++cmd;
- --cmdlen;
- break; /* Absolute line number. */
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- *addr_found = 1;
- F_SET(exp, EX_ABSMARK);
-
- cur->cno = 0;
-/* 8-bit XXX */ cur->lno = strtol(cmd, &endp, 10);
- cmdlen -= (endp - cmd);
- cmd = endp;
- break;
- case '\'': /* Use a mark. */
- *addr_found = 1;
- F_SET(exp, EX_ABSMARK);
-
- if (cmdlen == 1) {
- msgq(sp, M_ERR, "No mark name supplied");
- return (1);
- }
- if (mark_get(sp, ep, cmd[1], cur))
- return (1);
- cmd += 2;
- cmdlen -= 2;
- break;
- case '\\': /* Search: forward/backward. */
- /*
- * !!!
- * I can't find any difference between // and \/ or between
- * ?? and \?. Mark Horton doesn't remember there being any
- * difference. C'est la vie.
- */
- if (cmdlen < 2 || cmd[1] != '/' && cmd[1] != '?') {
- msgq(sp, M_ERR, "\\ not followed by / or ?");
- return (1);
- }
- ++cmd;
- --cmdlen;
- sf = cmd[0] == '/' ? f_search : b_search;
- goto search;
- case '/': /* Search forward. */
- sf = f_search;
- goto search;
- case '?': /* Search backward. */
- sf = b_search;
-search: F_SET(exp, EX_ABSMARK);
-
- if (ep == NULL) {
- msgq(sp, M_ERR,
- "A search address requires that a file have already been read in");
- return (1);
- }
- *addr_found = 1;
- m.lno = sp->lno;
- m.cno = sp->cno;
- flags = SEARCH_MSG | SEARCH_PARSE | SEARCH_SET;
- if (sf(sp, ep, &m, &m, cmd, &endp, &flags))
- return (1);
- cur->lno = m.lno;
- cur->cno = m.cno;
- cmdlen -= (endp - cmd);
- cmd = endp;
- break;
- case '.': /* Current position. */
- *addr_found = 1;
- cur->cno = sp->cno;
-
- /* If an empty file, then '.' is 0, not 1. */
- if (sp->lno == 1) {
- if (file_lline(sp, ep, &cur->lno))
- return (1);
- if (cur->lno != 0)
- cur->lno = 1;
- } else
- cur->lno = sp->lno;
- ++cmd;
- --cmdlen;
- break;
- }
-
- /*
- * Evaluate any offset. Offsets are +/- any number, or any number
- * of +/- signs, or any combination thereof. If no address found
- * yet, offset is relative to ".".
- */
- for (total = 0; cmdlen > 0 && (cmd[0] == '-' || cmd[0] == '+');) {
- if (!*addr_found) {
- cur->lno = sp->lno;
- cur->cno = sp->cno;
- *addr_found = 1;
- }
-
- if (cmdlen > 1 && isdigit(cmd[1])) {
-/* 8-bit XXX */ total += strtol(cmd, &endp, 10);
- cmdlen -= (endp - cmd);
- cmd = endp;
- } else {
- total += cmd[0] == '-' ? -1 : 1;
- --cmdlen;
- ++cmd;
- }
- }
-
- if (*addr_found) {
- if (total < 0 && -total > cur->lno) {
- msgq(sp, M_ERR,
- "Reference to a line number less than 0");
- return (1);
- }
- cur->lno += total;
-
- *cmdp = cmd;
- *cmdlenp = cmdlen;
- }
- return (0);
-}
-
-/*
- * ex_is_abbrev -
- * The vi text input routine needs to know if ex thinks this is
- * an [un]abbreviate command, so it can turn off abbreviations.
- * Usual ranting in the vi/v_ntext:txt_abbrev() routine.
- */
-int
-ex_is_abbrev(name, len)
- char *name;
- size_t len;
-{
- EXCMDLIST const *cp;
-
- return ((cp = ex_comm_search(name, len)) != NULL &&
- (cp == &cmds[C_ABBR] || cp == &cmds[C_UNABBREVIATE]));
-}
-
-/*
- * ex_is_unmap -
- * The vi text input routine needs to know if ex thinks this is
- * an unmap command, so it can turn off input mapping. Usual
- * ranting in the vi/v_ntext:txt_unmap() routine.
- */
-int
-ex_is_unmap(name, len)
- char *name;
- size_t len;
-{
- EXCMDLIST const *cp;
-
- /*
- * The command the vi input routines are really interested in
- * is "unmap!", not just unmap.
- */
- if (name[len - 1] != '!')
- return (0);
- --len;
- return ((cp = ex_comm_search(name, len)) != NULL &&
- cp == &cmds[C_UNMAP]);
-}
-
-static __inline EXCMDLIST const *
-ex_comm_search(name, len)
- char *name;
- size_t len;
-{
- EXCMDLIST const *cp;
-
- for (cp = cmds; cp->name != NULL; ++cp) {
- if (cp->name[0] > name[0])
- return (NULL);
- if (cp->name[0] != name[0])
- continue;
- if (!memcmp(name, cp->name, len))
- return (cp);
- }
- return (NULL);
-}
-
-static void
-badlno(sp, lno)
- SCR *sp;
- recno_t lno;
-{
- if (lno == 0)
- msgq(sp, M_ERR, "Illegal address: the file is empty");
- else
- msgq(sp, M_ERR, "Illegal address: only %lu line%s in the file",
- lno, lno > 1 ? "s" : "");
-}
diff --git a/usr.bin/vi/ex/ex_abbrev.c b/usr.bin/vi/ex/ex_abbrev.c
deleted file mode 100644
index 1360030..0000000
--- a/usr.bin/vi/ex/ex_abbrev.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_abbrev.c 8.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../vi/vcmd.h"
-
-/*
- * ex_abbr -- :abbreviate [key replacement]
- * Create an abbreviation or display abbreviations.
- */
-int
-ex_abbr(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- CHAR_T *p;
- size_t len;
-
- switch (cmdp->argc) {
- case 0:
- if (seq_dump(sp, SEQ_ABBREV, 0) == 0)
- msgq(sp, M_INFO, "No abbreviations to display");
- return (0);
- case 2:
- break;
- default:
- abort();
- }
-
- /* Check for illegal characters. */
- for (p = cmdp->argv[0]->bp, len = cmdp->argv[0]->len; len--; ++p)
- if (!inword(*p)) {
- msgq(sp, M_ERR,
- "%s may not be part of an abbreviated word",
- KEY_NAME(sp, *p));
- return (1);
- }
-
- if (seq_set(sp, NULL, 0, cmdp->argv[0]->bp, cmdp->argv[0]->len,
- cmdp->argv[1]->bp, cmdp->argv[1]->len, SEQ_ABBREV, SEQ_USERDEF))
- return (1);
-
- F_SET(sp->gp, G_ABBREV);
- return (0);
-}
-
-/*
- * ex_unabbr -- :unabbreviate key
- * Delete an abbreviation.
- */
-int
-ex_unabbr(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- ARGS *ap;
-
- ap = cmdp->argv[0];
- if (!F_ISSET(sp->gp, G_ABBREV) ||
- seq_delete(sp, ap->bp, ap->len, SEQ_ABBREV)) {
- msgq(sp, M_ERR, "\"%s\" is not an abbreviation", ap->bp);
- return (1);
- }
- return (0);
-}
-
-/*
- * abbr_save --
- * Save the abbreviation sequences to a file.
- */
-int
-abbr_save(sp, fp)
- SCR *sp;
- FILE *fp;
-{
- return (seq_save(sp, fp, "abbreviate ", SEQ_ABBREV));
-}
diff --git a/usr.bin/vi/ex/ex_append.c b/usr.bin/vi/ex/ex_append.c
deleted file mode 100644
index bb3f618..0000000
--- a/usr.bin/vi/ex/ex_append.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_append.c 8.24 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../sex/sex_screen.h"
-
-enum which {APPEND, CHANGE, INSERT};
-
-static int aci __P((SCR *, EXF *, EXCMDARG *, enum which));
-
-/*
- * ex_append -- :[line] a[ppend][!]
- * Append one or more lines of new text after the specified line,
- * or the current line if no address is specified.
- */
-int
-ex_append(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (aci(sp, ep, cmdp, APPEND));
-}
-
-/*
- * ex_change -- :[line[,line]] c[hange][!] [count]
- * Change one or more lines to the input text.
- */
-int
-ex_change(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (aci(sp, ep, cmdp, CHANGE));
-}
-
-/*
- * ex_insert -- :[line] i[nsert][!]
- * Insert one or more lines of new text before the specified line,
- * or the current line if no address is specified.
- */
-int
-ex_insert(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (aci(sp, ep, cmdp, INSERT));
-}
-
-static int
-aci(sp, ep, cmdp, cmd)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
- enum which cmd;
-{
- MARK m;
- TEXTH *sv_tiqp, tiq;
- TEXT *tp;
- struct termios t;
- u_int flags;
- int rval;
-
- rval = 0;
-
- /*
- * Set input flags; the ! flag turns off autoindent for append,
- * change and insert.
- */
- LF_INIT(TXT_DOTTERM | TXT_NLECHO);
- if (!F_ISSET(cmdp, E_FORCE) && O_ISSET(sp, O_AUTOINDENT))
- LF_SET(TXT_AUTOINDENT);
- if (O_ISSET(sp, O_BEAUTIFY))
- LF_SET(TXT_BEAUTIFY);
-
- /* Input is interruptible. */
- F_SET(sp, S_INTERRUPTIBLE);
-
- /*
- * If this code is called by vi, the screen TEXTH structure (sp->tiqp)
- * may already be in use, e.g. ":append|s/abc/ABC/" would fail as we're
- * only halfway through the line when the append code fires. Use the
- * local structure instead.
- *
- * If this code is called by vi, we want to reset the terminal and use
- * ex's s_get() routine. It actually works fine if we use vi's s_get()
- * routine, but it doesn't look as nice. Maybe if we had a separate
- * window or something, but getting a line at a time looks awkward.
- */
- if (IN_VI_MODE(sp)) {
- memset(&tiq, 0, sizeof(TEXTH));
- CIRCLEQ_INIT(&tiq);
- sv_tiqp = sp->tiqp;
- sp->tiqp = &tiq;
-
- if (F_ISSET(sp->gp, G_STDIN_TTY))
- SEX_RAW(t);
- (void)write(STDOUT_FILENO, "\n", 1);
- LF_SET(TXT_NLECHO);
-
- }
-
- /* Set the line number, so that autoindent works correctly. */
- sp->lno = cmdp->addr1.lno;
-
- if (sex_get(sp, ep, sp->tiqp, 0, flags) != INP_OK)
- goto err;
-
- /*
- * If doing a change, replace lines for as long as possible. Then,
- * append more lines or delete remaining lines. Changes to an empty
- * file are just appends, and inserts are the same as appends to the
- * previous line.
- *
- * !!!
- * Adjust the current line number for the commands to match historic
- * practice if the user doesn't enter anything, and set the address
- * to which we'll append. This is safe because an address of 0 is
- * illegal for change and insert.
- */
- m = cmdp->addr1;
- switch (cmd) {
- case INSERT:
- --m.lno;
- /* FALLTHROUGH */
- case APPEND:
- if (sp->lno == 0)
- sp->lno = 1;
- break;
- case CHANGE:
- --m.lno;
- if (sp->lno != 1)
- --sp->lno;
- break;
- }
-
- /*
- * !!!
- * Cut into the unnamed buffer.
- */
- if (cmd == CHANGE &&
- (cut(sp, ep, NULL, &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE) ||
- delete(sp, ep, &cmdp->addr1, &cmdp->addr2, 1)))
- goto err;
-
- for (tp = sp->tiqp->cqh_first;
- tp != (TEXT *)sp->tiqp; tp = tp->q.cqe_next) {
- if (file_aline(sp, ep, 1, m.lno, tp->lb, tp->len)) {
-err: rval = 1;
- break;
- }
- sp->lno = ++m.lno;
- }
-
- if (IN_VI_MODE(sp)) {
- sp->tiqp = sv_tiqp;
- text_lfree(&tiq);
-
- /* Reset the terminal state. */
- if (F_ISSET(sp->gp, G_STDIN_TTY)) {
- if (SEX_NORAW(t))
- rval = 1;
- F_SET(sp, S_REFRESH);
- }
- }
- return (rval);
-}
diff --git a/usr.bin/vi/ex/ex_args.c b/usr.bin/vi/ex/ex_args.c
deleted file mode 100644
index 4dfc18e..0000000
--- a/usr.bin/vi/ex/ex_args.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)ex_args.c 8.29 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_next -- :next [+cmd] [files]
- * Edit the next file, optionally setting the list of files.
- *
- * !!!
- * The :next command behaved differently from the :rewind command in
- * historic vi. See nvi/docs/autowrite for details, but the basic
- * idea was that it ignored the force flag if the autowrite flag was
- * set. This implementation handles them all identically.
- */
-int
-ex_next(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- ARGS **argv, **pc;
- FREF *frp;
- int noargs;
- char **ap;
-
- if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
- return (1);
-
- /*
- * If the first argument is a plus sign, '+', it's an initial
- * ex command.
- */
- argv = cmdp->argv;
- if (cmdp->argc && argv[0]->bp[0] == '+') {
- --cmdp->argc;
- pc = argv++;
- } else
- pc = NULL;
-
- /* Any other arguments are a replacement file list. */
- if (cmdp->argc) {
- /* Free the current list. */
- if (!F_ISSET(sp, S_ARGNOFREE) && sp->argv != NULL) {
- for (ap = sp->argv; *ap != NULL; ++ap)
- free(*ap);
- free(sp->argv);
- }
- F_CLR(sp, S_ARGNOFREE | S_ARGRECOVER);
- sp->cargv = NULL;
-
- /* Create a new list. */
- CALLOC_RET(sp,
- sp->argv, char **, cmdp->argc + 1, sizeof(char *));
- for (ap = sp->argv,
- argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv)
- if ((*ap =
- v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
- return (1);
- *ap = NULL;
-
- /* Switch to the first one. */
- sp->cargv = sp->argv;
- if ((frp = file_add(sp, *sp->cargv)) == NULL)
- return (1);
- noargs = 0;
- } else {
- if (sp->cargv == NULL || sp->cargv[1] == NULL) {
- msgq(sp, M_ERR, "No more files to edit");
- return (1);
- }
- if ((frp = file_add(sp, sp->cargv[1])) == NULL)
- return (1);
- if (F_ISSET(sp, S_ARGRECOVER))
- F_SET(frp, FR_RECOVER);
- noargs = 1;
- }
-
- if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
- return (1);
- if (noargs)
- ++sp->cargv;
-
- /* Push the initial command onto the stack. */
- if (pc != NULL)
- if (IN_EX_MODE(sp))
- (void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
- else if (IN_VI_MODE(sp)) {
- (void)term_push(sp, "\n", 1, 0);
- (void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
- (void)term_push(sp, ":", 1, 0);
- (void)file_lline(sp, sp->ep, &sp->frp->lno);
- F_SET(sp->frp, FR_CURSORSET);
- }
-
- F_SET(sp, S_FSWITCH);
- return (0);
-}
-
-/*
- * ex_prev -- :prev
- * Edit the previous file.
- */
-int
-ex_prev(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- FREF *frp;
-
- if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
- return (1);
-
- if (sp->cargv == sp->argv) {
- msgq(sp, M_ERR, "No previous files to edit");
- return (1);
- }
- if ((frp = file_add(sp, sp->cargv[-1])) == NULL)
- return (1);
-
- if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
- return (1);
-
- --sp->cargv;
- F_SET(sp, S_FSWITCH);
- return (0);
-}
-
-/*
- * ex_rew -- :rew
- * Re-edit the list of files.
- */
-int
-ex_rew(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- FREF *frp;
-
- /*
- * !!!
- * Historic practice -- you can rewind to the current file.
- */
- if (sp->argv == NULL) {
- msgq(sp, M_ERR, "No previous files to rewind");
- return (1);
- }
-
- if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
- return (1);
-
- /*
- * !!!
- * Historic practice, start at the beginning of the file.
- */
- for (frp = sp->frefq.cqh_first;
- frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next)
- F_CLR(frp, FR_CURSORSET | FR_FNONBLANK);
-
- /* Switch to the first one. */
- sp->cargv = sp->argv;
- if ((frp = file_add(sp, *sp->cargv)) == NULL)
- return (1);
- if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
- return (1);
-
- F_SET(sp, S_FSWITCH);
- return (0);
-}
-
-/*
- * ex_args -- :args
- * Display the list of files.
- */
-int
-ex_args(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- int cnt, col, len, sep;
- char **ap;
-
- if (sp->argv == NULL) {
- (void)ex_printf(EXCOOKIE, "No file list to display.\n");
- return (0);
- }
-
- col = len = sep = 0;
- for (cnt = 1, ap = sp->argv; *ap != NULL; ++ap) {
- col += len = strlen(*ap) + sep + (ap == sp->cargv ? 2 : 0);
- if (col >= sp->cols - 1) {
- col = len;
- sep = 0;
- (void)ex_printf(EXCOOKIE, "\n");
- } else if (cnt != 1) {
- sep = 1;
- (void)ex_printf(EXCOOKIE, " ");
- }
- ++cnt;
-
- if (ap == sp->cargv)
- (void)ex_printf(EXCOOKIE, "[%s]", *ap);
- else
- (void)ex_printf(EXCOOKIE, "%s", *ap);
- }
- (void)ex_printf(EXCOOKIE, "\n");
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_argv.c b/usr.bin/vi/ex/ex_argv.c
deleted file mode 100644
index 63d820e..0000000
--- a/usr.bin/vi/ex/ex_argv.c
+++ /dev/null
@@ -1,609 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_argv.c 8.38 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-static int argv_alloc __P((SCR *, size_t));
-static int argv_fexp __P((SCR *, EXCMDARG *,
- char *, size_t, char *, size_t *, char **, size_t *, int));
-static int argv_sexp __P((SCR *, char **, size_t *, size_t *));
-
-/*
- * argv_init --
- * Build a prototype arguments list.
- */
-int
-argv_init(sp, ep, excp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *excp;
-{
- EX_PRIVATE *exp;
-
- exp = EXP(sp);
- exp->argsoff = 0;
- argv_alloc(sp, 1);
-
- excp->argv = exp->args;
- excp->argc = exp->argsoff;
- return (0);
-}
-
-/*
- * argv_exp0 --
- * Append a string to the argument list.
- */
-int
-argv_exp0(sp, ep, excp, cmd, cmdlen)
- SCR *sp;
- EXF *ep;
- EXCMDARG *excp;
- char *cmd;
- size_t cmdlen;
-{
- EX_PRIVATE *exp;
-
- exp = EXP(sp);
- argv_alloc(sp, cmdlen);
- memmove(exp->args[exp->argsoff]->bp, cmd, cmdlen);
- exp->args[exp->argsoff]->bp[cmdlen] = '\0';
- exp->args[exp->argsoff]->len = cmdlen;
- ++exp->argsoff;
- excp->argv = exp->args;
- excp->argc = exp->argsoff;
- return (0);
-}
-
-/*
- * argv_exp1 --
- * Do file name expansion on a string, and append it to the
- * argument list.
- */
-int
-argv_exp1(sp, ep, excp, cmd, cmdlen, is_bang)
- SCR *sp;
- EXF *ep;
- EXCMDARG *excp;
- char *cmd;
- size_t cmdlen;
- int is_bang;
-{
- EX_PRIVATE *exp;
- size_t blen, len;
- char *bp, *p, *t;
-
- GET_SPACE_RET(sp, bp, blen, 512);
-
- len = 0;
- exp = EXP(sp);
- if (argv_fexp(sp, excp, cmd, cmdlen, bp, &len, &bp, &blen, is_bang)) {
- FREE_SPACE(sp, bp, blen);
- return (1);
- }
-
- /* If it's empty, we're done. */
- if (len != 0) {
- for (p = bp, t = bp + len; p < t; ++p)
- if (!isblank(*p))
- break;
- if (p == t)
- goto ret;
- } else
- goto ret;
-
- (void)argv_exp0(sp, ep, excp, bp, len);
-
-ret: FREE_SPACE(sp, bp, blen);
- return (0);
-}
-
-/*
- * argv_exp2 --
- * Do file name and shell expansion on a string, and append it to
- * the argument list.
- */
-int
-argv_exp2(sp, ep, excp, cmd, cmdlen, is_bang)
- SCR *sp;
- EXF *ep;
- EXCMDARG *excp;
- char *cmd;
- size_t cmdlen;
- int is_bang;
-{
- size_t blen, len, n;
- int rval;
- char *bp, *mp, *p;
-
- GET_SPACE_RET(sp, bp, blen, 512);
-
-#define SHELLECHO "echo "
-#define SHELLOFFSET (sizeof(SHELLECHO) - 1)
- memmove(bp, SHELLECHO, SHELLOFFSET);
- p = bp + SHELLOFFSET;
- len = SHELLOFFSET;
-
-#if defined(DEBUG) && 0
- TRACE(sp, "file_argv: {%.*s}\n", (int)cmdlen, cmd);
-#endif
-
- if (argv_fexp(sp, excp, cmd, cmdlen, p, &len, &bp, &blen, is_bang)) {
- rval = 1;
- goto err;
- }
-
-#if defined(DEBUG) && 0
- TRACE(sp, "before shell: %d: {%s}\n", len, bp);
-#endif
-
- /*
- * Do shell word expansion -- it's very, very hard to figure out what
- * magic characters the user's shell expects. Historically, it was a
- * union of v7 shell and csh meta characters. We match that practice
- * by default, so ":read \%" tries to read a file named '%'. It would
- * make more sense to pass any special characters through the shell,
- * but then, if your shell was csh, the above example will behave
- * differently in nvi than in vi. If you want to get other characters
- * passed through to your shell, change the "meta" option.
- *
- * To avoid a function call per character, we do a first pass through
- * the meta characters looking for characters that aren't expected
- * to be there.
- */
- for (p = mp = O_STR(sp, O_META); *p != '\0'; ++p)
- if (isblank(*p) || isalnum(*p))
- break;
- if (*p != '\0') {
- for (p = bp, n = len; n > 0; --n, ++p)
- if (strchr(mp, *p) != NULL)
- break;
- } else
- for (p = bp, n = len; n > 0; --n, ++p)
- if (!isblank(*p) &&
- !isalnum(*p) && strchr(mp, *p) != NULL)
- break;
- if (n > 0) {
- if (argv_sexp(sp, &bp, &blen, &len)) {
- rval = 1;
- goto err;
- }
- p = bp;
- } else {
- p = bp + SHELLOFFSET;
- len -= SHELLOFFSET;
- }
-
-#if defined(DEBUG) && 0
- TRACE(sp, "after shell: %d: {%s}\n", len, bp);
-#endif
-
- rval = argv_exp3(sp, ep, excp, p, len);
-
-err: FREE_SPACE(sp, bp, blen);
- return (rval);
-}
-
-/*
- * argv_exp3 --
- * Take a string and break it up into an argv, which is appended
- * to the argument list.
- */
-int
-argv_exp3(sp, ep, excp, cmd, cmdlen)
- SCR *sp;
- EXF *ep;
- EXCMDARG *excp;
- char *cmd;
- size_t cmdlen;
-{
- EX_PRIVATE *exp;
- size_t len;
- int ch, off;
- char *ap, *p;
-
- for (exp = EXP(sp); cmdlen > 0; ++exp->argsoff) {
- /* Skip any leading whitespace. */
- for (; cmdlen > 0; --cmdlen, ++cmd) {
- ch = *cmd;
- if (!isblank(ch))
- break;
- }
- if (cmdlen == 0)
- break;
-
- /*
- * Determine the length of this whitespace delimited
- * argument.
- *
- * QUOTING NOTE:
- *
- * Skip any character preceded by the user's quoting
- * character.
- */
- for (ap = cmd, len = 0; cmdlen > 0; ++cmd, --cmdlen, ++len) {
- ch = *cmd;
- if (IS_ESCAPE(sp, ch) && cmdlen > 1) {
- ++cmd;
- --cmdlen;
- } else if (isblank(ch))
- break;
- }
-
- /*
- * Copy the argument into place.
- *
- * QUOTING NOTE:
- *
- * Lose quote chars.
- */
- argv_alloc(sp, len);
- off = exp->argsoff;
- exp->args[off]->len = len;
- for (p = exp->args[off]->bp; len > 0; --len, *p++ = *ap++)
- if (IS_ESCAPE(sp, *ap))
- ++ap;
- *p = '\0';
- }
- excp->argv = exp->args;
- excp->argc = exp->argsoff;
-
-#if defined(DEBUG) && 0
- for (cnt = 0; cnt < exp->argsoff; ++cnt)
- TRACE(sp, "arg %d: {%s}\n", cnt, exp->argv[cnt]);
-#endif
- return (0);
-}
-
-/*
- * argv_fexp --
- * Do file name and bang command expansion.
- */
-static int
-argv_fexp(sp, excp, cmd, cmdlen, p, lenp, bpp, blenp, is_bang)
- SCR *sp;
- EXCMDARG *excp;
- char *cmd, *p, **bpp;
- size_t cmdlen, *lenp, *blenp;
- int is_bang;
-{
- EX_PRIVATE *exp;
- char *bp, *t;
- size_t blen, len, tlen;
-
- /* Replace file name characters. */
- for (bp = *bpp, blen = *blenp, len = *lenp; cmdlen > 0; --cmdlen, ++cmd)
- switch (*cmd) {
- case '!':
- if (!is_bang)
- goto ins_ch;
- exp = EXP(sp);
- if (exp->lastbcomm == NULL) {
- msgq(sp, M_ERR,
- "No previous command to replace \"!\"");
- return (1);
- }
- len += tlen = strlen(exp->lastbcomm);
- ADD_SPACE_RET(sp, bp, blen, len);
- memmove(p, exp->lastbcomm, tlen);
- p += tlen;
- F_SET(excp, E_MODIFY);
- break;
- case '%':
- if ((t = sp->frp->name) == NULL) {
- msgq(sp, M_ERR,
- "No filename to substitute for %%");
- return (1);
- }
- tlen = strlen(t);
- len += tlen;
- ADD_SPACE_RET(sp, bp, blen, len);
- memmove(p, t, tlen);
- p += tlen;
- F_SET(excp, E_MODIFY);
- break;
- case '#':
- if ((t = sp->alt_name) == NULL) {
- msgq(sp, M_ERR,
- "No filename to substitute for #");
- return (1);
- }
- len += tlen = strlen(t);
- ADD_SPACE_RET(sp, bp, blen, len);
- memmove(p, t, tlen);
- p += tlen;
- F_SET(excp, E_MODIFY);
- break;
- case '\\':
- /*
- * QUOTING NOTE:
- *
- * Strip any backslashes that protected the file
- * expansion characters.
- */
- if (cmdlen > 1 && (cmd[1] == '%' || cmd[1] == '#')) {
- ++cmd;
- --cmdlen;
- }
- /* FALLTHROUGH */
- default:
-ins_ch: ++len;
- ADD_SPACE_RET(sp, bp, blen, len);
- *p++ = *cmd;
- }
-
- /* Nul termination. */
- ++len;
- ADD_SPACE_RET(sp, bp, blen, len);
- *p = '\0';
-
- /* Return the new string length, buffer, buffer length. */
- *lenp = len - 1;
- *bpp = bp;
- *blenp = blen;
- return (0);
-}
-
-/*
- * argv_alloc --
- * Make more space for arguments.
- */
-static int
-argv_alloc(sp, len)
- SCR *sp;
- size_t len;
-{
- ARGS *ap;
- EX_PRIVATE *exp;
- int cnt, off;
-
- /*
- * Allocate room for another argument, always leaving
- * enough room for an ARGS structure with a length of 0.
- */
-#define INCREMENT 20
- exp = EXP(sp);
- off = exp->argsoff;
- if (exp->argscnt == 0 || off + 2 >= exp->argscnt - 1) {
- cnt = exp->argscnt + INCREMENT;
- REALLOC(sp, exp->args, ARGS **, cnt * sizeof(ARGS *));
- if (exp->args == NULL) {
- (void)argv_free(sp);
- goto mem;
- }
- memset(&exp->args[off], 0, INCREMENT * sizeof(ARGS *));
- exp->argscnt = cnt;
- }
-
- /* First argument. */
- if (exp->args[off] == NULL) {
- CALLOC(sp, exp->args[off], ARGS *, 1, sizeof(ARGS));
- if (exp->args[off] == NULL)
- goto mem;
- }
-
- /* First argument buffer. */
- ap = exp->args[off];
- ap->len = 0;
- if (ap->blen < len + 1) {
- ap->blen = len + 1;
- REALLOC(sp, ap->bp, CHAR_T *, ap->blen * sizeof(CHAR_T));
- if (ap->bp == NULL) {
- ap->bp = NULL;
- ap->blen = 0;
- F_CLR(ap, A_ALLOCATED);
-mem: msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- F_SET(ap, A_ALLOCATED);
- }
-
- /* Second argument. */
- if (exp->args[++off] == NULL) {
- CALLOC(sp, exp->args[off], ARGS *, 1, sizeof(ARGS));
- if (exp->args[off] == NULL)
- goto mem;
- }
- /* 0 length serves as end-of-argument marker. */
- exp->args[off]->len = 0;
- return (0);
-}
-
-/*
- * argv_free --
- * Free up argument structures.
- */
-int
-argv_free(sp)
- SCR *sp;
-{
- EX_PRIVATE *exp;
- int off;
-
- exp = EXP(sp);
- if (exp->args != NULL) {
- for (off = 0; off < exp->argscnt; ++off) {
- if (exp->args[off] == NULL)
- continue;
- if (F_ISSET(exp->args[off], A_ALLOCATED))
- free(exp->args[off]->bp);
- FREE(exp->args[off], sizeof(ARGS));
- }
- FREE(exp->args, exp->argscnt * sizeof(ARGS *));
- }
- exp->args = NULL;
- exp->argscnt = 0;
- exp->argsoff = 0;
- return (0);
-}
-
-/*
- * argv_sexp --
- * Fork a shell, pipe a command through it, and read the output into
- * a buffer.
- */
-static int
-argv_sexp(sp, bpp, blenp, lenp)
- SCR *sp;
- char **bpp;
- size_t *blenp, *lenp;
-{
- FILE *ifp;
- pid_t pid;
- size_t blen, len;
- int ch, rval, output[2];
- char *bp, *p, *sh, *sh_path;
-
- bp = *bpp;
- blen = *blenp;
-
- sh_path = O_STR(sp, O_SHELL);
- if ((sh = strrchr(sh_path, '/')) == NULL)
- sh = sh_path;
- else
- ++sh;
-
- /*
- * There are two different processes running through this code.
- * They are named the utility and the parent. The utility reads
- * from standard input and writes to the parent. The parent reads
- * from the utility and writes into the buffer. The parent reads
- * from output[0], and the utility writes to output[1].
- */
- if (pipe(output) < 0) {
- msgq(sp, M_SYSERR, "pipe");
- return (1);
- }
- if ((ifp = fdopen(output[0], "r")) == NULL) {
- msgq(sp, M_SYSERR, "fdopen");
- goto err;
- }
-
- /*
- * Do the minimal amount of work possible, the shell is going
- * to run briefly and then exit. Hopefully.
- */
- SIGBLOCK(sp->gp);
- switch (pid = vfork()) {
- case -1: /* Error. */
- SIGUNBLOCK(sp->gp);
-
- msgq(sp, M_SYSERR, "vfork");
-err: (void)close(output[0]);
- (void)close(output[1]);
- return (1);
- case 0: /* Utility. */
- /* The utility has default signal behavior. */
- sig_end();
-
- /* Redirect stdout/stderr to the write end of the pipe. */
- (void)dup2(output[1], STDOUT_FILENO);
- (void)dup2(output[1], STDERR_FILENO);
-
- /* Close the utility's file descriptors. */
- (void)close(output[0]);
- (void)close(output[1]);
-
- /* Assumes that all shells have -c. */
- execl(sh_path, sh, "-c", bp, NULL);
- msgq(sp, M_ERR,
- "Error: execl: %s: %s", sh_path, strerror(errno));
- _exit(127);
- default: /* Parent. */
- SIGUNBLOCK(sp->gp);
-
- /* Close the pipe end the parent won't use. */
- (void)close(output[1]);
- break;
- }
-
- rval = 0;
-
- /*
- * Copy process output into a buffer.
- *
- * !!!
- * Historic vi apparently discarded leading \n and \r's from
- * the shell output stream. We don't on the grounds that any
- * shell that does that is broken.
- */
- for (p = bp, len = 0, ch = EOF;
- (ch = getc(ifp)) != EOF; *p++ = ch, --blen, ++len)
- if (blen < 5) {
- ADD_SPACE_GOTO(sp, bp, blen, *blenp * 2);
- p = bp + len;
- blen = *blenp - len;
- }
-
- /* Delete the final newline, nul terminate the string. */
- if (p > bp && (p[-1] == '\n' || p[-1] == '\r')) {
- --len;
- *--p = '\0';
- } else
- *p = '\0';
- *lenp = len;
-
- if (ferror(ifp)) {
- msgq(sp, M_ERR, "I/O error: %s", sh);
-binc_err: rval = 1;
- }
- (void)fclose(ifp);
-
- *bpp = bp; /* *blenp is already updated. */
-
- /* Wait for the process. */
- return (proc_wait(sp, (long)pid, sh, 0) || rval);
-}
diff --git a/usr.bin/vi/ex/ex_at.c b/usr.bin/vi/ex/ex_at.c
deleted file mode 100644
index 147261d..0000000
--- a/usr.bin/vi/ex/ex_at.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_at.c 8.27 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_at -- :@[@ | buffer]
- * :*[* | buffer]
- *
- * Execute the contents of the buffer.
- */
-int
-ex_at(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- CB *cbp;
- EX_PRIVATE *exp;
- TEXT *tp;
- int name;
-
- exp = EXP(sp);
-
- /*
- * !!!
- * Historically, [@*]<carriage-return> and [@*][@*] executed the most
- * recently executed buffer in ex mode. In vi mode, only @@ repeated
- * the last buffer. We change historic practice and make @* work from
- * vi mode as well, it's simpler and more consistent.
- */
- name = F_ISSET(cmdp, E_BUFFER) ? cmdp->buffer : '@';
- if (name == '@' || name == '*') {
- if (!exp->at_lbuf_set) {
- msgq(sp, M_ERR, "No previous buffer to execute");
- return (1);
- }
- name = exp->at_lbuf;
- }
-
- CBNAME(sp, cbp, name);
- if (cbp == NULL) {
- msgq(sp, M_ERR, "Buffer %s is empty", KEY_NAME(sp, name));
- return (1);
- }
-
- /* Save for reuse. */
- exp->at_lbuf = name;
- exp->at_lbuf_set = 1;
-
- /*
- * !!!
- * Historic practice is that if the buffer was cut in line mode,
- * <newlines> were appended to each line as it was pushed onto
- * the stack. If the buffer was cut in character mode, <newlines>
- * were appended to all lines but the last one.
- */
- for (tp = cbp->textq.cqh_last;
- tp != (void *)&cbp->textq; tp = tp->q.cqe_prev)
- if ((F_ISSET(cbp, CB_LMODE) ||
- tp->q.cqe_next != (void *)&cbp->textq) &&
- term_push(sp, "\n", 1, 0) ||
- term_push(sp, tp->lb, tp->len, 0))
- return (1);
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_bang.c b/usr.bin/vi/ex/ex_bang.c
deleted file mode 100644
index d2ffaa4..0000000
--- a/usr.bin/vi/ex/ex_bang.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_bang.c 8.35 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../sex/sex_screen.h"
-
-/*
- * ex_bang -- :[line [,line]] ! command
- *
- * Pass the rest of the line after the ! character to the program named by
- * the O_SHELL option.
- *
- * Historical vi did NOT do shell expansion on the arguments before passing
- * them, only file name expansion. This means that the O_SHELL program got
- * "$t" as an argument if that is what the user entered. Also, there's a
- * special expansion done for the bang command. Any exclamation points in
- * the user's argument are replaced by the last, expanded ! command.
- *
- * There's some fairly amazing slop in this routine to make the different
- * ways of getting here display the right things. It took a long time to
- * get it right (wrong?), so be careful.
- */
-int
-ex_bang(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- enum filtertype ftype;
- ARGS *ap;
- EX_PRIVATE *exp;
- MARK rm;
- recno_t lno;
- size_t blen;
- int rval;
- char *bp, *msg;
-
- ap = cmdp->argv[0];
- if (ap->len == 0) {
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
-
- /* Set the last bang command. */
- exp = EXP(sp);
- if (exp->lastbcomm != NULL)
- free(exp->lastbcomm);
- if ((exp->lastbcomm = strdup(ap->bp)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
-
- /*
- * If the command was modified by the expansion, we redisplay it.
- * Redisplaying it in vi mode is tricky, and handled separately
- * in each case below. If we're in ex mode, it's easy, so we just
- * do it here.
- */
- bp = NULL;
- if (F_ISSET(cmdp, E_MODIFY) && !F_ISSET(sp, S_EXSILENT)) {
- if (IN_EX_MODE(sp)) {
- (void)ex_printf(EXCOOKIE, "!%s\n", ap->bp);
- (void)ex_fflush(EXCOOKIE);
- }
- /*
- * Vi: Display the command if modified. Historic vi displayed
- * the command if it was modified due to file name and/or bang
- * expansion. If piping lines, it was immediately overwritten
- * by any error or line change reporting. We don't the user to
- * have to page through the responses, so we only post it until
- * it's erased by something else. Otherwise, pass it on to the
- * ex_exec_proc routine to display after the screen has been
- * cleaned up.
- */
- if (IN_VI_MODE(sp)) {
- GET_SPACE_RET(sp, bp, blen, ap->len + 3);
- bp[0] = '!';
- memmove(bp + 1, ap->bp, ap->len);
- bp[ap->len + 1] = '\n';
- bp[ap->len + 2] = '\0';
- }
- }
-
- /*
- * If addresses were specified, pipe lines from the file through the
- * command.
- *
- * Historically, vi lines were replaced by both the stdout and stderr
- * lines of the command, but ex by only the stdout lines. This makes
- * no sense to me, so nvi makes it consistent for both, and matches
- * vi's historic behavior.
- */
- if (cmdp->addrcnt != 0) {
- /* Autoprint is set historically, even if the command fails. */
- F_SET(exp, EX_AUTOPRINT);
-
- /* Vi gets a busy message. */
- if (bp != NULL)
- (void)sp->s_busy(sp, bp);
-
- /*
- * !!!
- * Historical vi permitted "!!" in an empty file. When it
- * happens, we get called with two addresses of 1,1 and a
- * bad attitude. The simple solution is to turn it into a
- * FILTER_READ operation, but that means that we don't put
- * an empty line into the default cut buffer as did historic
- * vi. Tough.
- */
- ftype = FILTER;
- if (cmdp->addr1.lno == 1 && cmdp->addr2.lno == 1) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0) {
- cmdp->addr1.lno = cmdp->addr2.lno = 0;
- ftype = FILTER_READ;
- }
- }
- rval = filtercmd(sp, ep,
- &cmdp->addr1, &cmdp->addr2, &rm, ap->bp, ftype);
-
- /*
- * If in vi mode, move to the first nonblank.
- *
- * !!!
- * Historic vi wasn't consistent in this area -- if you used
- * a forward motion it moved to the first nonblank, but if you
- * did a backward motion it didn't. And, if you followed a
- * backward motion with a forward motion, it wouldn't move to
- * the nonblank for either. Going to the nonblank generally
- * seems more useful, so we do it.
- */
- if (rval == 0) {
- sp->lno = rm.lno;
- if (IN_VI_MODE(sp)) {
- sp->cno = 0;
- (void)nonblank(sp, ep, sp->lno, &sp->cno);
- }
- }
- goto ret2;
- }
-
- /*
- * If no addresses were specified, run the command. If the file
- * has been modified and autowrite is set, write the file back.
- * If the file has been modified, autowrite is not set and the
- * warn option is set, tell the user about the file.
- */
- msg = NULL;
- if (F_ISSET(ep, F_MODIFIED))
- if (O_ISSET(sp, O_AUTOWRITE)) {
- if (file_write(sp, ep, NULL, NULL, NULL, FS_ALL)) {
- rval = 1;
- goto ret1;
- }
- } else if (O_ISSET(sp, O_WARN) && !F_ISSET(sp, S_EXSILENT))
- msg = "File modified since last write.\n";
-
- /* Run the command. */
- rval = ex_exec_proc(sp, ap->bp, bp, msg);
-
- /* Vi requires user permission to continue. */
- if (IN_VI_MODE(sp))
- F_SET(sp, S_CONTINUE);
-
-ret2: if (IN_EX_MODE(sp)) {
- /*
- * Put ex error messages out so they aren't confused with
- * the autoprint output.
- */
- if (rval)
- (void)sex_refresh(sp, sp->ep);
-
- /* Ex terminates with a bang, even if the command fails. */
- if (!F_ISSET(sp, S_EXSILENT))
- (void)write(STDOUT_FILENO, "!\n", 2);
- }
-
- /* Free the extra space. */
-ret1: if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
-
- /*
- * XXX
- * The ! commands never return an error, so that autoprint always
- * happens in the ex parser.
- */
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_cd.c b/usr.bin/vi/ex/ex_cd.c
deleted file mode 100644
index 8a3d0f1b..0000000
--- a/usr.bin/vi/ex/ex_cd.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_cd.c 8.18 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_cd -- :cd[!] [directory]
- * Change directories.
- */
-int
-ex_cd(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- struct passwd *pw;
- ARGS *ap;
- CDPATH *cdp;
- char *dir; /* XXX END OF THE STACK, DON'T TRUST GETCWD. */
- char buf[MAXPATHLEN * 2];
-
- /*
- * !!!
- * Historic practice is that the cd isn't attempted if the file has
- * been modified, unless its name begins with a leading '/' or the
- * force flag is set.
- */
- if (F_ISSET(ep, F_MODIFIED) &&
- !F_ISSET(cmdp, E_FORCE) && sp->frp->name[0] != '/') {
- msgq(sp, M_ERR,
- "File modified since last complete write; write or use ! to override");
- return (1);
- }
-
- switch (cmdp->argc) {
- case 0:
- /* If no argument, change to the user's home directory. */
- if ((dir = getenv("HOME")) == NULL) {
- if ((pw = getpwuid(getuid())) == NULL ||
- pw->pw_dir == NULL || pw->pw_dir[0] == '\0') {
- msgq(sp, M_ERR,
- "Unable to find home directory location");
- return (1);
- }
- dir = pw->pw_dir;
- }
- break;
- case 1:
- dir = cmdp->argv[0]->bp;
- break;
- default:
- abort();
- }
-
- /* Try the current directory first. */
- if (!chdir(dir))
- goto ret;
-
- /*
- * If moving to the user's home directory, or, the path begins with
- * "/", "./" or "../", it's the only place we try.
- */
- if (cmdp->argc == 0 ||
- (ap = cmdp->argv[0])->bp[0] == '/' ||
- ap->len == 1 && ap->bp[0] == '.' ||
- ap->len >= 2 && ap->bp[0] == '.' && ap->bp[1] == '.' &&
- (ap->bp[2] == '/' || ap->bp[2] == '\0'))
- goto err;
-
- /* If the user has a CDPATH variable, try its elements. */
- for (cdp = EXP(sp)->cdq.tqh_first; cdp != NULL; cdp = cdp->q.tqe_next) {
- (void)snprintf(buf, sizeof(buf), "%s/%s", cdp->path, dir);
- if (!chdir(buf)) {
-ret: if (getcwd(buf, sizeof(buf)) != NULL)
- msgq(sp, M_INFO, "New directory: %s", buf);
- return (0);
- }
- }
-err: msgq(sp, M_SYSERR, "%s", dir);
- return (1);
-}
-
-#define FREE_CDPATH(cdp) { \
- TAILQ_REMOVE(&exp->cdq, (cdp), q); \
- free((cdp)->path); \
- FREE((cdp), sizeof(CDPATH)); \
-}
-/*
- * ex_cdalloc --
- * Create a new list of cd paths.
- */
-int
-ex_cdalloc(sp, str)
- SCR *sp;
- char *str;
-{
- EX_PRIVATE *exp;
- CDPATH *cdp;
- size_t len;
- int founddot;
- char *p, *t;
-
- /* Free current queue. */
- exp = EXP(sp);
- while ((cdp = exp->cdq.tqh_first) != NULL)
- FREE_CDPATH(cdp);
-
- /*
- * Create new queue. The CDPATH environmental variable (and the
- * user's manual entry) are delimited by colon characters.
- */
- for (p = t = str, founddot = 0;; ++p) {
- if (*p == '\0' || *p == ':') {
- /*
- * Empty strings specify ".". The only way to get an
- * empty string is a leading colon, colons in a row,
- * or a trailing colon. Or, to put it the other way,
- * if the the length is zero, then it's either ":XXX",
- * "XXX::XXXX" , "XXX:", or "", and the only failure
- * mode is the last one. Note, the string ":" gives
- * us two entries of '.', so we only include one of
- * them.
- */
- if ((len = p - t) == 0) {
- if (p == str && *p == '\0')
- break;
- if (founddot) {
- if (*p == '\0')
- break;
- continue;
- }
- len = 1;
- t = ".";
- founddot = 1;
- }
- MALLOC_RET(sp, cdp, CDPATH *, sizeof(CDPATH));
- MALLOC(sp, cdp->path, char *, len + 1);
- if (cdp->path == NULL) {
- free(cdp);
- return (1);
- }
- memmove(cdp->path, t, len);
- cdp->path[len] = '\0';
- TAILQ_INSERT_TAIL(&exp->cdq, cdp, q);
- t = p + 1;
- }
- if (*p == '\0')
- break;
- }
- return (0);
-}
- /* Free previous queue. */
-/*
- * ex_cdfree --
- * Free the cd path list.
- */
-int
-ex_cdfree(sp)
- SCR *sp;
-{
- EX_PRIVATE *exp;
- CDPATH *cdp;
-
- /* Free up cd path information. */
- exp = EXP(sp);
- while ((cdp = exp->cdq.tqh_first) != NULL)
- FREE_CDPATH(cdp);
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_delete.c b/usr.bin/vi/ex/ex_delete.c
deleted file mode 100644
index 4e1d241..0000000
--- a/usr.bin/vi/ex/ex_delete.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_delete.c 8.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_delete: [line [,line]] d[elete] [buffer] [count] [flags]
- *
- * Delete lines from the file.
- */
-int
-ex_delete(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- recno_t lno;
-
- /*
- * !!!
- * Historically, lines deleted in ex were not placed in the numeric
- * buffers. We follow historic practice so that we don't overwrite
- * vi buffers accidentally.
- */
- if (cut(sp, ep,
- F_ISSET(cmdp, E_BUFFER) ? &cmdp->buffer : NULL,
- &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE))
- return (1);
-
- /* Delete the lines. */
- if (delete(sp, ep, &cmdp->addr1, &cmdp->addr2, 1))
- return (1);
-
- /* Set the cursor to the line after the last line deleted. */
- sp->lno = cmdp->addr1.lno;
-
- /* Or the last line in the file if deleted to the end of the file. */
- if (file_lline(sp, ep, &lno))
- return (1);
- if (sp->lno > lno)
- sp->lno = lno;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_digraph.c b/usr.bin/vi/ex/ex_digraph.c
deleted file mode 100644
index 0db20bb..0000000
--- a/usr.bin/vi/ex/ex_digraph.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_digraph.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#ifndef NO_DIGRAPH
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-static void do_digraph __P((SCR *, EXF *, int, u_char *));
-
-/* This stuff is used to build the default digraphs table. */
-static u_char digtable[][4] = {
-# ifdef CS_IBMPC
- "C,\200", "u\"\1", "e'\2", "a^\3",
- "a\"\4", "a`\5", "a@\6", "c,\7",
- "e^\10", "e\"\211", "e`\12", "i\"\13",
- "i^\14", "i`\15", "A\"\16", "A@\17",
- "E'\20", "ae\21", "AE\22", "o^\23",
- "o\"\24", "o`\25", "u^\26", "u`\27",
- "y\"\30", "O\"\31", "U\"\32", "a'\240",
- "i'!", "o'\"", "u'#", "n~$",
- "N~%", "a-&", "o-'", "~?(",
- "~!-", "\"<.", "\">/",
-# ifdef CS_SPECIAL
- "2/+", "4/,", "^+;", "^q<",
- "^c=", "^r>", "^t?", "pp]",
- "^^^", "oo_", "*a`", "*ba",
- "*pc", "*Sd", "*se", "*uf",
- "*tg", "*Ph", "*Ti", "*Oj",
- "*dk", "*Hl", "*hm", "*En",
- "*No", "eqp", "pmq", "ger",
- "les", "*It", "*iu", "*/v",
- "*=w", "sq{", "^n|", "^2}",
- "^3~", "^_\377",
-# endif /* CS_SPECIAL */
-# endif /* CS_IBMPC */
-# ifdef CS_LATIN1
- "~!!", "a-*", "\">+", "o-:",
- "\"<>", "~??",
-
- "A`@", "A'A", "A^B", "A~C",
- "A\"D", "A@E", "AEF", "C,G",
- "E`H", "E'I", "E^J", "E\"K",
- "I`L", "I'M", "I^N", "I\"O",
- "-DP", "N~Q", "O`R", "O'S",
- "O^T", "O~U", "O\"V", "O/X",
- "U`Y", "U'Z", "U^[", "U\"\\",
- "Y'_",
-
- "a``", "a'a", "a^b", "a~c",
- "a\"d", "a@e", "aef", "c,g",
- "e`h", "e'i", "e^j", "e\"k",
- "i`l", "i'm", "i^n", "i\"o",
- "-dp", "n~q", "o`r", "o's",
- "o^t", "o~u", "o\"v", "o/x",
- "u`y", "u'z", "u^{", "u\"|",
- "y'~",
-# endif /* CS_LATIN1 */
- ""
-};
-
-int
-digraph_init(sp)
- SCR *sp;
-{
- int i;
-
- for (i = 0; *digtable[i]; i++)
- do_digraph(sp, NULL, 0, digtable[i]);
- do_digraph(sp, NULL, 0, NULL);
- return (0);
-}
-
-int
-ex_digraph(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- do_digraph(sp, ep, F_ISSET(cmdp, E_FORCE), cmdp->argv[0]->bp);
- return (0);
-}
-
-static struct _DIG
-{
- struct _DIG *next;
- char key1;
- char key2;
- char dig;
- char save;
-} *digs;
-
-int
-digraph(sp, key1, key2)
- SCR *sp;
- char key1; /* the underlying character */
- char key2; /* the second character */
-{
- int new_key;
- register struct _DIG *dp;
-
- /* if digraphs are disabled, then just return the new char */
- if (O_ISSET(sp, O_DIGRAPH))
- {
- return key2;
- }
-
- /* remember the new key, so we can return it if this isn't a digraph */
- new_key = key2;
-
- /* sort key1 and key2, so that their original order won't matter */
- if (key1 > key2)
- {
- key2 = key1;
- key1 = new_key;
- }
-
- /* scan through the digraph chart */
- for (dp = digs;
- dp && (dp->key1 != key1 || dp->key2 != key2);
- dp = dp->next)
- {
- }
-
- /* if this combination isn't in there, just use the new key */
- if (!dp)
- {
- return new_key;
- }
-
- /* else use the digraph key */
- return dp->dig;
-}
-
-/* this function lists or defines digraphs */
-static void
-do_digraph(sp, ep, bang, extra)
- SCR *sp;
- EXF *ep;
- int bang;
- u_char *extra;
-{
- int dig;
- register struct _DIG *dp;
- struct _DIG *prev;
- static int user_defined = 0; /* boolean: are all later digraphs user-defined? */
- char listbuf[8];
-
- /* if "extra" is NULL, then we've reached the end of the built-ins */
- if (!extra)
- {
- user_defined = 1;
- return;
- }
-
- /* if no args, then display the existing digraphs */
- if (*extra < ' ')
- {
- listbuf[0] = listbuf[1] = listbuf[2] = listbuf[5] = ' ';
- listbuf[7] = '\0';
- for (dig = 0, dp = digs; dp; dp = dp->next)
- {
- if (dp->save || bang)
- {
- dig += 7;
- if (dig >= sp->cno)
- {
- addch('\n');
- refresh();
- dig = 7;
- }
- listbuf[3] = dp->key1;
- listbuf[4] = dp->key2;
- listbuf[6] = dp->dig;
- addstr(listbuf);
- }
- }
- addch('\n');
- refresh();
- return;
- }
-
- /* make sure we have at least two characters */
- if (!extra[1])
- {
- msgq(sp, M_ERR,
- "Digraphs must be composed of two characters");
- return;
- }
-
- /* sort key1 and key2, so that their original order won't matter */
- if (extra[0] > extra[1])
- {
- dig = extra[0];
- extra[0] = extra[1];
- extra[1] = dig;
- }
-
- /* locate the new digraph character */
- for (dig = 2; extra[dig] == ' ' || extra[dig] == '\t'; dig++)
- {
- }
- dig = extra[dig];
- if (!bang && dig)
- {
- dig |= 0x80;
- }
-
- /* search for the digraph */
- for (prev = (struct _DIG *)0, dp = digs;
- dp && (dp->key1 != extra[0] || dp->key2 != extra[1]);
- prev = dp, dp = dp->next)
- {
- }
-
- /* deleting the digraph? */
- if (!dig)
- {
- if (!dp)
- {
-#ifndef CRUNCH
- msgq(sp, M_ERR,
- "%c%c not a digraph", extra[0], extra[1]);
-#endif
- return;
- }
- if (prev)
- prev->next = dp->next;
- else
- digs = dp->next;
- free(dp);
- return;
- }
-
- /* if necessary, create a new digraph struct for the new digraph */
- if (dig && !dp)
- {
- MALLOC(sp, dp, struct _DIG *, sizeof(struct _DIG));
- if (dp == NULL)
- return;
- if (prev)
- prev->next = dp;
- else
- digs = dp;
- dp->next = (struct _DIG *)0;
- }
-
- /* assign it the new digraph value */
- dp->key1 = extra[0];
- dp->key2 = extra[1];
- dp->dig = dig;
- dp->save = user_defined;
-}
-
-void
-digraph_save(sp, fd)
- SCR *sp;
- int fd;
-{
- static char buf[] = "digraph! XX Y\n";
- register struct _DIG *dp;
-
- for (dp = digs; dp; dp = dp->next)
- {
- if (dp->save)
- {
- buf[9] = dp->key1;
- buf[10] = dp->key2;
- buf[12] = dp->dig;
- write(fd, buf, (unsigned)14);
- }
- }
-}
-#endif
diff --git a/usr.bin/vi/ex/ex_display.c b/usr.bin/vi/ex/ex_display.c
deleted file mode 100644
index 7f90ef2..0000000
--- a/usr.bin/vi/ex/ex_display.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_display.c 8.23 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "tag.h"
-#include "excmd.h"
-
-static int bdisplay __P((SCR *, EXF *));
-static void db __P((SCR *, CB *, CHAR_T *));
-
-/*
- * ex_display -- :display b[uffers] | s[creens] | t[ags]
- *
- * Display buffers, tags or screens.
- */
-int
-ex_display(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- switch (cmdp->argv[0]->bp[0]) {
- case 'b':
-#undef ARG
-#define ARG "buffers"
- if (cmdp->argv[0]->len >= sizeof(ARG) ||
- memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
- break;
- return (bdisplay(sp, ep));
- case 's':
-#undef ARG
-#define ARG "screens"
- if (cmdp->argv[0]->len >= sizeof(ARG) ||
- memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
- break;
- return (ex_sdisplay(sp, ep));
- case 't':
-#undef ARG
-#define ARG "tags"
- if (cmdp->argv[0]->len >= sizeof(ARG) ||
- memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
- break;
- return (ex_tagdisplay(sp, ep));
- }
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
-}
-
-/*
- * bdisplay --
- *
- * Display buffers.
- */
-static int
-bdisplay(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- CB *cbp;
-
- if (sp->gp->cutq.lh_first == NULL && sp->gp->dcbp == NULL) {
- (void)ex_printf(EXCOOKIE, "No cut buffers to display.\n");
- return (0);
- }
-
- /* Buffers can be infinitely long, make it interruptible. */
- F_SET(sp, S_INTERRUPTIBLE);
-
- /* Display regular cut buffers. */
- for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
- if (isdigit(cbp->name))
- continue;
- if (cbp->textq.cqh_first != (void *)&cbp->textq)
- db(sp, cbp, NULL);
- if (INTERRUPTED(sp))
- return (0);
- }
- /* Display numbered buffers. */
- for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
- if (!isdigit(cbp->name))
- continue;
- if (cbp->textq.cqh_first != (void *)&cbp->textq)
- db(sp, cbp, NULL);
- if (INTERRUPTED(sp))
- return (0);
- }
- /* Display default buffer. */
- if ((cbp = sp->gp->dcbp) != NULL)
- db(sp, cbp, "default buffer");
- return (0);
-}
-
-/*
- * db --
- * Display a buffer.
- */
-static void
-db(sp, cbp, name)
- SCR *sp;
- CB *cbp;
- CHAR_T *name;
-{
- CHAR_T *p;
- TEXT *tp;
- size_t len;
-
- (void)ex_printf(EXCOOKIE, "********** %s%s\n",
- name == NULL ? KEY_NAME(sp, cbp->name) : name,
- F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)");
- for (tp = cbp->textq.cqh_first;
- tp != (void *)&cbp->textq; tp = tp->q.cqe_next) {
- for (len = tp->len, p = tp->lb; len--; ++p) {
- (void)ex_printf(EXCOOKIE, "%s", KEY_NAME(sp, *p));
- if (INTERRUPTED(sp))
- return;
- }
- (void)ex_printf(EXCOOKIE, "\n");
- }
-}
diff --git a/usr.bin/vi/ex/ex_edit.c b/usr.bin/vi/ex/ex_edit.c
deleted file mode 100644
index 5a54e73..0000000
--- a/usr.bin/vi/ex/ex_edit.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_edit.c 8.20 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_edit -- :e[dit][!] [+cmd] [file]
- * :vi[sual][!] [+cmd] [file]
- *
- * Edit a file; if none specified, re-edit the current file. The second
- * form of the command can only be executed while in vi mode. See the
- * hack in ex.c:ex_cmd().
- *
- * !!!
- * Historic vi didn't permit the '+' command form without specifying
- * a file name as well.
- */
-int
-ex_edit(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- ARGS *ap;
- FREF *frp;
-
- frp = sp->frp;
- switch (cmdp->argc) {
- case 0:
- /*
- * If the name has been changed, we edit that file, not the
- * original name. If the user was editing a temporary file,
- * create another one. The reason for this is that we do
- * special exit processing of temporary files, and reusing
- * them is tricky.
- */
- if (F_ISSET(frp, FR_TMPFILE)) {
- if ((frp = file_add(sp, NULL)) == NULL)
- return (1);
- } else {
- if ((frp = file_add(sp, frp->name)) == NULL)
- return (1);
- set_alt_name(sp, sp->frp->name);
- }
- break;
- case 1:
- ap = cmdp->argv[0];
- if ((frp = file_add(sp, ap->bp)) == NULL)
- return (1);
- set_alt_name(sp, ap->bp);
- break;
- default:
- abort();
- }
-
- /*
- * Check for modifications.
- *
- * !!!
- * Contrary to POSIX 1003.2-1992, autowrite did not affect :edit.
- */
- if (file_m2(sp, ep, F_ISSET(cmdp, E_FORCE)))
- return (1);
-
- /* Switch files. */
- if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
- return (1);
- F_SET(sp, S_FSWITCH);
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_equal.c b/usr.bin/vi/ex/ex_equal.c
deleted file mode 100644
index ec979a0..0000000
--- a/usr.bin/vi/ex/ex_equal.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_equal.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_equal -- :address =
- */
-int
-ex_equal(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- recno_t lno;
-
- /*
- * Print out the line number matching the specified address,
- * or the number of the last line in the file if no address
- * specified.
- *
- * !!!
- * Historically, ":0=" displayed 0, and ":=" or ":1=" in an
- * empty file displayed 1. Until somebody complains loudly,
- * we're going to do it right. The tables in excmd.c permit
- * lno to get away with any address from 0 to the end of the
- * file, which, in an empty file, is 0.
- */
- if (F_ISSET(cmdp, E_ADDRDEF)) {
- if (file_lline(sp, ep, &lno))
- return (1);
- } else
- lno = cmdp->addr1.lno;
-
- (void)ex_printf(EXCOOKIE, "%ld\n", lno);
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_exit.c b/usr.bin/vi/ex/ex_exit.c
deleted file mode 100644
index 79c4039..0000000
--- a/usr.bin/vi/ex/ex_exit.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_exit.c 8.15 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_quit -- :quit[!]
- * Quit.
- */
-int
-ex_quit(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- int force;
-
- force = F_ISSET(cmdp, E_FORCE);
-
- /* Check for modifications. */
- if (file_m2(sp, ep, force))
- return (1);
-
- /* Check for more files to edit. */
- if (ex_ncheck(sp, force))
- return (1);
-
- F_SET(sp, force ? S_EXIT_FORCE : S_EXIT);
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_file.c b/usr.bin/vi/ex/ex_file.c
deleted file mode 100644
index cf5f329..0000000
--- a/usr.bin/vi/ex/ex_file.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_file.c 8.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_file -- :f[ile] [name]
- * Change the file's name and display the status line.
- */
-int
-ex_file(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- CHAR_T *p;
- FREF *frp;
-
- switch (cmdp->argc) {
- case 0:
- break;
- case 1:
- frp = sp->frp;
-
- /* Make sure can allocate enough space. */
- if ((p = v_strdup(sp,
- cmdp->argv[0]->bp, cmdp->argv[0]->len)) == NULL)
- return (1);
-
- /* If already have a file name, it becomes the alternate. */
- if (!F_ISSET(frp, FR_TMPFILE))
- set_alt_name(sp, frp->name);
-
- /* Free the previous name. */
- free(frp->name);
- frp->name = p;
-
- /*
- * The read-only bit follows the file name; clear it.
- * The file has a real name, it's no longer a temporary.
- */
- F_CLR(frp, FR_RDONLY | FR_TMPFILE);
-
- /* Have to force a write if the file exists, next time. */
- F_SET(frp, FR_NAMECHANGE);
- break;
- default:
- abort();
- }
- return (msg_status(sp, ep, sp->lno, 1));
-}
diff --git a/usr.bin/vi/ex/ex_global.c b/usr.bin/vi/ex/ex_global.c
deleted file mode 100644
index 5fb134d..0000000
--- a/usr.bin/vi/ex/ex_global.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_global.c 8.43 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-enum which {GLOBAL, VGLOBAL};
-
-static int global __P((SCR *, EXF *, EXCMDARG *, enum which));
-
-/*
- * ex_global -- [line [,line]] g[lobal][!] /pattern/ [commands]
- * Exec on lines matching a pattern.
- */
-int
-ex_global(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (global(sp, ep,
- cmdp, F_ISSET(cmdp, E_FORCE) ? VGLOBAL : GLOBAL));
-}
-
-/*
- * ex_vglobal -- [line [,line]] v[global] /pattern/ [commands]
- * Exec on lines not matching a pattern.
- */
-int
-ex_vglobal(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (global(sp, ep, cmdp, VGLOBAL));
-}
-
-static int
-global(sp, ep, cmdp, cmd)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
- enum which cmd;
-{
- MARK abs;
- RANGE *rp;
- EX_PRIVATE *exp;
- recno_t elno, lno;
- regmatch_t match[1];
- regex_t *re, lre;
- size_t clen, len;
- int delim, eval, reflags, replaced, rval;
- char *cb, *ptrn, *p, *t;
-
- /*
- * Skip leading white space. Historic vi allowed any non-
- * alphanumeric to serve as the global command delimiter.
- */
- for (p = cmdp->argv[0]->bp; isblank(*p); ++p);
- if (*p == '\0' || isalnum(*p)) {
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
- delim = *p++;
-
- /*
- * Get the pattern string, toss escaped characters.
- *
- * QUOTING NOTE:
- * Only toss an escaped character if it escapes a delimiter.
- */
- for (ptrn = t = p;;) {
- if (p[0] == '\0' || p[0] == delim) {
- if (p[0] == delim)
- ++p;
- /*
- * !!!
- * Nul terminate the pattern string -- it's passed
- * to regcomp which doesn't understand anything else.
- */
- *t = '\0';
- break;
- }
- if (p[0] == '\\' && p[1] == delim)
- ++p;
- *t++ = *p++;
- }
-
- /* If the pattern string is empty, use the last one. */
- if (*ptrn == '\0') {
- if (!F_ISSET(sp, S_SRE_SET)) {
- msgq(sp, M_ERR, "No previous regular expression");
- return (1);
- }
- re = &sp->sre;
- } else {
- /* Set RE flags. */
- reflags = 0;
- if (O_ISSET(sp, O_EXTENDED))
- reflags |= REG_EXTENDED;
- if (O_ISSET(sp, O_IGNORECASE))
- reflags |= REG_ICASE;
-
- /* Convert vi-style RE's to POSIX 1003.2 RE's. */
- if (re_conv(sp, &ptrn, &replaced))
- return (1);
-
- /* Compile the RE. */
- re = &lre;
- eval = regcomp(re, ptrn, reflags);
-
- /* Free up any allocated memory. */
- if (replaced)
- FREE_SPACE(sp, ptrn, 0);
-
- if (eval) {
- re_error(sp, eval, re);
- return (1);
- }
-
- /*
- * Set saved RE. Historic practice is that
- * globals set direction as well as the RE.
- */
- sp->sre = lre;
- sp->searchdir = FORWARD;
- F_SET(sp, S_SRE_SET);
- }
-
- /*
- * Get a copy of the command string; the default command is print.
- * Don't worry about a set of <blank>s with no command, that will
- * default to print in the ex parser.
- */
- if ((clen = strlen(p)) == 0) {
- p = "p";
- clen = 1;
- }
- MALLOC_RET(sp, cb, char *, clen);
- memmove(cb, p, clen);
-
- /*
- * The global commands sets the substitute RE as well as
- * the everything-else RE.
- */
- sp->subre = sp->sre;
- F_SET(sp, S_SUBRE_SET);
-
- /* Set the global flag. */
- F_SET(sp, S_GLOBAL);
-
- /* The global commands always set the previous context mark. */
- abs.lno = sp->lno;
- abs.cno = sp->cno;
- if (mark_set(sp, ep, ABSMARK1, &abs, 1))
- goto err;
-
- /*
- * For each line... The semantics of global matching are that we first
- * have to decide which lines are going to get passed to the command,
- * and then pass them to the command, ignoring other changes. There's
- * really no way to do this in a single pass, since arbitrary line
- * creation, deletion and movement can be done in the ex command. For
- * example, a good vi clone test is ":g/X/mo.-3", or "g/X/.,.+1d".
- * What we do is create linked list of lines that are tracked through
- * each ex command. There's a callback routine which the DB interface
- * routines call when a line is created or deleted. This doesn't help
- * the layering much.
- */
- exp = EXP(sp);
- for (rval = 0, lno = cmdp->addr1.lno,
- elno = cmdp->addr2.lno; lno <= elno; ++lno) {
- /* Someone's unhappy, time to stop. */
- if (INTERRUPTED(sp))
- goto interrupted;
-
- /* Get the line and search for a match. */
- if ((t = file_gline(sp, ep, lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- goto err;
- }
- match[0].rm_so = 0;
- match[0].rm_eo = len;
- switch(eval = regexec(re, t, 1, match, REG_STARTEND)) {
- case 0:
- if (cmd == VGLOBAL)
- continue;
- break;
- case REG_NOMATCH:
- if (cmd == GLOBAL)
- continue;
- break;
- default:
- re_error(sp, eval, re);
- goto err;
- }
-
- /* If follows the last entry, extend the last entry's range. */
- if ((rp = exp->rangeq.cqh_last) != (void *)&exp->rangeq &&
- rp->stop == lno - 1) {
- ++rp->stop;
- continue;
- }
-
- /* Allocate a new range, and append it to the list. */
- CALLOC(sp, rp, RANGE *, 1, sizeof(RANGE));
- if (rp == NULL)
- goto err;
- rp->start = rp->stop = lno;
- CIRCLEQ_INSERT_TAIL(&exp->rangeq, rp, q);
- }
-
- exp = EXP(sp);
- exp->range_lno = OOBLNO;
- for (;;) {
- /*
- * Start at the beginning of the range each time, it may have
- * been changed (or exhausted) if lines were inserted/deleted.
- */
- if ((rp = exp->rangeq.cqh_first) == (void *)&exp->rangeq)
- break;
- if (rp->start > rp->stop) {
- CIRCLEQ_REMOVE(&exp->rangeq, exp->rangeq.cqh_first, q);
- free(rp);
- continue;
- }
-
- /*
- * Execute the command, setting the cursor to the line so that
- * relative addressing works. This means that the cursor moves
- * to the last line sent to the command, by default, even if
- * the command fails.
- */
- exp->range_lno = sp->lno = rp->start++;
- if (ex_cmd(sp, ep, cb, clen, 0))
- goto err;
-
- /* Someone's unhappy, time to stop. */
- if (INTERRUPTED(sp)) {
-interrupted: msgq(sp, M_INFO, "Interrupted");
- break;
- }
- }
-
- /* Set the cursor to the new value, making sure it exists. */
- if (exp->range_lno != OOBLNO) {
- if (file_lline(sp, ep, &lno))
- return (1);
- sp->lno =
- lno < exp->range_lno ? (lno ? lno : 1) : exp->range_lno;
- }
- if (0) {
-err: rval = 1;
- }
-
- /* Command we ran may have set the autoprint flag, clear it. */
- F_CLR(exp, EX_AUTOPRINT);
-
- /* Clear the global flag. */
- F_CLR(sp, S_GLOBAL);
-
- /* Free any remaining ranges and the command buffer. */
- while ((rp = exp->rangeq.cqh_first) != (void *)&exp->rangeq) {
- CIRCLEQ_REMOVE(&exp->rangeq, exp->rangeq.cqh_first, q);
- free(rp);
- }
- free(cb);
- return (rval);
-}
-
-/*
- * global_insdel --
- * Update the ranges based on an insertion or deletion.
- */
-void
-global_insdel(sp, ep, op, lno)
- SCR *sp;
- EXF *ep;
- enum operation op;
- recno_t lno;
-{
- EX_PRIVATE *exp;
- RANGE *nrp, *rp;
-
- exp = EXP(sp);
-
- switch (op) {
- case LINE_APPEND:
- return;
- case LINE_DELETE:
- for (rp = exp->rangeq.cqh_first;
- rp != (void *)&exp->rangeq; rp = nrp) {
- nrp = rp->q.cqe_next;
- /* If range less than the line, ignore it. */
- if (rp->stop < lno)
- continue;
- /* If range greater than the line, decrement range. */
- if (rp->start > lno) {
- --rp->start;
- --rp->stop;
- continue;
- }
- /* Lno is inside the range, decrement the end point. */
- if (rp->start > --rp->stop) {
- CIRCLEQ_REMOVE(&exp->rangeq, rp, q);
- free(rp);
- }
- }
- break;
- case LINE_INSERT:
- for (rp = exp->rangeq.cqh_first;
- rp != (void *)&exp->rangeq; rp = rp->q.cqe_next) {
- /* If range less than the line, ignore it. */
- if (rp->stop < lno)
- continue;
- /* If range greater than the line, increment range. */
- if (rp->start >= lno) {
- ++rp->start;
- ++rp->stop;
- continue;
- }
- /*
- * Lno is inside the range, so the range must be split.
- * Since we're inserting a new element, neither range
- * can be exhausted.
- */
- CALLOC(sp, nrp, RANGE *, 1, sizeof(RANGE));
- if (nrp == NULL) {
- F_SET(sp, S_INTERRUPTED);
- return;
- }
- nrp->start = lno + 1;
- nrp->stop = rp->stop + 1;
- rp->stop = lno - 1;
- CIRCLEQ_INSERT_AFTER(&exp->rangeq, rp, nrp, q);
- rp = nrp;
- }
- break;
- case LINE_RESET:
- return;
- }
- /*
- * If the command deleted/inserted lines, the cursor moves to
- * the line after the deleted/inserted line.
- */
- exp->range_lno = lno;
-}
diff --git a/usr.bin/vi/ex/ex_init.c b/usr.bin/vi/ex/ex_init.c
deleted file mode 100644
index 46f9c37..0000000
--- a/usr.bin/vi/ex/ex_init.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_init.c 8.18 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "tag.h"
-
-/*
- * ex_screen_copy --
- * Copy ex screen.
- */
-int
-ex_screen_copy(orig, sp)
- SCR *orig, *sp;
-{
- EX_PRIVATE *oexp, *nexp;
-
- /* Create the private ex structure. */
- CALLOC_RET(orig, nexp, EX_PRIVATE *, 1, sizeof(EX_PRIVATE));
- sp->ex_private = nexp;
-
- /* Initialize queues. */
- TAILQ_INIT(&nexp->tagq);
- TAILQ_INIT(&nexp->tagfq);
- TAILQ_INIT(&nexp->cdq);
- CIRCLEQ_INIT(&nexp->rangeq);
-
- if (orig == NULL) {
- nexp->at_lbuf_set = 0;
- } else {
- oexp = EXP(orig);
-
- nexp->at_lbuf = oexp->at_lbuf;
- nexp->at_lbuf_set = oexp->at_lbuf_set;
-
- if (oexp->lastbcomm != NULL &&
- (nexp->lastbcomm = strdup(oexp->lastbcomm)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return(1);
- }
-
- if (ex_tagcopy(orig, sp))
- return (1);
- }
- return (0);
-}
-
-/*
- * ex_screen_end --
- * End a vi screen.
- */
-int
-ex_screen_end(sp)
- SCR *sp;
-{
- EX_PRIVATE *exp;
- int rval;
-
- rval = 0;
- exp = EXP(sp);
-
- if (argv_free(sp))
- rval = 1;
-
- if (exp->ibp != NULL)
- FREE(exp->ibp, exp->ibp_len);
-
- if (exp->lastbcomm != NULL)
- FREE(exp->lastbcomm, strlen(exp->lastbcomm) + 1);
-
- if (ex_tagfree(sp))
- rval = 1;
-
- if (ex_cdfree(sp))
- rval = 1;
-
- /* Free private memory. */
- FREE(exp, sizeof(EX_PRIVATE));
- sp->ex_private = NULL;
-
- return (rval);
-}
-
-/*
- * ex_init --
- * Initialize ex.
- */
-int
-ex_init(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- size_t len;
-
- /*
- * The default address is the last line of the file. 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 (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 {
- if (file_lline(sp, ep, &sp->lno))
- return (1);
- if (sp->lno == 0)
- sp->lno = 1;
- sp->cno = 0;
- }
-
- /* Display the status line. */
- return (msg_status(sp, ep, sp->lno, 0));
-}
-
-/*
- * ex_end --
- * End ex session.
- */
-int
-ex_end(sp)
- SCR *sp;
-{
- return (0);
-}
-
-/*
- * ex_optchange --
- * Handle change of options for vi.
- */
-int
-ex_optchange(sp, opt)
- SCR *sp;
- int opt;
-{
- switch (opt) {
- case O_CDPATH:
- return (ex_cdalloc(sp, O_STR(sp, O_CDPATH)));
- case O_TAGS:
- return (ex_tagalloc(sp, O_STR(sp, O_TAGS)));
- }
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_join.c b/usr.bin/vi/ex/ex_join.c
deleted file mode 100644
index 4ac045b..0000000
--- a/usr.bin/vi/ex/ex_join.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_join.c 8.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_join -- :[line [,line]] j[oin][!] [count] [flags]
- * Join lines.
- */
-int
-ex_join(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- recno_t from, to;
- size_t blen, clen, len, tlen;
- int echar, extra, first;
- char *bp, *p, *tbp;
-
- from = cmdp->addr1.lno;
- to = cmdp->addr2.lno;
-
- /* Check for no lines to join. */
- if ((p = file_gline(sp, ep, from + 1, &len)) == NULL) {
- msgq(sp, M_ERR, "No following lines to join");
- return (1);
- }
-
- GET_SPACE_RET(sp, bp, blen, 256);
-
- /*
- * The count for the join command was off-by-one,
- * historically, to other counts for other commands.
- */
- if (F_ISSET(cmdp, E_COUNT))
- ++cmdp->addr2.lno;
-
- /*
- * If only a single address specified, or, the same address
- * specified twice, the from/two addresses will be the same.
- */
- if (cmdp->addr1.lno == cmdp->addr2.lno)
- ++cmdp->addr2.lno;
-
- clen = tlen = 0;
- for (first = 1,
- from = cmdp->addr1.lno, to = cmdp->addr2.lno; from <= to; ++from) {
- /*
- * Get next line. Historic versions of vi allowed "10J" while
- * less than 10 lines from the end-of-file, so we do too.
- */
- if ((p = file_gline(sp, ep, from, &len)) == NULL) {
- cmdp->addr2.lno = from - 1;
- break;
- }
-
- /* Empty lines just go away. */
- if (len == 0)
- continue;
-
- /*
- * Get more space if necessary. Note, tlen isn't the length
- * of the new line, it's roughly the amount of space needed.
- * tbp - bp is the length of the new line.
- */
- tlen += len + 2;
- ADD_SPACE_RET(sp, bp, blen, tlen);
- tbp = bp + clen;
-
- /*
- * Historic practice:
- *
- * If force specified, join without modification.
- * If the current line ends with whitespace, strip leading
- * whitespace from the joined line.
- * If the next line starts with a ), do nothing.
- * If the current line ends with ., ? or !, insert two spaces.
- * Else, insert one space.
- *
- * Echar is the last character in the last line joined.
- */
- extra = 0;
- if (!first && !F_ISSET(cmdp, E_FORCE)) {
- if (isblank(echar))
- for (; len && isblank(*p); --len, ++p);
- else if (p[0] != ')') {
- if (strchr(".?!", echar)) {
- *tbp++ = ' ';
- ++clen;
- extra = 1;
- }
- *tbp++ = ' ';
- ++clen;
- for (; len && isblank(*p); --len, ++p);
- }
- }
-
- if (len != 0) {
- memmove(tbp, p, len);
- tbp += len;
- clen += len;
- echar = p[len - 1];
- } else
- echar = ' ';
-
- /*
- * Historic practice for vi was to put the cursor at the first
- * inserted whitespace character, if there was one, or the
- * first character of the joined line, if there wasn't, or the
- * last character of the line if joined to an empty line. If
- * a count was specified, the cursor was moved as described
- * for the first line joined, ignoring subsequent lines. If
- * the join was a ':' command, the cursor was placed at the
- * first non-blank character of the line unless the cursor was
- * "attracted" to the end of line when the command was executed
- * in which case it moved to the new end of line. There are
- * probably several more special cases, but frankly, my dear,
- * I don't give a damn. This implementation puts the cursor
- * on the first inserted whitespace character, the first
- * character of the joined line, or the last character of the
- * line regardless. Note, if the cursor isn't on the joined
- * line (possible with : commands), it is reset to the starting
- * line.
- */
- if (first) {
- sp->cno = (tbp - bp) - (1 + extra);
- first = 0;
- } else
- sp->cno = (tbp - bp) - len - (1 + extra);
- }
- sp->lno = cmdp->addr1.lno;
-
- /* Delete the joined lines. */
- for (from = cmdp->addr1.lno, to = cmdp->addr2.lno; to > from; --to)
- if (file_dline(sp, ep, to))
- goto err;
-
- /* If the original line changed, reset it. */
- if (!first && file_sline(sp, ep, from, bp, tbp - bp)) {
-err: FREE_SPACE(sp, bp, blen);
- return (1);
- }
- FREE_SPACE(sp, bp, blen);
-
- sp->rptlines[L_JOINED] += (cmdp->addr2.lno - cmdp->addr1.lno) + 1;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_map.c b/usr.bin/vi/ex/ex_map.c
deleted file mode 100644
index ec67dbd..0000000
--- a/usr.bin/vi/ex/ex_map.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_map.c 8.19 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_map -- :map[!] [input] [replacement]
- * Map a key/string or display mapped keys.
- *
- * Historical note:
- * Historic vi maps were fairly bizarre, and likely to differ in
- * very subtle and strange ways from this implementation. Two
- * things worth noting are that vi would often hang or drop core
- * if the map was strange enough (ex: map X "xy$@x^V), or, simply
- * not work. One trick worth remembering is that if you put a
- * mark at the start of the map, e.g. map X mx"xy ...), or if you
- * put the map in a .exrc file, things would often work much better.
- * No clue why.
- */
-int
-ex_map(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- enum seqtype stype;
- CHAR_T *input, *p;
-
- stype = F_ISSET(cmdp, E_FORCE) ? SEQ_INPUT : SEQ_COMMAND;
-
- switch (cmdp->argc) {
- case 0:
- if (seq_dump(sp, stype, 1) == 0)
- msgq(sp, M_INFO, "No %s map entries",
- stype == SEQ_INPUT ? "input" : "command");
- return (0);
- case 2:
- input = cmdp->argv[0]->bp;
- break;
- default:
- abort();
- }
-
- /*
- * If the mapped string is #[0-9]* (and wasn't quoted) then store
- * the function key mapping, and call the screen specific routine.
- * Note, if the screen specific routine is able to create the
- * mapping, the SEQ_FUNCMAP type stays around, maybe the next screen
- * type can get it right.
- */
- if (input[0] == '#') {
- for (p = input + 1; isdigit(*p); ++p);
- if (p[0] != '\0')
- goto nofunc;
-
- if (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
- cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_FUNCMAP))
- return (1);
- return (sp->s_fmap(sp, stype, input, cmdp->argv[0]->len,
- cmdp->argv[1]->bp, cmdp->argv[1]->len));
- }
-
- /* Some single keys may not be remapped in command mode. */
-nofunc: if (stype == SEQ_COMMAND && input[1] == '\0')
- switch (KEY_VAL(sp, input[0])) {
- case K_COLON:
- case K_ESCAPE:
- case K_NL:
- msgq(sp, M_ERR, "The %s character may not be remapped",
- KEY_NAME(sp, input[0]));
- return (1);
- }
- return (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
- cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_USERDEF));
-}
-
-/*
- * ex_unmap -- (:unmap[!] key)
- * Unmap a key.
- */
-int
-ex_unmap(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (seq_delete(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len,
- F_ISSET(cmdp, E_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) {
- msgq(sp, M_INFO, "\"%s\" isn't mapped", cmdp->argv[0]->bp);
- return (1);
- }
- return (0);
-}
-
-/*
- * map_save --
- * Save the mapped sequences to a file.
- */
-int
-map_save(sp, fp)
- SCR *sp;
- FILE *fp;
-{
- if (seq_save(sp, fp, "map ", SEQ_COMMAND))
- return (1);
- return (seq_save(sp, fp, "map! ", SEQ_INPUT));
-}
diff --git a/usr.bin/vi/ex/ex_mark.c b/usr.bin/vi/ex/ex_mark.c
deleted file mode 100644
index b74bfb1..0000000
--- a/usr.bin/vi/ex/ex_mark.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_mark.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-int
-ex_mark(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (cmdp->argv[0]->len != 1) {
- msgq(sp, M_ERR, "Mark names must be a single character");
- return (1);
- }
- return (mark_set(sp, ep, cmdp->argv[0]->bp[0], &cmdp->addr1, 1));
-}
diff --git a/usr.bin/vi/ex/ex_mkexrc.c b/usr.bin/vi/ex/ex_mkexrc.c
deleted file mode 100644
index 158fb23..0000000
--- a/usr.bin/vi/ex/ex_mkexrc.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_mkexrc.c 8.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include <pathnames.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_mkexrc -- :mkexrc[!] [file]
- *
- * Create (or overwrite) a .exrc file with the current info.
- */
-int
-ex_mkexrc(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- struct stat sb;
- FILE *fp;
- int fd, sverrno;
- char *fname;
-
- switch (cmdp->argc) {
- case 0:
- fname = _PATH_EXRC;
- break;
- case 1:
- fname = cmdp->argv[0]->bp;
- set_alt_name(sp, fname);
- break;
- default:
- abort();
- }
-
- if (!F_ISSET(cmdp, E_FORCE) && !stat(fname, &sb)) {
- msgq(sp, M_ERR,
- "%s exists, not written; use ! to override", fname);
- return (1);
- }
-
- /* Create with max permissions of rw-r--r--. */
- if ((fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
- msgq(sp, M_SYSERR, fname);
- return (1);
- }
-
- if ((fp = fdopen(fd, "w")) == NULL) {
- sverrno = errno;
- (void)close(fd);
- errno = sverrno;
- goto e2;
- }
-
- if (abbr_save(sp, fp) || ferror(fp))
- goto e1;
- if (map_save(sp, fp) || ferror(fp))
- goto e1;
- if (opts_save(sp, fp) || ferror(fp))
- goto e1;
-#ifndef NO_DIGRAPH
- digraph_save(sp, fd);
-#endif
- if (fclose(fp))
- goto e2;
-
- msgq(sp, M_INFO, "New .exrc file: %s. ", fname);
- return (0);
-
-e1: sverrno = errno;
- (void)fclose(fp);
- errno = sverrno;
-e2: msgq(sp, M_ERR, "%s: incomplete: %s", fname, strerror(errno));
- return (1);
-}
diff --git a/usr.bin/vi/ex/ex_move.c b/usr.bin/vi/ex/ex_move.c
deleted file mode 100644
index 52a8f53..0000000
--- a/usr.bin/vi/ex/ex_move.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_move.c 8.19 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_copy -- :[line [,line]] co[py] line [flags]
- * Copy selected lines.
- */
-int
-ex_copy(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- CB cb;
- MARK fm1, fm2, m, tm;
- recno_t cnt;
- int rval;
-
- rval = 0;
-
- /*
- * It's possible to copy things into the area that's being
- * copied, e.g. "2,5copy3" is legitimate. Save the text to
- * a cut buffer.
- */
- fm1 = cmdp->addr1;
- fm2 = cmdp->addr2;
- memset(&cb, 0, sizeof(cb));
- CIRCLEQ_INIT(&cb.textq);
- for (cnt = fm1.lno; cnt <= fm2.lno; ++cnt)
- if (cut_line(sp, ep, cnt, 0, 0, &cb)) {
- rval = 1;
- goto err;
- }
- cb.flags |= CB_LMODE;
-
- /* Put the text into place. */
- tm.lno = cmdp->lineno;
- tm.cno = 0;
- if (put(sp, ep, &cb, NULL, &tm, &m, 1))
- rval = 1;
- else {
- /*
- * Copy puts the cursor on the last line copied. The cursor
- * returned by the put routine is the first line put, not the
- * last, because that's the historic semantic of vi.
- */
- cnt = (fm2.lno - fm1.lno) + 1;
- sp->lno = m.lno + (cnt - 1);
- sp->cno = 0;
- }
-err: text_lfree(&cb.textq);
- return (rval);
-}
-
-/*
- * ex_move -- :[line [,line]] mo[ve] line
- * Move selected lines.
- */
-int
-ex_move(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- LMARK *lmp;
- MARK fm1, fm2;
- recno_t cnt, diff, fl, tl, mfl, mtl;
- size_t blen, len;
- int mark_reset;
- char *bp, *p;
-
- /*
- * It's not possible to move things into the area that's being
- * moved.
- */
- fm1 = cmdp->addr1;
- fm2 = cmdp->addr2;
- if (cmdp->lineno >= fm1.lno && cmdp->lineno <= fm2.lno) {
- msgq(sp, M_ERR, "Destination line is inside move range");
- return (1);
- }
-
- /*
- * Log the positions of any marks in the to-be-deleted lines. This
- * has to work with the logging code. What happens is that we log
- * the old mark positions, make the changes, then log the new mark
- * positions. Then the marks end up in the right positions no matter
- * which way the log is traversed.
- *
- * XXX
- * Reset the MARK_USERSET flag so that the log can undo the mark.
- * This isn't very clean, and should probably be fixed.
- */
- fl = fm1.lno;
- tl = cmdp->lineno;
-
- /* Log the old positions of the marks. */
- mark_reset = 0;
- for (lmp = ep->marks.lh_first; lmp != NULL; lmp = lmp->q.le_next)
- if (lmp->name != ABSMARK1 &&
- lmp->lno >= fl && lmp->lno <= tl) {
- mark_reset = 1;
- F_CLR(lmp, MARK_USERSET);
- (void)log_mark(sp, ep, lmp);
- }
-
- /* Get memory for the copy. */
- GET_SPACE_RET(sp, bp, blen, 256);
-
- /* Move the lines. */
- diff = (fm2.lno - fm1.lno) + 1;
- if (tl > fl) { /* Destination > source. */
- mfl = tl - diff;
- mtl = tl;
- for (cnt = diff; cnt--;) {
- if ((p = file_gline(sp, ep, fl, &len)) == NULL)
- return (1);
- BINC_RET(sp, bp, blen, len);
- memmove(bp, p, len);
- if (file_aline(sp, ep, 1, tl, bp, len))
- return (1);
- if (mark_reset)
- for (lmp = ep->marks.lh_first;
- lmp != NULL; lmp = lmp->q.le_next)
- if (lmp->name != ABSMARK1 &&
- lmp->lno == fl)
- lmp->lno = tl + 1;
- if (file_dline(sp, ep, fl))
- return (1);
- }
- } else { /* Destination < source. */
- mfl = tl;
- mtl = tl + diff;
- for (cnt = diff; cnt--;) {
- if ((p = file_gline(sp, ep, fl, &len)) == NULL)
- return (1);
- BINC_RET(sp, bp, blen, len);
- memmove(bp, p, len);
- if (file_aline(sp, ep, 1, tl++, bp, len))
- return (1);
- if (mark_reset)
- for (lmp = ep->marks.lh_first;
- lmp != NULL; lmp = lmp->q.le_next)
- if (lmp->name != ABSMARK1 &&
- lmp->lno == fl)
- lmp->lno = tl;
- ++fl;
- if (file_dline(sp, ep, fl))
- return (1);
- }
- }
- FREE_SPACE(sp, bp, blen);
-
- sp->lno = tl; /* Last line moved. */
- sp->cno = 0;
-
- /* Log the new positions of the marks. */
- if (mark_reset)
- for (lmp = ep->marks.lh_first;
- lmp != NULL; lmp = lmp->q.le_next)
- if (lmp->name != ABSMARK1 &&
- lmp->lno >= mfl && lmp->lno <= mtl)
- (void)log_mark(sp, ep, lmp);
-
-
- sp->rptlines[L_MOVED] += diff;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_open.c b/usr.bin/vi/ex/ex_open.c
deleted file mode 100644
index 187a29b..0000000
--- a/usr.bin/vi/ex/ex_open.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_open.c 8.6 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_open -- :[line] o[pen] [/pattern/] [flags]
- *
- * Switch to single line "open" mode.
- */
-int
-ex_open(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- /* If open option off, disallow open command. */
- if (!O_ISSET(sp, O_OPEN)) {
- msgq(sp, M_ERR,
- "The open command requires that the open option be set");
- return (1);
- }
-
- msgq(sp, M_ERR, "The open command is not yet implemented");
- return (1);
-}
diff --git a/usr.bin/vi/ex/ex_preserve.c b/usr.bin/vi/ex/ex_preserve.c
deleted file mode 100644
index 7bef07e..0000000
--- a/usr.bin/vi/ex/ex_preserve.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_preserve.c 8.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_preserve -- :pre[serve]
- * Push the file to recovery.
- */
-int
-ex_preserve(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- recno_t lno;
-
- if (!F_ISSET(ep, F_RCV_ON)) {
- msgq(sp, M_ERR, "Preservation of this file not possible");
- return (1);
- }
-
- /* If recovery not initialized, do so. */
- if (F_ISSET(ep, F_FIRSTMODIFY) && rcv_init(sp, ep))
- return (1);
-
- /* Force the file to be read in, in case it hasn't yet. */
- if (file_lline(sp, ep, &lno))
- return (1);
-
- /* Sync to disk. */
- if (rcv_sync(sp, ep, RCV_SNAPSHOT))
- return (1);
-
- msgq(sp, M_INFO, "File preserved");
- return (0);
-}
-
-/*
- * ex_recover -- :rec[over][!] file
- *
- * Recover the file.
- */
-int
-ex_recover(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- ARGS *ap;
- FREF *frp;
-
- ap = cmdp->argv[0];
-
- /* Set the alternate file name. */
- set_alt_name(sp, ap->bp);
-
- /*
- * Check for modifications. Autowrite did not historically
- * affect :recover.
- */
- if (file_m2(sp, ep, F_ISSET(cmdp, E_FORCE)))
- return (1);
-
- /* Get a file structure for the file. */
- if ((frp = file_add(sp, ap->bp)) == NULL)
- return (1);
-
- /* Set the recover bit. */
- F_SET(frp, FR_RECOVER);
-
- /* Switch files. */
- if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
- return (1);
- F_SET(sp, S_FSWITCH);
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_print.c b/usr.bin/vi/ex/ex_print.c
deleted file mode 100644
index 6bcab28..0000000
--- a/usr.bin/vi/ex/ex_print.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_print.c 8.16 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_list -- :[line [,line]] l[ist] [count] [flags]
- *
- * Display the addressed lines such that the output is unambiguous.
- */
-int
-ex_list(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (ex_print(sp, ep,
- &cmdp->addr1, &cmdp->addr2, cmdp->flags | E_F_LIST))
- return (1);
- sp->lno = cmdp->addr2.lno;
- sp->cno = cmdp->addr2.cno;
- return (0);
-}
-
-/*
- * ex_number -- :[line [,line]] nu[mber] [count] [flags]
- *
- * Display the addressed lines with a leading line number.
- */
-int
-ex_number(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (ex_print(sp, ep,
- &cmdp->addr1, &cmdp->addr2, cmdp->flags | E_F_HASH))
- return (1);
- sp->lno = cmdp->addr2.lno;
- sp->cno = cmdp->addr2.cno;
- return (0);
-}
-
-/*
- * ex_pr -- :[line [,line]] p[rint] [count] [flags]
- *
- * Display the addressed lines.
- */
-int
-ex_pr(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (ex_print(sp, ep, &cmdp->addr1, &cmdp->addr2, cmdp->flags))
- return (1);
- sp->lno = cmdp->addr2.lno;
- sp->cno = cmdp->addr2.cno;
- return (0);
-}
-
-/*
- * ex_print --
- * Print the selected lines.
- */
-int
-ex_print(sp, ep, fp, tp, flags)
- SCR *sp;
- EXF *ep;
- MARK *fp, *tp;
- register int flags;
-{
- recno_t from, to;
- size_t col, len;
- char *p;
-
- F_SET(sp, S_INTERRUPTIBLE);
- for (from = fp->lno, to = tp->lno; from <= to; ++from) {
- /*
- * Display the line number. The %6 format is specified
- * by POSIX 1003.2, and is almost certainly large enough.
- * Check, though, just in case.
- */
- if (LF_ISSET(E_F_HASH))
- if (from <= 999999)
- col = ex_printf(EXCOOKIE, "%6ld ", from);
- else
- col = ex_printf(EXCOOKIE, "TOOBIG ");
- else
- col = 0;
-
- /*
- * Display the line. The format for E_F_PRINT isn't very good,
- * especially in handling end-of-line tabs, but they're almost
- * backward compatible.
- */
- if ((p = file_gline(sp, ep, from, &len)) == NULL) {
- GETLINE_ERR(sp, from);
- return (1);
- }
-
- if (len == 0 && !LF_ISSET(E_F_LIST))
- (void)ex_printf(EXCOOKIE, "\n");
- else if (ex_ldisplay(sp, p, len, col, flags))
- return (1);
-
- if (INTERRUPTED(sp))
- break;
- }
-
- return (0);
-}
-
-/*
- * ex_ldisplay --
- * Display a line.
- */
-int
-ex_ldisplay(sp, lp, len, col, flags)
- SCR *sp;
- CHAR_T *lp;
- size_t len, col;
- u_int flags;
-{
- CHAR_T ch, *kp;
- u_long ts;
- size_t tlen;
-
- ts = O_VAL(sp, O_TABSTOP);
- for (;; --len) {
- if (len > 0)
- ch = *lp++;
- else if (LF_ISSET(E_F_LIST))
- ch = '$';
- else
- break;
- if (ch == '\t' && !LF_ISSET(E_F_LIST))
- for (tlen = ts - col % ts;
- col < sp->cols && tlen--; ++col)
- (void)ex_printf(EXCOOKIE, " ");
- else {
- kp = KEY_NAME(sp, ch);
- tlen = KEY_LEN(sp, ch);
- if (col + tlen < sp->cols) {
- (void)ex_printf(EXCOOKIE, "%s", kp);
- col += tlen;
- } else
- for (; tlen--; ++kp, ++col) {
- if (col == sp->cols) {
- col = 0;
- (void)ex_printf(EXCOOKIE, "\n");
- }
- (void)ex_printf(EXCOOKIE, "%c", *kp);
- }
- }
- if (len == 0)
- break;
- }
- (void)ex_printf(EXCOOKIE, "\n");
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_put.c b/usr.bin/vi/ex/ex_put.c
deleted file mode 100644
index a947d85..0000000
--- a/usr.bin/vi/ex/ex_put.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_put.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_put -- [line] pu[t] [buffer]
- *
- * Append a cut buffer into the file.
- */
-int
-ex_put(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- MARK m;
-
- m.lno = sp->lno;
- m.cno = sp->cno;
- if (put(sp, ep, NULL, F_ISSET(cmdp, E_BUFFER) ? &cmdp->buffer : NULL,
- &cmdp->addr1, &m, 1))
- return (1);
- sp->lno = m.lno;
- sp->cno = m.cno;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_read.c b/usr.bin/vi/ex/ex_read.c
deleted file mode 100644
index cef1e3a..0000000
--- a/usr.bin/vi/ex/ex_read.c
+++ /dev/null
@@ -1,300 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_read.c 8.41 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_read -- :read [file]
- * :read [!cmd]
- * Read from a file or utility.
- *
- * !!!
- * Historical vi wouldn't undo a filter read, for no apparent reason.
- */
-int
-ex_read(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- struct stat sb;
- CHAR_T *arg, *name;
- EX_PRIVATE *exp;
- FILE *fp;
- MARK rm;
- recno_t nlines;
- size_t arglen, blen, len;
- int btear, farg, rval;
- char *p;
-
- /*
- * 0 args: we're done.
- * 1 args: check for "read !arg".
- * 2 args: check for "read ! arg".
- * >2 args: object, too many args.
- */
- farg = 0;
- switch (cmdp->argc) {
- case 0:
- break;
- case 1:
- arg = cmdp->argv[0]->bp;
- arglen = cmdp->argv[0]->len;
- if (*arg == '!') {
- ++arg;
- --arglen;
- farg = 1;
- }
- break;
- case 2:
- if (cmdp->argv[0]->len == 1 && cmdp->argv[0]->bp[0] == '!') {
- arg = cmdp->argv[1]->bp;
- arglen = cmdp->argv[1]->len;
- farg = 2;
- break;
- }
- /* FALLTHROUGH */
- default:
- goto badarg;
- }
-
- if (farg != 0) {
- /* File name and bang expand the user's argument. */
- if (argv_exp1(sp, ep, cmdp, arg, arglen, 1))
- return (1);
-
- /* If argc unchanged, there wasn't anything to expand. */
- if (cmdp->argc == farg)
- goto usage;
-
- /* Set the last bang command. */
- exp = EXP(sp);
- if (exp->lastbcomm != NULL)
- free(exp->lastbcomm);
- if ((exp->lastbcomm = strdup(cmdp->argv[farg]->bp)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
-
- /* Redisplay the user's argument if it's changed. */
- if (F_ISSET(cmdp, E_MODIFY) && IN_VI_MODE(sp)) {
- len = cmdp->argv[farg]->len;
- GET_SPACE_RET(sp, p, blen, len + 2);
- p[0] = '!';
- memmove(p + 1,
- cmdp->argv[farg]->bp, cmdp->argv[farg]->len + 1);
- (void)sp->s_busy(sp, p);
- FREE_SPACE(sp, p, blen);
- }
-
- if (filtercmd(sp, ep, &cmdp->addr1,
- NULL, &rm, cmdp->argv[farg]->bp, FILTER_READ))
- return (1);
-
- /* The filter version of read set the autoprint flag. */
- F_SET(EXP(sp), EX_AUTOPRINT);
-
- /* If in vi mode, move to the first nonblank. */
- sp->lno = rm.lno;
- if (IN_VI_MODE(sp)) {
- sp->cno = 0;
- (void)nonblank(sp, ep, sp->lno, &sp->cno);
- }
- return (0);
- }
-
- /* Shell and file name expand the user's argument. */
- if (argv_exp2(sp, ep, cmdp, arg, arglen, 0))
- return (1);
-
- /*
- * 0 args: no arguments, read the current file, don't set the
- * alternate file name.
- * 1 args: read it, switching to it or settgin the alternate file
- * name.
- * >1 args: object, too many args.
- */
- switch (cmdp->argc) {
- case 1:
- name = sp->frp->name;
- break;
- case 2:
- name = cmdp->argv[1]->bp;
- /*
- * !!!
- * Historically, if you had an "unnamed" file, the read command
- * renamed the file.
- */
- if (F_ISSET(sp->frp, FR_TMPFILE) &&
- !F_ISSET(sp->frp, FR_READNAMED)) {
- if ((p = v_strdup(sp,
- cmdp->argv[1]->bp, cmdp->argv[1]->len)) != NULL) {
- free(sp->frp->name);
- sp->frp->name = p;
- }
- F_SET(sp->frp, FR_NAMECHANGE | FR_READNAMED);
- } else
- set_alt_name(sp, name);
- break;
- default:
-badarg: msgq(sp, M_ERR,
- "%s expanded into too many file names", cmdp->argv[0]->bp);
-usage: msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
-
- /*
- * !!!
- * Historically, vi did not permit reads from non-regular files,
- * nor did it distinguish between "read !" and "read!", so there
- * was no way to "force" it.
- */
- if ((fp = fopen(name, "r")) == NULL || fstat(fileno(fp), &sb)) {
- msgq(sp, M_SYSERR, "%s", name);
- return (1);
- }
- if (!S_ISREG(sb.st_mode)) {
- (void)fclose(fp);
- msgq(sp, M_ERR, "Only regular files may be read");
- return (1);
- }
-
- /* Turn on busy message. */
- btear = F_ISSET(sp, S_EXSILENT) ? 0 : !busy_on(sp, "Reading...");
- rval = ex_readfp(sp, ep, name, fp, &cmdp->addr1, &nlines, 1);
- if (btear)
- busy_off(sp);
-
- /*
- * Set the cursor to the first line read in, if anything read
- * in, otherwise, the address. (Historic vi set it to the
- * line after the address regardless, but since that line may
- * not exist we don't bother.)
- */
- sp->lno = cmdp->addr1.lno;
- if (nlines)
- ++sp->lno;
-
- return (rval);
-}
-
-/*
- * ex_readfp --
- * Read lines into the file.
- */
-int
-ex_readfp(sp, ep, name, fp, fm, nlinesp, success_msg)
- SCR *sp;
- EXF *ep;
- char *name;
- FILE *fp;
- MARK *fm;
- recno_t *nlinesp;
- int success_msg;
-{
- EX_PRIVATE *exp;
- recno_t lcnt, lno;
- size_t len;
- u_long ccnt; /* XXX: can't print off_t portably. */
- int rval;
-
- rval = 0;
- exp = EXP(sp);
-
- /*
- * Add in the lines from the output. Insertion starts at the line
- * following the address.
- */
- ccnt = 0;
- lcnt = 0;
- for (lno = fm->lno; !ex_getline(sp, fp, &len); ++lno, ++lcnt) {
- if (INTERRUPTED(sp)) {
- if (!success_msg)
- msgq(sp, M_INFO, "Interrupted");
- break;
- }
- if (file_aline(sp, ep, 1, lno, exp->ibp, len)) {
- rval = 1;
- break;
- }
- ccnt += len;
- }
-
- if (ferror(fp)) {
- msgq(sp, M_SYSERR, "%s", name);
- rval = 1;
- }
-
- if (fclose(fp)) {
- msgq(sp, M_SYSERR, "%s", name);
- return (1);
- }
-
- if (rval)
- return (1);
-
- /* Return the number of lines read in. */
- if (nlinesp != NULL)
- *nlinesp = lcnt;
-
- if (success_msg)
- msgq(sp, M_INFO, "%s%s: %lu line%s, %lu characters",
- INTERRUPTED(sp) ? "Interrupted read: " : "",
- name, lcnt, lcnt == 1 ? "" : "s", ccnt);
-
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_screen.c b/usr.bin/vi/ex/ex_screen.c
deleted file mode 100644
index e190588..0000000
--- a/usr.bin/vi/ex/ex_screen.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_screen.c 8.15 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_split -- :s[plit] [file ...]
- * Split the screen, optionally setting the file list.
- */
-int
-ex_split(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (sp->s_split(sp, cmdp->argc ? cmdp->argv : NULL, cmdp->argc));
-}
-
-/*
- * ex_bg -- :bg
- * Hide the screen.
- */
-int
-ex_bg(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (sp->s_bg(sp));
-}
-
-/*
- * ex_fg -- :fg [file]
- * Show the screen.
- */
-int
-ex_fg(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (sp->s_fg(sp, cmdp->argc ? cmdp->argv[0]->bp : NULL));
-}
-
-/*
- * ex_resize -- :resize [+-]rows
- * Change the screen size.
- */
-int
-ex_resize(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- enum adjust adj;
-
- if (!F_ISSET(cmdp, E_COUNT)) {
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
- if (F_ISSET(cmdp, E_COUNT_NEG))
- adj = A_DECREASE;
- else if (F_ISSET(cmdp, E_COUNT_POS))
- adj = A_INCREASE;
- else
- adj = A_SET;
- return (sp->s_rabs(sp, cmdp->count, adj));
-}
-
-/*
- * ex_sdisplay --
- * Display the list of screens.
- */
-int
-ex_sdisplay(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- SCR *tsp;
- int cnt, col, len, sep;
-
- if ((tsp = sp->gp->hq.cqh_first) == (void *)&sp->gp->hq) {
- (void)ex_printf(EXCOOKIE,
- "No backgrounded screens to display.\n");
- return (0);
- }
-
- col = len = sep = 0;
- for (cnt = 1; tsp != (void *)&sp->gp->hq; tsp = tsp->q.cqe_next) {
- col += len = strlen(tsp->frp->name) + sep;
- if (col >= sp->cols - 1) {
- col = len;
- sep = 0;
- (void)ex_printf(EXCOOKIE, "\n");
- } else if (cnt != 1) {
- sep = 1;
- (void)ex_printf(EXCOOKIE, " ");
- }
- (void)ex_printf(EXCOOKIE, "%s", tsp->frp->name);
- ++cnt;
- }
- (void)ex_printf(EXCOOKIE, "\n");
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_script.c b/usr.bin/vi/ex/ex_script.c
deleted file mode 100644
index a364e2b..0000000
--- a/usr.bin/vi/ex/ex_script.c
+++ /dev/null
@@ -1,582 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_script.c 8.19 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "script.h"
-
-/*
- * XXX
- */
-int openpty __P((int *, int *, char *, struct termios *, struct winsize *));
-
-static int sscr_getprompt __P((SCR *, EXF *));
-static int sscr_init __P((SCR *, EXF *));
-static int sscr_matchprompt __P((SCR *, char *, size_t, size_t *));
-static int sscr_setprompt __P((SCR *, char *, size_t));
-
-/*
- * ex_script -- : sc[ript][!] [file]
- *
- * Switch to script mode.
- */
-int
-ex_script(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- /* Vi only command. */
- if (!IN_VI_MODE(sp)) {
- msgq(sp, M_ERR,
- "The script command is only available in vi mode");
- return (1);
- }
-
- /* Switch to the new file. */
- if (cmdp->argc != 0 && ex_edit(sp, ep, cmdp))
- return (1);
-
- /*
- * Create the shell, figure out the prompt.
- *
- * !!!
- * The files just switched, use sp->ep.
- */
- if (sscr_init(sp, sp->ep))
- return (1);
-
- return (0);
-}
-
-/*
- * sscr_init --
- * Create a pty setup for a shell.
- */
-static int
-sscr_init(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- SCRIPT *sc;
- char *sh, *sh_path;
-
- MALLOC_RET(sp, sc, SCRIPT *, sizeof(SCRIPT));
- sp->script = sc;
- sc->sh_prompt = NULL;
- sc->sh_prompt_len = 0;
-
- /*
- * There are two different processes running through this code.
- * They are the shell and the parent.
- */
- sc->sh_master = sc->sh_slave = -1;
-
- if (tcgetattr(STDIN_FILENO, &sc->sh_term) == -1) {
- msgq(sp, M_SYSERR, "tcgetattr");
- goto err;
- }
-
- /*
- * Turn off output postprocessing and echo.
- */
- sc->sh_term.c_oflag &= ~OPOST;
- sc->sh_term.c_cflag &= ~(ECHO|ECHOE|ECHONL|ECHOK);
-
- if (ioctl(STDIN_FILENO, TIOCGWINSZ, &sc->sh_win) == -1) {
- msgq(sp, M_SYSERR, "tcgetattr");
- goto err;
- }
-
- if (openpty(&sc->sh_master,
- &sc->sh_slave, sc->sh_name, &sc->sh_term, &sc->sh_win) == -1) {
- msgq(sp, M_SYSERR, "openpty");
- goto err;
- }
-
- /*
- * Don't use vfork() here, because the signal semantics differ from
- * implementation to implementation.
- */
- SIGBLOCK(sp->gp);
- switch (sc->sh_pid = fork()) {
- case -1: /* Error. */
- SIGUNBLOCK(sp->gp);
-
- msgq(sp, M_SYSERR, "fork");
-err: if (sc->sh_master != -1)
- (void)close(sc->sh_master);
- if (sc->sh_slave != -1)
- (void)close(sc->sh_slave);
- return (1);
- case 0: /* Utility. */
- /* The utility has default signal behavior. */
- sig_end();
-
- /*
- * XXX
- * So that shells that do command line editing turn it off.
- */
- (void)putenv("TERM=emacs");
- (void)putenv("TERMCAP=emacs:");
- (void)putenv("EMACS=t");
-
- (void)setsid();
-#ifdef TIOCSCTTY
- /*
- * 4.4BSD allocates a controlling terminal using the TIOCSCTTY
- * ioctl, not by opening a terminal device file. POSIX 1003.1
- * doesn't define a portable way to do this. If TIOCSCTTY is
- * not available, hope that the open does it.
- */
- (void)ioctl(sc->sh_slave, TIOCSCTTY, 0);
-#endif
- (void)close(sc->sh_master);
- (void)dup2(sc->sh_slave, STDIN_FILENO);
- (void)dup2(sc->sh_slave, STDOUT_FILENO);
- (void)dup2(sc->sh_slave, STDERR_FILENO);
- (void)close(sc->sh_slave);
-
- /* Assumes that all shells have -i. */
- sh_path = O_STR(sp, O_SHELL);
- if ((sh = strrchr(sh_path, '/')) == NULL)
- sh = sh_path;
- else
- ++sh;
- execl(sh_path, sh, "-i", NULL);
- msgq(sp, M_ERR,
- "Error: execl: %s: %s", sh_path, strerror(errno));
- _exit(127);
- default: /* Parent. */
- SIGUNBLOCK(sp->gp);
- break;
- }
-
- if (sscr_getprompt(sp, ep))
- return (1);
-
- F_SET(sp, S_REDRAW | S_SCRIPT);
- return (0);
-
-}
-
-/*
- * sscr_getprompt --
- * Eat lines printed by the shell until a line with no trailing
- * carriage return comes; set the prompt from that line.
- */
-static int
-sscr_getprompt(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- struct timeval tv;
- CHAR_T *endp, *p, *t, buf[1024];
- SCRIPT *sc;
- fd_set fdset;
- recno_t lline;
- size_t llen, len;
- u_int value;
- int nr;
-
- FD_ZERO(&fdset);
- endp = buf;
- len = sizeof(buf);
-
- /* Wait up to a second for characters to read. */
- tv.tv_sec = 5;
- tv.tv_usec = 0;
- sc = sp->script;
- FD_SET(sc->sh_master, &fdset);
- switch (select(sc->sh_master + 1, &fdset, NULL, NULL, &tv)) {
- case -1: /* Error or interrupt. */
- msgq(sp, M_SYSERR, "select");
- goto prompterr;
- case 0: /* Timeout */
- msgq(sp, M_ERR, "Error: timed out");
- goto prompterr;
- case 1: /* Characters to read. */
- break;
- }
-
- /* Read the characters. */
-more: len = sizeof(buf) - (endp - buf);
- switch (nr = read(sc->sh_master, endp, len)) {
- case 0: /* EOF. */
- msgq(sp, M_ERR, "Error: shell: EOF");
- goto prompterr;
- case -1: /* Error or interrupt. */
- msgq(sp, M_SYSERR, "shell");
- goto prompterr;
- default:
- endp += nr;
- break;
- }
-
- /* If any complete lines, push them into the file. */
- for (p = t = buf; p < endp; ++p) {
- value = KEY_VAL(sp, *p);
- if (value == K_CR || value == K_NL) {
- if (file_lline(sp, ep, &lline) ||
- file_aline(sp, ep, 0, lline, t, p - t))
- goto prompterr;
- t = p + 1;
- }
- }
- if (p > buf) {
- memmove(buf, t, endp - t);
- endp = buf + (endp - t);
- }
- if (endp == buf)
- goto more;
-
- /* Wait up 1/10 of a second to make sure that we got it all. */
- tv.tv_sec = 0;
- tv.tv_usec = 100000;
- switch (select(sc->sh_master + 1, &fdset, NULL, NULL, &tv)) {
- case -1: /* Error or interrupt. */
- msgq(sp, M_SYSERR, "select");
- goto prompterr;
- case 0: /* Timeout */
- break;
- case 1: /* Characters to read. */
- goto more;
- }
-
- /* Timed out, so theoretically we have a prompt. */
- llen = endp - buf;
- endp = buf;
-
- /* Append the line into the file. */
- if (file_lline(sp, ep, &lline) ||
- file_aline(sp, ep, 0, lline, buf, llen)) {
-prompterr: sscr_end(sp);
- return (1);
- }
-
- return (sscr_setprompt(sp, buf, llen));
-}
-
-/*
- * sscr_exec --
- * Take a line and hand it off to the shell.
- */
-int
-sscr_exec(sp, ep, lno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
-{
- SCRIPT *sc;
- recno_t last_lno;
- size_t blen, len, last_len, tlen;
- int matchprompt, nw, rval;
- char *bp, *p;
-
- /* If there's a prompt on the last line, append the command. */
- if (file_lline(sp, ep, &last_lno))
- return (1);
- if ((p = file_gline(sp, ep, last_lno, &last_len)) == NULL) {
- GETLINE_ERR(sp, last_lno);
- return (1);
- }
- if (sscr_matchprompt(sp, p, last_len, &tlen) && tlen == 0) {
- matchprompt = 1;
- GET_SPACE_RET(sp, bp, blen, last_len + 128);
- memmove(bp, p, last_len);
- } else
- matchprompt = 0;
-
- /* Get something to execute. */
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- goto err1;
- if (lno == 0)
- goto empty;
- else
- GETLINE_ERR(sp, lno);
- goto err1;
- }
-
- /* Empty lines aren't interesting. */
- if (len == 0)
- goto empty;
-
- /* Delete any prompt. */
- if (sscr_matchprompt(sp, p, len, &tlen)) {
- if (tlen == len) {
-empty: msgq(sp, M_BERR, "Nothing to execute");
- goto err1;
- }
- p += (len - tlen);
- len = tlen;
- }
-
- /* Push the line to the shell. */
- sc = sp->script;
- if ((nw = write(sc->sh_master, p, len)) != len)
- goto err2;
- rval = 0;
- if (write(sc->sh_master, "\n", 1) != 1) {
-err2: if (nw == 0)
- errno = EIO;
- msgq(sp, M_SYSERR, "shell");
- goto err1;
- }
-
- if (matchprompt) {
- ADD_SPACE_RET(sp, bp, blen, last_len + len);
- memmove(bp + last_len, p, len);
- if (file_sline(sp, ep, last_lno, bp, last_len + len))
-err1: rval = 1;
- }
- if (matchprompt)
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
-
-/*
- * sscr_input --
- * Take a line from the shell and insert it into the file.
- */
-int
-sscr_input(sp)
- SCR *sp;
-{
- struct timeval tv;
- CHAR_T *endp, *p, *t;
- EXF *ep;
- SCRIPT *sc;
- recno_t lno;
- size_t blen, len, tlen;
- u_int value;
- int nr, rval;
- char *bp;
-
- /* Find out where the end of the file is. */
- ep = sp->ep;
- if (file_lline(sp, ep, &lno))
- return (1);
-
-#define MINREAD 1024
- GET_SPACE_RET(sp, bp, blen, MINREAD);
- endp = bp;
-
- /* Read the characters. */
- rval = 1;
- sc = sp->script;
-more: switch (nr = read(sc->sh_master, endp, MINREAD)) {
- case 0: /* EOF; shell just exited. */
- sscr_end(sp);
- F_CLR(sp, S_SCRIPT);
- rval = 0;
- goto ret;
- case -1: /* Error or interrupt. */
- msgq(sp, M_SYSERR, "shell");
- goto ret;
- default:
- endp += nr;
- break;
- }
-
- /* Append the lines into the file. */
- for (p = t = bp; p < endp; ++p) {
- value = KEY_VAL(sp, *p);
- if (value == K_CR || value == K_NL) {
- len = p - t;
- if (file_aline(sp, ep, 1, lno++, t, len))
- goto ret;
- t = p + 1;
- }
- }
- if (p > t) {
- len = p - t;
- /*
- * If the last thing from the shell isn't another prompt, wait
- * up to 1/10 of a second for more stuff to show up, so that
- * we don't break the output into two separate lines. Don't
- * want to hang indefinitely because some program is hanging,
- * confused the shell, or whatever.
- */
- if (!sscr_matchprompt(sp, t, len, &tlen) || tlen != 0) {
- tv.tv_sec = 0;
- tv.tv_usec = 100000;
- FD_SET(sc->sh_master, &sp->rdfd);
- FD_CLR(STDIN_FILENO, &sp->rdfd);
- if (select(sc->sh_master + 1,
- &sp->rdfd, NULL, NULL, &tv) == 1) {
- memmove(bp, t, len);
- endp = bp + len;
- goto more;
- }
- }
- if (sscr_setprompt(sp, t, len))
- return (1);
- if (file_aline(sp, ep, 1, lno++, t, len))
- goto ret;
- }
-
- /* The cursor moves to EOF. */
- sp->lno = lno;
- sp->cno = len ? len - 1 : 0;
- rval = sp->s_refresh(sp, ep);
-
-ret: FREE_SPACE(sp, bp, blen);
- return (rval);
-}
-
-/*
- * sscr_setprompt --
- *
- * Set the prompt to the last line we got from the shell.
- *
- */
-static int
-sscr_setprompt(sp, buf, len)
- SCR *sp;
- char* buf;
- size_t len;
-{
- SCRIPT *sc;
-
- sc = sp->script;
- if (sc->sh_prompt)
- FREE(sc->sh_prompt, sc->sh_prompt_len);
- MALLOC(sp, sc->sh_prompt, char *, len + 1);
- if (sc->sh_prompt == NULL) {
- sscr_end(sp);
- return (1);
- }
- memmove(sc->sh_prompt, buf, len);
- sc->sh_prompt_len = len;
- sc->sh_prompt[len] = '\0';
- return (0);
-}
-
-/*
- * sscr_matchprompt --
- * Check to see if a line matches the prompt. Nul's indicate
- * parts that can change, in both content and size.
- */
-static int
-sscr_matchprompt(sp, lp, line_len, lenp)
- SCR *sp;
- char *lp;
- size_t line_len, *lenp;
-{
- SCRIPT *sc;
- size_t prompt_len;
- char *pp;
-
- sc = sp->script;
- if (line_len < (prompt_len = sc->sh_prompt_len))
- return (0);
-
- for (pp = sc->sh_prompt;
- prompt_len && line_len; --prompt_len, --line_len) {
- if (*pp == '\0') {
- for (; prompt_len && *pp == '\0'; --prompt_len, ++pp);
- if (!prompt_len)
- return (0);
- for (; line_len && *lp != *pp; --line_len, ++lp);
- if (!line_len)
- return (0);
- }
- if (*pp++ != *lp++)
- break;
- }
-
- if (prompt_len)
- return (0);
- if (lenp != NULL)
- *lenp = line_len;
- return (1);
-}
-
-/*
- * sscr_end --
- * End the pipe to a shell.
- */
-int
-sscr_end(sp)
- SCR *sp;
-{
- SCRIPT *sc;
- int rval;
-
- if ((sc = sp->script) == NULL)
- return (0);
-
- /* Turn off the script flag. */
- F_CLR(sp, S_SCRIPT);
-
- /* Close down the parent's file descriptors. */
- if (sc->sh_master != -1)
- (void)close(sc->sh_master);
- if (sc->sh_slave != -1)
- (void)close(sc->sh_slave);
-
- /* This should have killed the child. */
- rval = proc_wait(sp, (long)sc->sh_pid, "script-shell", 0);
-
- /* Free memory. */
- FREE(sc->sh_prompt, sc->sh_prompt_len);
- FREE(sc, sizeof(SCRIPT));
- sp->script = NULL;
-
- return (rval);
-}
diff --git a/usr.bin/vi/ex/ex_set.c b/usr.bin/vi/ex/ex_set.c
deleted file mode 100644
index a2abb08..0000000
--- a/usr.bin/vi/ex/ex_set.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_set.c 8.6 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-int
-ex_set(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- switch(cmdp->argc) {
- case 0:
- opts_dump(sp, CHANGED_DISPLAY);
- break;
- default:
- opts_set(sp, cmdp->cmd->usage, cmdp->argv);
- break;
- }
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_shell.c b/usr.bin/vi/ex/ex_shell.c
deleted file mode 100644
index b6f9aed..0000000
--- a/usr.bin/vi/ex/ex_shell.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_shell.c 8.26 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../svi/svi_screen.h"
-
-/*
- * ex_shell -- :sh[ell]
- * Invoke the program named in the SHELL environment variable
- * with the argument -i.
- */
-int
-ex_shell(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- char buf[MAXPATHLEN];
-
- (void)snprintf(buf, sizeof(buf), "%s -i", O_STR(sp, O_SHELL));
- return (ex_exec_proc(sp, buf, "\n", NULL));
-}
-
-/*
- * ex_exec_proc --
- * Run a separate process.
- */
-int
-ex_exec_proc(sp, cmd, p1, p2)
- SCR *sp;
- char *cmd, *p1, *p2;
-{
- const char *name;
- pid_t pid;
- int rval, teardown;
-
- /* Clear the rest of the screen. */
- if (sp->s_clear(sp))
- return (1);
-
- /* Save ex/vi terminal settings, and restore the original ones. */
- teardown = !ex_sleave(sp);
-
- /*
- * Flush waiting messages (autowrite, for example) so the output
- * matches historic practice.
- */
- (void)sex_refresh(sp, sp->ep);
-
- /* Put out various messages. */
- if (p1 != NULL)
- (void)write(STDOUT_FILENO, p1, strlen(p1));
- if (p2 != NULL)
- (void)write(STDOUT_FILENO, p2, strlen(p2));
-
- SIGBLOCK(sp->gp);
- switch (pid = vfork()) {
- case -1: /* Error. */
- SIGUNBLOCK(sp->gp);
-
- msgq(sp, M_SYSERR, "vfork");
- rval = 1;
- break;
- case 0: /* Utility. */
- /* The utility has default signal behavior. */
- sig_end();
-
- if ((name = strrchr(O_STR(sp, O_SHELL), '/')) == NULL)
- name = O_STR(sp, O_SHELL);
- else
- ++name;
- execl(O_STR(sp, O_SHELL), name, "-c", cmd, NULL);
- msgq(sp, M_ERR, "Error: execl: %s: %s",
- O_STR(sp, O_SHELL), strerror(errno));
- _exit(127);
- /* NOTREACHED */
- default: /* Parent. */
- SIGUNBLOCK(sp->gp);
-
- rval = proc_wait(sp, (long)pid, cmd, 0);
- break;
- }
-
- /* Restore ex/vi terminal settings. */
- if (teardown)
- ex_rleave(sp);
-
- /*
- * XXX
- * Stat of the tty structures (see ex_sleave, ex_rleave) only give
- * us 1-second resolution on the tty changes. A fast '!' command,
- * e.g. ":!pwd" can beat us to the refresh. When there's better
- * resolution from the stat(2) timers, this can go away.
- */
- F_SET(sp, S_REFRESH);
-
- return (rval);
-}
diff --git a/usr.bin/vi/ex/ex_shift.c b/usr.bin/vi/ex/ex_shift.c
deleted file mode 100644
index 61264c0..0000000
--- a/usr.bin/vi/ex/ex_shift.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_shift.c 8.16 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-enum which {LEFT, RIGHT};
-static int shift __P((SCR *, EXF *, EXCMDARG *, enum which));
-
-int
-ex_shiftl(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (shift(sp, ep, cmdp, LEFT));
-}
-
-int
-ex_shiftr(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (shift(sp, ep, cmdp, RIGHT));
-}
-
-static int
-shift(sp, ep, cmdp, rl)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
- enum which rl;
-{
- recno_t from, to;
- size_t blen, len, newcol, newidx, oldcol, oldidx, sw;
- int curset;
- char *p, *bp, *tbp;
-
- if (O_VAL(sp, O_SHIFTWIDTH) == 0) {
- msgq(sp, M_INFO, "shiftwidth option set to 0");
- return (0);
- }
-
- /*
- * The historic version of vi permitted the user to string any number
- * of '>' or '<' characters together, resulting in an indent of the
- * appropriate levels. There's a special hack in ex_cmd() so that
- * cmdp->argv[0] points to the string of '>' or '<' characters.
- *
- * Q: What's the difference between the people adding features
- * to vi and the Girl Scouts?
- * A: The Girl Scouts have mint cookies and adult supervision.
- */
- for (p = cmdp->argv[0]->bp, sw = 0; *p == '>' || *p == '<'; ++p)
- sw += O_VAL(sp, O_SHIFTWIDTH);
-
- GET_SPACE_RET(sp, bp, blen, 256);
-
- curset = 0;
- for (from = cmdp->addr1.lno, to = cmdp->addr2.lno; from <= to; ++from) {
- if ((p = file_gline(sp, ep, from, &len)) == NULL)
- goto err;
- if (!len) {
- if (sp->lno == from)
- curset = 1;
- continue;
- }
-
- /*
- * Calculate the old indent amount and the number of
- * characters it used.
- */
- for (oldidx = 0, oldcol = 0; oldidx < len; ++oldidx)
- if (p[oldidx] == ' ')
- ++oldcol;
- else if (p[oldidx] == '\t')
- oldcol += O_VAL(sp, O_TABSTOP) -
- oldcol % O_VAL(sp, O_TABSTOP);
- else
- break;
-
- /* Calculate the new indent amount. */
- if (rl == RIGHT)
- newcol = oldcol + sw;
- else {
- newcol = oldcol < sw ? 0 : oldcol - sw;
- if (newcol == oldcol) {
- if (sp->lno == from)
- curset = 1;
- continue;
- }
- }
-
- /* Get a buffer that will hold the new line. */
- ADD_SPACE_RET(sp, bp, blen, newcol + len);
-
- /*
- * Build a new indent string and count the number of
- * characters it uses.
- */
- for (tbp = bp, newidx = 0;
- newcol >= O_VAL(sp, O_TABSTOP); ++newidx) {
- *tbp++ = '\t';
- newcol -= O_VAL(sp, O_TABSTOP);
- }
- for (; newcol > 0; --newcol, ++newidx)
- *tbp++ = ' ';
-
- /* Add the original line. */
- memmove(tbp, p + oldidx, len - oldidx);
-
- /* Set the replacement line. */
- if (file_sline(sp, ep, from, bp, (tbp + (len - oldidx)) - bp)) {
-err: FREE_SPACE(sp, bp, blen);
- return (1);
- }
-
- /*
- * !!!
- * The shift command in historic vi had the usual bizarre
- * collection of cursor semantics. If called from vi, the
- * cursor was repositioned to the first non-blank character
- * of the lowest numbered line shifted. If called from ex,
- * the cursor was repositioned to the first non-blank of the
- * highest numbered line shifted. Here, if the cursor isn't
- * part of the set of lines that are moved, move it to the
- * first non-blank of the last line shifted. (This makes
- * ":3>>" in vi work reasonably.) If the cursor is part of
- * the shifted lines, it doesn't get moved at all. This
- * permits shifting of marked areas, i.e. ">'a." shifts the
- * marked area twice, something that couldn't be done with
- * historic vi.
- */
- if (sp->lno == from) {
- curset = 1;
- if (newidx > oldidx)
- sp->cno += newidx - oldidx;
- else if (sp->cno >= oldidx - newidx)
- sp->cno -= oldidx - newidx;
- }
- }
- if (!curset) {
- sp->lno = to;
- sp->cno = 0;
- (void)nonblank(sp, ep, to, &sp->cno);
- }
-
- FREE_SPACE(sp, bp, blen);
-
- sp->rptlines[rl == RIGHT ? L_RSHIFT : L_LSHIFT] +=
- cmdp->addr2.lno - cmdp->addr1.lno + 1;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_source.c b/usr.bin/vi/ex/ex_source.c
deleted file mode 100644
index b8af556..0000000
--- a/usr.bin/vi/ex/ex_source.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_source.c 8.7 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_source -- :source file
- * Execute ex commands from a file.
- */
-int
-ex_source(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (ex_cfile(sp, ep, cmdp->argv[0]->bp, 0));
-}
diff --git a/usr.bin/vi/ex/ex_stop.c b/usr.bin/vi/ex/ex_stop.c
deleted file mode 100644
index 543f649..0000000
--- a/usr.bin/vi/ex/ex_stop.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_stop.c 8.9 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../sex/sex_screen.h"
-
-/*
- * ex_stop -- :stop[!]
- * :suspend[!]
- * Suspend execution.
- */
-int
-ex_stop(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- /* For some strange reason, the force flag turns off autowrite. */
- if (!F_ISSET(cmdp, E_FORCE) &&
- F_ISSET(ep, F_MODIFIED) && O_ISSET(sp, O_AUTOWRITE) &&
- file_write(sp, ep, NULL, NULL, NULL, FS_ALL))
- return (1);
- return (sp->s_suspend(sp));
-}
diff --git a/usr.bin/vi/ex/ex_subst.c b/usr.bin/vi/ex/ex_subst.c
deleted file mode 100644
index de413f8..0000000
--- a/usr.bin/vi/ex/ex_subst.c
+++ /dev/null
@@ -1,1001 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_subst.c 8.59 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-#define SUB_FIRST 0x01 /* The 'r' flag isn't reasonable. */
-#define SUB_MUSTSETR 0x02 /* The 'r' flag is required. */
-
-static __inline int regsub __P((SCR *, char *,
- char **, size_t *, size_t *, regmatch_t [10]));
-static int substitute __P((SCR *, EXF *,
- EXCMDARG *, char *, regex_t *, u_int));
-
-/*
- * ex_substitute --
- * [line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]
- *
- * Substitute on lines matching a pattern.
- */
-int
-ex_substitute(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- regex_t *re, lre;
- size_t blen, len;
- u_int flags;
- int delim, eval, reflags, replaced;
- char *bp, *ptrn, *rep, *p, *t;
-
- /*
- * Skip leading white space.
- *
- * !!!
- * Historic vi allowed any non-alphanumeric to serve as the
- * substitution command delimiter.
- *
- * !!!
- * If the arguments are empty, it's the same as &, i.e. we
- * repeat the last substitution.
- */
- for (p = cmdp->argv[0]->bp,
- len = cmdp->argv[0]->len; len > 0; --len, ++p) {
- if (!isblank(*p))
- break;
- }
- if (len == 0)
- return (ex_subagain(sp, ep, cmdp));
- delim = *p++;
- if (isalnum(delim))
- return (substitute(sp, ep,
- cmdp, p, &sp->subre, SUB_MUSTSETR));
-
- /*
- * !!!
- * The full-blown substitute command reset the remembered
- * state of the 'c' and 'g' suffices.
- */
- sp->c_suffix = sp->g_suffix = 0;
-
- /*
- * Get the pattern string, toss escaped characters.
- *
- * !!!
- * Historic vi accepted any of the following forms:
- *
- * :s/abc/def/ change "abc" to "def"
- * :s/abc/def change "abc" to "def"
- * :s/abc/ delete "abc"
- * :s/abc delete "abc"
- *
- * QUOTING NOTE:
- *
- * Only toss an escape character if it escapes a delimiter.
- * This means that "s/A/\\\\f" replaces "A" with "\\f". It
- * would be nice to be more regular, i.e. for each layer of
- * escaping a single escape character is removed, but that's
- * not how the historic vi worked.
- */
- for (ptrn = t = p;;) {
- if (p[0] == '\0' || p[0] == delim) {
- if (p[0] == delim)
- ++p;
- /*
- * !!!
- * Nul terminate the pattern string -- it's passed
- * to regcomp which doesn't understand anything else.
- */
- *t = '\0';
- break;
- }
- if (p[0] == '\\')
- if (p[1] == delim)
- ++p;
- else if (p[1] == '\\')
- *t++ = *p++;
- *t++ = *p++;
- }
-
- /*
- * If the pattern string is empty, use the last RE (not just the
- * last substitution RE).
- */
- if (*ptrn == '\0') {
- if (!F_ISSET(sp, S_SRE_SET)) {
- msgq(sp, M_ERR, "No previous regular expression");
- return (1);
- }
- re = &sp->sre;
- flags = 0;
- } else {
- /* Set RE flags. */
- reflags = 0;
- if (O_ISSET(sp, O_EXTENDED))
- reflags |= REG_EXTENDED;
- if (O_ISSET(sp, O_IGNORECASE))
- reflags |= REG_ICASE;
-
- /* Convert vi-style RE's to POSIX 1003.2 RE's. */
- if (re_conv(sp, &ptrn, &replaced))
- return (1);
-
- /* Compile the RE. */
- eval = regcomp(&lre, (char *)ptrn, reflags);
-
- /* Free up any allocated memory. */
- if (replaced)
- FREE_SPACE(sp, ptrn, 0);
-
- if (eval) {
- re_error(sp, eval, &lre);
- return (1);
- }
-
- /*
- * Set saved RE.
- *
- * !!!
- * Historic practice is that substitutes set the search
- * direction as well as both substitute and search RE's.
- */
- sp->searchdir = FORWARD;
- sp->sre = lre;
- F_SET(sp, S_SRE_SET);
- sp->subre = lre;
- F_SET(sp, S_SUBRE_SET);
-
- re = &lre;
- flags = SUB_FIRST;
- }
-
- /*
- * Get the replacement string.
- *
- * The special character & (\& if O_MAGIC not set) matches the
- * entire RE. No handling of & is required here, it's done by
- * regsub().
- *
- * The special character ~ (\~ if O_MAGIC not set) inserts the
- * previous replacement string into this replacement string.
- * Count ~'s to figure out how much space we need. We could
- * special case nonexistent last patterns or whether or not
- * O_MAGIC is set, but it's probably not worth the effort.
- *
- * QUOTING NOTE:
- *
- * Only toss an escape character if it escapes a delimiter or
- * if O_MAGIC is set and it escapes a tilde.
- *
- * !!!
- * If the entire replacement pattern is "%", then use the last
- * replacement pattern. This semantic was added to vi in System
- * V and then percolated elsewhere, presumably around the time
- * that it was added to their version of ed(1).
- */
- if (p[0] == '\0' || p[0] == delim) {
- if (p[0] == delim)
- ++p;
- if (sp->repl != NULL)
- FREE(sp->repl, sp->repl_len);
- sp->repl = NULL;
- sp->repl_len = 0;
- } else if (p[0] == '%' && (p[1] == '\0' || p[1] == delim))
- p += p[1] == delim ? 2 : 1;
- else {
- for (rep = p, len = 0;
- p[0] != '\0' && p[0] != delim; ++p, ++len)
- if (p[0] == '~')
- len += sp->repl_len;
- GET_SPACE_RET(sp, bp, blen, len);
- for (t = bp, len = 0, p = rep;;) {
- if (p[0] == '\0' || p[0] == delim) {
- if (p[0] == delim)
- ++p;
- break;
- }
- if (p[0] == '\\') {
- if (p[1] == delim)
- ++p;
- else if (p[1] == '\\') {
- *t++ = *p++;
- ++len;
- } else if (p[1] == '~') {
- ++p;
- if (!O_ISSET(sp, O_MAGIC))
- goto tilde;
- }
- } else if (p[0] == '~' && O_ISSET(sp, O_MAGIC)) {
-tilde: ++p;
- memmove(t, sp->repl, sp->repl_len);
- t += sp->repl_len;
- len += sp->repl_len;
- continue;
- }
- *t++ = *p++;
- ++len;
- }
- if ((sp->repl_len = len) != 0) {
- if (sp->repl != NULL)
- free(sp->repl);
- if ((sp->repl = malloc(len)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- FREE_SPACE(sp, bp, blen);
- return (1);
- }
- memmove(sp->repl, bp, len);
- }
- FREE_SPACE(sp, bp, blen);
- }
- return (substitute(sp, ep, cmdp, p, re, flags));
-}
-
-/*
- * ex_subagain --
- * [line [,line]] & [cgr] [count] [#lp]]
- *
- * Substitute using the last substitute RE and replacement pattern.
- */
-int
-ex_subagain(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (!F_ISSET(sp, S_SUBRE_SET)) {
- msgq(sp, M_ERR, "No previous regular expression");
- return (1);
- }
- return (substitute(sp, ep, cmdp, cmdp->argv[0]->bp, &sp->subre, 0));
-}
-
-/*
- * ex_subtilde --
- * [line [,line]] ~ [cgr] [count] [#lp]]
- *
- * Substitute using the last RE and last substitute replacement pattern.
- */
-int
-ex_subtilde(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (!F_ISSET(sp, S_SRE_SET)) {
- msgq(sp, M_ERR, "No previous regular expression");
- return (1);
- }
- return (substitute(sp, ep, cmdp, cmdp->argv[0]->bp, &sp->sre, 0));
-}
-
-/*
- * The nasty part of the substitution is what happens when the replacement
- * string contains newlines. It's a bit tricky -- consider the information
- * that has to be retained for "s/f\(o\)o/^M\1^M\1/". The solution here is
- * to build a set of newline offsets which we use to break the line up later,
- * when the replacement is done. Don't change it unless you're pretty damned
- * confident.
- */
-#define NEEDNEWLINE(sp) { \
- if (sp->newl_len == sp->newl_cnt) { \
- sp->newl_len += 25; \
- REALLOC(sp, sp->newl, size_t *, \
- sp->newl_len * sizeof(size_t)); \
- if (sp->newl == NULL) { \
- sp->newl_len = 0; \
- return (1); \
- } \
- } \
-}
-
-#define BUILD(sp, l, len) { \
- if (lbclen + (len) > lblen) { \
- lblen += MAX(lbclen + (len), 256); \
- REALLOC(sp, lb, char *, lblen); \
- if (lb == NULL) { \
- lbclen = 0; \
- return (1); \
- } \
- } \
- memmove(lb + lbclen, l, len); \
- lbclen += len; \
-}
-
-#define NEEDSP(sp, len, pnt) { \
- if (lbclen + (len) > lblen) { \
- lblen += MAX(lbclen + (len), 256); \
- REALLOC(sp, lb, char *, lblen); \
- if (lb == NULL) { \
- lbclen = 0; \
- return (1); \
- } \
- pnt = lb + lbclen; \
- } \
-}
-
-/*
- * substitute --
- * Do the substitution. This stuff is *really* tricky. There are
- * lots of special cases, and general nastiness. Don't mess with it
- * unless you're pretty confident.
- */
-static int
-substitute(sp, ep, cmdp, s, re, flags)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
- char *s;
- regex_t *re;
- u_int flags;
-{
- MARK from, to;
- recno_t elno, lno;
- regmatch_t match[10];
- size_t blen, cnt, last, lbclen, lblen, len, llen, offset, saved_offset;
- int cflag, lflag, nflag, pflag, rflag;
- int didsub, do_eol_match, eflags, empty_ok, eval;
- int linechanged, matched, quit, rval;
- char *bp, *lb;
-
- /*
- * !!!
- * Historically, the 'g' and 'c' suffices were always toggled as flags,
- * so ":s/A/B/" was the same as ":s/A/B/ccgg". If O_EDCOMPATIBLE was
- * not set, they were initialized to 0 for all substitute commands. If
- * O_EDCOMPATIBLE was set, they were initialized to 0 only if the user
- * specified substitute/replacement patterns (see ex_substitute()).
- */
- if (!O_ISSET(sp, O_EDCOMPATIBLE))
- sp->c_suffix = sp->g_suffix = 0;
-
- /*
- * Historic vi permitted the '#', 'l' and 'p' options in vi mode, but
- * it only displayed the last change. I'd disallow them, but they are
- * useful in combination with the [v]global commands. In the current
- * model the problem is combining them with the 'c' flag -- the screen
- * would have to flip back and forth between the confirm screen and the
- * ex print screen, which would be pretty awful. We do display all
- * changes, though, for what that's worth.
- *
- * !!!
- * Historic vi was fairly strict about the order of "options", the
- * count, and "flags". I'm somewhat fuzzy on the difference between
- * options and flags, anyway, so this is a simpler approach, and we
- * just take it them in whatever order the user gives them. (The ex
- * usage statement doesn't reflect this.)
- */
- cflag = lflag = nflag = pflag = rflag = 0;
- for (lno = OOBLNO; *s != '\0'; ++s)
- switch (*s) {
- case ' ':
- case '\t':
- continue;
- case '+':
- ++cmdp->flagoff;
- break;
- case '-':
- --cmdp->flagoff;
- break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- if (lno != OOBLNO)
- goto usage;
- errno = 0;
- lno = strtoul(s, &s, 10);
- if (*s == '\0') /* Loop increment correction. */
- --s;
- if (errno == ERANGE) {
- if (lno == LONG_MAX)
- msgq(sp, M_ERR, "Count overflow");
- else if (lno == LONG_MIN)
- msgq(sp, M_ERR, "Count underflow");
- else
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- /*
- * In historic vi, the count was inclusive from the
- * second address.
- */
- cmdp->addr1.lno = cmdp->addr2.lno;
- cmdp->addr2.lno += lno - 1;
- break;
- case '#':
- nflag = 1;
- break;
- case 'c':
- sp->c_suffix = !sp->c_suffix;
- break;
- case 'g':
- sp->g_suffix = !sp->g_suffix;
- break;
- case 'l':
- lflag = 1;
- break;
- case 'p':
- pflag = 1;
- break;
- case 'r':
- if (LF_ISSET(SUB_FIRST)) {
- msgq(sp, M_ERR,
- "Regular expression specified; r flag meaningless");
- return (1);
- }
- if (!F_ISSET(sp, S_SRE_SET)) {
- msgq(sp, M_ERR,
- "No previous regular expression");
- return (1);
- }
- rflag = 1;
- re = &sp->sre;
- break;
- default:
- goto usage;
- }
-
- if (*s != '\0' || !rflag && LF_ISSET(SUB_MUSTSETR)) {
-usage: msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
-
- if (IN_VI_MODE(sp) && sp->c_suffix && (lflag || nflag || pflag)) {
- msgq(sp, M_ERR,
- "The #, l and p flags may not be combined with the c flag in vi mode");
- return (1);
- }
-
- /*
- * bp: if interactive, line cache
- * blen: if interactive, line cache length
- * lb: build buffer pointer.
- * lbclen: current length of built buffer.
- * lblen; length of build buffer.
- */
- bp = lb = NULL;
- blen = lbclen = lblen = 0;
-
- /* For each line... */
- for (matched = quit = 0, lno = cmdp->addr1.lno,
- elno = cmdp->addr2.lno; !quit && lno <= elno; ++lno) {
-
- /* Someone's unhappy, time to stop. */
- if (INTERRUPTED(sp)) {
- if (!F_ISSET(sp, S_GLOBAL))
- msgq(sp, M_INFO, "Interrupted");
- break;
- }
-
- /* Get the line. */
- if ((s = file_gline(sp, ep, lno, &llen)) == NULL) {
- GETLINE_ERR(sp, lno);
- goto ret1;
- }
-
- /*
- * Make a local copy if doing confirmation -- when calling
- * the confirm routine we're likely to lose the cached copy.
- */
- if (sp->c_suffix) {
- if (bp == NULL) {
- GET_SPACE_RET(sp, bp, blen, llen);
- } else
- ADD_SPACE_RET(sp, bp, blen, llen);
- memmove(bp, s, llen);
- s = bp;
- }
-
- /* Start searching from the beginning. */
- offset = 0;
- len = llen;
-
- /* Reset the build buffer offset. */
- lbclen = 0;
-
- /* Reset empty match flag. */
- empty_ok = 1;
-
- /*
- * We don't want to have to do a setline if the line didn't
- * change -- keep track of whether or not this line changed.
- * If doing confirmations, don't want to keep setting the
- * line if change is refused -- keep track of substitutions.
- */
- didsub = linechanged = 0;
-
- /* New line, do an EOL match. */
- do_eol_match = 1;
-
- /* It's not nul terminated, but we pretend it is. */
- eflags = REG_STARTEND;
-
- /*
- * The search area is from s + offset to the EOL.
- *
- * Generally, match[0].rm_so is the offset of the start
- * of the match from the start of the search, and offset
- * is the offset of the start of the last search.
- */
-nextmatch: match[0].rm_so = 0;
- match[0].rm_eo = len;
-
- /* Get the next match. */
- eval = regexec(re, (char *)s + offset, 10, match, eflags);
-
- /*
- * There wasn't a match or if there was an error, deal with
- * it. If there was a previous match in this line, resolve
- * the changes into the database. Otherwise, just move on.
- */
- if (eval == REG_NOMATCH)
- goto endmatch;
- if (eval != 0) {
- re_error(sp, eval, re);
- goto ret1;
- }
- matched = 1;
-
- /* Only the first search can match an anchored expression. */
- eflags |= REG_NOTBOL;
-
- /*
- * !!!
- * It's possible to match 0-length strings -- for example, the
- * command s;a*;X;, when matched against the string "aabb" will
- * result in "XbXbX", i.e. the matches are "aa", the space
- * between the b's and the space between the b's and the end of
- * the string. There is a similar space between the beginning
- * of the string and the a's. The rule that we use (because vi
- * historically used it) is that any 0-length match, occurring
- * immediately after a match, is ignored. Otherwise, the above
- * example would have resulted in "XXbXbX". Another example is
- * incorrectly using " *" to replace groups of spaces with one
- * space.
- *
- * The way we do this is that if we just had a successful match,
- * the starting offset does not skip characters, and the match
- * is empty, ignore the match and move forward. If there's no
- * more characters in the string, we were attempting to match
- * after the last character, so quit.
- */
- if (!empty_ok && match[0].rm_so == 0 && match[0].rm_eo == 0) {
- empty_ok = 1;
- if (len == 0)
- goto endmatch;
- BUILD(sp, s + offset, 1)
- ++offset;
- --len;
- goto nextmatch;
- }
-
- /* Confirm change. */
- if (sp->c_suffix) {
- /*
- * Set the cursor position for confirmation. Note,
- * if we matched on a '$', the cursor may be past
- * the end of line.
- *
- * XXX
- * We may want to "fix" this in the confirm routine,
- * if the confirm routine should be able to display
- * a cursor past EOL.
- */
- from.lno = to.lno = lno;
- from.cno = match[0].rm_so + offset;
- to.cno = match[0].rm_eo;
- if (llen == 0)
- from.cno = to.cno = 0;
- else {
- if (to.cno >= llen)
- to.cno = llen - 1;
- if (from.cno >= llen)
- from.cno = llen - 1;
- }
- switch (sp->s_confirm(sp, ep, &from, &to)) {
- case CONF_YES:
- break;
- case CONF_NO:
- didsub = 0;
- BUILD(sp, s +offset, match[0].rm_eo);
- goto skip;
- case CONF_QUIT:
- /* Set the quit flag. */
- quit = 1;
-
- /* If interruptible, pass the info back. */
- if (F_ISSET(sp, S_INTERRUPTIBLE))
- F_SET(sp, S_INTERRUPTED);
-
- /*
- * If any changes, resolve them, otherwise
- * return to the main loop.
- */
- goto endmatch;
- }
- }
-
- /* Copy the bytes before the match into the build buffer. */
- BUILD(sp, s + offset, match[0].rm_so);
-
- /* Substitute the matching bytes. */
- didsub = 1;
- if (regsub(sp, s + offset, &lb, &lbclen, &lblen, match))
- goto ret1;
-
- /* Set the change flag so we know this line was modified. */
- linechanged = 1;
-
- /* Move past the matched bytes. */
-skip: offset += match[0].rm_eo;
- len -= match[0].rm_eo;
-
- /* A match cannot be followed by an empty pattern. */
- empty_ok = 0;
-
- /*
- * If doing a global change with confirmation, we have to
- * update the screen. The basic idea is to store the line
- * so the screen update routines can find it, and restart.
- */
- if (didsub && sp->c_suffix && sp->g_suffix) {
- /*
- * The new search offset will be the end of the
- * modified line.
- */
- saved_offset = lbclen;
-
- /* Copy the rest of the line. */
- if (len)
- BUILD(sp, s + offset, len)
-
- /* Set the new offset. */
- offset = saved_offset;
-
- /* Store inserted lines, adjusting the build buffer. */
- last = 0;
- if (sp->newl_cnt) {
- for (cnt = 0;
- cnt < sp->newl_cnt; ++cnt, ++lno, ++elno) {
- if (file_iline(sp, ep, lno,
- lb + last, sp->newl[cnt] - last))
- goto ret1;
- last = sp->newl[cnt] + 1;
- ++sp->rptlines[L_ADDED];
- }
- lbclen -= last;
- offset -= last;
- sp->newl_cnt = 0;
- }
-
- /* Store and retrieve the line. */
- if (file_sline(sp, ep, lno, lb + last, lbclen))
- goto ret1;
- if ((s = file_gline(sp, ep, lno, &llen)) == NULL) {
- GETLINE_ERR(sp, lno);
- goto ret1;
- }
- ADD_SPACE_RET(sp, bp, blen, llen)
- memmove(bp, s, llen);
- s = bp;
- len = llen - offset;
-
- /* Restart the build. */
- lbclen = 0;
- BUILD(sp, s, offset);
-
- /*
- * If we haven't already done the after-the-string
- * match, do one. Set REG_NOTEOL so the '$' pattern
- * only matches once.
- */
- if (!do_eol_match)
- goto endmatch;
- if (offset == len) {
- do_eol_match = 0;
- eflags |= REG_NOTEOL;
- }
- goto nextmatch;
- }
-
- /*
- * If it's a global:
- *
- * If at the end of the string, do a test for the after
- * the string match. Set REG_NOTEOL so the '$' pattern
- * only matches once.
- */
- if (sp->g_suffix && do_eol_match) {
- if (len == 0) {
- do_eol_match = 0;
- eflags |= REG_NOTEOL;
- }
- goto nextmatch;
- }
-
-endmatch: if (!linechanged)
- continue;
-
- /* Copy any remaining bytes into the build buffer. */
- if (len)
- BUILD(sp, s + offset, len)
-
- /* Store inserted lines, adjusting the build buffer. */
- last = 0;
- if (sp->newl_cnt) {
- for (cnt = 0;
- cnt < sp->newl_cnt; ++cnt, ++lno, ++elno) {
- if (file_iline(sp, ep,
- lno, lb + last, sp->newl[cnt] - last))
- goto ret1;
- last = sp->newl[cnt] + 1;
- ++sp->rptlines[L_ADDED];
- }
- lbclen -= last;
- sp->newl_cnt = 0;
- }
-
- /* Store the changed line. */
- if (file_sline(sp, ep, lno, lb + last, lbclen))
- goto ret1;
-
- /* Update changed line counter. */
- if (sp->rptlchange != lno) {
- sp->rptlchange = lno;
- ++sp->rptlines[L_CHANGED];
- }
-
- /*
- * !!!
- * Display as necessary. Historic practice is to only
- * display the last line of a line split into multiple
- * lines.
- */
- if (lflag || nflag || pflag) {
- from.lno = to.lno = lno;
- from.cno = to.cno = 0;
- if (lflag)
- ex_print(sp, ep, &from, &to, E_F_LIST);
- if (nflag)
- ex_print(sp, ep, &from, &to, E_F_HASH);
- if (pflag)
- ex_print(sp, ep, &from, &to, E_F_PRINT);
- }
-
- if (!sp->c_suffix)
- sp->lno = lno;
-
- /*
- * !!!
- * Move the cursor to the last line changed.
- */
- if (!sp->c_suffix)
- sp->lno = lno;
- }
-
- /*
- * !!!
- * Move the cursor to the first non-blank of the last line change.
- *
- * XXX
- * This is NOT backward compatible with historic vi, which always
- * moved to the last line actually changed.
- */
- if (!sp->c_suffix) {
- sp->cno = 0;
- (void)nonblank(sp, ep, sp->lno, &sp->cno);
- }
-
- /*
- * If not in a global command, and nothing matched, say so.
- * Else, if none of the lines displayed, put something up.
- */
- if (!matched) {
- if (!F_ISSET(sp, S_GLOBAL))
- msgq(sp, M_INFO, "No match found");
- } else if (!lflag && !nflag && !pflag)
- F_SET(EXP(sp), EX_AUTOPRINT);
-
- rval = 0;
- if (0) {
-ret1: rval = 1;
- }
-
- if (bp != NULL)
- FREE_SPACE(sp, bp, blen);
- if (lb != NULL)
- free(lb);
- return (rval);
-}
-
-/*
- * regsub --
- * Do the substitution for a regular expression.
- */
-static __inline int
-regsub(sp, ip, lbp, lbclenp, lblenp, match)
- SCR *sp;
- char *ip; /* Input line. */
- char **lbp;
- size_t *lbclenp, *lblenp;
- regmatch_t match[10];
-{
- enum { C_NOTSET, C_LOWER, C_ONELOWER, C_ONEUPPER, C_UPPER } conv;
- size_t lbclen, lblen; /* Local copies. */
- size_t mlen; /* Match length. */
- size_t rpl; /* Remaining replacement length. */
- char *rp; /* Replacement pointer. */
- int ch;
- int no; /* Match replacement offset. */
- char *p, *t; /* Buffer pointers. */
- char *lb; /* Local copies. */
-
- lb = *lbp; /* Get local copies. */
- lbclen = *lbclenp;
- lblen = *lblenp;
-
- /*
- * QUOTING NOTE:
- *
- * There are some special sequences that vi provides in the
- * replacement patterns.
- * & string the RE matched (\& if nomagic set)
- * \# n-th regular subexpression
- * \E end \U, \L conversion
- * \e end \U, \L conversion
- * \l convert the next character to lower-case
- * \L convert to lower-case, until \E, \e, or end of replacement
- * \u convert the next character to upper-case
- * \U convert to upper-case, until \E, \e, or end of replacement
- *
- * Otherwise, since this is the lowest level of replacement, discard
- * all escape characters. This (hopefully) follows historic practice.
- */
-#define ADDCH(ch) { \
- CHAR_T __ch = (ch); \
- u_int __value = KEY_VAL(sp, __ch); \
- if (__value == K_CR || __value == K_NL) { \
- NEEDNEWLINE(sp); \
- sp->newl[sp->newl_cnt++] = lbclen; \
- } else if (conv != C_NOTSET) { \
- switch (conv) { \
- case C_ONELOWER: \
- conv = C_NOTSET; \
- /* FALLTHROUGH */ \
- case C_LOWER: \
- if (isupper(__ch)) \
- __ch = tolower(__ch); \
- break; \
- case C_ONEUPPER: \
- conv = C_NOTSET; \
- /* FALLTHROUGH */ \
- case C_UPPER: \
- if (islower(__ch)) \
- __ch = toupper(__ch); \
- break; \
- default: \
- abort(); \
- } \
- } \
- NEEDSP(sp, 1, p); \
- *p++ = __ch; \
- ++lbclen; \
-}
- conv = C_NOTSET;
- for (rp = sp->repl, rpl = sp->repl_len, p = lb + lbclen; rpl--;) {
- switch (ch = *rp++) {
- case '&':
- if (O_ISSET(sp, O_MAGIC)) {
- no = 0;
- goto subzero;
- }
- break;
- case '\\':
- if (rpl == 0)
- break;
- --rpl;
- switch (ch = *rp) {
- case '&':
- ++rp;
- if (!O_ISSET(sp, O_MAGIC)) {
- no = 0;
- goto subzero;
- }
- break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- no = *rp++ - '0';
-subzero: if (match[no].rm_so == -1 ||
- match[no].rm_eo == -1)
- break;
- mlen = match[no].rm_eo - match[no].rm_so;
- for (t = ip + match[no].rm_so; mlen--; ++t)
- ADDCH(*t);
- continue;
- case 'e':
- case 'E':
- ++rp;
- conv = C_NOTSET;
- continue;
- case 'l':
- ++rp;
- conv = C_ONELOWER;
- continue;
- case 'L':
- ++rp;
- conv = C_LOWER;
- continue;
- case 'u':
- ++rp;
- conv = C_ONEUPPER;
- continue;
- case 'U':
- ++rp;
- conv = C_UPPER;
- continue;
- default:
- ++rp;
- break;
- }
- }
- ADDCH(ch);
- }
-
- *lbp = lb; /* Update caller's information. */
- *lbclenp = lbclen;
- *lblenp = lblen;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_tag.c b/usr.bin/vi/ex/ex_tag.c
deleted file mode 100644
index 4378803..0000000
--- a/usr.bin/vi/ex/ex_tag.c
+++ /dev/null
@@ -1,905 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * David Hitz of Auspex Systems, Inc.
- *
- * 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[] = "@(#)ex_tag.c 8.45 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/mman.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "tag.h"
-
-static char *binary_search __P((char *, char *, char *));
-static int compare __P((char *, char *, char *));
-static char *linear_search __P((char *, char *, char *));
-static int search __P((SCR *, char *, char *, char **));
-static int tag_get __P((SCR *, char *, char **, char **, char **));
-
-/*
- * ex_tagfirst --
- * The tag code can be entered from main, i.e. "vi -t tag".
- */
-int
-ex_tagfirst(sp, tagarg)
- SCR *sp;
- char *tagarg;
-{
- FREF *frp;
- MARK m;
- long tl;
- u_int flags;
- int sval;
- char *p, *tag, *name, *search;
-
- /* Taglength may limit the number of characters. */
- if ((tl = O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(tagarg) > tl)
- tagarg[tl] = '\0';
-
- /* Get the tag information. */
- if (tag_get(sp, tagarg, &tag, &name, &search))
- return (1);
-
- /* Create the file entry. */
- if ((frp = file_add(sp, name)) == NULL)
- return (1);
- if (file_init(sp, frp, NULL, 0))
- return (1);
-
- /*
- * !!!
- * The historic tags file format (from a long, long time ago...)
- * used a line number, not a search string. I got complaints, so
- * people are still using the format.
- */
- if (isdigit(search[0])) {
- m.lno = atoi(search);
- m.cno = 0;
- } else {
- /*
- * Search for the tag; cheap fallback for C functions if
- * the name is the same but the arguments have changed.
- */
- m.lno = 1;
- m.cno = 0;
- flags = SEARCH_FILE | SEARCH_TAG | SEARCH_TERM;
- sval = f_search(sp, sp->ep, &m, &m, search, NULL, &flags);
- if (sval && (p = strrchr(search, '(')) != NULL) {
- p[1] = '\0';
- sval = f_search(sp, sp->ep,
- &m, &m, search, NULL, &flags);
- }
- if (sval)
- msgq(sp, M_ERR, "%s: search pattern not found", tag);
- }
-
- /* Set up the screen. */
- frp->lno = m.lno;
- frp->cno = m.cno;
- F_SET(frp, FR_CURSORSET);
-
- /* Might as well make this the default tag. */
- if ((EXP(sp)->tlast = strdup(tagarg)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- return (0);
-}
-
-/* Free a tag or tagf structure from a queue. */
-#define FREETAG(tp) { \
- TAILQ_REMOVE(&exp->tagq, (tp), q); \
- if ((tp)->search != NULL) \
- free((tp)->search); \
- FREE((tp), sizeof(TAGF)); \
-}
-#define FREETAGF(tfp) { \
- TAILQ_REMOVE(&exp->tagfq, (tfp), q); \
- free((tfp)->name); \
- FREE((tfp), sizeof(TAGF)); \
-}
-
-/*
- * ex_tagpush -- :tag [file]
- * Move to a new tag.
- *
- * The tags stacks in nvi are a bit tricky. Each tag contains a file name,
- * search string, and line/column numbers. The search string is only used
- * for the first access and for user display. The first record on the stack
- * is the place where we first did a tag, so it has no search string. The
- * second record is the first tag, and so on. Note, this means that the
- * "current" tag is always on the stack. Each tag has a line/column which is
- * the location from which the user tagged the following TAG entry, and which
- * is used as the return location.
- */
-int
-ex_tagpush(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- enum {TC_CHANGE, TC_CURRENT} which;
- EX_PRIVATE *exp;
- FREF *frp;
- MARK m;
- TAG *tp;
- u_int flags;
- int sval;
- long tl;
- char *name, *p, *search, *tag;
-
- exp = EXP(sp);
- switch (cmdp->argc) {
- case 1:
- if (exp->tlast != NULL)
- FREE(exp->tlast, strlen(exp->tlast) + 1);
- if ((exp->tlast = strdup(cmdp->argv[0]->bp)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- break;
- case 0:
- if (exp->tlast == NULL) {
- msgq(sp, M_ERR, "No previous tag entered");
- return (1);
- }
- break;
- default:
- abort();
- }
-
- /* Taglength may limit the number of characters. */
- if ((tl = O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(exp->tlast) > tl)
- exp->tlast[tl] = '\0';
-
- /* Get the tag information. */
- if (tag_get(sp, exp->tlast, &tag, &name, &search))
- return (1);
-
- /* Get the (possibly new) FREF structure. */
- if ((frp = file_add(sp, name)) == NULL)
- goto err;
-
- if (sp->frp == frp)
- which = TC_CURRENT;
- else {
- if (file_m1(sp, sp->ep,
- F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
- goto err;
- which = TC_CHANGE;
- }
-
- /*
- * Get a tag structure -- if this is the first tag, push it on the
- * stack as a placeholder and get another tag structure. Set the
- * line/column of the most recent element on the stack to be the
- * current values, including the file pointer. Then push the new
- * TAG onto the stack with the new file and search string for user
- * display.
- */
- CALLOC(sp, tp, TAG *, 1, sizeof(TAG));
- if (tp != NULL && exp->tagq.tqh_first == NULL) {
- TAILQ_INSERT_HEAD(&exp->tagq, tp, q);
- CALLOC(sp, tp, TAG *, 1, sizeof(TAG));
- }
- if (exp->tagq.tqh_first != NULL) {
- exp->tagq.tqh_first->frp = sp->frp;
- exp->tagq.tqh_first->lno = sp->lno;
- exp->tagq.tqh_first->cno = sp->cno;
- }
- if (tp != NULL) {
- if ((tp->search = strdup(search)) == NULL)
- msgq(sp, M_SYSERR, NULL);
- else
- tp->slen = strlen(search);
- tp->frp = frp;
- TAILQ_INSERT_HEAD(&exp->tagq, tp, q);
- }
-
- /* Switch files. */
- if (which == TC_CHANGE && file_init(sp, frp, NULL, 0)) {
- if (tp != NULL)
- FREETAG(tp);
- /* Handle special, first-tag case. */
- if (exp->tagq.tqh_first->q.tqe_next == NULL)
- TAILQ_REMOVE(&exp->tagq, exp->tagq.tqh_first, q);
-err: free(tag);
- return (1);
- }
-
- /*
- * !!!
- * Historic vi accepted a line number as well as a search
- * string, and people are apparently still using the format.
- */
- if (isdigit(search[0])) {
- m.lno = atoi(search);
- m.cno = 0;
- sval = 0;
- } else {
- /*
- * Search for the tag; cheap fallback for C functions
- * if the name is the same but the arguments have changed.
- */
- m.lno = 1;
- m.cno = 0;
- flags = SEARCH_FILE | SEARCH_TAG | SEARCH_TERM;
- sval = f_search(sp, sp->ep, &m, &m, search, NULL, &flags);
- if (sval && (p = strrchr(search, '(')) != NULL) {
- p[1] = '\0';
- sval = f_search(sp, sp->ep,
- &m, &m, search, NULL, &flags);
- p[1] = '(';
- }
- if (sval)
- msgq(sp, M_ERR, "%s: search pattern not found", tag);
- }
- free(tag);
-
- switch (which) {
- case TC_CHANGE:
- frp->lno = m.lno;
- frp->cno = m.cno;
- F_SET(frp, FR_CURSORSET);
- F_SET(sp, S_FSWITCH);
- break;
- case TC_CURRENT:
- if (sval)
- return (1);
- sp->lno = m.lno;
- sp->cno = m.cno;
- break;
- }
- return (0);
-}
-
-/*
- * ex_tagpop -- :tagp[op][!] [number | file]
- * Pop the tag stack.
- */
-int
-ex_tagpop(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- EX_PRIVATE *exp;
- TAG *ntp, *tp;
- long off;
- size_t arglen;
- char *arg, *p, *t;
-
- /* Check for an empty stack. */
- exp = EXP(sp);
- if (exp->tagq.tqh_first == NULL) {
- msgq(sp, M_INFO, "The tags stack is empty");
- return (1);
- }
-
- switch (cmdp->argc) {
- case 0: /* Pop one tag. */
- ntp = exp->tagq.tqh_first;
- break;
- case 1: /* Name or number. */
- arg = cmdp->argv[0]->bp;
- off = strtol(arg, &p, 10);
- if (*p == '\0') {
- if (off < 1)
- return (0);
- for (tp = exp->tagq.tqh_first;
- tp != NULL && --off > 1; tp = tp->q.tqe_next);
- if (tp == NULL) {
- msgq(sp, M_ERR,
-"Less than %s entries on the tags stack; use :display to see the tags stack",
- arg);
- return (1);
- }
- ntp = tp;
- } else {
- arglen = strlen(arg);
- for (tp = exp->tagq.tqh_first;
- tp != NULL; ntp = tp, tp = tp->q.tqe_next) {
- /* Use the user's original file name. */
- p = tp->frp->name;
- if ((t = strrchr(p, '/')) == NULL)
- t = p;
- else
- ++t;
- if (!strncmp(arg, t, arglen))
- break;
- }
- if (tp == NULL) {
- msgq(sp, M_ERR,
-"No file named %s on the tags stack; use :display to see the tags stack",
- arg);
- return (1);
- }
- }
- break;
- default:
- abort();
- }
-
- /* Update the cursor from the saved TAG information. */
- tp = ntp->q.tqe_next;
- if (tp->frp == sp->frp) {
- sp->lno = tp->lno;
- sp->cno = tp->cno;
- } else {
- if (file_m1(sp, ep,
- F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
- return (1);
- if (file_init(sp, tp->frp, NULL, 0))
- return (1);
-
- tp->frp->lno = tp->lno;
- tp->frp->cno = tp->cno;
- F_SET(sp->frp, FR_CURSORSET);
-
- F_SET(sp, S_FSWITCH);
- }
-
- /* Pop entries off the queue up to ntp. */
- for (;;) {
- tp = exp->tagq.tqh_first;
- FREETAG(tp);
- if (tp == ntp)
- break;
- }
-
- /* If returning to the first tag, the stack is now empty. */
- if (exp->tagq.tqh_first->q.tqe_next == NULL)
- TAILQ_REMOVE(&exp->tagq, exp->tagq.tqh_first, q);
- return (0);
-}
-
-/*
- * ex_tagtop -- :tagt[op][!]
- * Clear the tag stack.
- */
-int
-ex_tagtop(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- EX_PRIVATE *exp;
- TAG *tp;
-
- /* Find oldest saved information. */
- exp = EXP(sp);
- for (tp = exp->tagq.tqh_first;
- tp != NULL && tp->q.tqe_next != NULL; tp = tp->q.tqe_next);
- if (tp == NULL) {
- msgq(sp, M_INFO, "The tags stack is empty");
- return (1);
- }
-
- /* If not switching files, it's easy; else do the work. */
- if (tp->frp == sp->frp) {
- sp->lno = tp->lno;
- sp->cno = tp->cno;
- } else {
- if (file_m1(sp, sp->ep,
- F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
- return (1);
- if (file_init(sp, tp->frp, NULL, 0))
- return (1);
-
- tp->frp->lno = tp->lno;
- tp->frp->cno = tp->cno;
-
- F_SET(sp->frp, FR_CURSORSET);
- F_SET(sp, S_FSWITCH);
- }
-
- /* Empty out the queue. */
- while ((tp = exp->tagq.tqh_first) != NULL)
- FREETAG(tp);
- return (0);
-}
-
-/*
- * ex_tagdisplay --
- * Display the list of tags.
- */
-int
-ex_tagdisplay(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- EX_PRIVATE *exp;
- TAG *tp;
- size_t len, maxlen;
- int cnt;
- char *name;
-
- exp = EXP(sp);
- if ((tp = exp->tagq.tqh_first) == NULL) {
- (void)ex_printf(EXCOOKIE, "No tags to display.\n");
- return (0);
- }
-
- /*
- * Figure out the formatting. MNOC is the maximum
- * number of file name columns before we split the line.
- */
-#define MNOC 15
- for (maxlen = 0,
- tp = exp->tagq.tqh_first; tp != NULL; tp = tp->q.tqe_next) {
- len = strlen(name = tp->frp->name); /* The original name. */
- if (maxlen < len && len < MNOC)
- maxlen = len;
- }
-
- for (cnt = 1, tp = exp->tagq.tqh_first; tp != NULL;
- ++cnt, tp = tp->q.tqe_next) {
- len = strlen(name = tp->frp->name); /* The original name. */
- if (len > maxlen || len + tp->slen > sp->cols)
- if (tp == NULL || tp->search == NULL)
- (void)ex_printf(EXCOOKIE,
- "%2d %s\n", cnt, name);
- else
- (void)ex_printf(EXCOOKIE,
- "%2d %s\n** %*.*s %s\n", cnt, name,
- (int)maxlen, (int)maxlen, "", tp->search);
- else
- if (tp == NULL || tp->search == NULL)
- (void)ex_printf(EXCOOKIE, "%2d %*.*s\n",
- cnt, (int)maxlen, (int)len, name);
- else
- (void)ex_printf(EXCOOKIE, "%2d %*.*s %s\n",
- cnt, (int)maxlen, (int)len, name,
- tp->search);
- }
- return (0);
-}
-
-/*
- * ex_tagalloc --
- * Create a new list of tag files.
- */
-int
-ex_tagalloc(sp, str)
- SCR *sp;
- char *str;
-{
- EX_PRIVATE *exp;
- TAGF *tp;
- size_t len;
- char *p, *t;
-
- /* Free current queue. */
- exp = EXP(sp);
- while ((tp = exp->tagfq.tqh_first) != NULL)
- FREETAGF(tp);
-
- /* Create new queue. */
- for (p = t = str;; ++p) {
- if (*p == '\0' || isblank(*p)) {
- if ((len = p - t) > 1) {
- MALLOC_RET(sp, tp, TAGF *, sizeof(TAGF));
- MALLOC(sp, tp->name, char *, len + 1);
- if (tp->name == NULL) {
- FREE(tp, sizeof(TAGF));
- return (1);
- }
- memmove(tp->name, t, len);
- tp->name[len] = '\0';
- tp->flags = 0;
- TAILQ_INSERT_TAIL(&exp->tagfq, tp, q);
- }
- t = p + 1;
- }
- if (*p == '\0')
- break;
- }
- return (0);
-}
- /* Free previous queue. */
-/*
- * ex_tagfree --
- * Free the tags file list.
- */
-int
-ex_tagfree(sp)
- SCR *sp;
-{
- EX_PRIVATE *exp;
- TAG *tp;
- TAGF *tfp;
-
- /* Free up tag information. */
- exp = EXP(sp);
- while ((tp = exp->tagq.tqh_first) != NULL)
- FREETAG(tp);
- while ((tfp = exp->tagfq.tqh_first) != NULL)
- FREETAGF(tfp);
- if (exp->tlast != NULL)
- free(exp->tlast);
- return (0);
-}
-
-/*
- * ex_tagcopy --
- * Copy a screen's tag structures.
- */
-int
-ex_tagcopy(orig, sp)
- SCR *orig, *sp;
-{
- EX_PRIVATE *oexp, *nexp;
- TAG *ap, *tp;
- TAGF *atfp, *tfp;
-
- /* Copy tag stack. */
- oexp = EXP(orig);
- nexp = EXP(sp);
- for (ap = oexp->tagq.tqh_first; ap != NULL; ap = ap->q.tqe_next) {
- MALLOC(sp, tp, TAG *, sizeof(TAG));
- if (tp == NULL)
- goto nomem;
- *tp = *ap;
- if (ap->search != NULL &&
- (tp->search = strdup(ap->search)) == NULL)
- goto nomem;
- TAILQ_INSERT_TAIL(&nexp->tagq, tp, q);
- }
-
- /* Copy list of tag files. */
- for (atfp = oexp->tagfq.tqh_first;
- atfp != NULL; atfp = atfp->q.tqe_next) {
- MALLOC(sp, tfp, TAGF *, sizeof(TAGF));
- if (tfp == NULL)
- goto nomem;
- *tfp = *atfp;
- if ((tfp->name = strdup(atfp->name)) == NULL)
- goto nomem;
- TAILQ_INSERT_TAIL(&nexp->tagfq, tfp, q);
- }
-
- /* Copy the last tag. */
- if (oexp->tlast != NULL &&
- (nexp->tlast = strdup(oexp->tlast)) == NULL) {
-nomem: msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- return (0);
-}
-
-/*
- * tag_get --
- * Get a tag from the tags files.
- */
-static int
-tag_get(sp, tag, tagp, filep, searchp)
- SCR *sp;
- char *tag, **tagp, **filep, **searchp;
-{
- struct stat sb;
- EX_PRIVATE *exp;
- TAGF *tfp;
- size_t plen, slen, tlen;
- int dne;
- char *p, pbuf[MAXPATHLEN];
-
- /*
- * Find the tag, only display missing file messages once, and
- * then only if we didn't find the tag.
- */
- dne = 0;
- exp = EXP(sp);
- for (p = NULL, tfp = exp->tagfq.tqh_first;
- tfp != NULL && p == NULL; tfp = tfp->q.tqe_next) {
- errno = 0;
- F_CLR(tfp, TAGF_DNE);
- if (search(sp, tfp->name, tag, &p))
- if (errno == ENOENT) {
- if (!F_ISSET(tfp, TAGF_DNE_WARN)) {
- dne = 1;
- F_SET(tfp, TAGF_DNE);
- }
- } else
- msgq(sp, M_SYSERR, tfp->name);
- else
- if (p != NULL)
- break;
- }
-
- if (p == NULL) {
- msgq(sp, M_ERR, "%s: tag not found", tag);
- if (dne)
- for (tfp = exp->tagfq.tqh_first;
- tfp != NULL; tfp = tfp->q.tqe_next)
- if (F_ISSET(tfp, TAGF_DNE)) {
- errno = ENOENT;
- msgq(sp, M_SYSERR, tfp->name);
- F_SET(tfp, TAGF_DNE_WARN);
- }
- return (1);
- }
-
- /*
- * Set the return pointers; tagp points to the tag, and, incidentally
- * the allocated string, filep points to the file name, and searchp
- * points to the search string. All three are nul-terminated.
- */
- for (*tagp = p; *p && !isblank(*p); ++p);
- if (*p == '\0')
- goto malformed;
- for (*p++ = '\0'; isblank(*p); ++p);
- for (*filep = p; *p && !isblank(*p); ++p);
- if (*p == '\0')
- goto malformed;
- for (*p++ = '\0'; isblank(*p); ++p);
- *searchp = p;
- if (*p == '\0') {
-malformed: free(*tagp);
- msgq(sp, M_ERR, "%s: corrupted tag in %s", tag, tfp->name);
- return (1);
- }
-
- /*
- * !!!
- * If the tag file path is a relative path, see if it exists. If it
- * doesn't, look relative to the tags file path. It's okay for a tag
- * file to not exist, and, historically, vi simply displayed a "new"
- * file. However, if the path exists relative to the tag file, it's
- * pretty clear what's happening, so we may as well do it right.
- */
- if ((*filep)[0] != '/'
- && stat(*filep, &sb) && (p = strrchr(tfp->name, '/')) != NULL) {
- *p = '\0';
- plen = snprintf(pbuf, sizeof(pbuf), "%s/%s", tfp->name, *filep);
- *p = '/';
- if (stat(pbuf, &sb) == 0) {
- slen = strlen(*searchp);
- tlen = strlen(*tagp);
- MALLOC(sp, p, char *, plen + slen + tlen + 5);
- if (p != NULL) {
- memmove(p, *tagp, tlen);
- free(*tagp);
- *tagp = p;
- *(p += tlen) = '\0';
- memmove(++p, pbuf, plen);
- *filep = p;
- *(p += plen) = '\0';
- memmove(++p, *searchp, slen);
- *searchp = p;
- *(p += slen) = '\0';
- }
- }
- }
- return (0);
-}
-
-#define EQUAL 0
-#define GREATER 1
-#define LESS (-1)
-
-/*
- * search --
- * Search a file for a tag.
- */
-static int
-search(sp, name, tname, tag)
- SCR *sp;
- char *name, *tname, **tag;
-{
- struct stat sb;
- int fd, len;
- char *endp, *back, *front, *map, *p;
-
- if ((fd = open(name, O_RDONLY, 0)) < 0)
- return (1);
-
- /*
- * XXX
- * We'd like to test if the file is too big to mmap. Since we don't
- * know what size or type off_t's or size_t's are, what the largest
- * unsigned integral type is, or what random insanity the local C
- * compiler will perpetrate, doing the comparison in a portable way
- * is flatly impossible. Hope that malloc fails if the file is too
- * large.
- */
- if (fstat(fd, &sb) || (map = mmap(NULL, (size_t)sb.st_size,
- PROT_READ, MAP_PRIVATE, fd, (off_t)0)) == (caddr_t)-1) {
- (void)close(fd);
- return (1);
- }
- front = map;
- back = front + sb.st_size;
-
- front = binary_search(tname, front, back);
- front = linear_search(tname, front, back);
-
- if (front == NULL || (endp = strchr(front, '\n')) == NULL) {
- *tag = NULL;
- goto done;
- }
-
- len = endp - front;
- MALLOC(sp, p, char *, len + 1);
- if (p == NULL) {
- *tag = NULL;
- goto done;
- }
- memmove(p, front, len);
- p[len] = '\0';
- *tag = p;
-
-done: if (munmap(map, (size_t)sb.st_size))
- msgq(sp, M_SYSERR, "munmap");
- if (close(fd))
- msgq(sp, M_SYSERR, "close");
- return (0);
-}
-
-/*
- * Binary search for "string" in memory between "front" and "back".
- *
- * This routine is expected to return a pointer to the start of a line at
- * *or before* the first word matching "string". Relaxing the constraint
- * this way simplifies the algorithm.
- *
- * Invariants:
- * front points to the beginning of a line at or before the first
- * matching string.
- *
- * back points to the beginning of a line at or after the first
- * matching line.
- *
- * Base of the Invariants.
- * front = NULL;
- * back = EOF;
- *
- * Advancing the Invariants:
- *
- * p = first newline after halfway point from front to back.
- *
- * If the string at "p" is not greater than the string to match,
- * p is the new front. Otherwise it is the new back.
- *
- * Termination:
- *
- * The definition of the routine allows it return at any point,
- * since front is always at or before the line to print.
- *
- * In fact, it returns when the chosen "p" equals "back". This
- * implies that there exists a string is least half as long as
- * (back - front), which in turn implies that a linear search will
- * be no more expensive than the cost of simply printing a string or two.
- *
- * Trying to continue with binary search at this point would be
- * more trouble than it's worth.
- */
-#define SKIP_PAST_NEWLINE(p, back) while (p < back && *p++ != '\n');
-
-static char *
-binary_search(string, front, back)
- register char *string, *front, *back;
-{
- register char *p;
-
- p = front + (back - front) / 2;
- SKIP_PAST_NEWLINE(p, back);
-
- while (p != back) {
- if (compare(string, p, back) == GREATER)
- front = p;
- else
- back = p;
- p = front + (back - front) / 2;
- SKIP_PAST_NEWLINE(p, back);
- }
- return (front);
-}
-
-/*
- * Find the first line that starts with string, linearly searching from front
- * to back.
- *
- * Return NULL for no such line.
- *
- * This routine assumes:
- *
- * o front points at the first character in a line.
- * o front is before or at the first line to be printed.
- */
-static char *
-linear_search(string, front, back)
- char *string, *front, *back;
-{
- while (front < back) {
- switch (compare(string, front, back)) {
- case EQUAL: /* Found it. */
- return (front);
- case LESS: /* No such string. */
- return (NULL);
- case GREATER: /* Keep going. */
- break;
- }
- SKIP_PAST_NEWLINE(front, back);
- }
- return (NULL);
-}
-
-/*
- * Return LESS, GREATER, or EQUAL depending on how the string1 compares
- * with string2 (s1 ??? s2).
- *
- * o Matches up to len(s1) are EQUAL.
- * o Matches up to len(s2) are GREATER.
- *
- * The string "s1" is null terminated. The string s2 is '\t', space, (or
- * "back") terminated.
- *
- * !!!
- * Reasonably modern ctags programs use tabs as separators, not spaces.
- * However, historic programs did use spaces, and, I got complaints.
- */
-static int
-compare(s1, s2, back)
- register char *s1, *s2, *back;
-{
- for (; *s1 && s2 < back && (*s2 != '\t' && *s2 != ' '); ++s1, ++s2)
- if (*s1 != *s2)
- return (*s1 < *s2 ? LESS : GREATER);
- return (*s1 ? GREATER : s2 < back &&
- (*s2 != '\t' && *s2 != ' ') ? LESS : EQUAL);
-}
diff --git a/usr.bin/vi/ex/ex_undo.c b/usr.bin/vi/ex/ex_undo.c
deleted file mode 100644
index 1b8ba69..0000000
--- a/usr.bin/vi/ex/ex_undo.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_undo.c 8.9 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_undo -- u
- * Undo the last change.
- */
-int
-ex_undo(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- MARK m;
-
- /*
- * !!!
- * Historic undo always set the previous context mark.
- */
- m.lno = sp->lno;
- m.cno = sp->cno;
- if (mark_set(sp, ep, ABSMARK1, &m, 1))
- return (1);
-
- /*
- * !!!
- * Multiple undo isn't available in ex, as there's no '.' command.
- * Whether 'u' is undo or redo is toggled each time, unless there
- * was a change since the last undo, in which case it's an undo.
- */
- if (!F_ISSET(ep, F_UNDO)) {
- F_SET(ep, F_UNDO);
- ep->lundo = FORWARD;
- }
- switch (ep->lundo) {
- case BACKWARD:
- if (log_forward(sp, ep, &m))
- return (1);
- ep->lundo = FORWARD;
- break;
- case FORWARD:
- if (log_backward(sp, ep, &m))
- return (1);
- ep->lundo = BACKWARD;
- break;
- case NOTSET:
- abort();
- }
- sp->lno = m.lno;
- sp->cno = m.cno;
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_usage.c b/usr.bin/vi/ex/ex_usage.c
deleted file mode 100644
index 424b79b..0000000
--- a/usr.bin/vi/ex/ex_usage.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_usage.c 8.21 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../vi/vcmd.h"
-
-/*
- * ex_help -- :help
- * Display help message.
- */
-int
-ex_help(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- (void)ex_printf(EXCOOKIE,
- "To see the list of vi commands, enter \":viusage<CR>\"\n");
- (void)ex_printf(EXCOOKIE,
- "To see the list of ex commands, enter \":exusage<CR>\"\n");
- (void)ex_printf(EXCOOKIE,
- "For an ex command usage statement enter \":exusage [cmd]<CR>\"\n");
- (void)ex_printf(EXCOOKIE,
- "For a vi key usage statement enter \":viusage [key]<CR>\"\n");
- (void)ex_printf(EXCOOKIE, "To exit, enter \":q!\"\n");
- return (0);
-}
-
-/*
- * ex_usage -- :exusage [cmd]
- * Display ex usage strings.
- */
-int
-ex_usage(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- ARGS *ap;
- EXCMDLIST const *cp;
- char *name;
-
- switch (cmdp->argc) {
- case 1:
- ap = cmdp->argv[0];
- for (cp = cmds; cp->name != NULL &&
- memcmp(ap->bp, cp->name, ap->len); ++cp);
- if (cp->name == NULL)
- (void)ex_printf(EXCOOKIE,
- "The %.*s command is unknown",
- (int)ap->len, ap->bp);
- else {
- (void)ex_printf(EXCOOKIE,
- "Command: %s\n Usage: %s\n", cp->help, cp->usage);
- /*
- * !!!
- * The "visual" command has two modes, one from ex,
- * one from the vi colon line. Don't ask.
- */
- if (cp != &cmds[C_VISUAL_EX] &&
- cp != &cmds[C_VISUAL_VI])
- break;
- if (cp == &cmds[C_VISUAL_EX])
- cp = &cmds[C_VISUAL_VI];
- else
- cp = &cmds[C_VISUAL_EX];
- (void)ex_printf(EXCOOKIE,
- "Command: %s\n Usage: %s\n", cp->help, cp->usage);
- }
- break;
- case 0:
- F_SET(sp, S_INTERRUPTIBLE);
- for (cp = cmds; cp->name != NULL; ++cp) {
- /* The ^D command has an unprintable name. */
- if (cp == &cmds[C_SCROLL])
- name = "^D";
- else
- name = cp->name;
- (void)ex_printf(EXCOOKIE,
- "%*s: %s\n", MAXCMDNAMELEN, name, cp->help);
- }
- break;
- default:
- abort();
- }
- return (0);
-}
-
-/*
- * ex_viusage -- :viusage [key]
- * Display vi usage strings.
- */
-int
-ex_viusage(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- VIKEYS const *kp;
- int key;
-
- switch (cmdp->argc) {
- case 1:
- if (cmdp->argv[0]->len != 1) {
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
- key = cmdp->argv[0]->bp[0];
- if (key > MAXVIKEY)
- goto nokey;
-
- /* Special case: '[' and ']' commands. */
- if ((key == '[' || key == ']') && cmdp->argv[0]->bp[1] != key)
- goto nokey;
-
- /* Special case: ~ command. */
- if (key == '~' && O_ISSET(sp, O_TILDEOP))
- kp = &tmotion;
- else
- kp = &vikeys[key];
-
- if (kp->func == NULL)
-nokey: (void)ex_printf(EXCOOKIE,
- "The %s key has no current meaning",
- KEY_NAME(sp, key));
- else
- (void)ex_printf(EXCOOKIE,
- " Key:%s%s\nUsage: %s\n",
- isblank(*kp->help) ? "" : " ", kp->help, kp->usage);
- break;
- case 0:
- F_SET(sp, S_INTERRUPTIBLE);
- for (key = 0; key <= MAXVIKEY; ++key) {
- /* Special case: ~ command. */
- if (key == '~' && O_ISSET(sp, O_TILDEOP))
- kp = &tmotion;
- else
- kp = &vikeys[key];
- if (kp->help != NULL)
- (void)ex_printf(EXCOOKIE, "%s\n", kp->help);
- }
- break;
- default:
- abort();
- }
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_util.c b/usr.bin/vi/ex/ex_util.c
deleted file mode 100644
index a32b2a4..0000000
--- a/usr.bin/vi/ex/ex_util.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_util.c 8.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_getline --
- * Return a line from the terminal.
- */
-int
-ex_getline(sp, fp, lenp)
- SCR *sp;
- FILE *fp;
- size_t *lenp;
-{
- EX_PRIVATE *exp;
- size_t off;
- int ch;
- char *p;
-
- exp = EXP(sp);
- for (errno = 0, off = 0, p = exp->ibp;;) {
- if (off >= exp->ibp_len) {
- BINC_RET(sp, exp->ibp, exp->ibp_len, off + 1);
- p = exp->ibp + off;
- }
- if ((ch = getc(fp)) == EOF && !feof(fp)) {
- if (errno == EINTR) {
- errno = 0;
- clearerr(fp);
- continue;
- }
- return (1);
- }
- if (ch == EOF || ch == '\n') {
- if (ch == EOF && !off)
- return (1);
- *lenp = off;
- return (0);
- }
- *p++ = ch;
- ++off;
- }
- /* NOTREACHED */
-}
-
-/*
- * ex_sleave --
- * Save the terminal/signal state, screen modification time.
- * Specific to ex/filter.c and ex/ex_shell.c.
- */
-int
-ex_sleave(sp)
- SCR *sp;
-{
- struct stat sb;
- EX_PRIVATE *exp;
-
- /* Ignore sessions not using tty's. */
- if (!F_ISSET(sp->gp, G_STDIN_TTY))
- return (1);
-
- exp = EXP(sp);
- if (tcgetattr(STDIN_FILENO, &exp->leave_term)) {
- msgq(sp, M_SYSERR, "tcgetattr");
- return (1);
- }
- if (tcsetattr(STDIN_FILENO,
- TCSANOW | TCSASOFT, &sp->gp->original_termios)) {
- msgq(sp, M_SYSERR, "tcsetattr");
- return (1);
- }
- /*
- * The process may write to the terminal. Save the access time
- * (read) and modification time (write) of the tty; if they have
- * changed when we restore the modes, will have to refresh the
- * screen.
- */
- if (fstat(STDIN_FILENO, &sb)) {
- msgq(sp, M_SYSERR, "stat: stdin");
- exp->leave_atime = exp->leave_mtime = 0;
- } else {
- exp->leave_atime = sb.st_atime;
- exp->leave_mtime = sb.st_mtime;
- }
- return (0);
-}
-
-/*
- * ex_rleave --
- * Return the terminal/signal state, not screen modification time.
- * Specific to ex/filter.c and ex/ex_shell.c.
- */
-void
-ex_rleave(sp)
- SCR *sp;
-{
- EX_PRIVATE *exp;
- struct stat sb;
-
- exp = EXP(sp);
-
- /* Restore the terminal modes. */
- if (tcsetattr(STDIN_FILENO, TCSANOW | TCSASOFT, &exp->leave_term))
- msgq(sp, M_SYSERR, "tcsetattr");
-
- /* If the terminal was used, refresh the screen. */
- if (fstat(STDIN_FILENO, &sb) || exp->leave_atime == 0 ||
- exp->leave_atime != sb.st_atime || exp->leave_mtime != sb.st_mtime)
- F_SET(sp, S_REFRESH);
-}
-
-/*
- * ex_ncheck --
- * Check for more files to edit.
- */
-int
-ex_ncheck(sp, force)
- SCR *sp;
- int force;
-{
- /*
- * !!!
- * Historic practice: quit! or two quit's done in succession
- * (where ZZ counts as a quit) didn't check for other files.
- */
- if (!force && sp->ccnt != sp->q_ccnt + 1 &&
- sp->cargv != NULL && sp->cargv[1] != NULL) {
- sp->q_ccnt = sp->ccnt;
- msgq(sp, M_ERR,
- "More files to edit; use n[ext] to go to the next file, q[uit]! to quit");
- return (1);
- }
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_version.c b/usr.bin/vi/ex/ex_version.c
deleted file mode 100644
index 011c257..0000000
--- a/usr.bin/vi/ex/ex_version.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)ex_version.c 8.66 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_version -- :version
- * Display the program version.
- */
-int
-ex_version(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- static const time_t then = 777148668;
-
- (void)ex_printf(EXCOOKIE,
-"Version 1.34, %sThe CSRG, University of California, Berkeley.\n",
- ctime(&then));
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_visual.c b/usr.bin/vi/ex/ex_visual.c
deleted file mode 100644
index acfd537..0000000
--- a/usr.bin/vi/ex/ex_visual.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_visual.c 8.15 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
- *
- * Switch to visual mode.
- */
-int
-ex_visual(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- size_t len;
- int pos;
- char buf[256];
-
- /* If open option off, disallow visual command. */
- if (!O_ISSET(sp, O_OPEN)) {
- msgq(sp, M_ERR,
- "The visual command requires that the open option be set");
- return (1);
- }
-
- /* If a line specified, move to that line. */
- if (cmdp->addrcnt)
- sp->lno = cmdp->addr1.lno;
-
- /*
- * Push a command based on the line position flags. If no
- * flag specified, the line goes at the top of the screen.
- */
- switch (F_ISSET(cmdp, E_F_CARAT | E_F_DASH | E_F_DOT | E_F_PLUS)) {
- case E_F_CARAT:
- pos = '^';
- break;
- case E_F_DASH:
- pos = '-';
- break;
- case E_F_DOT:
- pos = '.';
- break;
- case E_F_PLUS:
- pos = '+';
- break;
- default:
- sp->frp->lno = sp->lno;
- sp->frp->cno = 0;
- F_SET(sp->frp, FR_CURSORSET | FR_FNONBLANK);
- goto nopush;
- }
-
- if (F_ISSET(cmdp, E_COUNT))
- len = snprintf(buf, sizeof(buf),
- "%luz%c%lu", sp->lno, pos, cmdp->count);
- else
- len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos);
- (void)term_push(sp, buf, len, CH_NOMAP | CH_QUOTED);
-
- /*
- * !!!
- * Historically, if no line address was specified, the [p#l] flags
- * caused the cursor to be moved to the last line of the file, which
- * was then positioned as described above. This seems useless, so
- * I haven't implemented it.
- */
- switch (F_ISSET(cmdp, E_F_HASH | E_F_LIST | E_F_PRINT)) {
- case E_F_HASH:
- O_SET(sp, O_NUMBER);
- break;
- case E_F_LIST:
- O_SET(sp, O_LIST);
- break;
- case E_F_PRINT:
- break;
- }
-
- /* Switch modes. */
-nopush: F_CLR(sp, S_SCREENS);
- F_SET(sp, sp->saved_vi_mode);
-
- return (0);
-}
diff --git a/usr.bin/vi/ex/ex_write.c b/usr.bin/vi/ex/ex_write.c
deleted file mode 100644
index e5273e4..0000000
--- a/usr.bin/vi/ex/ex_write.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_write.c 8.38 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-enum which {WN, WQ, WRITE, XIT};
-
-static int exwr __P((SCR *, EXF *, EXCMDARG *, enum which));
-
-/*
- * ex_wn -- :wn[!] [>>] [file]
- * Write to a file and switch to the next one.
- */
-int
-ex_wn(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- if (exwr(sp, ep, cmdp, WN))
- return (1);
- if (file_m3(sp, ep, 0))
- return (1);
-
- /* The file name isn't a new file to edit. */
- cmdp->argc = 0;
-
- return (ex_next(sp, ep, cmdp));
-}
-
-/*
- * ex_wq -- :wq[!] [>>] [file]
- * Write to a file and quit.
- */
-int
-ex_wq(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- int force;
-
- if (exwr(sp, ep, cmdp, WQ))
- return (1);
- if (file_m3(sp, ep, 0))
- return (1);
-
- force = F_ISSET(cmdp, E_FORCE);
-
- if (ex_ncheck(sp, force))
- return (1);
-
- F_SET(sp, force ? S_EXIT_FORCE : S_EXIT);
- return (0);
-}
-
-/*
- * ex_write -- :write[!] [>>] [file]
- * :write [!] [cmd]
- * Write to a file.
- */
-int
-ex_write(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (exwr(sp, ep, cmdp, WRITE));
-}
-
-
-/*
- * ex_xit -- :x[it]! [file]
- *
- * Write out any modifications and quit.
- */
-int
-ex_xit(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- int force;
-
- if (F_ISSET((ep), F_MODIFIED) && exwr(sp, ep, cmdp, XIT))
- return (1);
- if (file_m3(sp, ep, 0))
- return (1);
-
- force = F_ISSET(cmdp, E_FORCE);
-
- if (ex_ncheck(sp, force))
- return (1);
-
- F_SET(sp, force ? S_EXIT_FORCE : S_EXIT);
- return (0);
-}
-
-/*
- * exwr --
- * The guts of the ex write commands.
- */
-static int
-exwr(sp, ep, cmdp, cmd)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
- enum which cmd;
-{
- EX_PRIVATE *exp;
- MARK rm;
- int flags;
- char *name, *p;
-
- /* All write commands can have an associated '!'. */
- LF_INIT(FS_POSSIBLE);
- if (F_ISSET(cmdp, E_FORCE))
- LF_SET(FS_FORCE);
-
- /* Skip any leading whitespace. */
- if (cmdp->argc != 0)
- for (p = cmdp->argv[0]->bp; *p && isblank(*p); ++p);
-
- /* If no arguments, just write the file back. */
- if (cmdp->argc == 0 || *p == '\0') {
- if (F_ISSET(cmdp, E_ADDR2_ALL))
- LF_SET(FS_ALL);
- return (file_write(sp, ep,
- &cmdp->addr1, &cmdp->addr2, NULL, flags));
- }
-
- /* If "write !" it's a pipe to a utility. */
- exp = EXP(sp);
- if (cmd == WRITE && *p == '!') {
- for (++p; *p && isblank(*p); ++p);
- if (*p == '\0') {
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
- /* Expand the argument. */
- if (argv_exp1(sp, ep, cmdp, p, strlen(p), 0))
- return (1);
- if (filtercmd(sp, ep, &cmdp->addr1, &cmdp->addr2,
- &rm, cmdp->argv[1]->bp, FILTER_WRITE))
- return (1);
- sp->lno = rm.lno;
- return (0);
- }
-
- /* If "write >>" it's an append to a file. */
- if (cmd != XIT && p[0] == '>' && p[1] == '>') {
- LF_SET(FS_APPEND);
-
- /* Skip ">>" and whitespace. */
- for (p += 2; *p && isblank(*p); ++p);
- }
-
- /* Build an argv so we get an argument count and file expansion. */
- if (argv_exp2(sp, ep, cmdp, p, strlen(p), 0))
- return (1);
-
- switch (cmdp->argc) {
- case 1:
- /*
- * Nothing to expand, write the current file.
- * XXX
- * Should never happen, already checked this case.
- */
- name = NULL;
- break;
- case 2:
- /* One new argument, write it. */
- name = cmdp->argv[exp->argsoff - 1]->bp;
- set_alt_name(sp, name);
- break;
- default:
- /* If expanded to more than one argument, object. */
- msgq(sp, M_ERR, "%s expanded into too many file names",
- cmdp->argv[0]->bp);
- msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
- return (1);
- }
-
- if (F_ISSET(cmdp, E_ADDR2_ALL))
- LF_SET(FS_ALL);
- return (file_write(sp, ep, &cmdp->addr1, &cmdp->addr2, name, flags));
-}
-
-/*
- * ex_writefp --
- * Write a range of lines to a FILE *.
- */
-int
-ex_writefp(sp, ep, name, fp, fm, tm, nlno, nch)
- SCR *sp;
- EXF *ep;
- char *name;
- FILE *fp;
- MARK *fm, *tm;
- u_long *nlno, *nch;
-{
- struct stat sb;
- u_long ccnt; /* XXX: can't print off_t portably. */
- recno_t fline, tline, lcnt;
- size_t len;
- int sv_errno;
- char *p;
-
- fline = fm->lno;
- tline = tm->lno;
-
- if (nlno != NULL) {
- *nch = 0;
- *nlno = 0;
- }
-
- /*
- * The vi filter code has multiple processes running simultaneously,
- * and one of them calls ex_writefp(). The "unsafe" function calls
- * in this code are to file_gline() and msgq(). File_gline() is safe,
- * see the comment in filter.c:filtercmd() for details. We don't call
- * msgq if the multiple process bit in the EXF is set.
- *
- * !!!
- * Historic vi permitted files of 0 length to be written. However,
- * since the way vi got around dealing with "empty" files was to
- * always have a line in the file no matter what, it wrote them as
- * files of a single, empty line. We write empty files.
- *
- * "Alex, I'll take vi trivia for $1000."
- */
- ccnt = 0;
- lcnt = 0;
- if (tline != 0) {
- for (; fline <= tline; ++fline, ++lcnt) {
- /* Caller has to provide any interrupt message. */
- if (INTERRUPTED(sp))
- break;
- if ((p = file_gline(sp, ep, fline, &len)) == NULL)
- break;
- if (fwrite(p, 1, len, fp) != len) {
- msgq(sp, M_SYSERR, name);
- (void)fclose(fp);
- return (1);
- }
- ccnt += len;
- if (putc('\n', fp) != '\n')
- break;
- ++ccnt;
- }
- }
-
- /* If it's a regular file, sync it so that NFS is forced to flush. */
- if (!fstat(fileno(fp), &sb) &&
- S_ISREG(sb.st_mode) && fsync(fileno(fp))) {
- sv_errno = errno;
- (void)fclose(fp);
- errno = sv_errno;
- goto err;
- }
- if (fclose(fp))
- goto err;
- if (nlno != NULL) {
- *nch = ccnt;
- *nlno = lcnt;
- }
- return (0);
-
-err: if (!F_ISSET(ep, F_MULTILOCK))
- msgq(sp, M_SYSERR, name);
- return (1);
-}
diff --git a/usr.bin/vi/ex/ex_yank.c b/usr.bin/vi/ex/ex_yank.c
deleted file mode 100644
index aa44d2b..0000000
--- a/usr.bin/vi/ex/ex_yank.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)ex_yank.c 8.7 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_yank -- :[line [,line]] ya[nk] [buffer] [count]
- *
- * Yank the lines into a buffer.
- */
-int
-ex_yank(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- return (cut(sp, ep,
- F_ISSET(cmdp, E_BUFFER) ? &cmdp->buffer : NULL,
- &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE));
-}
diff --git a/usr.bin/vi/ex/ex_z.c b/usr.bin/vi/ex/ex_z.c
deleted file mode 100644
index d130646..0000000
--- a/usr.bin/vi/ex/ex_z.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)ex_z.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * ex_z -- :[line] z [^-.+=] [count] [flags]
- *
- * Adjust window.
- */
-int
-ex_z(sp, ep, cmdp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *cmdp;
-{
- MARK abs;
- recno_t cnt, equals, lno;
- int eofcheck;
-
- /*
- * !!!
- * If no count specified, use either two times the size of the
- * scrolling region, or the size of the window option. POSIX
- * 1003.2 claims that the latter is correct, but historic ex/vi
- * documentation and practice appear to use the scrolling region.
- * I'm using the window size as it means that the entire screen
- * is used instead of losing a line to roundoff. Note, we drop
- * a line from the cnt if using the window size to leave room for
- * the next ex prompt.
- */
- if (F_ISSET(cmdp, E_COUNT))
- cnt = cmdp->count;
- else
-#ifdef HISTORIC_PRACTICE
- cnt = O_VAL(sp, O_SCROLL) * 2;
-#else
- cnt = O_VAL(sp, O_WINDOW) - 1;
-#endif
-
- equals = 0;
- eofcheck = 0;
- lno = cmdp->addr1.lno;
-
- switch (F_ISSET(cmdp,
- E_F_CARAT | E_F_DASH | E_F_DOT | E_F_EQUAL | E_F_PLUS)) {
- case E_F_CARAT: /* Display cnt * 2 before the line. */
- eofcheck = 1;
- if (lno > cnt * 2)
- cmdp->addr1.lno = (lno - cnt * 2) + 1;
- else
- cmdp->addr1.lno = 1;
- cmdp->addr2.lno = (cmdp->addr1.lno + cnt) - 1;
- break;
- case E_F_DASH: /* Line goes at the bottom of the screen. */
- cmdp->addr1.lno = lno > cnt ? (lno - cnt) + 1 : 1;
- cmdp->addr2.lno = lno;
- break;
- case E_F_DOT: /* Line goes in the middle of the screen. */
- /*
- * !!!
- * Historically, the "middleness" of the line overrode the
- * count, so that "3z.19" or "3z.20" would display the first
- * 12 lines of the file, i.e. (N - 1) / 2 lines before and
- * after the specified line.
- */
- eofcheck = 1;
- cnt = (cnt - 1) / 2;
- cmdp->addr1.lno = lno > cnt ? lno - cnt : 1;
- cmdp->addr2.lno = lno + cnt;
-
- /*
- * !!!
- * Historically, z. set the absolute cursor mark.
- */
- abs.lno = sp->lno;
- abs.cno = sp->cno;
- (void)mark_set(sp, ep, ABSMARK1, &abs, 1);
- break;
- case E_F_EQUAL: /* Center with hyphens. */
- /*
- * !!!
- * Strangeness. The '=' flag is like the '.' flag (see the
- * above comment, it applies here as well) but with a special
- * little hack. Print out lines of hyphens before and after
- * the specified line. Additionally, the cursor remains set
- * on that line.
- */
- eofcheck = 1;
- cnt = (cnt - 1) / 2;
- cmdp->addr1.lno = lno > cnt ? lno - cnt : 1;
- cmdp->addr2.lno = lno - 1;
- if (ex_pr(sp, ep, cmdp))
- return (1);
- (void)ex_printf(EXCOOKIE,
- "%s", "----------------------------------------\n");
- cmdp->addr2.lno = cmdp->addr1.lno = equals = lno;
- if (ex_pr(sp, ep, cmdp))
- return (1);
- (void)ex_printf(EXCOOKIE,
- "%s", "----------------------------------------\n");
- cmdp->addr1.lno = lno + 1;
- cmdp->addr2.lno = (lno + cnt) - 1;
- break;
- default:
- /* If no line specified, move to the next one. */
- if (F_ISSET(cmdp, E_ADDRDEF))
- ++lno;
- /* FALLTHROUGH */
- case E_F_PLUS: /* Line goes at the top of the screen. */
- eofcheck = 1;
- cmdp->addr1.lno = lno;
- cmdp->addr2.lno = (lno + cnt) - 1;
- break;
- }
-
- if (eofcheck) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (cmdp->addr2.lno > lno)
- cmdp->addr2.lno = lno;
- }
-
- if (ex_pr(sp, ep, cmdp))
- return (1);
- if (equals)
- sp->lno = equals;
- return (0);
-}
diff --git a/usr.bin/vi/ex/excmd.awk b/usr.bin/vi/ex/excmd.awk
deleted file mode 100644
index 2890220..0000000
--- a/usr.bin/vi/ex/excmd.awk
+++ /dev/null
@@ -1,6 +0,0 @@
-# @(#)excmd.awk 8.1 (Berkeley) 4/17/94
-
-/^\/\* C_[0-9A-Z_]* \*\/$/ {
- printf("#define %s %d\n", $2, cnt++);
- next;
-}
diff --git a/usr.bin/vi/ex/excmd.c b/usr.bin/vi/ex/excmd.c
deleted file mode 100644
index 422578a..0000000
--- a/usr.bin/vi/ex/excmd.c
+++ /dev/null
@@ -1,458 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)excmd.c 8.60 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-/*
- * This array maps ex command names to command functions.
- *
- * The order in which command names are listed below is important --
- * ambiguous abbreviations are resolved to be the first possible match,
- * e.g. "r" means "read", not "rewind", because "read" is listed before
- * "rewind".
- *
- * The syntax of the ex commands is unbelievably irregular, and a special
- * case from beginning to end. Each command has an associated "syntax
- * script" which describes the "arguments" that are possible. The script
- * syntax is as follows:
- *
- * ! -- ! flag
- * 1 -- flags: [+-]*[pl#][+-]*
- * 2 -- flags: [-.+^]
- * 3 -- flags: [-.+^=]
- * b -- buffer
- * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
- * f[N#][or] -- file (a number or N, optional or required)
- * l -- line
- * S -- string with file name expansion
- * s -- string
- * W -- word string
- * w[N#][or] -- word (a number or N, optional or required)
- */
-EXCMDLIST const cmds[] = {
-/* C_SCROLL */
- {"\004", ex_pr, E_ADDR2|E_NORC,
- "",
- "^D",
- "scroll lines"},
-/* C_BANG */
- {"!", ex_bang, E_ADDR2_NONE|E_NORC,
- "S",
- "[line [,line]] ! command",
- "filter lines through commands or run commands"},
-/* C_HASH */
- {"#", ex_number, E_ADDR2|E_F_PRCLEAR|E_NORC,
- "ca1",
- "[line [,line]] # [count] [l]",
- "display numbered lines"},
-/* C_SUBAGAIN */
- {"&", ex_subagain, E_ADDR2|E_NORC,
- "s",
- "[line [,line]] & [cgr] [count] [#lp]",
- "repeat the last subsitution"},
-/* C_STAR */
- {"*", ex_at, 0,
- "b",
- "* [buffer]",
- "execute a buffer"},
-/* C_SHIFTL */
- {"<", ex_shiftl, E_ADDR2|E_AUTOPRINT|E_NORC,
- "ca1",
- "[line [,line]] <[<...] [count] [flags]",
- "shift lines left"},
-/* C_EQUAL */
- {"=", ex_equal, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
- "1",
- "[line] = [flags]",
- "display line number"},
-/* C_SHIFTR */
- {">", ex_shiftr, E_ADDR2|E_AUTOPRINT|E_NORC,
- "ca1",
- "[line [,line]] >[>...] [count] [flags]",
- "shift lines right"},
-/* C_AT */
- {"@", ex_at, 0,
- "b",
- "@ [buffer]",
- "execute a buffer"},
-/* C_APPEND */
- {"append", ex_append, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
- "!",
- "[line] a[ppend][!]",
- "append input to a line"},
-/* C_ABBR */
- {"abbreviate", ex_abbr, E_NOGLOBAL,
- "W",
- "ab[brev] [word replace]",
- "specify an input abbreviation"},
-/* C_ARGS */
- {"args", ex_args, E_NOGLOBAL|E_NORC,
- "",
- "ar[gs]",
- "display file argument list"},
-/* C_BG */
- {"bg", ex_bg, E_NOGLOBAL|E_NORC,
- "",
- "bg",
- "background the current screen"},
-/* C_CHANGE */
- {"change", ex_change, E_ADDR2|E_NORC|E_ZERODEF,
- "!ca",
- "[line [,line]] c[hange][!] [count]",
- "change lines to input"},
-/* C_CD */
- {"cd", ex_cd, E_NOGLOBAL,
- "!f1o",
- "cd[!] [directory]",
- "change the current directory"},
-/* C_CHDIR */
- {"chdir", ex_cd, E_NOGLOBAL,
- "!f1o",
- "chd[ir][!] [directory]",
- "change the current directory"},
-/* C_COPY */
- {"copy", ex_copy, E_ADDR2|E_AUTOPRINT|E_NORC,
- "l1",
- "[line [,line]] co[py] line [flags]",
- "copy lines elsewhere in the file"},
-/*
- * !!!
- * Adding new commands starting with 'd' may break the delete command code
- * in ex_cmd() (the ex parser). Read through the comments there, first.
- */
-/* C_DELETE */
- {"delete", ex_delete, E_ADDR2|E_AUTOPRINT|E_NORC,
- "bca1",
- "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
- "delete lines from the file"},
-/* C_DISPLAY */
- {"display", ex_display, E_NOGLOBAL|E_NORC,
- "w1r",
- "display b[uffers] | s[creens] | t[ags]",
- "display buffers, screens or tags"},
-/* C_DIGRAPH */
- {"digraph", ex_digraph, E_NOGLOBAL|E_NOPERM|E_NORC,
- "",
- "digraph",
- "specify digraphs (not implemented)"},
-/* C_EDIT */
- {"edit", ex_edit, E_NOGLOBAL|E_NORC,
- "f1o",
- "e[dit][!] [+cmd] [file]",
- "begin editing another file"},
-/* C_EX */
- {"ex", ex_edit, E_NOGLOBAL|E_NORC,
- "f1o",
- "ex[!] [+cmd] [file]",
- "begin editing another file"},
-/* C_EXUSAGE */
- {"exusage", ex_usage, E_NOGLOBAL|E_NORC,
- "w1o",
- "[exu]sage [command]",
- "display ex command usage statement"},
-/* C_FILE */
- {"file", ex_file, E_NOGLOBAL|E_NORC,
- "f1o",
- "f[ile] [name]",
- "display (and optionally set) file name"},
-/* C_FG */
- {"fg", ex_fg, E_NOGLOBAL|E_NORC,
- "f1o",
- "fg [file]",
- "switch the current screen and a backgrounded screen"},
-/* C_GLOBAL */
- {"global", ex_global, E_ADDR2_ALL|E_NOGLOBAL|E_NORC,
- "!s",
- "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
- "execute a global command on lines matching an RE"},
-/* C_HELP */
- {"help", ex_help, E_NOGLOBAL|E_NORC,
- "",
- "he[lp]",
- "display help statement"},
-/* C_INSERT */
- {"insert", ex_insert, E_ADDR1|E_NORC,
- "!",
- "[line] i[nsert][!]",
- "insert input before a line"},
-/* C_JOIN */
- {"join", ex_join, E_ADDR2|E_AUTOPRINT|E_NORC,
- "!ca1",
- "[line [,line]] j[oin][!] [count] [flags]",
- "join lines into a single line"},
-/* C_K */
- {"k", ex_mark, E_ADDR1|E_NORC,
- "w1r",
- "[line] k key",
- "mark a line position"},
-/* C_LIST */
- {"list", ex_list, E_ADDR2|E_F_PRCLEAR|E_NORC,
- "ca1",
- "[line [,line]] l[ist] [count] [#]",
- "display lines in an unambiguous form"},
-/* C_MOVE */
- {"move", ex_move, E_ADDR2|E_AUTOPRINT|E_NORC,
- "l",
- "[line [,line]] m[ove] line",
- "move lines elsewhere in the file"},
-/* C_MARK */
- {"mark", ex_mark, E_ADDR1|E_NORC,
- "w1r",
- "[line] ma[rk] key",
- "mark a line position"},
-/* C_MAP */
- {"map", ex_map, 0,
- "!W",
- "map[!] [keys replace]",
- "map input or commands to one or more keys"},
-/* C_MKEXRC */
- {"mkexrc", ex_mkexrc, E_NOGLOBAL|E_NORC,
- "!f1r",
- "mkexrc[!] file",
- "write a .exrc file"},
-/* C_NEXT */
- {"next", ex_next, E_NOGLOBAL|E_NORC,
- "!fN",
- "n[ext][!] [+cmd] [file ...]",
- "edit (and optionally specify) the next file"},
-/* C_NUMBER */
- {"number", ex_number, E_ADDR2|E_F_PRCLEAR|E_NORC,
- "ca1",
- "[line [,line]] nu[mber] [count] [l]",
- "change display to number lines"},
-/* C_OPEN */
- {"open", ex_open, E_ADDR1,
- "s",
- "[line] o[pen] [/RE/] [flags]",
- "enter \"open\" mode (not implemented)"},
-/* C_PRINT */
- {"print", ex_pr, E_ADDR2|E_F_PRCLEAR|E_NORC,
- "ca1",
- "[line [,line]] p[rint] [count] [#l]",
- "display lines"},
-/* C_PRESERVE */
- {"preserve", ex_preserve, E_NOGLOBAL|E_NORC,
- "",
- "pre[serve]",
- "preserve an edit session for recovery"},
-/* C_PREVIOUS */
- {"previous", ex_prev, E_NOGLOBAL|E_NORC,
- "!",
- "prev[ious][!]",
- "edit the previous file in the file argument list"},
-/* C_PUT */
- {"put", ex_put, E_ADDR1|E_AUTOPRINT|E_NORC|E_ZERO,
- "b",
- "[line] pu[t] [buffer]",
- "append a cut buffer to the line"},
-/* C_QUIT */
- {"quit", ex_quit, E_NOGLOBAL|E_NORC,
- "!",
- "q[uit][!]",
- "exit ex/vi"},
-/* C_READ */
- {"read", ex_read, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
- "s",
- "[line] r[ead] [!cmd | [file]]",
- "append input from a command or file to the line"},
-/* C_RECOVER */
- {"recover", ex_recover, E_NOGLOBAL|E_NORC,
- "!f1r",
- "recover[!] file",
- "recover a saved file"},
-/* C_RESIZE */
- {"resize", ex_resize, E_NOGLOBAL|E_NORC,
- "c+",
- "resize [+-]rows",
- "grow or shrink the current screen"},
-/* C_REWIND */
- {"rewind", ex_rew, E_NOGLOBAL|E_NORC,
- "!",
- "rew[ind][!]",
- "re-edit all the files in the file argument list"},
-/* C_SUBSTITUTE */
- {"substitute", ex_substitute, E_ADDR2|E_NORC,
- "s",
-"[line [,line]] s[ubstitute] [[/;]RE[/;]/repl[/;] [cgr] [count] [#lp]]",
- "substitute on lines matching an RE"},
-/* C_SCRIPT */
- {"script", ex_script, E_NOGLOBAL|E_NORC,
- "!f1o",
- "sc[ript][!] [file]",
- "run a shell in a screen"},
-/* C_SET */
- {"set", ex_set, E_NOGLOBAL,
- "wN",
- "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
- "set options (use \":set all\" to see all options)"},
-/* C_SHELL */
- {"shell", ex_shell, E_NOGLOBAL|E_NORC,
- "",
- "sh[ell]",
- "suspend editing and run a shell"},
-/* C_SOURCE */
- {"source", ex_source, E_NOGLOBAL,
- "f1r",
- "so[urce] file",
- "read a file of ex commands"},
-/* C_SPLIT */
- {"split", ex_split, E_NOGLOBAL|E_NORC,
- "fNo",
- "sp[lit] [file ...]",
- "split the current screen into two screens"},
-/* C_STOP */
- {"stop", ex_stop, E_NOGLOBAL|E_NORC,
- "!",
- "st[op][!]",
- "suspend the edit session"},
-/* C_SUSPEND */
- {"suspend", ex_stop, E_NOGLOBAL|E_NORC,
- "!",
- "su[spend][!]",
- "suspend the edit session"},
-/* C_T */
- {"t", ex_copy, E_ADDR2|E_AUTOPRINT|E_NORC,
- "l1",
- "[line [,line]] t line [flags]",
- "copy lines elsewhere in the file"},
-/* C_TAG */
- {"tag", ex_tagpush, E_NOGLOBAL,
- "!w1o",
- "ta[g][!] [string]",
- "edit the file containing the tag"},
-/* C_TAGPOP */
- {"tagpop", ex_tagpop, E_NOGLOBAL|E_NORC,
- "!w1o",
- "tagp[op][!] [number | file]",
- "return to a previous tag"},
-/* C_TAGTOP */
- {"tagtop", ex_tagtop, E_NOGLOBAL|E_NORC,
- "!",
- "tagt[op][!]",
- "return to the first tag"},
-/* C_UNDO */
- {"undo", ex_undo, E_AUTOPRINT|E_NOGLOBAL|E_NORC,
- "",
- "u[ndo]",
- "undo the most recent change"},
-/* C_UNABBREVIATE */
- {"unabbreviate",ex_unabbr, E_NOGLOBAL,
- "w1r",
- "una[bbrev] word",
- "delete an abbreviation"},
-/* C_UNMAP */
- {"unmap", ex_unmap, E_NOGLOBAL,
- "!w1r",
- "unm[ap][!] word",
- "delete an input or command map"},
-/* C_VGLOBAL */
- {"vglobal", ex_vglobal, E_ADDR2_ALL|E_NOGLOBAL|E_NORC,
- "s",
- "[line [,line]] v[global] [;/]RE[;/] [commands]",
- "execute a global command on lines NOT matching an RE"},
-/* C_VERSION */
- {"version", ex_version, E_NOGLOBAL|E_NORC,
- "",
- "version",
- "display the program version information"},
-/* C_VISUAL_EX */
- {"visual", ex_visual, E_ADDR1|E_NOGLOBAL|E_NORC|E_ZERODEF,
- "2c11",
- "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
- "enter visual (vi) mode from ex mode"},
-/* C_VISUAL_VI */
- {"visual", ex_edit, E_NOGLOBAL|E_NORC,
- "f1o",
- "vi[sual][!] [+cmd] [file]",
- "edit another file (from vi mode only)"},
-/* C_VIUSAGE */
- {"viusage", ex_viusage, E_NOGLOBAL|E_NORC,
- "w1o",
- "[viu]sage [key]",
- "display vi key usage statement"},
-/* C_WRITE */
- {"write", ex_write, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
- "!s",
- "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
- "write the file"},
-/* C_WN */
- {"wn", ex_wn, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
- "!s",
- "[line [,line]] wn[!] [>>] [file]",
- "write the file and switch to the next file"},
-/* C_WQ */
- {"wq", ex_wq, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
- "!s",
- "[line [,line]] wq[!] [>>] [file]",
- "write the file and exit"},
-/* C_XIT */
- {"xit", ex_xit, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
- "!f1o",
- "[line [,line]] x[it][!] [file]",
- "exit"},
-/* C_YANK */
- {"yank", ex_yank, E_ADDR2|E_NORC,
- "bca",
- "[line [,line]] ya[nk] [buffer] [count]",
- "copy lines to a cut buffer"},
-/* C_Z */
- {"z", ex_z, E_ADDR1|E_NOGLOBAL|E_NORC,
- "3c01",
- "[line] z [-|.|+|^|=] [count] [flags]",
- "display different screens of the file"},
-/* C_SUBTILDE */
- {"~", ex_subtilde, E_ADDR2|E_NORC,
- "s",
- "[line [,line]] ~ [cgr] [count] [#lp]",
- "replace previous RE with previous replacement string,"},
- {NULL},
-};
diff --git a/usr.bin/vi/ex/excmd.h.stub b/usr.bin/vi/ex/excmd.h.stub
deleted file mode 100644
index 3b4051b..0000000
--- a/usr.bin/vi/ex/excmd.h.stub
+++ /dev/null
@@ -1,285 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)excmd.h.stub 8.73 (Berkeley) 8/9/94
- */
-
-#define PROMPTCHAR ':' /* Prompt character. */
-
-/* Ex command structure. */
-typedef struct _excmdlist {
- char *name; /* Command name. */
- /* Underlying function. */
- int (*fn) __P((SCR *, EXF *, EXCMDARG *));
-
-#define E_ADDR1 0x0000001 /* One address. */
-#define E_ADDR2 0x0000002 /* Two address. */
-#define E_ADDR2_ALL 0x0000004 /* Zero/two addresses; zero == all. */
-#define E_ADDR2_NONE 0x0000008 /* Zero/two addresses; zero == none. */
-#define E_ADDRDEF 0x0000010 /* Default addresses used. */
-#define E_AUTOPRINT 0x0000020 /* Command always sets autoprint. */
-#define E_BUFFER 0x0000040 /* Buffer name supplied. */
-#define E_COUNT 0x0000080 /* Count supplied. */
-#define E_COUNT_NEG 0x0000100 /* Count was signed negative. */
-#define E_COUNT_POS 0x0000200 /* Count was signed positive. */
-#define E_FORCE 0x0000400 /* ! */
-
-#define E_F_CARAT 0x0000800 /* ^ flag. */
-#define E_F_DASH 0x0001000 /* - flag. */
-#define E_F_DOT 0x0002000 /* . flag. */
-#define E_F_EQUAL 0x0004000 /* = flag. */
-#define E_F_HASH 0x0008000 /* # flag. */
-#define E_F_LIST 0x0010000 /* l flag. */
-#define E_F_PLUS 0x0020000 /* + flag. */
-#define E_F_PRINT 0x0040000 /* p flag. */
-
-#define E_F_PRCLEAR 0x0080000 /* Clear the print (#, l, p) flags. */
-#define E_MODIFY 0x0100000 /* File name expansion modified arg. */
-#define E_NOGLOBAL 0x0200000 /* Not in a global. */
-#define E_NOPERM 0x0400000 /* Permission denied for now. */
-#define E_NORC 0x0800000 /* Not from a .exrc or EXINIT. */
-#define E_ZERO 0x1000000 /* 0 is a legal addr1. */
-#define E_ZERODEF 0x2000000 /* 0 is default addr1 of empty files. */
- u_int32_t flags;
- char *syntax; /* Syntax script. */
- char *usage; /* Usage line. */
- char *help; /* Help line. */
-} EXCMDLIST;
-#define MAXCMDNAMELEN 12 /* Longest command name. */
-extern EXCMDLIST const cmds[]; /* List of ex commands. */
-
-/*
- * Structure passed around to functions implementing ex commands.
- * There are several commands in vi that build one of these and
- * call ex directly. See vi/v_ex.c for details.
- */
-struct _excmdarg {
- EXCMDLIST const *cmd; /* Command entry in command table. */
- CHAR_T buffer; /* Named buffer. */
- recno_t lineno; /* Line number. */
- long count; /* Signed, specified count. */
- long flagoff; /* Signed, flag offset parsed by command. */
- int addrcnt; /* Number of addresses (0, 1 or 2). */
- MARK addr1; /* 1st address. */
- MARK addr2; /* 2nd address. */
- ARGS **argv; /* Array of arguments. */
- int argc; /* Count of arguments. */
- u_int32_t flags; /* Selected flags from EXCMDLIST. */
-};
-
-/* Global ranges. */
-typedef struct _range RANGE;
-struct _range {
- CIRCLEQ_ENTRY(_range) q; /* Linked list of ranges. */
- recno_t start, stop; /* Start/stop of the range. */
-};
-
-/* Cd paths. */
-typedef struct _cdpath CDPATH;
-struct _cdpath {
- TAILQ_ENTRY(_cdpath) q; /* Linked list of cd paths. */
- char *path; /* Path. */
-};
-
-/* Ex private, per-screen memory. */
-typedef struct _ex_private {
- ARGS **args; /* Arguments. */
- int argscnt; /* Argument count. */
- int argsoff; /* Offset into arguments. */
-
- CHAR_T at_lbuf; /* Last executed at buffer's name. */
- int at_lbuf_set; /* If at_lbuf is set. */
-
- char *ibp; /* Line input buffer. */
- size_t ibp_len; /* Line input buffer length. */
-
- u_int32_t fdef; /* Default command flags. */
-
- CHAR_T *lastbcomm; /* Last bang command. */
-
- struct termios leave_term; /* ex_[sr]leave tty state. */
- /* XXX: Should be struct timespec's, but time_t is more portable. */
- time_t leave_atime; /* ex_[sr]leave old access time. */
- time_t leave_mtime; /* ex_[sr]leave old mod time. */
-
- TAILQ_HEAD(_tagh, _tag) tagq; /* Tag list (stack). */
- TAILQ_HEAD(_tagfh, _tagf) tagfq;/* Tag file list. */
- char *tlast; /* Saved last tag. */
-
- TAILQ_HEAD(_cdh, _cdpath) cdq; /* Cd path list. */
-
- /* Linked list of ranges. */
- CIRCLEQ_HEAD(_rangeh, _range) rangeq;
- recno_t range_lno; /* Range set line number. */
-
-#define EX_ABSMARK 0x01 /* Set the absolute mark. */
-#define EX_AUTOPRINT 0x02 /* Autoprint flag. */
- u_int8_t flags;
-} EX_PRIVATE;
-#define EXP(sp) ((EX_PRIVATE *)((sp)->ex_private))
-
-/*
- * !!!
- * Historically, .exrc files and EXINIT variables could only use ^V
- * as an escape character, neither ^Q or a user specified character
- * worked. We enforce that here, just in case someone depends on it.
- */
-#define IS_ESCAPE(sp, ch) \
- (F_ISSET(sp, S_VLITONLY) ? \
- (ch) == CH_LITERAL : KEY_VAL(sp, ch) == K_VLNEXT)
-
-/*
- * Filter actions:
- *
- * FILTER Filter text through the utility.
- * FILTER_READ Read from the utility into the file.
- * FILTER_WRITE Write to the utility, display its output.
- */
-enum filtertype { FILTER, FILTER_READ, FILTER_WRITE };
-int filtercmd __P((SCR *, EXF *,
- MARK *, MARK *, MARK *, char *, enum filtertype));
-
-/* Argument expansion routines. */
-int argv_init __P((SCR *, EXF *, EXCMDARG *));
-int argv_exp0 __P((SCR *, EXF *, EXCMDARG *, char *, size_t));
-int argv_exp1 __P((SCR *, EXF *, EXCMDARG *, char *, size_t, int));
-int argv_exp2 __P((SCR *, EXF *, EXCMDARG *, char *, size_t, int));
-int argv_exp3 __P((SCR *, EXF *, EXCMDARG *, char *, size_t));
-int argv_free __P((SCR *));
-
-/* Ex function prototypes. */
-int ex __P((SCR *, EXF *));
-int ex_cfile __P((SCR *, EXF *, char *, int));
-int ex_cmd __P((SCR *, EXF *, char *, size_t, int));
-int ex_cdalloc __P((SCR *, char *));
-int ex_cdfree __P((SCR *));
-int ex_end __P((SCR *));
-int ex_exec_proc __P((SCR *, char *, char *, char *));
-int ex_gb __P((SCR *, EXF *, TEXTH *, int, u_int));
-int ex_getline __P((SCR *, FILE *, size_t *));
-int ex_icmd __P((SCR *, EXF *, char *, size_t, int));
-int ex_init __P((SCR *, EXF *));
-int ex_is_abbrev __P((char *, size_t));
-int ex_is_unmap __P((char *, size_t));
-int ex_ldisplay __P((SCR *, CHAR_T *, size_t, size_t, u_int));
-int ex_ncheck __P((SCR *, int));
-int ex_optchange __P((SCR *, int));
-int ex_print __P((SCR *, EXF *, MARK *, MARK *, int));
-int ex_readfp __P((SCR *, EXF *, char *, FILE *, MARK *, recno_t *, int));
-void ex_refresh __P((SCR *, EXF *));
-void ex_rleave __P((SCR *));
-int ex_screen_copy __P((SCR *, SCR *));
-int ex_screen_end __P((SCR *));
-int ex_sdisplay __P((SCR *, EXF *));
-int ex_sleave __P((SCR *));
-int ex_suspend __P((SCR *));
-int ex_tdisplay __P((SCR *, EXF *));
-int ex_writefp __P((SCR *, EXF *,
- char *, FILE *, MARK *, MARK *, u_long *, u_long *));
-void global_insdel __P((SCR *, EXF *, enum operation, recno_t));
-int proc_wait __P((SCR *, long, const char *, int));
-int sscr_end __P((SCR *));
-int sscr_exec __P((SCR *, EXF *, recno_t));
-int sscr_input __P((SCR *));
-
-int abbr_save __P((SCR *, FILE *));
-int map_save __P((SCR *, FILE *));
-
-#define EXPROTO(name) int name __P((SCR *, EXF *, EXCMDARG *))
-EXPROTO(ex_abbr);
-EXPROTO(ex_append);
-EXPROTO(ex_args);
-EXPROTO(ex_at);
-EXPROTO(ex_bang);
-EXPROTO(ex_bg);
-EXPROTO(ex_cd);
-EXPROTO(ex_change);
-EXPROTO(ex_color);
-EXPROTO(ex_copy);
-EXPROTO(ex_debug);
-EXPROTO(ex_delete);
-EXPROTO(ex_digraph);
-EXPROTO(ex_display);
-EXPROTO(ex_edit);
-EXPROTO(ex_equal);
-EXPROTO(ex_fg);
-EXPROTO(ex_file);
-EXPROTO(ex_global);
-EXPROTO(ex_help);
-EXPROTO(ex_insert);
-EXPROTO(ex_join);
-EXPROTO(ex_list);
-EXPROTO(ex_map);
-EXPROTO(ex_mark);
-EXPROTO(ex_mkexrc);
-EXPROTO(ex_move);
-EXPROTO(ex_next);
-EXPROTO(ex_number);
-EXPROTO(ex_open);
-EXPROTO(ex_pr);
-EXPROTO(ex_preserve);
-EXPROTO(ex_prev);
-EXPROTO(ex_put);
-EXPROTO(ex_quit);
-EXPROTO(ex_read);
-EXPROTO(ex_recover);
-EXPROTO(ex_resize);
-EXPROTO(ex_rew);
-EXPROTO(ex_script);
-EXPROTO(ex_set);
-EXPROTO(ex_shell);
-EXPROTO(ex_shiftl);
-EXPROTO(ex_shiftr);
-EXPROTO(ex_source);
-EXPROTO(ex_split);
-EXPROTO(ex_stop);
-EXPROTO(ex_subagain);
-EXPROTO(ex_substitute);
-EXPROTO(ex_subtilde);
-EXPROTO(ex_tagpop);
-EXPROTO(ex_tagpush);
-EXPROTO(ex_tagtop);
-EXPROTO(ex_unabbr);
-EXPROTO(ex_undo);
-EXPROTO(ex_unmap);
-EXPROTO(ex_usage);
-EXPROTO(ex_validate);
-EXPROTO(ex_version);
-EXPROTO(ex_vglobal);
-EXPROTO(ex_visual);
-EXPROTO(ex_viusage);
-EXPROTO(ex_wn);
-EXPROTO(ex_wq);
-EXPROTO(ex_write);
-EXPROTO(ex_xit);
-EXPROTO(ex_yank);
-EXPROTO(ex_z);
diff --git a/usr.bin/vi/ex/filter.c b/usr.bin/vi/ex/filter.c
deleted file mode 100644
index abe7ca1..0000000
--- a/usr.bin/vi/ex/filter.c
+++ /dev/null
@@ -1,414 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993, 1994
- * 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[] = "@(#)filter.c 8.45 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-#include <pathnames.h>
-
-#include "vi.h"
-#include "excmd.h"
-
-static int filter_ldisplay __P((SCR *, FILE *));
-
-/*
- * filtercmd --
- * Run a range of lines through a filter utility and optionally
- * replace the original text with the stdout/stderr output of
- * the utility.
- */
-int
-filtercmd(sp, ep, fm, tm, rp, cmd, ftype)
- SCR *sp;
- EXF *ep;
- MARK *fm, *tm, *rp;
- char *cmd;
- enum filtertype ftype;
-{
- FILE *ifp, *ofp;
- pid_t parent_writer_pid, utility_pid;
- recno_t nread;
- int input[2], output[2], rval, teardown;
- char *name;
-
- /* Set return cursor position; guard against a line number of zero. */
- *rp = *fm;
- if (fm->lno == 0)
- rp->lno = 1;
-
- /*
- * There are three different processes running through this code.
- * They are the utility, the parent-writer and the parent-reader.
- * The parent-writer is the process that writes from the file to
- * the utility, the parent reader is the process that reads from
- * the utility.
- *
- * Input and output are named from the utility's point of view.
- * The utility reads from input[0] and the parent(s) write to
- * input[1]. The parent(s) read from output[0] and the utility
- * writes to output[1].
- *
- * In the FILTER_READ case, the utility isn't expected to want
- * input. Redirect its input from /dev/null. Otherwise open
- * up utility input pipe.
- */
- teardown = 0;
- ofp = NULL;
- input[0] = input[1] = output[0] = output[1] = -1;
- if (ftype == FILTER_READ) {
- if ((input[0] = open(_PATH_DEVNULL, O_RDONLY, 0)) < 0) {
- msgq(sp, M_ERR,
- "filter: %s: %s", _PATH_DEVNULL, strerror(errno));
- return (1);
- }
- } else
- if (pipe(input) < 0) {
- msgq(sp, M_SYSERR, "pipe");
- goto err;
- }
-
- /* Open up utility output pipe. */
- if (pipe(output) < 0) {
- msgq(sp, M_SYSERR, "pipe");
- goto err;
- }
- if ((ofp = fdopen(output[0], "r")) == NULL) {
- msgq(sp, M_SYSERR, "fdopen");
- goto err;
- }
-
- /*
- * Save ex/vi terminal settings, and restore the original ones.
- * Restoration so that users can do things like ":r! cat /dev/tty".
- */
- teardown = ftype != FILTER_WRITE && !ex_sleave(sp);
-
- /* Fork off the utility process. */
- SIGBLOCK(sp->gp);
- switch (utility_pid = vfork()) {
- case -1: /* Error. */
- SIGUNBLOCK(sp->gp);
-
- msgq(sp, M_SYSERR, "vfork");
-err: if (input[0] != -1)
- (void)close(input[0]);
- if (input[1] != -1)
- (void)close(input[1]);
- if (ofp != NULL)
- (void)fclose(ofp);
- else if (output[0] != -1)
- (void)close(output[0]);
- if (output[1] != -1)
- (void)close(output[1]);
- rval = 1;
- goto ret;
- case 0: /* Utility. */
- /* The utility has default signal behavior. */
- sig_end();
-
- /*
- * Redirect stdin from the read end of the input pipe, and
- * redirect stdout/stderr to the write end of the output pipe.
- *
- * !!!
- * Historically, ex only directed stdout into the input pipe,
- * letting stderr come out on the terminal as usual. Vi did
- * not, directing both stdout and stderr into the input pipe.
- * We match that practice for both ex and vi for consistency.
- */
- (void)dup2(input[0], STDIN_FILENO);
- (void)dup2(output[1], STDOUT_FILENO);
- (void)dup2(output[1], STDERR_FILENO);
-
- /* Close the utility's file descriptors. */
- (void)close(input[0]);
- (void)close(input[1]);
- (void)close(output[0]);
- (void)close(output[1]);
-
- if ((name = strrchr(O_STR(sp, O_SHELL), '/')) == NULL)
- name = O_STR(sp, O_SHELL);
- else
- ++name;
-
- execl(O_STR(sp, O_SHELL), name, "-c", cmd, NULL);
- msgq(sp, M_ERR, "Error: execl: %s: %s",
- O_STR(sp, O_SHELL), strerror(errno));
- _exit (127);
- /* NOTREACHED */
- default: /* Parent-reader, parent-writer. */
- SIGUNBLOCK(sp->gp);
-
- /* Close the pipe ends neither parent will use. */
- (void)close(input[0]);
- (void)close(output[1]);
- break;
- }
-
- /*
- * FILTER_READ:
- *
- * Reading is the simple case -- we don't need a parent writer,
- * so the parent reads the output from the read end of the output
- * pipe until it finishes, then waits for the child. Ex_readfp
- * appends to the MARK, and closes ofp.
- *
- * !!!
- * Set the return cursor to the last line read in. Historically,
- * this behaves differently from ":r file" command, which leaves
- * the cursor at the first line read in. Check to make sure that
- * it's not past EOF because we were reading into an empty file.
- */
- if (ftype == FILTER_READ) {
- rval = ex_readfp(sp, ep, "filter", ofp, fm, &nread, 0);
- sp->rptlines[L_ADDED] += nread;
- if (fm->lno == 0)
- rp->lno = nread;
- else
- rp->lno += nread;
- goto uwait;
- }
-
- /*
- * FILTER, FILTER_WRITE
- *
- * Here we need both a reader and a writer. Temporary files are
- * expensive and we'd like to avoid disk I/O. Using pipes has the
- * obvious starvation conditions. It's done as follows:
- *
- * fork
- * child
- * write lines out
- * exit
- * parent
- * FILTER:
- * read lines into the file
- * delete old lines
- * FILTER_WRITE
- * read and display lines
- * wait for child
- *
- * XXX
- * We get away without locking the underlying database because we know
- * that none of the records that we're reading will be modified until
- * after we've read them. This depends on the fact that the current
- * B+tree implementation doesn't balance pages or similar things when
- * it inserts new records. When the DB code has locking, we should
- * treat vi as if it were multiple applications sharing a database, and
- * do the required locking. If necessary a work-around would be to do
- * explicit locking in the line.c:file_gline() code, based on the flag
- * set here.
- */
- rval = 0;
- F_SET(ep, F_MULTILOCK);
-
- SIGBLOCK(sp->gp);
- switch (parent_writer_pid = fork()) {
- case -1: /* Error. */
- SIGUNBLOCK(sp->gp);
-
- msgq(sp, M_SYSERR, "fork");
- (void)close(input[1]);
- (void)close(output[0]);
- rval = 1;
- break;
- case 0: /* Parent-writer. */
- /*
- * Write the selected lines to the write end of the input
- * pipe. This instance of ifp is closed by ex_writefp.
- */
- (void)close(output[0]);
- if ((ifp = fdopen(input[1], "w")) == NULL)
- _exit (1);
- _exit(ex_writefp(sp, ep, "filter", ifp, fm, tm, NULL, NULL));
-
- /* NOTREACHED */
- default: /* Parent-reader. */
- SIGUNBLOCK(sp->gp);
-
- (void)close(input[1]);
- if (ftype == FILTER_WRITE)
- /*
- * Read the output from the read end of the output
- * pipe and display it. Filter_ldisplay closes ofp.
- */
- rval = filter_ldisplay(sp, ofp);
- else {
- /*
- * Read the output from the read end of the output
- * pipe. Ex_readfp appends to the MARK and closes
- * ofp.
- */
- rval = ex_readfp(sp, ep, "filter", ofp, tm, &nread, 0);
- sp->rptlines[L_ADDED] += nread;
- }
-
- /* Wait for the parent-writer. */
- rval |= proc_wait(sp,
- (long)parent_writer_pid, "parent-writer", 1);
-
- /* Delete any lines written to the utility. */
- if (rval == 0 && ftype == FILTER &&
- (cut(sp, ep, NULL, fm, tm, CUT_LINEMODE) ||
- delete(sp, ep, fm, tm, 1))) {
- rval = 1;
- break;
- }
-
- /*
- * If the filter had no output, we may have just deleted
- * the cursor. Don't do any real error correction, we'll
- * try and recover later.
- */
- if (rp->lno > 1 && file_gline(sp, ep, rp->lno, NULL) == NULL)
- --rp->lno;
- break;
- }
- F_CLR(ep, F_MULTILOCK);
-
-uwait: rval |= proc_wait(sp, (long)utility_pid, cmd, 0);
-
- /* Restore ex/vi terminal settings. */
-ret: if (teardown)
- ex_rleave(sp);
- return (rval);
-}
-
-/*
- * proc_wait --
- * Wait for one of the processes.
- *
- * !!!
- * The pid_t type varies in size from a short to a long depending on the
- * system. It has to be cast into something or the standard promotion
- * rules get you. I'm using a long based on the belief that nobody is
- * going to make it unsigned and it's unlikely to be a quad.
- */
-int
-proc_wait(sp, pid, cmd, okpipe)
- SCR *sp;
- long pid;
- const char *cmd;
- int okpipe;
-{
- extern const char *const sys_siglist[];
- size_t len;
- int pstat;
-
- /*
- * Wait for the utility to finish. We can get interrupted
- * by SIGALRM, just ignore it.
- */
- for (;;) {
- errno = 0;
- if (waitpid((pid_t)pid, &pstat, 0) != -1)
- break;
- if (errno != EINTR) {
- msgq(sp, M_SYSERR, "wait error");
- return (1);
- }
- }
-
- /*
- * Display the utility's exit status. Ignore SIGPIPE from the
- * parent-writer, as that only means that the utility chose to
- * exit before reading all of its input.
- */
- if (WIFSIGNALED(pstat) && (!okpipe || WTERMSIG(pstat) != SIGPIPE)) {
- for (; isblank(*cmd); ++cmd);
- len = strlen(cmd);
- msgq(sp, M_ERR, "%.*s%s: received signal: %s%s",
- MIN(len, 20), cmd, len > 20 ? "..." : "",
- sys_siglist[WTERMSIG(pstat)],
- WCOREDUMP(pstat) ? "; core dumped" : "");
- return (1);
- }
- if (WIFEXITED(pstat) && WEXITSTATUS(pstat)) {
- for (; isblank(*cmd); ++cmd);
- len = strlen(cmd);
- msgq(sp, M_ERR, "%.*s%s: exited with status %d",
- MIN(len, 20), cmd, len > 20 ? "..." : "",
- WEXITSTATUS(pstat));
- return (1);
- }
- return (0);
-}
-
-/*
- * filter_ldisplay --
- * Display output from a utility.
- *
- * !!!
- * Historically, the characters were passed unmodified to the terminal.
- * We use the ex print routines to make sure they're printable.
- */
-static int
-filter_ldisplay(sp, fp)
- SCR *sp;
- FILE *fp;
-{
- size_t len;
-
- EX_PRIVATE *exp;
-
- F_SET(sp, S_INTERRUPTIBLE);
- for (exp = EXP(sp); !ex_getline(sp, fp, &len);) {
- if (ex_ldisplay(sp, exp->ibp, len, 0, 0))
- break;
- if (INTERRUPTED(sp))
- break;
- }
- if (ferror(fp))
- msgq(sp, M_SYSERR, "filter input");
- (void)fclose(fp);
- return (0);
-}
diff --git a/usr.bin/vi/ex/script.h b/usr.bin/vi/ex/script.h
deleted file mode 100644
index b21c63a..0000000
--- a/usr.bin/vi/ex/script.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)script.h 8.2 (Berkeley) 4/17/94
- */
-
-struct _script {
- pid_t sh_pid; /* Shell pid. */
- int sh_master; /* Master pty fd. */
- int sh_slave; /* Slave pty fd. */
- char *sh_prompt; /* Prompt. */
- size_t sh_prompt_len; /* Prompt length. */
- char sh_name[64]; /* Pty name */
- struct winsize sh_win; /* Window size. */
- struct termios sh_term; /* Terminal information. */
-};
diff --git a/usr.bin/vi/ex/tag.h b/usr.bin/vi/ex/tag.h
deleted file mode 100644
index a9fd59d..0000000
--- a/usr.bin/vi/ex/tag.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.
- *
- * @(#)tag.h 8.13 (Berkeley) 7/17/94
- */
-
-struct _tagf { /* Tag file. */
- TAILQ_ENTRY(_tagf) q; /* Linked list of tag files. */
- char *name; /* Tag file name. */
-
-#define TAGF_DNE 0x01 /* Didn't exist. */
-#define TAGF_DNE_WARN 0x02 /* DNE error reported. */
- u_int8_t flags;
-};
-
-struct _tag { /* Tag stack. */
- TAILQ_ENTRY(_tag) q; /* Linked list of tags. */
- FREF *frp; /* Saved file name. */
- recno_t lno; /* Saved line number. */
- size_t cno; /* Saved column number. */
- char *search; /* Search string. */
- size_t slen; /* Search string length. */
-};
-
-int ex_tagalloc __P((SCR *, char *));
-int ex_tagcopy __P((SCR *, SCR *));
-int ex_tagdisplay __P((SCR *, EXF *));
-int ex_tagfirst __P((SCR *, char *));
-int ex_tagfree __P((SCR *));
diff --git a/usr.bin/vi/install/recover.script b/usr.bin/vi/install/recover.script
deleted file mode 100644
index 2fbce72..0000000
--- a/usr.bin/vi/install/recover.script
+++ /dev/null
@@ -1,46 +0,0 @@
-# @(#)recover.script 8.7 (Berkeley) 8/16/94
-#
-# Script to recover nvi edit sessions.
-#
-RECDIR=/var/tmp/vi.recover
-SENDMAIL=/usr/lib/sendmail
-echo 'Recovering nvi editor sessions.'
-
-# Check editor backup files.
-vibackup=`echo $RECDIR/vi.*`
-if [ "$vibackup" != "$RECDIR/vi.*" ]; then
- for i in $vibackup; do
- # Only test files that are readable.
- if test ! -r $i; then
- continue
- fi
-
- # Unmodified nvi editor backup files either have the
- # execute bit set or are zero length. Delete them.
- if test -x $i -o ! -s $i; then
- rm $i
- fi
- done
-fi
-
-# It is possible to get incomplete recovery files, if the editor crashes
-# at the right time.
-virecovery=`echo $RECDIR/recover.*`
-if [ "$virecovery" != "$RECDIR/recover.*" ]; then
- for i in $virecovery; do
- # Only test files that are readable.
- if test ! -r $i; then
- continue
- fi
-
- # Delete any recovery files that are zero length, corrupted,
- # or that have no corresponding backup file. Else send mail
- # to the user.
- recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
- if test -n "$recfile" -a -s "$recfile"; then
- $SENDMAIL -t < $i
- else
- rm $i
- fi
- done
-fi
diff --git a/usr.bin/vi/sex/sex_confirm.c b/usr.bin/vi/sex/sex_confirm.c
deleted file mode 100644
index f2bdcb9..0000000
--- a/usr.bin/vi/sex/sex_confirm.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)sex_confirm.c 8.9 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "sex_screen.h"
-
-enum confirm
-sex_confirm(sp, ep, fp, tp)
- SCR *sp;
- EXF *ep;
- MARK *fp, *tp;
-{
- CH ikey;
- recno_t cnt;
-
- if (ex_print(sp, ep, fp, tp, 0))
- return (CONF_QUIT);
-
- for (cnt = fp->cno; cnt; --cnt)
- (void)putc(' ', stdout);
- for (cnt = tp->cno; cnt; --cnt)
- (void)putc('^', stdout);
- (void)fprintf(stdout, "[ynq]");
-
- if (term_key(sp, &ikey, 0) != INP_OK)
- return (CONF_QUIT);
- switch (ikey.ch) {
- case CH_YES:
- return (CONF_YES);
- case CH_QUIT:
- return (CONF_QUIT);
- default:
- case CH_NO:
- return (CONF_NO);
- }
- /* NOTREACHED */
-}
diff --git a/usr.bin/vi/sex/sex_get.c b/usr.bin/vi/sex/sex_get.c
deleted file mode 100644
index 45092af..0000000
--- a/usr.bin/vi/sex/sex_get.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)sex_get.c 8.39 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../vi/vcmd.h"
-#include "sex_screen.h"
-
-/*
- * !!!
- * The ex input didn't have escape characters like ^V. The only special
- * character was the backslash character, and that only when it preceded
- * a newline as part of a substitution replacement pattern. For example,
- * the command input ":a\<cr>" failed immediately with an error, as the
- * <cr> wasn't part of a substitution replacement pattern. This implies
- * a frightening integration of the editor and the RE engine. There's no
- * way we're going to reproduce those semantics. So, if backslashes are
- * special, this code inserts the backslash and the next character into the
- * string, without regard for the character or the command being entered.
- * Since "\<cr>" was illegal historically (except for the one special case),
- * and the command will fail eventually, historical scripts shouldn't break
- * (presuming they didn't depend on the failure mode itself or the characters
- * remaining when failure occurred.
- */
-static void txt_display __P((SCR *, TEXT *, size_t, size_t *));
-static int txt_outdent __P((SCR *, TEXT *));
-
-#define ERASECH { \
- for (cnt = tp->wd[tp->len]; cnt-- > 0; --col) \
- (void)printf("\b \b"); \
-}
-
-/*
- * sex_get --
- * Get lines from the terminal for ex.
- */
-enum input
-sex_get(sp, ep, tiqh, prompt, flags)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
- ARG_CHAR_T prompt;
- u_int flags;
-{
- /* State of the "[^0]^D" sequences. */
- enum { C_NOTSET, C_CARATSET, C_NOCHANGE, C_ZEROSET } carat_st;
- TEXT *ntp, *tp, ait; /* Input and autoindent text structures. */
- CH ikey; /* Input character. */
- size_t col; /* 0-N: screen column. */
- size_t cnt;
- int rval, istty;
-
- /*
- * !!!
- * Most of the special capabilities (like autoindent, erase,
- * etc.) are turned off if ex isn't talking to a terminal.
- */
- istty = F_ISSET(sp->gp, G_STDIN_TTY);
-
- /*
- * Get a 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 (tiqh->cqh_first != (void *)tiqh) {
- tp = tiqh->cqh_first;
- if (tp->q.cqe_next != (void *)tiqh || tp->lb_len < 32) {
- text_lfree(tiqh);
- goto newtp;
- }
- tp->len = 0;
- } else {
-newtp: if ((tp = text_init(sp, NULL, 0, 32)) == NULL)
- return (INP_ERR);
- CIRCLEQ_INSERT_HEAD(tiqh, tp, q);
- }
-
- if (istty) {
- /* Display the prompt. */
- if (LF_ISSET(TXT_PROMPT)) {
- col = KEY_LEN(sp, prompt);
- (void)printf("%s", KEY_NAME(sp, prompt));
- }
-
- /* Initialize autoindent value and print it out. */
- if (LF_ISSET(TXT_AUTOINDENT)) {
- if (txt_auto(sp, ep, sp->lno, NULL, 0, tp))
- return (INP_ERR);
- BINC_GOTO(sp, tp->wd, tp->wd_len, tp->len + 1);
- for (cnt = 0; cnt < tp->ai; ++cnt)
- txt_display(sp, tp, cnt, &col);
- }
- } else {
- col = 0;
-
- /* Turn off autoindent here, less special casing below. */
- LF_CLR(TXT_AUTOINDENT);
- }
-
- for (carat_st = C_NOTSET;;) {
- if (istty)
- (void)fflush(stdout);
- /*
- * !!!
- * Historically, ex never mapped commands or keys.
- */
- if (rval = term_key(sp, &ikey, 0))
- return (rval);
-
- if (INTERRUPTED(sp))
- return (INP_INTR);
-
- BINC_GOTO(sp, tp->lb, tp->lb_len, tp->len + 1);
- BINC_GOTO(sp, tp->wd, tp->wd_len, tp->len + 1);
-
- switch (ikey.value) {
- case K_CR:
- case K_NL:
- /* '\' can escape <carriage-return>/<newline>. */
- if (LF_ISSET(TXT_BACKSLASH) &&
- tp->len != 0 && tp->lb[tp->len - 1] == '\\')
- goto ins_ch;
-
- /* Echo the newline if requested. */
- if (istty && LF_ISSET(TXT_NLECHO)) {
- (void)putc('\r', stdout);
- (void)putc('\n', stdout);
- (void)fflush(stdout);
- }
-
- /*
- * CR returns from the ex command line, interrupt
- * always returns.
- */
- if (LF_ISSET(TXT_CR)) {
- /* Terminate with a nul, needed by filter. */
- tp->lb[tp->len] = '\0';
- return (INP_OK);
- }
-
- /* '.' terminates ex input modes. */
- if (LF_ISSET(TXT_DOTTERM) &&
- tp->len == tp->ai + 1 &&
- tp->lb[tp->len - 1] == '.') {
- /* Release the current TEXT. */
- ntp = tp->q.cqe_prev;
- CIRCLEQ_REMOVE(tiqh, tp, q);
- text_free(tp);
- tp = ntp;
- return (INP_OK);
- }
-
- /*
- * If we echoed the newline, display any accumulated
- * error messages.
- */
- if (LF_ISSET(TXT_NLECHO) && sex_refresh(sp, ep))
- return (INP_ERR);
-
- /* Set up bookkeeping for the new line. */
- if ((ntp = text_init(sp, NULL, 0, 32)) == NULL)
- return (INP_ERR);
- ntp->lno = tp->lno + 1;
-
- /*
- * 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.
- */
- col = 0;
- if (LF_ISSET(TXT_AUTOINDENT)) {
- if (carat_st == C_NOCHANGE) {
- if (txt_auto(sp, ep,
- OOBLNO, &ait, ait.ai, ntp))
- return (INP_ERR);
- FREE_SPACE(sp, ait.lb, ait.lb_len);
- } else
- if (txt_auto(sp, ep,
- OOBLNO, tp, tp->len, ntp))
- return (INP_ERR);
- carat_st = C_NOTSET;
-
- if (ntp->ai) {
- BINC_GOTO(sp,
- ntp->wd, ntp->wd_len, ntp->len + 1);
- for (cnt = 0; cnt < ntp->ai; ++cnt)
- txt_display(sp, ntp, cnt, &col);
- }
- }
- /*
- * Swap old and new TEXT's, and insert the new TEXT
- * into the queue.
- */
- tp = ntp;
- CIRCLEQ_INSERT_TAIL(tiqh, tp, q);
- break;
- case K_CARAT: /* Delete autoindent chars. */
- if (LF_ISSET(TXT_AUTOINDENT) && tp->len <= tp->ai)
- carat_st = C_CARATSET;
- goto ins_ch;
- case K_ZERO: /* Delete autoindent chars. */
- if (LF_ISSET(TXT_AUTOINDENT) && tp->len <= tp->ai)
- carat_st = C_ZEROSET;
- goto ins_ch;
- case K_CNTRLD: /* Delete autoindent char. */
- /*
- * !!!
- * Historically, the ^D command took (but then ignored)
- * a count. For simplicity, we don't return it unless
- * it's the first character entered. The check for len
- * equal to 0 is okay, TXT_AUTOINDENT won't be set.
- */
- if (LF_ISSET(TXT_CNTRLD)) {
- for (cnt = 0; cnt < tp->len; ++cnt)
- if (!isblank(tp->lb[cnt]))
- break;
- if (cnt == tp->len) {
- tp->len = 1;
- tp->lb[0] = '\004';
- tp->lb[1] = '\0';
- return (INP_OK);
- }
- }
-
- /*
- * 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 (tp->len == 0)
- break;
- switch (carat_st) {
- case C_CARATSET: /* ^^D */
- if (tp->len > tp->ai + 1)
- goto ins_ch;
- /* Save the ai string for later. */
- ait.lb = NULL;
- ait.lb_len = 0;
- BINC_GOTO(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 (tp->len > tp->ai + 1)
- goto ins_ch;
- carat_st = C_NOTSET;
-leftmargin: (void)printf("\b \r");
- tp->ai = tp->len = 0;
- break;
- case C_NOTSET: /* ^D */
- if (tp->len > tp->ai)
- goto ins_ch;
- if (txt_outdent(sp, tp))
- return (INP_ERR);
- break;
- default:
- abort();
- }
- break;
- case K_VERASE:
- if (!istty)
- goto ins_ch;
- if (tp->len) {
- --tp->len;
- if (tp->lb[tp->len] == '\n' ||
- tp->lb[tp->len] == '\r')
- goto repaint;
- ERASECH;
- }
- break;
- case K_VWERASE:
- if (!istty)
- goto ins_ch;
-
- /* Move to the last non-space character. */
- while (tp->len) {
- --tp->len;
- if (tp->lb[tp->len] == '\n' ||
- tp->lb[tp->len] == '\r')
- goto repaint;
- if (!isblank(tp->lb[tp->len])) {
- ++tp->len;
- break;
- } else
- ERASECH;
- }
-
- /* Move to the last space character. */
- while (tp->len) {
- --tp->len;
- if (tp->lb[tp->len] == '\n' ||
- tp->lb[tp->len] == '\r')
- goto repaint;
- if (isblank(tp->lb[tp->len])) {
- ++tp->len;
- break;
- } else
- ERASECH;
- }
- break;
- case K_VKILL:
- if (!istty)
- goto ins_ch;
- while (tp->len) {
- --tp->len;
- if (tp->lb[tp->len] == '\n' ||
- tp->lb[tp->len] == '\r') {
- tp->len = 0;
- goto repaint;
- }
- ERASECH;
- }
- break;
- /*
- * XXX
- * Historic practice is that ^Z suspended command mode, and
- * that it was unaffected by the autowrite option. ^Z ended
- * insert mode, retaining all but the current line of input,
- * which was discarded. When ex was foregrounded, it was in
- * command mode. I don't want to discard input because a user
- * tried to enter a ^Z, and I'd like to be consistent with vi.
- * So, nex matches vi's historic practice, and doesn't permit
- * ^Z in input mode.
- */
- case K_CNTRLZ:
- if (!istty || !LF_ISSET(TXT_EXSUSPEND))
- goto ins_ch;
- sex_suspend(sp);
- goto repaint;
- case K_CNTRLR:
- if (!istty)
- goto ins_ch;
-repaint: if (LF_ISSET(TXT_PROMPT)) {
- col = KEY_LEN(sp, prompt);
- (void)printf("\r%s", KEY_NAME(sp, prompt));
- } else {
- col = 0;
- (void)putc('\r', stdout);
- }
- for (cnt = 0; cnt < tp->len; ++cnt)
- txt_display(sp, tp, cnt, &col);
- break;
- default:
- /*
- * See the TXT_BEAUTIFY comment in vi/v_ntext.c.
- *
- * Silently eliminate any iscntrl() character that
- * wasn't already handled specially, except for <tab>
- * and <ff>.
- */
-ins_ch: if (LF_ISSET(TXT_BEAUTIFY) && iscntrl(ikey.ch) &&
- ikey.value != K_FORMFEED && ikey.value != K_TAB)
- break;
- tp->lb[tp->len] = ikey.ch;
- if (istty)
- txt_display(sp, tp, tp->len, &col);
- ++tp->len;
- break;
- }
- }
- /* NOTREACHED */
-
-binc_err:
- return (INP_ERR);
-}
-
-/*
- * txt_display --
- * Display the character.
- */
-static void
-txt_display(sp, tp, off, colp)
- SCR *sp;
- TEXT *tp;
- size_t off, *colp;
-{
- CHAR_T ch;
- size_t width;
-
- switch (ch = tp->lb[off]) {
- case '\t':
- *colp += tp->wd[off] = width =
- O_VAL(sp, O_TABSTOP) - *colp % O_VAL(sp, O_TABSTOP);
- while (width--)
- putc(' ', stdout);
- break;
- case '\n':
- case '\r':
- (void)putc('\r', stdout);
- (void)putc('\n', stdout);
- break;
- default:
- *colp += tp->wd[off] = KEY_LEN(sp, ch);
- (void)printf("%s", KEY_NAME(sp, ch));
- }
-}
-
-/*
- * txt_outdent --
- * Handle ^D outdents.
- *
- * Ex version of vi/v_ntext.c:txt_outdent(). See that code for the
- * usual ranting and raving.
- */
-static int
-txt_outdent(sp, tp)
- SCR *sp;
- TEXT *tp;
-{
- u_long sw, ts;
- size_t cno, cnt, 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 < tp->len; ++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; --tp->ai) {
- for (cnt = tp->wd[--tp->len]; cnt-- > 0;)
- (void)printf("\b \b");
- 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);
-
- /* Maybe that was enough. */
- if (spaces == 0)
- return (0);
-
- /* Add new space characters. */
- for (; spaces--; ++tp->ai)
- tp->lb[tp->len++] = ' ';
- return (0);
-}
diff --git a/usr.bin/vi/sex/sex_refresh.c b/usr.bin/vi/sex/sex_refresh.c
deleted file mode 100644
index d665268..0000000
--- a/usr.bin/vi/sex/sex_refresh.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)sex_refresh.c 8.16 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "sex_screen.h"
-
-#ifndef SYSV_CURSES
-#define A_NORMAL 1
-#define A_STANDOUT 2
-#define vidattr(attr) Xvidattr(sp, attr)
-
-static int Xvidattr __P((SCR *, int));
-#endif
-
-/*
- * sex_refresh --
- * In ex, just display any messages.
- */
-int
-sex_refresh(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- MSG *mp;
-
- /* Check for screen resize. */
- if (F_ISSET(sp, S_RESIZE)) {
- sp->rows = O_VAL(sp, O_LINES);
- sp->cols = O_VAL(sp, O_COLUMNS);
- F_CLR(sp, S_RESIZE);
- }
-
- /* Ring the bell. */
- if (F_ISSET(sp, S_BELLSCHED)) {
- sex_bell(sp);
- F_CLR(sp, S_BELLSCHED);
- }
-
- /* Display messages. */
- for (mp = sp->msgq.lh_first;
- mp != NULL && !(F_ISSET(mp, M_EMPTY)); mp = mp->q.le_next) {
- if (F_ISSET(mp, M_INV_VIDEO) &&
- vidattr(A_STANDOUT) == ERR && O_ISSET(sp, O_ERRORBELLS))
- (void)printf("\07");
- (void)printf("%.*s.\n", (int)mp->len, mp->mbuf);
- F_SET(mp, M_EMPTY);
-
- if (F_ISSET(mp, M_INV_VIDEO))
- vidattr(A_NORMAL);
- (void)fflush(stdout);
- }
- return (0);
-}
-
-#ifndef SYSV_CURSES
-/*
- * Xvidattr --
- * Set the video attributes to a value.
- *
- * XXX
- * Just enough to make the above code work when using non-System V
- * curses.
- */
-static int
-Xvidattr(sp, attr)
- SCR *sp;
- int attr;
-{
- SEX_PRIVATE *sxp;
-
- sxp = SXP(sp);
-
- /* Check to see if standout isn't available. */
- if (sxp->SO == NULL)
- return (ERR);
-
- switch (attr) {
- case A_NORMAL:
- (void)tputs(SXP(sp)->SE, 1, vi_putchar);
- break;
- case A_STANDOUT:
- (void)tputs(SXP(sp)->SO, 1, vi_putchar);
- break;
- default:
- abort();
- }
- return (0);
-}
-#endif
diff --git a/usr.bin/vi/sex/sex_screen.c b/usr.bin/vi/sex/sex_screen.c
deleted file mode 100644
index 606ff5e..0000000
--- a/usr.bin/vi/sex/sex_screen.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)sex_screen.c 8.49 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "sex_screen.h"
-#include "../svi/svi_screen.h"
-
-static void sex_abort __P((void));
-static int sex_noop __P((void));
-static int sex_nope __P((SCR *));
-static int sex_term_init __P((SCR *));
-static void so_se_init __P((SCR *));
-
-/*
- * sex_screen_init --
- * Initialize the ex screen.
- */
-int
-sex_screen_init(sp)
- SCR *sp;
-{
- /* Initialize support routines. */
- sp->s_bell = sex_bell;
- sp->s_bg = (int (*)())sex_nope;
- sp->s_busy = (int (*)())sex_busy;
- sp->s_change = (int (*)())sex_noop;
- sp->s_clear = (int (*)())sex_noop;
- sp->s_colpos = (size_t (*)())sex_abort;
- sp->s_column = (int (*)())sex_abort;
- sp->s_confirm = sex_confirm;
- sp->s_crel = (int (*)())sex_nope;
- sp->s_edit = sex_screen_edit;
- sp->s_end = (int (*)())sex_noop;
- sp->s_ex_cmd = (int (*)())sex_abort;
- sp->s_ex_run = (int (*)())sex_abort;
- sp->s_ex_write = (int (*)())sex_abort;
- sp->s_fg = (int (*)())sex_nope;
- sp->s_fill = (int (*)())sex_abort;
- sp->s_get = sex_get;
- sp->s_key_read = sex_key_read;
- sp->s_optchange = sex_optchange;
- sp->s_fmap = (int (*)())sex_noop;
- sp->s_position = (int (*)())sex_abort;
- sp->s_rabs = (int (*)())sex_nope;
- sp->s_rcm = (size_t (*)())sex_abort;
- sp->s_refresh = sex_refresh;
- sp->s_scroll = (int (*)())sex_abort;
- sp->s_split = (int (*)())sex_nope;
- sp->s_suspend = sex_suspend;
- sp->s_window = sex_window;
-
- return (0);
-}
-
-/*
- * sex_screen_copy --
- * Copy to a new screen.
- */
-int
-sex_screen_copy(orig, sp)
- SCR *orig, *sp;
-{
- SEX_PRIVATE *osex, *nsex;
-
- /* Create the private screen structure. */
- CALLOC_RET(orig, nsex, SEX_PRIVATE *, 1, sizeof(SEX_PRIVATE));
- sp->sex_private = nsex;
-
-/* INITIALIZED AT SCREEN CREATE. */
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
- if (orig == NULL) {
- } else {
- osex = SXP(orig);
-#ifndef SYSV_CURSES
- if (osex->SE != NULL && (nsex->SE = strdup(osex->SE)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
- if (osex->SO != NULL && (nsex->SO = strdup(osex->SO)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- free(osex->SE);
- return (1);
- }
-#endif
- }
-
- return (0);
-}
-
-/*
- * sex_screen_end --
- * End a screen.
- */
-int
-sex_screen_end(sp)
- SCR *sp;
-{
-#ifndef SYSV_CURSES
- /* Free inverse video strings. */
- if (SXP(sp)->SE != NULL)
- free(SXP(sp)->SE);
- if (SXP(sp)->SO != NULL)
- free(SXP(sp)->SO);
-#endif
-
- /* Free private memory. */
- FREE(SXP(sp), sizeof(SEX_PRIVATE));
- sp->sex_private = NULL;
-
- return (0);
-}
-
-/*
- * sex_screen_edit --
- * Main ex screen loop. The ex screen is relatively uncomplicated.
- * As long as it has a stdio FILE pointer for output, it's happy.
- */
-int
-sex_screen_edit(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- struct termios t;
- GS *gp;
- int force, rval;
-
- /* Initialize the terminal state. */
- gp = sp->gp;
- if (F_ISSET(gp, G_STDIN_TTY))
- SEX_RAW(t);
-
- /* Write to the terminal. */
- sp->stdfp = stdout;
-
- /*
- * The resize bit is probably set, but clear it, we're
- * going to initialize the screen right now.
- */
- F_CLR(sp, S_RESIZE);
-
- /* Initialize the termcap buffer. */
- if (sex_term_init(sp))
- return (1);
-
- for (;;) {
- /*
- * Run ex. If ex fails, sex data structures
- * may be corrupted, be careful what you do.
- */
- if (rval = ex(sp, sp->ep)) {
- (void)rcv_sync(sp, sp->ep,
- RCV_EMAIL | RCV_ENDSESSION | RCV_PRESERVE);
- (void)screen_end(sp); /* General SCR info. */
- break;
- }
-
- force = 0;
- switch (F_ISSET(sp, S_MAJOR_CHANGE)) {
- case S_EXIT_FORCE:
- force = 1;
- /* FALLTHROUGH */
- case S_EXIT:
- F_CLR(sp, S_EXIT_FORCE | S_EXIT);
- if (file_end(sp, sp->ep, force))
- break;
- (void)screen_end(sp); /* General SCR info. */
- goto ret;
- case 0: /* Changing from ex mode. */
- goto ret;
- case S_FSWITCH:
- F_CLR(sp, S_FSWITCH);
- break;
- case S_SSWITCH:
- default:
- abort();
- }
- }
-
- /* Reset the terminal state. */
-ret: if (F_ISSET(gp, G_STDIN_TTY) && SEX_NORAW(t))
- rval = 1;
- return (rval);
-}
-
-/*
- * sex_term_init --
- * Initialize ex's relationship with the termcap/terminfo entry.
- */
-static int
-sex_term_init(sp)
- SCR *sp;
-{
-
-#ifndef SYSV_CURSES
- /* Initialize standout information. */
- so_se_init(sp);
-#endif
-
- sp->rows = O_VAL(sp, O_LINES);
- sp->cols = O_VAL(sp, O_COLUMNS);
- return (0);
-}
-
-#ifndef SYSV_CURSES
-/*
- * so_se_init --
- * Initialize the inverse video strings.
- */
-static void
-so_se_init(sp)
- SCR *sp;
-{
- SEX_PRIVATE *sxp;
- size_t len;
- char *s, *t, buf[128], tbuf[2048];
-
- if (tgetent(tbuf, O_STR(sp, O_TERM)) != 1)
- return;
-
- sxp = SXP(sp);
-
- /* Get SE. */
- t = buf;
- if ((t = tgetstr("se", &t)) == NULL)
- return;
- if ((len = strlen(t)) == 0)
- return;
- MALLOC_NOMSG(sp, s, char *, len + 1);
- if (s == NULL)
- return;
- memmove(s, buf, len);
- s[len] = '\0';
- sxp->SE = s;
-
- /* Get SO. */
- t = buf;
- if ((t = tgetstr("so", &t)) == NULL)
- goto err;
- if ((len = strlen(t)) == 0)
- goto err;
- MALLOC_NOMSG(sp, s, char *, len + 1);
- if (s == NULL)
- goto err;
- memmove(s, buf, len);
- s[len] = '\0';
- sxp->SO = s;
-
- return;
-
-err: free(sxp->SE);
- sxp->SE = NULL;
- return;
-}
-#endif
-
-/*
- * sex_abort --
- * Fake function. Die.
- */
-static void
-sex_abort()
-{
- abort();
-}
-
-/*
- * sex_noop --
- * Fake function. Do nothing.
- */
-static int
-sex_noop()
-{
- return (0);
-}
-
-/*
- * sex_nope --
- * Fake function. Not in ex, you don't.
- */
-static int
-sex_nope(sp)
- SCR *sp;
-{
- msgq(sp, M_ERR, "Command not applicable to ex mode");
- return (1);
-}
diff --git a/usr.bin/vi/sex/sex_screen.h b/usr.bin/vi/sex/sex_screen.h
deleted file mode 100644
index a2dfeb8..0000000
--- a/usr.bin/vi/sex/sex_screen.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)sex_screen.h 8.20 (Berkeley) 8/8/94
- */
-
-#define SEX_NORAW(t) \
- tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &(t))
-
-#define SEX_RAW(t) { \
- struct termios __rawt; \
- if (tcgetattr(STDIN_FILENO, &(t))) \
- return (1); \
- __rawt = (t); \
- __rawt.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INLCR|IGNCR|ICRNL); \
- __rawt.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); \
- __rawt.c_oflag |= OPOST | ONLCR; \
- __rawt.c_cc[VMIN] = 1; \
- __rawt.c_cc[VTIME] = 0; \
- if (tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &__rawt)) \
- return (1); \
-}
-
-typedef struct _sex_private {
-/* INITIALIZED AT SCREEN CREATE. */
- int __sex_unused; /* Make sure it's not empty. */
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
-#ifndef SYSV_CURSES
- char *SE, *SO; /* Inverse video termcap strings. */
-#endif
-} SEX_PRIVATE;
-
-#define SXP(sp) ((SEX_PRIVATE *)((sp)->sex_private))
-
-void sex_bell __P((SCR *));
-void sex_busy __P((SCR *, char const *));
-enum confirm
- sex_confirm __P((SCR *, EXF *, MARK *, MARK *));
-enum input
- sex_get __P((SCR *, EXF *, TEXTH *, ARG_CHAR_T, u_int));
-enum input
- sex_key_read __P((SCR *, int *, struct timeval *));
-int sex_optchange __P((SCR *, int));
-int sex_refresh __P((SCR *, EXF *));
-int sex_screen_copy __P((SCR *, SCR *));
-int sex_screen_edit __P((SCR *, EXF *));
-int sex_screen_end __P((SCR *));
-int sex_suspend __P((SCR *));
-int sex_window __P((SCR *, int));
diff --git a/usr.bin/vi/sex/sex_term.c b/usr.bin/vi/sex/sex_term.c
deleted file mode 100644
index 1eaf34b..0000000
--- a/usr.bin/vi/sex/sex_term.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)sex_term.c 8.40 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "../ex/script.h"
-
-/*
- * sex_key_read --
- * Read characters from the input.
- */
-enum input
-sex_key_read(sp, nrp, timeout)
- SCR *sp;
- int *nrp;
- struct timeval *timeout;
-{
- struct timeval t, *tp;
- GS *gp;
- IBUF *tty;
- int maxfd, nr;
-
- *nrp = 0;
- gp = sp->gp;
- tty = gp->tty;
-
- /*
- * We're about to block; check for signals. If a signal received,
- * clear it immediately, so that if it's reset while being serviced
- * we won't miss it.
- *
- * These signal recipients set global flags. None of this has
- * anything to do with input keys, but it's something that can't
- * be done asynchronously without adding locking to handle race
- * conditions, and which needs to be done periodically.
- */
-sigchk: while (F_ISSET(gp, G_SIGINT | G_SIGWINCH)) {
- if (F_ISSET(gp, G_SIGINT))
- return (INP_INTR);
- if (F_ISSET(gp, G_SIGWINCH)) {
- F_CLR(gp, G_SIGWINCH);
- if (!sp->s_window(sp, 1))
- (void)sp->s_refresh(sp, sp->ep);
- }
- }
-
- /*
- * There are three cases here:
- *
- * 1: A read from a file or a pipe. In this case, the reads
- * never timeout regardless. This means that we can hang
- * when trying to complete a map, but we're going to hang
- * on the next read anyway.
- */
- if (!F_ISSET(gp, G_STDIN_TTY)) {
- if ((nr = read(STDIN_FILENO,
- tty->ch + tty->next + tty->cnt,
- tty->nelem - (tty->next + tty->cnt))) > 0)
- goto success;
- return (INP_EOF);
- }
-
- /*
- * 2: A read with an associated timeout. In this case, we are trying
- * to complete a map sequence. Ignore script windows and timeout
- * as specified. If input arrives, we fall into #3, but because
- * timeout isn't NULL, don't read anything but command input.
- *
- * If interrupted, go back and check to see what it was.
- */
- if (timeout != NULL) {
- if (F_ISSET(sp, S_SCRIPT))
- FD_CLR(sp->script->sh_master, &sp->rdfd);
- FD_SET(STDIN_FILENO, &sp->rdfd);
- for (;;) {
- switch (select(STDIN_FILENO + 1,
- &sp->rdfd, NULL, NULL, timeout)) {
- case -1: /* Error or interrupt. */
- if (errno == EINTR)
- goto sigchk;
- goto err;
- case 1: /* Characters ready. */
- break;
- case 0: /* Timeout. */
- return (INP_OK);
- }
- break;
- }
- }
-
- /*
- * 3: At this point, we'll take anything that comes. Select on the
- * command file descriptor and the file descriptor for the script
- * window if there is one. Poll the fd's, increasing the timeout
- * each time each time we don't get anything until we're blocked
- * on I/O.
- *
- * If interrupted, go back and check to see what it was.
- */
- for (t.tv_sec = t.tv_usec = 0;;) {
- /*
- * Reset each time -- sscr_input() may call other
- * routines which could reset bits.
- */
- if (timeout == NULL && F_ISSET(sp, S_SCRIPT)) {
- tp = &t;
-
- FD_SET(STDIN_FILENO, &sp->rdfd);
- if (F_ISSET(sp, S_SCRIPT)) {
- FD_SET(sp->script->sh_master, &sp->rdfd);
- maxfd =
- MAX(STDIN_FILENO, sp->script->sh_master);
- } else
- maxfd = STDIN_FILENO;
- } else {
- tp = NULL;
-
- FD_SET(STDIN_FILENO, &sp->rdfd);
- if (F_ISSET(sp, S_SCRIPT))
- FD_CLR(sp->script->sh_master, &sp->rdfd);
- maxfd = STDIN_FILENO;
- }
-
- switch (select(maxfd + 1, &sp->rdfd, NULL, NULL, tp)) {
- case -1: /* Error or interrupt. */
- if (errno == EINTR)
- goto sigchk;
-err: msgq(sp, M_SYSERR, "select");
- return (INP_ERR);
- case 0: /* Timeout. */
- if (t.tv_usec) {
- ++t.tv_sec;
- t.tv_usec = 0;
- } else
- t.tv_usec += 500000;
- continue;
- }
-
- if (timeout == NULL && F_ISSET(sp, S_SCRIPT) &&
- FD_ISSET(sp->script->sh_master, &sp->rdfd)) {
- sscr_input(sp);
- continue;
- }
-
- switch (nr = read(STDIN_FILENO,
- tty->ch + tty->next + tty->cnt,
- tty->nelem - (tty->next + tty->cnt))) {
- case 0: /* EOF. */
- return (INP_EOF);
- case -1: /* Error or interrupt. */
- if (errno == EINTR)
- goto sigchk;
- msgq(sp, M_SYSERR, "read");
- return (INP_ERR);
- default:
- goto success;
- }
- /* NOTREACHED */
- }
-
-success:
- MEMSET(tty->chf + tty->next + tty->cnt, 0, nr);
- tty->cnt += *nrp = nr;
- return (INP_OK);
-}
diff --git a/usr.bin/vi/sex/sex_util.c b/usr.bin/vi/sex/sex_util.c
deleted file mode 100644
index 482c358..0000000
--- a/usr.bin/vi/sex/sex_util.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)sex_util.c 8.17 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "sex_screen.h"
-
-/*
- * sex_bell --
- * Ring the bell.
- */
-void
-sex_bell(sp)
- SCR *sp;
-{
- (void)write(STDOUT_FILENO, "\07", 1); /* \a */
-}
-
-void
-sex_busy(sp, msg)
- SCR *sp;
- char const *msg;
-{
- (void)fprintf(stdout, "%s\n", msg);
- (void)fflush(stdout);
-}
-
-/*
- * sex_optchange --
- * Screen specific "option changed" routine.
- */
-int
-sex_optchange(sp, opt)
- SCR *sp;
- int opt;
-{
- switch (opt) {
- case O_TERM:
- /* Reset the screen size. */
- if (sp->s_window(sp, 0))
- return (1);
- F_SET(sp, S_RESIZE);
- break;
- }
-
- (void)ex_optchange(sp, opt);
-
- return (0);
-}
-
-/*
- * sex_suspend --
- * Suspend an ex screen.
- */
-int
-sex_suspend(sp)
- SCR *sp;
-{
- struct termios t;
- GS *gp;
- int rval;
-
- rval = 0;
-
- /* Save current terminal settings, and restore the original ones. */
- gp = sp->gp;
- if (F_ISSET(gp, G_STDIN_TTY)) {
- if (tcgetattr(STDIN_FILENO, &t)) {
- msgq(sp, M_SYSERR, "suspend: tcgetattr");
- return (1);
- }
- if (F_ISSET(gp, G_TERMIOS_SET) && tcsetattr(STDIN_FILENO,
- TCSASOFT | TCSADRAIN, &gp->original_termios)) {
- msgq(sp, M_SYSERR, "suspend: tcsetattr original");
- return (1);
- }
- }
-
- /* Push out any waiting messages. */
- (void)sex_refresh(sp, sp->ep);
-
- /* Stop the process group. */
- if (kill(0, SIGTSTP)) {
- msgq(sp, M_SYSERR, "suspend: kill");
- rval = 1;
- }
-
- /* Time passes ... */
-
- /* Restore current terminal settings. */
- if (F_ISSET(gp, G_STDIN_TTY) &&
- tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t)) {
- msgq(sp, M_SYSERR, "suspend: tcsetattr current");
- rval = 1;
- }
- return (rval);
-}
diff --git a/usr.bin/vi/sex/sex_window.c b/usr.bin/vi/sex/sex_window.c
deleted file mode 100644
index 61000fb..0000000
--- a/usr.bin/vi/sex/sex_window.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)sex_window.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * sex_window --
- * Set the window size.
- */
-int
-sex_window(sp, sigwinch)
- SCR *sp;
- int sigwinch;
-{
- struct winsize win;
- size_t col, row;
- int rval, user_set;
- ARGS *argv[2], a, b;
- char *s, buf[2048];
-
- /*
- * Get the screen rows and columns. If the values are wrong, it's
- * not a big deal -- as soon as the user sets them explicitly the
- * environment will be set and the screen package will use the new
- * values.
- *
- * Try TIOCGWINSZ.
- */
- errno = row = col = 0;
-#ifdef TIOCGWINSZ
- if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) != -1) {
- row = win.ws_row;
- col = win.ws_col;
- }
-#endif
- /* If here because of a signal, TIOCGWINSZ is all we trust. */
- if (sigwinch) {
- if (row == 0 || col == 0) {
- if (errno > 0)
- msgq(sp, M_SYSERR, "TIOCGWINSZ");
- return (1);
- }
-
- /*
- * !!!
- * SunOS systems deliver SIGWINCH when windows are uncovered
- * as well as when they change size. In addition, we call
- * here when continuing after being suspended since the window
- * may have changed size. Since we don't want to background
- * all of the screens just because the window was uncovered,
- * ignore the signal if there's no change.
- */
- if (row == O_VAL(sp, O_LINES) && col == O_VAL(sp, O_COLUMNS))
- return (1);
-
- goto sigw;
- }
-
- /*
- * !!!
- * If TIOCGWINSZ failed, or had entries of 0, try termcap. This
- * routine is called before any termcap or terminal information
- * has been set up. If there's no TERM environmental variable set,
- * let it go, at least ex can run.
- */
- if (row == 0 || col == 0) {
- if ((s = getenv("TERM")) == NULL)
- goto noterm;
-#ifdef SYSV_CURSES
- if (row == 0)
- if ((rval = tigetnum("lines")) < 0)
- msgq(sp, M_SYSERR, "tigetnum: lines");
- else
- row = rval;
- if (col == 0)
- if ((rval = tigetnum("cols")) < 0)
- msgq(sp, M_SYSERR, "tigetnum: cols");
- else
- col = rval;
-#else
- switch (tgetent(buf, s)) {
- case -1:
- msgq(sp, M_SYSERR, "tgetent: %s", s);
- return (1);
- case 0:
- msgq(sp, M_ERR, "%s: unknown terminal type", s);
- return (1);
- }
- if (row == 0)
- if ((rval = tgetnum("li")) < 0)
- msgq(sp, M_ERR,
- "no \"li\" capability for %s", s);
- else
- row = rval;
- if (col == 0)
- if ((rval = tgetnum("co")) < 0)
- msgq(sp, M_ERR,
- "no \"co\" capability for %s", s);
- else
- col = rval;
-#endif
- }
-
- /* If nothing else, well, it's probably a VT100. */
-noterm: if (row == 0)
- row = 24;
- if (col == 0)
- col = 80;
-
- /* POSIX 1003.2 requires the environment to override. */
- if ((s = getenv("LINES")) != NULL)
- row = strtol(s, NULL, 10);
- if ((s = getenv("COLUMNS")) != NULL)
- col = strtol(s, NULL, 10);
-
-sigw: a.bp = buf;
- b.bp = NULL;
- b.len = 0;
- argv[0] = &a;
- argv[1] = &b;;
-
- /*
- * Tell the options code that the screen size has changed.
- * Since the user didn't do the set, clear the set bits.
- */
- user_set = F_ISSET(&sp->opts[O_LINES], OPT_SET);
- a.len = snprintf(buf, sizeof(buf), "lines=%u", row);
- if (opts_set(sp, NULL, argv))
- return (1);
- if (user_set)
- F_CLR(&sp->opts[O_LINES], OPT_SET);
-
- user_set = F_ISSET(&sp->opts[O_COLUMNS], OPT_SET);
- a.len = snprintf(buf, sizeof(buf), "columns=%u", col);
- if (opts_set(sp, NULL, argv))
- return (1);
- if (user_set)
- F_CLR(&sp->opts[O_COLUMNS], OPT_SET);
-
- F_SET(sp, S_RESIZE);
- return (0);
-}
diff --git a/usr.bin/vi/svi/svi_confirm.c b/usr.bin/vi/svi/svi_confirm.c
deleted file mode 100644
index e3f703e..0000000
--- a/usr.bin/vi/svi/svi_confirm.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)svi_confirm.c 8.10 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "svi_screen.h"
-
-enum confirm
-svi_confirm(sp, ep, fp, tp)
- SCR *sp;
- EXF *ep;
- MARK *fp, *tp;
-{
- CH ikey;
- size_t oldy, oldx;
-
- /*
- * Refresh the cursor first -- this means that we won't have to
- * set S_UPDATE_MODE to keep refresh from erasing the mode line
- * or SVI_CUR_INVALID because we sneaked the cursor off somewhere
- * else.
- */
- sp->lno = fp->lno;
- sp->cno = fp->cno;
- if (svi_paint(sp, ep))
- return (CONF_QUIT);
-
- getyx(stdscr, oldy, oldx);
- MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
- ADDNSTR(STR_CONFIRM, sizeof(STR_CONFIRM) - 1);
- MOVEA(sp, oldy, oldx);
- refresh();
-
- if (term_key(sp, &ikey, 0) != INP_OK)
- return (CONF_QUIT);
- switch (ikey.ch) {
- case CH_YES:
- return (CONF_YES);
- case CH_QUIT:
- return (CONF_QUIT);
- default:
- case CH_NO:
- return (CONF_NO);
- }
- /* NOTREACHED */
-}
diff --git a/usr.bin/vi/svi/svi_curses.c b/usr.bin/vi/svi/svi_curses.c
deleted file mode 100644
index 6fec895..0000000
--- a/usr.bin/vi/svi/svi_curses.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_curses.c 8.5 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "svi_screen.h"
-
-/*
- * svi_curses_init --
- * Initialize curses.
- */
-int
-svi_curses_init(sp)
- SCR *sp;
-{
- struct termios t;
- char *p;
-
-#ifdef SYSV_CURSES
- /*
- * The SunOS/System V initscr() isn't reentrant. Don't even think
- * about trying to use it. It fails in subtle ways (e.g. select(2)
- * on fileno(stdin) stops working). We don't care about the SCREEN
- * reference returned by newterm, we never have more than one SCREEN
- * at a time.
- */
- errno = 0;
- if (newterm(O_STR(sp, O_TERM), stdout, stdin) == NULL) {
- msgq(sp, errno ? M_SYSERR : M_ERR, "newterm failed");
- return (1);
- }
-#else
- /*
- * Initscr() doesn't provide useful error values or messages. The
- * reasonable guess is that either malloc failed or the terminal was
- * unknown or lacking some essential feature. Try and guess so the
- * user isn't even more pissed off because of the error message.
- */
- errno = 0;
- if (initscr() == NULL) {
- char kbuf[2048];
- msgq(sp, errno ? M_SYSERR : M_ERR, "initscr failed");
- if ((p = getenv("TERM")) == NULL || !strcmp(p, "unknown"))
- msgq(sp, M_ERR,
- "No TERM environment variable set, or TERM set to \"unknown\"");
- else if (tgetent(kbuf, p) != 1)
- msgq(sp, M_ERR,
-"%s: unknown terminal type, or terminal lacks necessary features", p);
- else
- msgq(sp, M_ERR,
- "%s: terminal type lacks necessary features", p);
- return (1);
- }
-#endif
- /*
- * We use raw mode. What we want is 8-bit clean, however, signals
- * and flow control should continue to work. Admittedly, it sounds
- * like cbreak, but it isn't. Using cbreak() can get you additional
- * things like IEXTEN, which turns on things like DISCARD and LNEXT.
- *
- * !!!
- * If raw isn't turning off echo and newlines, something's wrong.
- * However, it doesn't hurt.
- */
- noecho(); /* No character echo. */
- nonl(); /* No CR/NL translation. */
- raw(); /* 8-bit clean. */
- idlok(stdscr, 1); /* Use hardware insert/delete line. */
-
- /*
- * XXX
- * Historic implementations of curses handled SIGTSTP signals
- * in one of three ways. They either:
- *
- * 1: Set their own handler, regardless.
- * 2: Did not set a handler if a handler was already installed.
- * 3: Set their own handler, but then called any previously set
- * handler after completing their own cleanup.
- *
- * We don't try and figure out which behavior is in place, we
- * just set it to SIG_DFL after initializing the curses interface.
- */
- (void)signal(SIGTSTP, SIG_DFL);
-
- /*
- * If flow control was on, turn it back on. Turn signals on. ISIG
- * turns on VINTR, VQUIT, VDSUSP and VSUSP. See signal.c:sig_init()
- * for a discussion of what's going on here. To sum up, sig_init()
- * already installed a handler for VINTR. We're going to disable the
- * other three.
- *
- * XXX
- * We want to use ^Y as a vi scrolling command. If the user has the
- * DSUSP character set to ^Y (common practice) clean it up. As it's
- * equally possible that the user has VDSUSP set to 'a', we disable
- * it regardless. It doesn't make much sense to suspend vi at read,
- * so I don't think anyone will care. Alternatively, we could look
- * it up in the table of legal command characters and turn it off if
- * it matches one. VDSUSP wasn't in POSIX 1003.1-1990, so we test for
- * it.
- *
- * XXX
- * We don't check to see if the user had signals enabled to start with.
- * If they didn't, it's unclear what we're supposed to do here, but it
- * is also pretty unlikely.
- */
- if (!tcgetattr(STDIN_FILENO, &t)) {
- if (sp->gp->original_termios.c_iflag & IXON)
- t.c_iflag |= IXON;
- if (sp->gp->original_termios.c_iflag & IXOFF)
- t.c_iflag |= IXOFF;
-
- t.c_lflag |= ISIG;
-#ifdef VDSUSP
- t.c_cc[VDSUSP] = _POSIX_VDISABLE;
-#endif
- t.c_cc[VQUIT] = _POSIX_VDISABLE;
- t.c_cc[VSUSP] = _POSIX_VDISABLE;
-
- (void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);
- }
-
- /* Put the cursor keys into application mode. */
- svi_keypad(sp, 1);
-
- /*
- * The first screen in the list gets it all. All other screens
- * are hidden and lose their maps.
- */
- svi_dtoh(sp, "Window resize");
-
- /* Initialize terminal values. */
- SVP(sp)->srows = O_VAL(sp, O_LINES);
-
- /*
- * Initialize screen values.
- *
- * Small windows: see svi/svi_refresh.c:svi_refresh, section 3b.
- *
- * Setup:
- * t_minrows is the minimum rows to display
- * t_maxrows is the maximum rows to display (rows - 1)
- * t_rows is the rows currently being displayed
- */
- sp->rows = SVP(sp)->srows;
- sp->cols = O_VAL(sp, O_COLUMNS);
- sp->woff = 0;
- sp->t_rows = sp->t_minrows = O_VAL(sp, O_WINDOW);
- if (sp->t_rows > sp->rows - 1) {
- sp->t_minrows = sp->t_rows = sp->rows - 1;
- msgq(sp, M_INFO,
- "Windows option value is too large, max is %u", sp->t_rows);
- }
- sp->t_maxrows = sp->rows - 1;
-
- /* Create the screen map. */
- CALLOC(sp, HMAP, SMAP *, SIZE_HMAP(sp), sizeof(SMAP));
- if (HMAP == NULL) {
- if (endwin() == ERR)
- msgq(sp, M_SYSERR, "endwin");
- return (1);
- }
- TMAP = HMAP + (sp->t_rows - 1);
-
- F_SET(SVP(sp), SVI_CUR_INVALID); /* Cursor is invalid. */
- F_SET(SVP(sp), SVI_CURSES_INIT); /* It's initialized. */
-
- return (0);
-}
-
-/*
- * svi_curses_end --
- * Move to the bottom of the screen, end curses.
- */
-int
-svi_curses_end(sp)
- SCR *sp;
-{
- /*
- * XXX
- * By the time we get here, the screen private area (SVI_PRIVATE)
- * is probably gone. Don't use it, and don't call any routines
- * that do.
- *
- * Restore the cursor keys to normal mode.
- */
- svi_keypad(sp, 0);
-
- /* Move to the bottom of the screen. */
- if (move(INFOLINE(sp), 0) == OK) {
- clrtoeol();
- refresh();
- }
-
- /* End curses window. */
- if (endwin() == ERR)
- msgq(sp, M_SYSERR, "endwin");
-
- return (0);
-}
diff --git a/usr.bin/vi/svi/svi_ex.c b/usr.bin/vi/svi/svi_ex.c
deleted file mode 100644
index 0d20b01..0000000
--- a/usr.bin/vi/svi/svi_ex.c
+++ /dev/null
@@ -1,650 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_ex.c 8.56 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "excmd.h"
-#include "svi_screen.h"
-#include "../sex/sex_screen.h"
-
-static int svi_ex_divider __P((SCR *));
-static int svi_ex_done __P((SCR *, EXF *, MARK *));
-static int svi_ex_inv __P((SCR *));
-static int svi_ex_scroll __P((SCR *, int, CH *));
-
-#define MSGS_WAITING(sp) \
- ((sp)->msgq.lh_first != NULL && \
- !F_ISSET((sp)->msgq.lh_first, M_EMPTY))
-
-/*
- * svi_ex_cmd --
- * Execute an ex command.
- */
-int
-svi_ex_cmd(sp, ep, exp, rp)
- SCR *sp;
- EXF *ep;
- EXCMDARG *exp;
- MARK *rp;
-{
- SVI_PRIVATE *svp;
- int rval;
-
- svp = SVP(sp);
- svp->exlcontinue = svp->exlinecount = svp->extotalcount = 0;
-
- (void)svi_busy(sp, NULL);
- rval = exp->cmd->fn(sp, ep, exp);
-
- (void)msg_rpt(sp, 0);
- (void)ex_fflush(EXCOOKIE);
-
- /*
- * If displayed anything, figure out if we have to wait. If the
- * screen wasn't trashed, only one line output and there are no
- * waiting messages, don't wait, but don't overwrite it with mode
- * information either.
- */
- if (svp->extotalcount > 0)
- if (!F_ISSET(sp, S_REFRESH) &&
- svp->extotalcount == 1 && !MSGS_WAITING(sp)) {
- F_SET(sp, S_UPDATE_MODE);
- if (sp->q.cqe_next != (void *)&sp->gp->dq)
- (void)svi_ex_inv(sp);
- } else {
- /* This message isn't interruptible. */
- F_CLR(sp, S_INTERRUPTIBLE);
- (void)svi_ex_scroll(sp, 1, NULL);
- }
- return (svi_ex_done(sp, ep, rp) || rval);
-}
-
-/*
- * svi_ex_run --
- * Execute strings of ex commands.
- */
-int
-svi_ex_run(sp, ep, rp)
- SCR *sp;
- EXF *ep;
- MARK *rp;
-{
- enum input (*get) __P((SCR *, EXF *, TEXTH *, ARG_CHAR_T, u_int));
- struct termios t;
- CH ikey;
- SVI_PRIVATE *svp;
- TEXT *tp;
- int flags, in_exmode, rval;
-
- svp = SVP(sp);
- svp->exlcontinue = svp->exlinecount = svp->extotalcount = 0;
-
- /*
- * There's some tricky stuff going on here to handle when a user has
- * mapped a key to multiple ex commands. Historic practice was that
- * vi ran without any special actions, as if the user were entering
- * the characters, until ex trashed the screen, e.g. something like a
- * '!' command. At that point, we no longer know what the screen
- * looks like, so we can't afford to overwrite anything. The solution
- * is to go into real ex mode until we get to the end of the command
- * strings.
- */
- get = svi_get;
- flags = TXT_BS | TXT_PROMPT;
- for (in_exmode = rval = 0;;) {
- /*
- * Get the next command. Interrupt flag manipulation is safe
- * because ex_icmd clears them all.
- */
- F_SET(sp, S_INTERRUPTIBLE);
- if (get(sp, ep, sp->tiqp, ':', flags) != INP_OK) {
- rval = 1;
- break;
- }
- if (INTERRUPTED(sp))
- break;
-
- /*
- * Len is 0 if the user backspaced over the prompt,
- * 1 if only a CR was entered.
- */
- tp = sp->tiqp->cqh_first;
- if (tp->len == 0)
- break;
-
- if (!in_exmode)
- (void)svi_busy(sp, NULL);
-
- /* Ignore return, presumably an error message was displayed. */
- (void)ex_icmd(sp, ep, tp->lb, tp->len, 0);
- (void)ex_fflush(EXCOOKIE);
-
- /*
- * The file or screen may have changed, in which case, the
- * main editor loop takes care of it.
- */
- if (F_ISSET(sp, S_MAJOR_CHANGE))
- break;
-
- /*
- * If continue not required, and one or no lines, and there
- * are no waiting messages, don't wait, but don't overwrite
- * it with mode information either.
- */
- if (!F_ISSET(sp, S_CONTINUE) && (svp->extotalcount == 0 ||
- svp->extotalcount == 1 && !MSGS_WAITING(sp))) {
- if (svp->extotalcount == 1) {
- F_SET(sp, S_UPDATE_MODE);
- if (sp->q.cqe_next != (void *)&sp->gp->dq)
- svi_ex_inv(sp);
- }
- break;
- }
-
- if (INTERRUPTED(sp))
- break;
-
- /*
- * If the screen is trashed, or there are messages waiting,
- * go into ex mode.
- */
- if (!in_exmode &&
- (F_ISSET(sp, S_REFRESH) || MSGS_WAITING(sp))) {
- /* Initialize the terminal state. */
- if (F_ISSET(sp->gp, G_STDIN_TTY))
- SEX_RAW(t);
- get = sex_get;
- flags = TXT_CR | TXT_NLECHO | TXT_PROMPT;
- in_exmode = 1;
- }
-
- /* Display any waiting messages. */
- if (MSGS_WAITING(sp))
- (void)sex_refresh(sp, ep);
-
- /*
- * Get a continue character; users may continue in ex mode by
- * entering a ':'.
- *
- * !!!
- * Historic practice is that any key can be used to continue.
- * Nvi used to require that the user enter a <carriage-return>
- * or <newline>, but this broke historic users.
- */
- if (in_exmode) {
- (void)write(STDOUT_FILENO,
- STR_CMSG, sizeof(STR_CMSG) - 1);
- if (term_key(sp, &ikey, 0) != INP_OK) {
- rval = 1;
- goto ret;
- }
- } else {
- /* This message isn't interruptible. */
- F_CLR(sp, S_INTERRUPTIBLE);
- (void)svi_ex_scroll(sp, 1, &ikey);
- }
- if (ikey.ch != ':')
- break;
-
- if (in_exmode)
- (void)write(STDOUT_FILENO, "\n", 1);
- else {
- ++svp->extotalcount;
- ++svp->exlinecount;
- }
- }
-
-ret: if (in_exmode) {
- /* Reset the terminal state. */
- if (F_ISSET(sp->gp, G_STDIN_TTY) && SEX_NORAW(t))
- rval = 1;
- F_SET(sp, S_REFRESH);
- } else
- if (svi_ex_done(sp, ep, rp))
- rval = 1;
-
- F_CLR(sp, S_CONTINUE);
- return (rval);
-}
-
-/*
- * svi_msgflush --
- * Flush any accumulated messages.
- */
-int
-svi_msgflush(sp)
- SCR *sp;
-{
- enum {INVERSE, NORMAL} inverse;
- SVI_PRIVATE *svp;
- MSG *mp;
- int rval;
-
- svp = SVP(sp);
- svp->exlcontinue = svp->exlinecount = svp->extotalcount = 0;
-
- /*
- * XXX
- * S_IVIDEO is a bit of a kluge. We can only pass a single magic
- * cookie into the svi_ex_write routine, and it has to be the SCR
- * structure. So, the inverse video bit has to be there.
- */
- inverse = NORMAL;
- for (mp = sp->msgq.lh_first;
- mp != NULL && !F_ISSET(mp, M_EMPTY); mp = mp->q.le_next) {
- /*
- * If the second and subsequent messages fit on the current
- * line, write a separator. Otherwise, put out a newline
- * and break the line.
- */
- if (mp != sp->msgq.lh_first)
- if (mp->len + svp->exlcontinue + 3 >= sp->cols) {
- if (inverse == INVERSE)
- F_SET(sp, S_IVIDEO);
- (void)svi_ex_write(sp, ".\n", 2);
- F_CLR(sp, S_IVIDEO);
- } else {
- if (inverse == INVERSE)
- F_SET(sp, S_IVIDEO);
- (void)svi_ex_write(sp, ";", 1);
- F_CLR(sp, S_IVIDEO);
- (void)svi_ex_write(sp, " ", 2);
- }
-
- inverse = F_ISSET(mp, M_INV_VIDEO) ? INVERSE : NORMAL;
- if (inverse == INVERSE)
- F_SET(sp, S_IVIDEO);
- (void)svi_ex_write(sp, mp->mbuf, mp->len);
- F_CLR(sp, S_IVIDEO);
-
- F_SET(mp, M_EMPTY);
- }
-
- /*
- * None of the messages end with periods, we do it in the message
- * flush routine, which makes it possible to join messages.
- */
- if (inverse == INVERSE)
- F_SET(sp, S_IVIDEO);
- (void)svi_ex_write(sp, ".", 1);
- F_CLR(sp, S_IVIDEO);
-
- /*
- * Figure out if we have to wait. Don't wait for only one line,
- * but don't overwrite it with mode information either.
- */
- if (svp->extotalcount == 1) {
- F_SET(sp, S_UPDATE_MODE);
- if (sp->q.cqe_next != (void *)&sp->gp->dq)
- svi_ex_inv(sp);
- return (0);
- }
-
- rval = svi_ex_scroll(sp, 1, NULL);
- if (svi_ex_done(sp, sp->ep, NULL))
- rval = 1;
- MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
- return (rval);
-}
-
-/*
- * svi_ex_done --
- * Cleanup from dipping into ex.
- */
-static int
-svi_ex_done(sp, ep, rp)
- SCR *sp;
- EXF *ep;
- MARK *rp;
-{
- SMAP *smp;
- SVI_PRIVATE *svp;
- recno_t lno;
- size_t cnt, len;
-
- /*
- * The file or screen may have changed, in which case,
- * the main editor loop takes care of it.
- */
- if (F_ISSET(sp, S_MAJOR_CHANGE))
- return (0);
-
- /*
- * Otherwise, the only cursor modifications will be real, however, the
- * underlying line may have changed; don't trust anything. This code
- * has been a remarkably fertile place for bugs.
- *
- * Repaint the entire screen if at least half the screen is trashed.
- * Else, repaint only over the overwritten lines. The "-2" comes
- * from one for the mode line and one for the fact that it's an offset.
- * Note the check for small screens.
- *
- * Don't trust ANYTHING.
- */
- svp = SVP(sp);
- if (svp->extotalcount >= HALFTEXT(sp))
- F_SET(sp, S_REDRAW);
- else
- for (cnt = sp->rows - 2; svp->extotalcount--; --cnt)
- if (cnt > sp->t_rows) {
- MOVE(sp, cnt, 0);
- clrtoeol();
- } else {
- smp = HMAP + cnt;
- SMAP_FLUSH(smp);
- if (svi_line(sp, ep, smp, NULL, NULL))
- return (1);
- }
-
- /* Ignore the cursor if the caller doesn't care. */
- if (rp == NULL)
- return (0);
-
- /*
- * Do a reality check on a cursor value, and make sure it's okay.
- * If necessary, change it. Ex keeps track of the line number,
- * but it doesn't care about the column and it may have disappeared.
- */
- if (file_gline(sp, ep, sp->lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0)
- GETLINE_ERR(sp, sp->lno);
- sp->lno = 1;
- sp->cno = 0;
- } else if (sp->cno >= len)
- sp->cno = len ? len - 1 : 0;
-
- rp->lno = sp->lno;
- rp->cno = sp->cno;
- return (0);
-}
-
-/*
- * svi_ex_write --
- * Write out the ex messages.
- */
-int
-svi_ex_write(cookie, line, llen)
- void *cookie;
- const char *line;
- int llen;
-{
- SCR *sp;
- SVI_PRIVATE *svp;
- size_t oldy, oldx;
- int len, rlen, tlen;
- const char *p, *t;
-
- /*
- * XXX
- * If it's a 4.4BSD system, we could just use fpurge(3).
- * This shouldn't be too expensive, though.
- */
- sp = cookie;
- svp = SVP(sp);
- if (INTERRUPTED(sp))
- return (llen);
-
- p = line; /* In case of a write of 0. */
- for (rlen = llen; llen;) {
- /* Get the next line. */
- if ((p = memchr(line, '\n', llen)) == NULL)
- len = llen;
- else
- len = p - line;
-
- /*
- * The max is sp->cols characters, and we may
- * have already written part of the line.
- */
- if (len + svp->exlcontinue > sp->cols)
- len = sp->cols - svp->exlcontinue;
-
- /*
- * If the first line output, do nothing.
- * If the second line output, draw the divider line.
- * If drew a full screen, remove the divider line.
- * If it's a continuation line, move to the continuation
- * point, else, move the screen up.
- */
- if (svp->exlcontinue == 0) {
- if (svp->extotalcount == 1) {
- MOVE(sp, INFOLINE(sp) - 1, 0);
- clrtoeol();
- if (svi_ex_divider(sp))
- return (-1);
- F_SET(svp, SVI_DIVIDER);
- ++svp->extotalcount;
- ++svp->exlinecount;
- }
- if (svp->extotalcount == sp->t_maxrows &&
- F_ISSET(svp, SVI_DIVIDER)) {
- --svp->extotalcount;
- --svp->exlinecount;
- F_CLR(svp, SVI_DIVIDER);
- }
- if (svp->extotalcount != 0 &&
- svi_ex_scroll(sp, 0, NULL))
- return (-1);
- MOVE(sp, INFOLINE(sp), 0);
- ++svp->extotalcount;
- ++svp->exlinecount;
- if (F_ISSET(sp, S_INTERRUPTIBLE) && INTERRUPTED(sp))
- break;
- } else
- MOVE(sp, INFOLINE(sp), svp->exlcontinue);
-
- /* Display the line, doing character translation. */
- if (F_ISSET(sp, S_IVIDEO))
- standout();
- for (t = line, tlen = len; tlen--; ++t)
- ADDCH(*t);
- if (F_ISSET(sp, S_IVIDEO))
- standend();
-
- /* Clear to EOL. */
- getyx(stdscr, oldy, oldx);
- if (oldx < sp->cols)
- clrtoeol();
-
- /* If we loop, it's a new line. */
- svp->exlcontinue = 0;
-
- /* Reset for the next line. */
- line += len;
- llen -= len;
- if (p != NULL) {
- ++line;
- --llen;
- }
- }
- /* Refresh the screen, even if it's a partial. */
- refresh();
-
- /* Set up next continuation line. */
- if (p == NULL)
- getyx(stdscr, oldy, svp->exlcontinue);
- return (rlen);
-}
-
-/*
- * svi_ex_scroll --
- * Scroll the screen for ex output.
- */
-static int
-svi_ex_scroll(sp, mustwait, chp)
- SCR *sp;
- int mustwait;
- CH *chp;
-{
- CH ikey;
- SVI_PRIVATE *svp;
-
- /*
- * Scroll the screen. Instead of scrolling the entire screen, delete
- * the line above the first line output so preserve the maximum amount
- * of the screen.
- */
- svp = SVP(sp);
- if (svp->extotalcount >= sp->rows) {
- MOVE(sp, 0, 0);
- } else
- MOVE(sp, INFOLINE(sp) - svp->extotalcount, 0);
-
- deleteln();
-
- /* If there are screens below us, push them back into place. */
- if (sp->q.cqe_next != (void *)&sp->gp->dq) {
- MOVE(sp, INFOLINE(sp), 0);
- insertln();
- }
-
- /* If just displayed a full screen, wait. */
- if (mustwait || svp->exlinecount == sp->t_maxrows) {
- MOVE(sp, INFOLINE(sp), 0);
- if (F_ISSET(sp, S_INTERRUPTIBLE)) {
- ADDNSTR(STR_QMSG, (int)sizeof(STR_QMSG) - 1);
- } else {
- ADDNSTR(STR_CMSG, (int)sizeof(STR_CMSG) - 1);
- }
- clrtoeol();
- refresh();
- /*
- * !!!
- * Historic practice is that any key can be used to continue.
- * Nvi used to require that the user enter a <carriage-return>
- * or <newline>, but this broke historic users.
- */
- if (term_key(sp, &ikey, 0) != INP_OK)
- return (-1);
- if (ikey.ch == CH_QUIT && F_ISSET(sp, S_INTERRUPTIBLE))
- F_SET(sp, S_INTERRUPTED);
- if (chp != NULL)
- *chp = ikey;
- svp->exlinecount = 0;
- }
- return (0);
-}
-
-/*
- * svi_ex_inv --
- * Change whatever is on the info line to inverse video so we have
- * a divider line between split screens.
- */
-static int
-svi_ex_inv(sp)
- SCR *sp;
-{
- CHAR_T ch;
- size_t spcnt, col, row;
-
- row = INFOLINE(sp);
-
- /*
- * Walk through the line, retrieving each character and writing
- * it back out in inverse video. Since curses doesn't have an
- * EOL marker, only put out trailing spaces if we find another
- * character.
- *
- * XXX
- * This is a major kluge -- curses should have an interface
- * that allows us to change attributes on a per line basis.
- */
- MOVE(sp, row, 0);
- standout();
- for (spcnt = col = 0;;) {
- ch = winch(stdscr);
- if (isspace(ch)) {
- ++spcnt;
- if (++col >= sp->cols)
- break;
- MOVE(sp, row, col);
- } else {
- if (spcnt) {
- MOVE(sp, row, col - spcnt);
- for (; spcnt > 0; --spcnt)
- ADDCH(' ');
- }
- ADDCH(ch);
- if (++col >= sp->cols)
- break;
- }
- }
- standend();
- return (0);
-}
-
-/*
- * svi_ex_divider --
- * Draw a dividing line between the screens.
- */
-static int
-svi_ex_divider(sp)
- SCR *sp;
-{
- size_t len;
-
-#define DIVIDESTR "+=+=+=+=+=+=+=+"
- len = sizeof(DIVIDESTR) - 1 > sp->cols ?
- sp->cols : sizeof(DIVIDESTR) - 1;
- standout();
- ADDNSTR(DIVIDESTR, len);
- standend();
- return (0);
-}
diff --git a/usr.bin/vi/svi/svi_get.c b/usr.bin/vi/svi/svi_get.c
deleted file mode 100644
index b58100b..0000000
--- a/usr.bin/vi/svi/svi_get.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)svi_get.c 8.27 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "svi_screen.h"
-
-/*
- * svi_get --
- * Fill a buffer from the terminal for vi.
- */
-enum input
-svi_get(sp, ep, tiqh, prompt, flags)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
- ARG_CHAR_T prompt;
- u_int flags;
-{
- MARK save;
- SMAP *esmp;
- recno_t bot_lno;
- size_t bot_off, cnt;
- int eval;
-
- /*
- * The approach used is to fake like the user is doing input on
- * the last line of the screen. This makes all of the scrolling
- * work correctly, and allows us the use of the vi text editing
- * routines, not to mention practically infinite length ex commands.
- *
- * Save the current location.
- */
- bot_lno = TMAP->lno;
- bot_off = TMAP->off;
- save.lno = sp->lno;
- save.cno = sp->cno;
-
- /*
- * If it's a small screen, TMAP may be small for the screen.
- * Fix it, filling in fake lines as we go.
- */
- if (ISSMALLSCREEN(sp))
- for (esmp = HMAP + (sp->t_maxrows - 1); TMAP < esmp; ++TMAP) {
- TMAP[1].lno = TMAP[0].lno + 1;
- TMAP[1].off = 1;
- }
-
- /* Build the fake entry. */
- TMAP[1].lno = TMAP[0].lno + 1;
- TMAP[1].off = 1;
- SMAP_FLUSH(&TMAP[1]);
- ++TMAP;
-
- /* Move to it. */
- sp->lno = TMAP[0].lno;
- sp->cno = 0;
-
- if (O_ISSET(sp, O_ALTWERASE))
- LF_SET(TXT_ALTWERASE);
- if (O_ISSET(sp, O_TTYWERASE))
- LF_SET(TXT_TTYWERASE);
- LF_SET(TXT_APPENDEOL |
- TXT_CR | TXT_ESCAPE | TXT_INFOLINE | TXT_MAPINPUT);
-
- /* Don't update the modeline for now. */
- F_SET(SVP(sp), SVI_INFOLINE);
-
- eval = v_ntext(sp, ep, tiqh, NULL, NULL, 0, NULL, prompt, 0, flags);
-
- F_CLR(SVP(sp), SVI_INFOLINE);
-
- /* Put it all back. */
- --TMAP;
- sp->lno = save.lno;
- sp->cno = save.cno;
-
- /*
- * If it's a small screen, TMAP may be wrong. Clear any
- * lines that might have been overwritten.
- */
- if (ISSMALLSCREEN(sp)) {
- for (cnt = sp->t_rows; cnt <= sp->t_maxrows; ++cnt) {
- MOVE(sp, cnt, 0);
- clrtoeol();
- }
- TMAP = HMAP + (sp->t_rows - 1);
- }
-
- /*
- * The map may be wrong if the user entered more than one
- * (logical) line. Fix it. If the user entered a whole
- * screen, this will be slow, but it's not worth caring.
- */
- while (bot_lno != TMAP->lno || bot_off != TMAP->off)
- if (svi_sm_1down(sp, ep))
- return (INP_ERR);
-
- /*
- * Invalidate the cursor and the line size cache, the line never
- * really existed. This fixes bugs where the user searches for
- * the last line on the screen + 1 and the refresh routine thinks
- * that's where we just were.
- */
- F_SET(SVP(sp), SVI_CUR_INVALID);
- SVI_SCR_CFLUSH(SVP(sp));
-
- return (eval ? INP_ERR : INP_OK);
-}
diff --git a/usr.bin/vi/svi/svi_line.c b/usr.bin/vi/svi/svi_line.c
deleted file mode 100644
index e1d50da..0000000
--- a/usr.bin/vi/svi/svi_line.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_line.c 8.27 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "svi_screen.h"
-
-#if defined(DEBUG) && 0
-#define TABCH '-'
-#define TABSTR "--------------------"
-#else
-#define TABSTR " "
-#define TABCH ' '
-#endif
-
-/*
- * svi_line --
- * Update one line on the screen.
- */
-int
-svi_line(sp, ep, smp, yp, xp)
- SCR *sp;
- EXF *ep;
- SMAP *smp;
- size_t *xp, *yp;
-{
- SMAP *tsmp;
- size_t chlen, cols_per_screen, cno_cnt, len, scno, skip_screens;
- size_t offset_in_char, offset_in_line;
- size_t oldy, oldx;
- int ch, is_cached, is_infoline, is_partial, is_tab;
- int list_tab, list_dollar;
- char *p, nbuf[10];
-
-#if defined(DEBUG) && 0
- TRACE(sp, "svi_line: row %u: line: %u off: %u\n",
- smp - HMAP, smp->lno, smp->off);
-#endif
-
- /*
- * Assume that, if the cache entry for the line is filled in, the
- * line is already on the screen, and all we need to do is return
- * the cursor position. If the calling routine doesn't need the
- * cursor position, we can just return.
- */
- is_cached = SMAP_CACHE(smp);
- if (yp == NULL && is_cached)
- return (0);
-
- /*
- * A nasty side effect of this routine is that it returns the screen
- * position for the "current" character. Not pretty, but this is the
- * only routine that really knows what's out there.
- *
- * Move to the line. This routine can be called by svi_sm_position(),
- * which uses it to fill in the cache entry so it can figure out what
- * the real contents of the screen are. Because of this, we have to
- * return to whereever we started from.
- */
- getyx(stdscr, oldy, oldx);
- MOVE(sp, smp - HMAP, 0);
-
- /* Get a copy of the line. */
- p = file_gline(sp, ep, smp->lno, &len);
-
- /*
- * Special case if we're printing the info/mode line. Skip printing
- * the leading number, as well as other minor setup. If painting the
- * line between two screens, it's always in reverse video. The only
- * time this code paints the mode line is when the user is entering
- * text for a ":" command, so we can put the code here instead of
- * dealing with the empty line logic below. This is a kludge, but it's
- * pretty much confined to this module.
- *
- * Set the number of screens to skip until a character is displayed.
- * Left-right screens are special, because we don't bother building
- * a buffer to be skipped over.
- *
- * Set the number of columns for this screen.
- */
- cols_per_screen = sp->cols;
- list_tab = O_ISSET(sp, O_LIST);
- if (is_infoline = ISINFOLINE(sp, smp)) {
- list_dollar = 0;
- if (O_ISSET(sp, O_LEFTRIGHT))
- skip_screens = 0;
- else
- skip_screens = smp->off - 1;
- } else {
- list_dollar = list_tab;
- skip_screens = smp->off - 1;
-
- /*
- * If O_NUMBER is set and it's line number 1 or the line exists
- * and this is the first screen of a folding line or any left-
- * right line, display the line number.
- */
- if (O_ISSET(sp, O_NUMBER)) {
- cols_per_screen -= O_NUMBER_LENGTH;
- if ((smp->lno == 1 || p != NULL) && skip_screens == 0) {
- (void)snprintf(nbuf,
- sizeof(nbuf), O_NUMBER_FMT, smp->lno);
- ADDSTR(nbuf);
- }
- }
- }
-
- /*
- * Special case non-existent lines and the first line of an empty
- * file. In both cases, the cursor position is 0, but corrected
- * for the O_NUMBER field if it was displayed.
- */
- if (p == NULL || len == 0) {
- /* Fill in the cursor. */
- if (yp != NULL && smp->lno == sp->lno) {
- *yp = smp - HMAP;
- *xp = sp->cols - cols_per_screen;
- }
-
- /* If the line is on the screen, quit. */
- if (is_cached)
- goto ret;
-
- /* Set line cacheing information. */
- smp->c_sboff = smp->c_eboff = 0;
- smp->c_scoff = smp->c_eclen = 0;
-
- /* Lots of special cases for empty lines. */
- if (skip_screens == 0)
- if (p == NULL) {
- if (smp->lno == 1) {
- if (list_dollar) {
- ch = '$';
- goto empty;
- }
- } else {
- ch = '~';
- goto empty;
- }
- } else
- if (list_dollar) {
- ch = '$';
-empty: ADDCH(ch);
- }
-
- clrtoeol();
- MOVEA(sp, oldy, oldx);
- return (0);
- }
-
- /*
- * If we wrote a line that's this or a previous one, we can do this
- * much more quickly -- we cached the starting and ending positions
- * of that line. The way it works is we keep information about the
- * lines displayed in the SMAP. If we're painting the screen in
- * the forward, this saves us from reformatting the physical line for
- * every line on the screen. This wins big on binary files with 10K
- * lines.
- *
- * Test for the first screen of the line, then the current screen line,
- * then the line behind us, then do the hard work. Note, it doesn't
- * do us any good to have a line in front of us -- it would be really
- * hard to try and figure out tabs in the reverse direction, i.e. how
- * many spaces a tab takes up in the reverse direction depends on
- * what characters preceded it.
- */
- if (smp->off == 1) {
- smp->c_sboff = offset_in_line = 0;
- smp->c_scoff = offset_in_char = 0;
- p = &p[offset_in_line];
- } else if (is_cached) {
- offset_in_line = smp->c_sboff;
- offset_in_char = smp->c_scoff;
- p = &p[offset_in_line];
- if (skip_screens != 0)
- cols_per_screen = sp->cols;
- } else if (smp != HMAP &&
- SMAP_CACHE(tsmp = smp - 1) && tsmp->lno == smp->lno) {
- if (tsmp->c_eclen != tsmp->c_ecsize) {
- offset_in_line = tsmp->c_eboff;
- offset_in_char = tsmp->c_eclen;
- } else {
- offset_in_line = tsmp->c_eboff + 1;
- offset_in_char = 0;
- }
-
- /* Put starting info for this line in the cache. */
- smp->c_sboff = offset_in_line;
- smp->c_scoff = offset_in_char;
- p = &p[offset_in_line];
- if (skip_screens != 0)
- cols_per_screen = sp->cols;
- } else {
- offset_in_line = 0;
- offset_in_char = 0;
-
- /* This is the loop that skips through screens. */
- if (skip_screens == 0) {
- smp->c_sboff = offset_in_line;
- smp->c_scoff = offset_in_char;
- } else for (scno = 0; offset_in_line < len; ++offset_in_line) {
- scno += chlen =
- (ch = *(u_char *)p++) == '\t' && !list_tab ?
- TAB_OFF(sp, scno) : KEY_LEN(sp, ch);
- if (scno < cols_per_screen)
- continue;
- /*
- * Reset cols_per_screen to second and subsequent line
- * length.
- */
- scno -= cols_per_screen;
- cols_per_screen = sp->cols;
-
- /*
- * If crossed the last skipped screen boundary, start
- * displaying the characters.
- */
- if (--skip_screens)
- continue;
-
- /* Put starting info for this line in the cache. */
- if (scno) {
- smp->c_sboff = offset_in_line;
- smp->c_scoff = offset_in_char = chlen - scno;
- --p;
- } else {
- smp->c_sboff = ++offset_in_line;
- smp->c_scoff = 0;
- }
- break;
- }
- }
-
- /*
- * Set the number of characters to skip before reaching the cursor
- * character. Offset by 1 and use 0 as a flag value. Svi_line is
- * called repeatedly with a valid pointer to a cursor position.
- * Don't fill anything in unless it's the right line and the right
- * character, and the right part of the character...
- */
- if (yp == NULL ||
- smp->lno != sp->lno || sp->cno < offset_in_line ||
- offset_in_line + cols_per_screen < sp->cno) {
- cno_cnt = 0;
- /* If the line is on the screen, quit. */
- if (is_cached)
- goto ret;
- } else
- cno_cnt = (sp->cno - offset_in_line) + 1;
-
- /* This is the loop that actually displays characters. */
- for (is_partial = 0, scno = 0;
- offset_in_line < len; ++offset_in_line, offset_in_char = 0) {
- if ((ch = *(u_char *)p++) == '\t' && !list_tab) {
- scno += chlen = TAB_OFF(sp, scno) - offset_in_char;
- is_tab = 1;
- } else {
- scno += chlen = KEY_LEN(sp, ch) - offset_in_char;
- is_tab = 0;
- }
-
- /*
- * Only display up to the right-hand column. Set a flag if
- * the entire character wasn't displayed for use in setting
- * the cursor. If reached the end of the line, set the cache
- * info for the screen. Don't worry about there not being
- * characters to display on the next screen, its lno/off won't
- * match up in that case.
- */
- if (scno >= cols_per_screen) {
- smp->c_ecsize = chlen;
- chlen -= scno - cols_per_screen;
- smp->c_eclen = chlen;
- smp->c_eboff = offset_in_line;
- if (scno > cols_per_screen)
- is_partial = 1;
-
- /* Terminate the loop. */
- offset_in_line = len;
- }
-
- /*
- * If the caller wants the cursor value, and this was the
- * cursor character, set the value. There are two ways to
- * put the cursor on a character -- if it's normal display
- * mode, it goes on the last column of the character. If
- * it's input mode, it goes on the first. In normal mode,
- * set the cursor only if the entire character was displayed.
- */
- if (cno_cnt &&
- --cno_cnt == 0 && (F_ISSET(sp, S_INPUT) || !is_partial)) {
- *yp = smp - HMAP;
- if (F_ISSET(sp, S_INPUT))
- *xp = scno - chlen;
- else
- *xp = scno - 1;
- if (O_ISSET(sp, O_NUMBER) &&
- !is_infoline && smp->off == 1)
- *xp += O_NUMBER_LENGTH;
-
- /* If the line is on the screen, quit. */
- if (is_cached)
- goto ret;
- }
-
- /* If the line is on the screen, don't display anything. */
- if (is_cached)
- continue;
-
- /*
- * Display the character. If it's a tab and tabs aren't some
- * ridiculous length, do it fast. (We do tab expansion here
- * because curses doesn't have a way to set the tab length.)
- */
- if (is_tab) {
- if (chlen <= sizeof(TABSTR) - 1) {
- ADDNSTR(TABSTR, chlen);
- } else
- while (chlen--)
- ADDCH(TABCH);
- } else
- ADDNSTR(KEY_NAME(sp, ch) + offset_in_char, chlen);
- }
-
- if (scno < cols_per_screen) {
- /* If didn't paint the whole line, update the cache. */
- smp->c_ecsize = smp->c_eclen = KEY_LEN(sp, ch);
- smp->c_eboff = len - 1;
-
- /*
- * If not the info/mode line, and O_LIST set, and at the
- * end of the line, and the line ended on this screen,
- * add a trailing $.
- */
- if (list_dollar) {
- ++scno;
- ADDCH('$');
- }
-
- /* If still didn't paint the whole line, clear the rest. */
- if (scno < cols_per_screen)
- clrtoeol();
- }
-
-ret: MOVEA(sp, oldy, oldx);
- return (0);
-}
-
-/*
- * svi_number --
- * Repaint the numbers on all the lines.
- */
-int
-svi_number(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- SMAP *smp;
- size_t oldy, oldx;
- char *lp, nbuf[10];
-
- /*
- * Try and avoid getting the last line in the file, by getting the
- * line after the last line in the screen -- if it exists, we know
- * we have to to number all the lines in the screen. Get the one
- * after the last instead of the last, so that the info line doesn't
- * fool us.
- *
- * If that test fails, we have to check each line for existence.
- *
- * XXX
- * The problem is that file_lline will lie, and tell us that the
- * info line is the last line in the file.
- */
- lp = file_gline(sp, ep, TMAP->lno + 1, NULL);
-
- getyx(stdscr, oldy, oldx);
- for (smp = HMAP; smp <= TMAP; ++smp) {
- if (smp->off != 1)
- continue;
- if (ISINFOLINE(sp, smp))
- break;
- if (smp->lno != 1 && lp == NULL &&
- file_gline(sp, ep, smp->lno, NULL) == NULL)
- break;
- MOVE(sp, smp - HMAP, 0);
- (void)snprintf(nbuf, sizeof(nbuf), O_NUMBER_FMT, smp->lno);
- ADDSTR(nbuf);
- }
- MOVEA(sp, oldy, oldx);
- return (0);
-}
diff --git a/usr.bin/vi/svi/svi_refresh.c b/usr.bin/vi/svi/svi_refresh.c
deleted file mode 100644
index 9cb2dce..0000000
--- a/usr.bin/vi/svi/svi_refresh.c
+++ /dev/null
@@ -1,818 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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[] = "@(#)svi_refresh.c 8.62 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "svi_screen.h"
-#include "../sex/sex_screen.h"
-
-static int svi_modeline __P((SCR *, EXF *));
-
-int
-svi_refresh(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- SCR *tsp;
- u_int paintbits;
-
- /*
- * 1: Resize the screen.
- *
- * Notice that a resize is requested, and set up everything so that
- * the file gets reinitialized. Done here, instead of in the vi loop
- * because there may be other initialization that other screens need
- * to do. The actual changing of the row/column values was done by
- * calling the ex options code which put them into the environment,
- * which is used by curses. Stupid, but ugly.
- */
- if (F_ISSET(sp, S_RESIZE)) {
- /* Reinitialize curses. */
- if (svi_curses_end(sp) || svi_curses_init(sp))
- return (1);
-
- /* Invalidate the line size cache. */
- SVI_SCR_CFLUSH(SVP(sp));
-
- /*
- * Fill the map, incidentally losing any svi_line()
- * cached information.
- */
- if (svi_sm_fill(sp, ep, sp->lno, P_FILL))
- return (1);
- F_CLR(sp, S_RESIZE | S_REFORMAT);
- F_SET(sp, S_REDRAW);
- }
-
- /*
- * 2: S_REFRESH
- *
- * If S_REFRESH is set in the current screen, repaint everything
- * that we can find.
- */
- if (F_ISSET(sp, S_REFRESH))
- for (tsp = sp->gp->dq.cqh_first;
- tsp != (void *)&sp->gp->dq; tsp = tsp->q.cqe_next)
- if (tsp != sp)
- F_SET(tsp, S_REDRAW);
- /*
- * 3: Related or dirtied screens, or screens with messages.
- *
- * If related screens share a view into a file, they may have been
- * modified as well. Refresh any screens with paint or dirty bits
- * set, or where messages are waiting. Finally, if we refresh any
- * screens other than the current one, the cursor will be trashed.
- */
- paintbits = S_REDRAW | S_REFORMAT | S_REFRESH;
- if (O_ISSET(sp, O_NUMBER))
- paintbits |= S_RENUMBER;
- for (tsp = sp->gp->dq.cqh_first;
- tsp != (void *)&sp->gp->dq; tsp = tsp->q.cqe_next)
- if (tsp != sp &&
- (F_ISSET(tsp, paintbits) ||
- F_ISSET(SVP(tsp), SVI_SCREENDIRTY) ||
- tsp->msgq.lh_first != NULL &&
- !F_ISSET(tsp->msgq.lh_first, M_EMPTY))) {
- (void)svi_paint(tsp, tsp->ep);
- F_CLR(SVP(tsp), SVI_SCREENDIRTY);
- F_SET(SVP(sp), SVI_CUR_INVALID);
- }
-
- /*
- * 4: Refresh the current screen.
- *
- * Always refresh the current screen, it may be a cursor movement.
- * Also, always do it last -- that way, S_REFRESH can be set in
- * the current screen only, and the screen won't flash.
- */
- F_CLR(sp, SVI_SCREENDIRTY);
- return (svi_paint(sp, ep));
-}
-
-/*
- * svi_paint --
- * This is the guts of the vi curses screen code. The idea is that
- * the SCR structure passed in contains the new coordinates of the
- * screen. What makes this hard is that we don't know how big
- * characters are, doing input can put the cursor in illegal places,
- * and we're frantically trying to avoid repainting unless it's
- * absolutely necessary. If you change this code, you'd better know
- * what you're doing. It's subtle and quick to anger.
- */
-int
-svi_paint(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- SMAP *smp, tmp;
- SVI_PRIVATE *svp;
- recno_t lastline, lcnt;
- size_t cwtotal, cnt, len, x, y;
- int ch, didpaint, leftright_warp;
- char *p;
-
-#define LNO sp->lno
-#define OLNO svp->olno
-#define CNO sp->cno
-#define OCNO svp->ocno
-#define SCNO svp->sc_col
-
- didpaint = leftright_warp = 0;
- svp = SVP(sp);
-
- /*
- * 1: Reformat the lines.
- *
- * If the lines themselves have changed (:set list, for example),
- * fill in the map from scratch. Adjust the screen that's being
- * displayed if the leftright flag is set.
- */
- if (F_ISSET(sp, S_REFORMAT)) {
- /* Invalidate the line size cache. */
- SVI_SCR_CFLUSH(SVP(sp));
-
- /* Toss svi_line() cached information. */
- if (svi_sm_fill(sp, ep, HMAP->lno, P_TOP))
- return (1);
- if (O_ISSET(sp, O_LEFTRIGHT) &&
- (cnt = svi_opt_screens(sp, ep, LNO, &CNO)) != 1)
- for (smp = HMAP; smp <= TMAP; ++smp)
- smp->off = cnt;
- F_CLR(sp, S_REFORMAT);
- F_SET(sp, S_REDRAW);
- }
-
- /*
- * 2: Line movement.
- *
- * Line changes can cause the top line to change as well. As
- * before, if the movement is large, the screen is repainted.
- *
- * 2a: Tiny screens.
- *
- * Tiny screens cannot be permitted into the "scrolling" parts of
- * the smap code for two reasons. If the screen size is 1 line,
- * HMAP == TMAP and the code will quickly drop core. If the screen
- * size is 2, none of the divisions by 2 will work, and scrolling
- * won't work. In fact, because no line change will be less than
- * HALFTEXT(sp), we always ending up "filling" the map, with a
- * P_MIDDLE flag, which isn't what the user wanted. Tiny screens
- * can go into the "fill" portions of the smap code, however.
- */
- if (sp->t_rows <= 2) {
- if (LNO < HMAP->lno) {
- if (svi_sm_fill(sp, ep, LNO, P_TOP))
- return (1);
- } else if (LNO > TMAP->lno)
- if (svi_sm_fill(sp, ep, LNO, P_BOTTOM))
- return (1);
- if (sp->t_rows == 1) {
- HMAP->off = svi_opt_screens(sp, ep, LNO, &CNO);
- goto paint;
- }
- F_SET(sp, S_REDRAW);
- goto adjust;
- }
-
- /*
- * 2b: Small screens.
- *
- * Users can use the window, w300, w1200 and w9600 options to make
- * the screen artificially small. The behavior of these options
- * in the historic vi wasn't all that consistent, and, in fact, it
- * was never documented how various screen movements affected the
- * screen size. Generally, one of three things would happen:
- * 1: The screen would expand in size, showing the line
- * 2: The screen would scroll, showing the line
- * 3: The screen would compress to its smallest size and
- * repaint.
- * In general, scrolling didn't cause compression (200^D was handled
- * the same as ^D), movement to a specific line would (:N where N
- * was 1 line below the screen caused a screen compress), and cursor
- * movement would scroll if it was 11 lines or less, and compress if
- * it was more than 11 lines. (And, no, I have no idea where the 11
- * comes from.)
- *
- * What we do is try and figure out if the line is less than half of
- * a full screen away. If it is, we expand the screen if there's
- * room, and then scroll as necessary. The alternative is to compress
- * and repaint.
- *
- * !!!
- * This code is a special case from beginning to end. Unfortunately,
- * home modems are still slow enough that it's worth having.
- *
- * XXX
- * If the line a really long one, i.e. part of the line is on the
- * screen but the column offset is not, we'll end up in the adjust
- * code, when we should probably have compressed the screen.
- */
- if (ISSMALLSCREEN(sp))
- if (LNO < HMAP->lno) {
- lcnt = svi_sm_nlines(sp, ep, HMAP, LNO, sp->t_maxrows);
- if (lcnt <= HALFSCREEN(sp))
- for (; lcnt && sp->t_rows != sp->t_maxrows;
- --lcnt, ++sp->t_rows) {
- ++TMAP;
- if (svi_sm_1down(sp, ep))
- return (1);
- }
- else
- goto small_fill;
- } else if (LNO > TMAP->lno) {
- lcnt = svi_sm_nlines(sp, ep, TMAP, LNO, sp->t_maxrows);
- if (lcnt <= HALFSCREEN(sp))
- for (; lcnt && sp->t_rows != sp->t_maxrows;
- --lcnt, ++sp->t_rows) {
- if (svi_sm_next(sp, ep, TMAP, TMAP + 1))
- return (1);
- ++TMAP;
- if (svi_line(sp, ep, TMAP, NULL, NULL))
- return (1);
- }
- else {
-small_fill: MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
- for (; sp->t_rows > sp->t_minrows;
- --sp->t_rows, --TMAP) {
- MOVE(sp, TMAP - HMAP, 0);
- clrtoeol();
- }
- if (svi_sm_fill(sp, ep, LNO, P_FILL))
- return (1);
- F_SET(sp, S_REDRAW);
- goto adjust;
- }
- }
-
- /*
- * 3a: Line down, or current screen.
- */
- if (LNO >= HMAP->lno) {
- /* Current screen. */
- if (LNO <= TMAP->lno)
- goto adjust;
-
- /*
- * If less than half a screen above the line, scroll down
- * until the line is on the screen.
- */
- lcnt = svi_sm_nlines(sp, ep, TMAP, LNO, HALFTEXT(sp));
- if (lcnt < HALFTEXT(sp)) {
- while (lcnt--)
- if (svi_sm_1up(sp, ep))
- return (1);
- goto adjust;
- }
- goto bottom;
- }
-
- /*
- * 3b: Line up.
- */
- lcnt = svi_sm_nlines(sp, ep, HMAP, LNO, HALFTEXT(sp));
- if (lcnt < HALFTEXT(sp)) {
- /*
- * If less than half a screen below the line, scroll up until
- * the line is the first line on the screen. Special check so
- * that if the screen has been emptied, we refill it.
- */
- if (file_gline(sp, ep, HMAP->lno, &len) != NULL) {
- while (lcnt--)
- if (svi_sm_1down(sp, ep))
- return (1);
- goto adjust;
- }
-
- /*
- * If less than a full screen from the bottom of the file,
- * put the last line of the file on the bottom of the screen.
- */
-bottom: if (file_lline(sp, ep, &lastline))
- return (1);
- tmp.lno = LNO;
- tmp.off = 1;
- lcnt = svi_sm_nlines(sp, ep, &tmp, lastline, sp->t_rows);
- if (lcnt < sp->t_rows) {
- if (svi_sm_fill(sp, ep, lastline, P_BOTTOM))
- return (1);
- F_SET(sp, S_REDRAW);
- goto adjust;
- }
- /* It's not close, just put the line in the middle. */
- goto middle;
- }
-
- /*
- * If less than half a screen from the top of the file, put the first
- * line of the file at the top of the screen. Otherwise, put the line
- * in the middle of the screen.
- */
- tmp.lno = 1;
- tmp.off = 1;
- lcnt = svi_sm_nlines(sp, ep, &tmp, LNO, HALFTEXT(sp));
- if (lcnt < HALFTEXT(sp)) {
- if (svi_sm_fill(sp, ep, 1, P_TOP))
- return (1);
- } else
-middle: if (svi_sm_fill(sp, ep, LNO, P_MIDDLE))
- return (1);
- F_SET(sp, S_REDRAW);
-
- /*
- * At this point we know part of the line is on the screen. Since
- * scrolling is done using logical lines, not physical, all of the
- * line may not be on the screen. While that's not necessarily bad,
- * if the part the cursor is on isn't there, we're going to lose.
- * This can be tricky; if the line covers the entire screen, lno
- * may be the same as both ends of the map, that's why we test BOTH
- * the top and the bottom of the map. This isn't a problem for
- * left-right scrolling, the cursor movement code handles the problem.
- *
- * There's a performance issue here if editing *really* long lines.
- * This gets to the right spot by scrolling, and, in a binary, by
- * scrolling hundreds of lines. If the adjustment looks like it's
- * going to be a serious problem, refill the screen and repaint.
- */
-adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
- (LNO == HMAP->lno || LNO == TMAP->lno)) {
- cnt = svi_opt_screens(sp, ep, LNO, &CNO);
- if (LNO == HMAP->lno && cnt < HMAP->off)
- if ((HMAP->off - cnt) > HALFTEXT(sp)) {
- HMAP->off = cnt;
- svi_sm_fill(sp, ep, OOBLNO, P_TOP);
- F_SET(sp, S_REDRAW);
- } else
- while (cnt < HMAP->off)
- if (svi_sm_1down(sp, ep))
- return (1);
- if (LNO == TMAP->lno && cnt > TMAP->off)
- if ((cnt - TMAP->off) > HALFTEXT(sp)) {
- TMAP->off = cnt;
- svi_sm_fill(sp, ep, OOBLNO, P_BOTTOM);
- F_SET(sp, S_REDRAW);
- } else
- while (cnt > TMAP->off)
- if (svi_sm_1up(sp, ep))
- return (1);
- }
-
- /*
- * If the screen needs to be repainted, skip cursor optimization.
- * However, in the code above we skipped leftright scrolling on
- * the grounds that the cursor code would handle it. Make sure
- * the right screen is up.
- */
- if (F_ISSET(sp, S_REDRAW)) {
- if (O_ISSET(sp, O_LEFTRIGHT)) {
- cnt = svi_opt_screens(sp, ep, LNO, &CNO);
- if (HMAP->off != cnt)
- for (smp = HMAP; smp <= TMAP; ++smp)
- smp->off = cnt;
- }
- goto paint;
- }
-
- /*
- * 4: Cursor movements.
- *
- * Decide cursor position. If the line has changed, the cursor has
- * moved over a tab, or don't know where the cursor was, reparse the
- * line. Otherwise, we've just moved over fixed-width characters,
- * and can calculate the left/right scrolling and cursor movement
- * without reparsing the line. Note that we don't know which (if any)
- * of the characters between the old and new cursor positions changed.
- *
- * XXX
- * With some work, it should be possible to handle tabs quickly, at
- * least in obvious situations, like moving right and encountering
- * a tab, without reparsing the whole line.
- */
-
- /* If the line we're working with has changed, reparse. */
- if (F_ISSET(SVP(sp), SVI_CUR_INVALID) || LNO != OLNO) {
- F_CLR(SVP(sp), SVI_CUR_INVALID);
- goto slow;
- }
-
- /* Otherwise, if nothing's changed, go fast. */
- if (CNO == OCNO)
- goto fast;
-
- /*
- * Get the current line. If this fails, we either have an empty
- * file and can just repaint, or there's a real problem. This
- * isn't a performance issue because there aren't any ways to get
- * here repeatedly.
- */
- if ((p = file_gline(sp, ep, LNO, &len)) == NULL) {
- if (file_lline(sp, ep, &lastline))
- return (1);
- if (lastline == 0)
- goto slow;
- GETLINE_ERR(sp, LNO);
- return (1);
- }
-
-#ifdef DEBUG
- /* This is just a test. */
- if (CNO >= len && len != 0) {
- msgq(sp, M_ERR, "Error: %s/%d: cno (%u) >= len (%u)",
- tail(__FILE__), __LINE__, CNO, len);
- return (1);
- }
-#endif
- /*
- * The basic scheme here is to look at the characters in between
- * the old and new positions and decide how big they are on the
- * screen, and therefore, how many screen positions to move.
- */
- if (CNO < OCNO) {
- /*
- * 4a: Cursor moved left.
- *
- * Point to the old character. The old cursor position can
- * be past EOL if, for example, we just deleted the rest of
- * the line. In this case, since we don't know the width of
- * the characters we traversed, we have to do it slowly.
- */
- p += OCNO;
- cnt = (OCNO - CNO) + 1;
- if (OCNO >= len)
- goto slow;
-
- /*
- * Quick sanity check -- it's hard to figure out exactly when
- * we cross a screen boundary as we do in the cursor right
- * movement. If cnt is so large that we're going to cross the
- * boundary no matter what, stop now.
- */
- if (SCNO + 1 + MAX_CHARACTER_COLUMNS < cnt)
- goto lscreen;
-
- /*
- * Count up the widths of the characters. If it's a tab
- * character, go do it the the slow way.
- */
- for (cwtotal = 0; cnt--; cwtotal += KEY_LEN(sp, ch))
- if ((ch = *(u_char *)p--) == '\t')
- goto slow;
-
- /*
- * Decrement the screen cursor by the total width of the
- * characters minus 1.
- */
- cwtotal -= 1;
-
- /*
- * If we're moving left, and there's a wide character in the
- * current position, go to the end of the character.
- */
- if (KEY_LEN(sp, ch) > 1)
- cwtotal -= KEY_LEN(sp, ch) - 1;
-
- /*
- * If the new column moved us off of the current logical line,
- * calculate a new one. If doing leftright scrolling, we've
- * moved off of the current screen, as well. Since most files
- * don't have more than two screens, we optimize moving from
- * screen 2 to screen 1.
- */
- if (SCNO < cwtotal) {
-lscreen: if (O_ISSET(sp, O_LEFTRIGHT)) {
- cnt = HMAP->off == 2 ? 1 :
- svi_opt_screens(sp, ep, LNO, &CNO);
- for (smp = HMAP; smp <= TMAP; ++smp)
- smp->off = cnt;
- leftright_warp = 1;
- goto paint;
- }
- goto slow;
- }
- SCNO -= cwtotal;
- } else {
- /*
- * 4b: Cursor moved right.
- *
- * Point to the first character to the right.
- */
- p += OCNO + 1;
- cnt = CNO - OCNO;
-
- /*
- * Count up the widths of the characters. If it's a tab
- * character, go do it the the slow way. If we cross a
- * screen boundary, we can quit.
- */
- for (cwtotal = SCNO; cnt--;) {
- if ((ch = *(u_char *)p++) == '\t')
- goto slow;
- if ((cwtotal += KEY_LEN(sp, ch)) >= SCREEN_COLS(sp))
- break;
- }
-
- /*
- * Increment the screen cursor by the total width of the
- * characters.
- */
- SCNO = cwtotal;
-
- /* See screen change comment in section 4a. */
- if (SCNO >= SCREEN_COLS(sp)) {
- if (O_ISSET(sp, O_LEFTRIGHT)) {
- cnt = svi_opt_screens(sp, ep, LNO, &CNO);
- for (smp = HMAP; smp <= TMAP; ++smp)
- smp->off = cnt;
- leftright_warp = 1;
- goto paint;
- }
- goto slow;
- }
- }
-
- /*
- * 4c: Fast cursor update.
- *
- * Retrieve the current cursor position, and correct it
- * for split screens.
- */
-fast: getyx(stdscr, y, x);
- y -= sp->woff;
- goto number;
-
- /*
- * 4d: Slow cursor update.
- *
- * Walk through the map and find the current line. If doing left-right
- * scrolling and the cursor movement has changed the screen displayed,
- * scroll the screen left or right, unless we're updating the info line
- * in which case we just scroll that one line. Then update the screen
- * lines for this file line until we have a new screen cursor position.
- */
-slow: for (smp = HMAP; smp->lno != LNO; ++smp);
- if (O_ISSET(sp, O_LEFTRIGHT)) {
- cnt = svi_opt_screens(sp, ep, LNO, &CNO) % SCREEN_COLS(sp);
- if (cnt != HMAP->off) {
- if (ISINFOLINE(sp, smp))
- smp->off = cnt;
- else {
- for (smp = HMAP; smp <= TMAP; ++smp)
- smp->off = cnt;
- leftright_warp = 1;
- }
- goto paint;
- }
- }
- for (y = -1; smp <= TMAP && smp->lno == LNO; ++smp) {
- if (svi_line(sp, ep, smp, &y, &SCNO))
- return (1);
- if (y != -1)
- break;
- }
- goto number;
-
- /*
- * 5: Repaint the entire screen.
- *
- * Lost big, do what you have to do. We flush the cache as S_REDRAW
- * gets set when the screen isn't worth fixing, and it's simpler to
- * repaint. So, don't trust anything that we think we know about it.
- */
-paint: for (smp = HMAP; smp <= TMAP; ++smp)
- SMAP_FLUSH(smp);
- for (smp = HMAP; smp <= TMAP; ++smp)
- if (svi_line(sp, ep, smp, &y, &SCNO))
- return (1);
- /*
- * If it's a small screen and we're redrawing, clear the unused lines,
- * ex may have overwritten them.
- */
- if (F_ISSET(sp, S_REDRAW)) {
- if (ISSMALLSCREEN(sp))
- for (cnt = sp->t_rows; cnt <= sp->t_maxrows; ++cnt) {
- MOVE(sp, cnt, 0);
- clrtoeol();
- }
- F_CLR(sp, S_REDRAW);
- }
-
- didpaint = 1;
-
- /*
- * 6: Repaint the line numbers.
- *
- * If O_NUMBER is set and the S_RENUMBER bit is set, and we didn't
- * repaint the screen, repaint all of the line numbers, they've
- * changed.
- */
-number: if (O_ISSET(sp, O_NUMBER) && F_ISSET(sp, S_RENUMBER) && !didpaint) {
- if (svi_number(sp, ep))
- return (1);
- F_CLR(sp, S_RENUMBER);
- }
-
- /*
- * 7: Refresh the screen.
- *
- * If the screen was corrupted, refresh it.
- */
- if (F_ISSET(sp, S_REFRESH)) {
- wrefresh(curscr);
- F_CLR(sp, S_REFRESH);
- }
-
- if (F_ISSET(sp, S_BELLSCHED))
- svi_bell(sp);
- /*
- * If the bottom line isn't in use by the colon command, and
- * we're not in the middle of a map:
- *
- * Display any messages. Don't test S_UPDATE_MODE. The
- * message printing routine set it to avoid anyone else
- * destroying the message we're about to display.
- *
- * If the bottom line isn't in use by anyone, put out the
- * standard status line.
- */
- if (!F_ISSET(SVP(sp), SVI_INFOLINE) && !KEYS_WAITING(sp))
- if (sp->msgq.lh_first != NULL &&
- !F_ISSET(sp->msgq.lh_first, M_EMPTY))
- svi_msgflush(sp);
- else if (!F_ISSET(sp, S_UPDATE_MODE))
- svi_modeline(sp, ep);
-
- /* Update saved information. */
- OCNO = CNO;
- OLNO = LNO;
-
- /* Place the cursor. */
- MOVE(sp, y, SCNO);
-
- /* Flush it all out. */
- refresh();
-
- /*
- * XXX
- * Recalculate the "most favorite" cursor position. Vi doesn't know
- * that we've warped the screen and it's going to have a completely
- * wrong idea about where the cursor should be. This is vi's problem,
- * and fixing it here is a gross violation of layering.
- */
- if (leftright_warp)
- (void)svi_column(sp, ep, &sp->rcm);
-
- return (0);
-}
-
-/*
- * svi_modeline --
- * Update the mode line.
- */
-static int
-svi_modeline(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- size_t cols, curlen, endpoint, len, midpoint;
- char *p, buf[20];
-
- /* Clear the mode line. */
- MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
-
- /*
- * We put down the file name, the ruler, the mode and the dirty flag.
- * If there's not enough room, there's not enough room, we don't play
- * any special games. We try to put the ruler in the middle and the
- * mode and dirty flag at the end.
- *
- * !!!
- * Leave the last character blank, in case it's a really dumb terminal
- * with hardware scroll. Second, don't paint the last character in the
- * screen, SunOS 4.1.1 and Ultrix 4.2 curses won't let you.
- */
- cols = sp->cols - 1;
-
- curlen = 0;
- if (sp->q.cqe_next != (void *)&sp->gp->dq) {
- for (p = sp->frp->name; *p != '\0'; ++p);
- while (--p > sp->frp->name) {
- if (*p == '/') {
- ++p;
- break;
- }
- if ((curlen += KEY_LEN(sp, *p)) > cols) {
- curlen -= KEY_LEN(sp, *p);
- ++p;
- break;
- }
- }
-
- MOVE(sp, INFOLINE(sp), 0);
- standout();
- for (; *p != '\0'; ++p)
- ADDCH(*p);
- standend();
- }
-
- /*
- * Display the ruler. If we're not at the midpoint yet, move there.
- * Otherwise, just add in two extra spaces.
- *
- * XXX
- * Assume that numbers, commas, and spaces only take up a single
- * column on the screen.
- */
- if (O_ISSET(sp, O_RULER)) {
- len = snprintf(buf,
- sizeof(buf), "%lu,%lu", sp->lno, sp->cno + 1);
- midpoint = (cols - ((len + 1) / 2)) / 2;
- if (curlen < midpoint) {
- MOVE(sp, INFOLINE(sp), midpoint);
- ADDSTR(buf);
- curlen += len;
- } else if (curlen + 2 + len < cols) {
- ADDSTR(" ");
- ADDSTR(buf);
- curlen += 2 + len;
- }
- }
-
- /*
- * Display the mode and the modified flag, as close to the end of the
- * line as possible, but guaranteeing at least two spaces between the
- * ruler and the modified flag.
- *
- * XXX
- * Assume that mode name characters, asterisks, and spaces only take
- * up a single column on the screen.
- */
- endpoint = cols;
- if (O_ISSET(sp, O_SHOWDIRTY) && F_ISSET(ep, F_MODIFIED))
- --endpoint;
-
-#define MODESIZE 9
- if (O_ISSET(sp, O_SHOWMODE))
- endpoint -= MAX_MODE_NAME;
-
- if (endpoint < curlen + 2)
- return (0);
-
- MOVE(sp, INFOLINE(sp), endpoint);
- if (O_ISSET(sp, O_SHOWDIRTY) && F_ISSET(ep, F_MODIFIED))
- ADDSTR("*");
- if (O_ISSET(sp, O_SHOWMODE))
- ADDSTR(sp->showmode);
- return (0);
-}
diff --git a/usr.bin/vi/svi/svi_relative.c b/usr.bin/vi/svi/svi_relative.c
deleted file mode 100644
index 31575b9..0000000
--- a/usr.bin/vi/svi/svi_relative.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_relative.c 8.18 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "svi_screen.h"
-
-static size_t svi_screens
- __P((SCR *, EXF *, char *, size_t, recno_t, size_t *));
-
-/*
- * svi_column --
- * Return the logical column of the cursor.
- */
-int
-svi_column(sp, ep, cp)
- SCR *sp;
- EXF *ep;
- size_t *cp;
-{
- size_t col;
-
- col = SVP(sp)->sc_col;
- if (O_ISSET(sp, O_NUMBER))
- col -= O_NUMBER_LENGTH;
- *cp = col;
- return (0);
-}
-
-/*
- * svi_opt_screens --
- * Return the screen columns necessary to display the line, or
- * if specified, the physical character column within the line,
- * including space required for the O_NUMBER and O_LIST options.
- */
-size_t
-svi_opt_screens(sp, ep, lno, cnop)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- size_t *cnop;
-{
- size_t cols, screens;
-
- /*
- * Check for a cached value. We maintain a cache because, if the
- * line is large, this routine gets called repeatedly. One other
- * hack, lots of time the cursor is on column one, which is an easy
- * one.
- */
- if (cnop == NULL) {
- if (SVP(sp)->ss_lno == lno)
- return (SVP(sp)->ss_screens);
- } else if (*cnop == 0)
- return (1);
-
- /* Figure out how many columns the line/column needs. */
- cols = svi_screens(sp, ep, NULL, 0, lno, cnop);
-
- /* Leading number if O_NUMBER option set. */
- if (O_ISSET(sp, O_NUMBER))
- cols += O_NUMBER_LENGTH;
-
- /* Trailing '$' if O_LIST option set. */
- if (O_ISSET(sp, O_LIST) && cnop == NULL)
- cols += KEY_LEN(sp, '$');
-
- screens = (cols / sp->cols + (cols % sp->cols ? 1 : 0));
- if (screens == 0)
- screens = 1;
-
- /* Cache the value. */
- if (cnop == NULL) {
- SVP(sp)->ss_lno = lno;
- SVP(sp)->ss_screens = screens;
- }
- return (screens);
-}
-
-/*
- * svi_screens --
- * Return the screen columns necessary to display the line, or,
- * if specified, the physical character column within the line.
- */
-static size_t
-svi_screens(sp, ep, lp, llen, lno, cnop)
- SCR *sp;
- EXF *ep;
- char *lp;
- size_t llen;
- recno_t lno;
- size_t *cnop;
-{
- size_t chlen, cno, len, scno, tab_off;
- int ch, listset;
- char *p;
-
- /* Need the line to go any further. */
- if (lp == NULL)
- lp = file_gline(sp, ep, lno, &llen);
-
- /* Missing or empty lines are easy. */
- if (lp == NULL || llen == 0)
- return (0);
-
- listset = O_ISSET(sp, O_LIST);
-
-#define SET_CHLEN { \
- chlen = (ch = *(u_char *)p++) == '\t' && \
- !listset ? TAB_OFF(sp, tab_off) : KEY_LEN(sp, ch); \
-}
-#define TAB_RESET { \
- /* \
- * If past the end of the screen, and the character was a tab, \
- * reset the screen column to 0. Otherwise, display the rest \
- * of the character on the next line. \
- */ \
- if ((tab_off += chlen) >= sp->cols) \
- if (ch == '\t') { \
- tab_off = 0; \
- scno -= scno % sp->cols; \
- } else \
- tab_off -= sp->cols; \
-}
- p = lp;
- len = llen;
- scno = tab_off = 0;
- if (cnop == NULL)
- while (len--) {
- SET_CHLEN;
- scno += chlen;
- TAB_RESET;
- }
- else
- for (cno = *cnop; len--; --cno) {
- SET_CHLEN;
- scno += chlen;
- TAB_RESET;
- if (cno == 0)
- break;
- }
- return (scno);
-}
-
-/*
- * svi_rcm --
- * Return the physical column from the line that will display a
- * character closest to the currently most attractive character
- * position (which is stored as a screen column).
- */
-size_t
-svi_rcm(sp, ep, lno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
-{
- size_t len;
-
- /* Last character is easy, and common. */
- if (sp->rcm_last)
- return (file_gline(sp,
- ep, lno, &len) == NULL || len == 0 ? 0 : len - 1);
-
- /* First character is easy, and common. */
- if (HMAP->off == 1 && sp->rcm == 0)
- return (0);
-
- /*
- * Get svi_cm_private() to do the hard work. If doing leftright
- * scrolling, we use the current screen offset, otherwise, use
- * the first screen, i.e. an offset of 1.
- *
- * XXX
- * I'm not sure that an offset of 1 is right. What happens is that
- * the vi main loop calls us for the VM_RCM case. By using an offset
- * of 1, we're assuming that every VM_RCM command changes lines, and
- * that we want to position on the first screen for that line. This
- * is currently the way it works, but it's not clean. I'd prefer it if
- * we could find the SMAP entry the cursor references, and use that
- * screen offset. Unfortunately, that's not going to be easy, as we
- * don't keep that information around and it may be expensive to get.
- */
- return (svi_cm_private(sp, ep, lno,
- O_ISSET(sp, O_LEFTRIGHT) ? HMAP->off : 1, sp->rcm));
-}
-
-/*
- * svi_cm_public --
- * Return the physical column from the line that will display a
- * character closest to the specified screen column.
- *
- * The extra interface is because it's called by vi, which doesn't
- * have a handle on the SMAP structure.
- */
-size_t
-svi_cm_public(sp, ep, lno, cno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- size_t cno;
-{
- return (svi_cm_private(sp, ep, lno, HMAP->off, cno));
-}
-
-/*
- * svi_cm_private --
- * Return the physical column from the line that will display a
- * character closest to the specified screen column, taking into
- * account the screen offset.
- *
- * The offset is for the commands that move logical distances, i.e.
- * if it's a logical scroll the closest physical distance is based
- * on the logical line, not the physical line.
- */
-size_t
-svi_cm_private(sp, ep, lno, off, cno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- size_t off, cno;
-{
- size_t chlen, len, llen, scno, tab_off;
- int ch, listset;
- char *lp, *p;
-
- /* Need the line to go any further. */
- lp = file_gline(sp, ep, lno, &llen);
-
- /* Missing or empty lines are easy. */
- if (lp == NULL || llen == 0)
- return (0);
-
- listset = O_ISSET(sp, O_LIST);
-
- /* Discard screen (logical) lines. */
- for (scno = 0, p = lp, len = llen; --off;) {
- for (; len && scno < sp->cols; --len)
- scno += (ch = *(u_char *)p++) == '\t' &&
- !listset ? TAB_OFF(sp, scno) : KEY_LEN(sp, ch);
-
- /*
- * If reached the end of the physical line, return
- * the last physical character in the line.
- */
- if (len == 0)
- return (llen - 1);
-
- /*
- * If the character was a tab, reset the screen column to 0.
- * Otherwise, the rest of the character is displayed on the
- * next line.
- */
- if (ch == '\t')
- scno = 0;
- else
- scno -= sp->cols;
- }
-
- /* Step through the line until reach the right character or EOL. */
- for (tab_off = scno; len--;) {
- SET_CHLEN;
-
- /*
- * If we've reached the specific character, there are three
- * cases.
- *
- * 1: scno == cno, i.e. the current character ends at the
- * screen character we care about.
- * a: off < llen - 1, i.e. not the last character in
- * the line, return the offset of the next character.
- * b: else return the offset of the last character.
- * 2: scno != cno, i.e. this character overruns the character
- * we care about, return the offset of this character.
- */
- if ((scno += chlen) >= cno) {
- off = p - lp;
- return (scno == cno ?
- (off < llen - 1 ? off : llen - 1) : off - 1);
- }
-
- TAB_RESET;
- }
-
- /* No such character; return the start of the last character. */
- return (llen - 1);
-}
diff --git a/usr.bin/vi/svi/svi_screen.c b/usr.bin/vi/svi/svi_screen.c
deleted file mode 100644
index f7d3f88..0000000
--- a/usr.bin/vi/svi/svi_screen.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_screen.c 8.94 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "svi_screen.h"
-#include "../sex/sex_screen.h"
-
-/*
- * svi_screen_init --
- * Initialize a screen.
- */
-int
-svi_screen_init(sp)
- SCR *sp;
-{
- /* Initialize support routines. */
- sp->s_bell = svi_bell;
- sp->s_bg = svi_bg;
- sp->s_busy = svi_busy;
- sp->s_change = svi_change;
- sp->s_clear = svi_clear;
- sp->s_colpos = svi_cm_public;
- sp->s_column = svi_column;
- sp->s_confirm = svi_confirm;
- sp->s_crel = svi_crel;
- sp->s_edit = svi_screen_edit;
- sp->s_end = svi_screen_end;
- sp->s_ex_cmd = svi_ex_cmd;
- sp->s_ex_run = svi_ex_run;
- sp->s_ex_write = svi_ex_write;
- sp->s_fg = svi_fg;
- sp->s_fill = svi_sm_fill;
- sp->s_get = svi_get;
- sp->s_key_read = sex_key_read;
- sp->s_optchange = svi_optchange;
- sp->s_fmap = svi_fmap;
- sp->s_position = svi_sm_position;
- sp->s_rabs = svi_rabs;
- sp->s_rcm = svi_rcm;
- sp->s_refresh = svi_refresh;
- sp->s_scroll = svi_sm_scroll;
- sp->s_split = svi_split;
- sp->s_suspend = svi_suspend;
- sp->s_window = sex_window;
-
- return (0);
-}
-
-/*
- * svi_screen_copy --
- * Copy to a new screen.
- */
-int
-svi_screen_copy(orig, sp)
- SCR *orig, *sp;
-{
- SVI_PRIVATE *osvi, *nsvi;
-
- /* Create the private screen structure. */
- CALLOC_RET(orig, nsvi, SVI_PRIVATE *, 1, sizeof(SVI_PRIVATE));
- sp->svi_private = nsvi;
-
-/* INITIALIZED AT SCREEN CREATE. */
- /* Invalidate the line size cache. */
- SVI_SCR_CFLUSH(nsvi);
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
- if (orig == NULL) {
- } else {
- osvi = SVP(orig);
- nsvi->srows = osvi->srows;
- if (osvi->VB != NULL && (nsvi->VB = strdup(osvi->VB)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
-
- F_SET(nsvi, F_ISSET(osvi, SVI_CURSES_INIT));
- }
- return (0);
-}
-
-/*
- * svi_screen_end --
- * End a screen.
- */
-int
-svi_screen_end(sp)
- SCR *sp;
-{
- SVI_PRIVATE *svp;
-
- svp = SVP(sp);
-
- /* Free the screen map. */
- if (HMAP != NULL)
- FREE(HMAP, SIZE_HMAP(sp) * sizeof(SMAP));
-
- /* Free the visual bell string. */
- if (svp->VB != NULL)
- free(svp->VB);
-
- /* Free private memory. */
- FREE(svp, sizeof(SVI_PRIVATE));
- sp->svi_private = NULL;
-
- return (0);
-}
-
-/*
- * We use a single curses "window" for each vi screen. The model would be
- * simpler with two windows (one for the text, and one for the modeline)
- * because scrolling the text window down would work correctly then, not
- * affecting the mode line. As it is we have to play games to make it look
- * right. The reason for this choice is that it would be difficult for
- * curses to optimize the movement, i.e. detect that the downward scroll
- * isn't going to change the modeline, set the scrolling region on the
- * terminal and only scroll the first part of the text window. (Even if
- * curses did detect it, the set-scrolling-region terminal commands can't
- * be used by curses because it's indeterminate where the cursor ends up
- * after they are sent.)
- */
-/*
- * svi_screen_edit --
- * Main vi curses screen loop.
- */
-int
-svi_screen_edit(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- SCR *tsp;
- int ecurses, escreen, force, rval;
-
- escreen = ecurses = rval = 0;
-
- /* Initialize curses. */
- if (svi_curses_init(sp)) {
- escreen = 1;
- goto err;
- }
- ecurses = 1;
-
- /*
- * The resize bit is probably set, as a result of the terminal being
- * set. We clear it as we just finished initializing the screen.
- * However, we will want to fill in the map from scratch, so provide
- * a line number just in case, and set the reformat flag.
- */
- HMAP->lno = 1;
- F_CLR(sp, S_RESIZE);
- F_SET(sp, S_REFORMAT);
-
- /*
- * The historic 4BSD curses had an uneasy relationship with termcap.
- * Termcap used a static buffer to hold the terminal information,
- * which was was then used by the curses functions. We want to use
- * it too, for lots of random things, but we've put it off until after
- * svi_curses_init:initscr() was called. Do it now.
- */
- if (svi_term_init(sp))
- goto err;
-
- for (;;) {
- /* Reset the cursor. */
- F_SET(SVP(sp), SVI_CUR_INVALID);
-
- /*
- * Run vi. If vi fails, svi data structures may be
- * corrupted, be extremely careful what you free up.
- */
- if (vi(sp, sp->ep)) {
- (void)rcv_sync(sp, sp->ep,
- RCV_EMAIL | RCV_ENDSESSION | RCV_PRESERVE);
- escreen = 1;
- goto err;
- }
-
- force = 0;
- switch (F_ISSET(sp, S_MAJOR_CHANGE)) {
- case S_EXIT_FORCE:
- force = 1;
- /* FALLTHROUGH */
- case S_EXIT:
- F_CLR(sp, S_EXIT_FORCE | S_EXIT);
- if (file_end(sp, sp->ep, force))/* File end. */
- break;
- /*
- * !!!
- * NB: sp->frp may now be NULL, if it was a tmp file.
- */
- (void)svi_join(sp, &tsp); /* Find a new screen. */
- if (tsp == NULL)
- (void)svi_swap(sp, &tsp, NULL);
- if (tsp == NULL) {
- escreen = 1;
- goto ret;
- }
- (void)screen_end(sp); /* Screen end. */
- sp = tsp;
- break;
- case 0: /* Exit vi mode. */
- svi_dtoh(sp, "Exit from vi");
- goto ret;
- case S_FSWITCH: /* File switch. */
- F_CLR(sp, S_FSWITCH);
- F_SET(sp, S_REFORMAT);
- break;
- case S_SSWITCH: /* Screen switch. */
- F_CLR(sp, S_SSWITCH);
- sp = sp->nextdisp;
- break;
- default:
- abort();
- }
- }
-
- if (0) {
-err: rval = 1;
- }
-
-ret: if (svi_term_end(sp)) /* Terminal end (uses sp). */
- rval = 1;
- if (ecurses && svi_curses_end(sp)) /* Curses end (uses sp). */
- rval = 1;
- if (escreen && screen_end(sp)) /* Screen end. */
- rval = 1;
- return (rval);
-}
-
-/*
- * svi_crel --
- * Change the relative size of the current screen.
- */
-int
-svi_crel(sp, count)
- SCR *sp;
- long count;
-{
- /* Can't grow beyond the size of the window. */
- if (count > O_VAL(sp, O_WINDOW))
- count = O_VAL(sp, O_WINDOW);
-
- sp->t_minrows = sp->t_rows = count;
- if (sp->t_rows > sp->rows - 1)
- sp->t_minrows = sp->t_rows = sp->rows - 1;
- TMAP = HMAP + (sp->t_rows - 1);
- F_SET(sp, S_REDRAW);
- return (0);
-}
-
-/*
- * svi_dtoh --
- * Move all but the current screen to the hidden queue.
- */
-void
-svi_dtoh(sp, emsg)
- SCR *sp;
- char *emsg;
-{
- SCR *tsp;
- int hidden;
-
- for (hidden = 0;
- (tsp = sp->gp->dq.cqh_first) != (void *)&sp->gp->dq; ++hidden) {
- if (_HMAP(tsp) != NULL) {
- FREE(_HMAP(tsp), SIZE_HMAP(tsp) * sizeof(SMAP));
- _HMAP(tsp) = NULL;
- }
- SIGBLOCK(sp->gp);
- CIRCLEQ_REMOVE(&sp->gp->dq, tsp, q);
- CIRCLEQ_INSERT_TAIL(&sp->gp->hq, tsp, q);
- SIGUNBLOCK(sp->gp);
- }
- SIGBLOCK(sp->gp);
- CIRCLEQ_REMOVE(&sp->gp->hq, sp, q);
- CIRCLEQ_INSERT_TAIL(&sp->gp->dq, sp, q);
- SIGUNBLOCK(sp->gp);
- if (hidden > 1)
- msgq(sp, M_INFO,
- "%s backgrounded %d screens; use :display to list the screens",
- emsg, hidden - 1);
-}
diff --git a/usr.bin/vi/svi/svi_screen.h b/usr.bin/vi/svi/svi_screen.h
deleted file mode 100644
index 3b4643d..0000000
--- a/usr.bin/vi/svi/svi_screen.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.
- *
- * @(#)svi_screen.h 8.52 (Berkeley) 7/20/94
- */
-
-/*
- * Structure for mapping lines to the screen. An SMAP is an array, with one
- * structure element per screen line, which holds information describing the
- * physical line which is displayed in the screen line. The first two fields
- * (lno and off) are all that are necessary to describe a line. The rest of
- * the information is useful to keep information from being re-calculated.
- *
- * Lno is the line number. Off is the screen offset into the line. For
- * example, the pair 2:1 would be the first screen of line 2, and 2:2 would
- * be the second. If doing left-right scrolling, all of the offsets will be
- * the same, i.e. for the second screen, 1:2, 2:2, 3:2, etc. If doing the
- * standard vi scrolling, it will be staggered, i.e. 1:1, 1:2, 1:3, 2:1, 3:1,
- * etc.
- *
- * The SMAP is always as large as the physical screen, plus a slot for the
- * info line, so that there is room to add any screen into another one at
- * screen exit.
- */
-typedef struct _smap {
- recno_t lno; /* 1-N: Physical file line number. */
- size_t off; /* 1-N: Screen offset in the line. */
-
- /* svi_line() cache information. */
- size_t c_sboff; /* 0-N: offset of first character byte. */
- size_t c_eboff; /* 0-N: offset of last character byte. */
- u_char c_scoff; /* 0-N: offset into the first character. */
- u_char c_eclen; /* 1-N: columns from the last character. */
- u_char c_ecsize; /* 1-N: size of the last character. */
-} SMAP;
-
- /* Macros to flush/test cached information. */
-#define SMAP_CACHE(smp) ((smp)->c_ecsize != 0)
-#define SMAP_FLUSH(smp) ((smp)->c_ecsize = 0)
-
-typedef struct _svi_private {
-/* INITIALIZED AT SCREEN CREATE. */
- SMAP *h_smap; /* First slot of the line map. */
- SMAP *t_smap; /* Last slot of the line map. */
-
- size_t exlinecount; /* Ex overwrite count. */
- size_t extotalcount; /* Ex overwrite count. */
- size_t exlcontinue; /* Ex line continue value. */
-
- /* svi_opt_screens() cache information. */
-#define SVI_SCR_CFLUSH(svp) svp->ss_lno = OOBLNO
- recno_t ss_lno; /* 1-N: Line number. */
- size_t ss_screens; /* Return value. */
-
- recno_t olno; /* 1-N: old cursor file line. */
- size_t ocno; /* 0-N: old file cursor column. */
- size_t sc_col; /* 0-N: LOGICAL screen column. */
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
- size_t srows; /* 1-N: Rows in the terminal/window. */
-
- char *VB; /* Visual bell termcap string. */
-
-#define SVI_CURSES_INIT 0x001 /* Curses/termcap initialized. */
-#define SVI_CUR_INVALID 0x002 /* Cursor position is unknown. */
-#define SVI_DIVIDER 0x004 /* Screen divider is displayed. */
-#define SVI_INFOLINE 0x008 /* The infoline is being used by v_ntext(). */
-#define SVI_SCREENDIRTY 0x010 /* Screen needs refreshing. */
- u_int8_t flags;
-} SVI_PRIVATE;
-
-#define SVP(sp) ((SVI_PRIVATE *)((sp)->svi_private))
-#define HMAP (SVP(sp)->h_smap)
-#define TMAP (SVP(sp)->t_smap)
-#define _HMAP(sp) (SVP(sp)->h_smap)
-#define _TMAP(sp) (SVP(sp)->t_smap)
-
-/*
- * One extra slot is always allocated for the map so that we can use
- * it to do vi :colon command input; see svi_get().
- */
-#define SIZE_HMAP(sp) (SVP(sp)->srows + 1)
-
-#define O_NUMBER_FMT "%7lu " /* O_NUMBER format, length. */
-#define O_NUMBER_LENGTH 8
- /* Columns on a screen. */
-#define SCREEN_COLS(sp) \
- ((O_ISSET(sp, O_NUMBER) ? (sp)->cols - O_NUMBER_LENGTH : (sp)->cols))
-
-#define HALFSCREEN(sp) ((sp)->t_maxrows / 2) /* Half the screen. */
-#define HALFTEXT(sp) ((sp)->t_rows / 2) /* Half the text. */
-
-#define INFOLINE(sp) ((sp)->t_maxrows) /* Info line test, offset. */
-#define ISINFOLINE(sp, smp) (((smp) - HMAP) == INFOLINE(sp))
-
- /* Small screen test. */
-#define ISSMALLSCREEN(sp) ((sp)->t_minrows != (sp)->t_maxrows)
-
-/*
- * Next tab offset.
- *
- * !!!
- * There are problems with how the historical vi handled tabs. For example,
- * by doing "set ts=3" and building lines that fold, you can get it to step
- * through tabs as if they were spaces and move inserted characters to new
- * positions when <esc> is entered. I think that nvi does tabs correctly,
- * but there may be some historical incompatibilities.
- */
-#define TAB_OFF(sp, c) (O_VAL(sp, O_TABSTOP) - (c) % O_VAL(sp, O_TABSTOP))
-
-/* Move in a screen (absolute), and fail if it doesn't work. */
-#ifdef DEBUG
-#define MOVEA(sp, lno, cno) { \
- if (move(lno, cno) == ERR) { \
- msgq(sp, M_ERR, \
- "Error: %s/%d: move:l(%u), c(%u), abs", \
- tail(__FILE__), __LINE__, lno, cno); \
- return (1); \
- } \
-}
-#else
-#define MOVEA(sp, lno, cno) (void)move(lno, cno)
-#endif
-
-/* Move in a window, and fail if it doesn't work. */
-#ifdef DEBUG
-#define MOVE(sp, lno, cno) { \
- size_t __lno = (sp)->woff + (lno); \
- if (move(__lno, cno) == ERR) { \
- msgq(sp, M_ERR, \
- "Error: %s/%d: move:l(%u), c(%u), o(%u)", \
- tail(__FILE__), __LINE__, lno, cno, sp->woff); \
- return (1); \
- } \
-}
-#else
-#define MOVE(sp, lno, cno) (void)move((sp)->woff + (lno), cno)
-#endif
-
-/* Add a character. */
-#define ADDCH(ch) { \
- CHAR_T __ch = ch; \
- ADDNSTR(KEY_NAME(sp, __ch), KEY_LEN(sp, __ch)); \
-}
-
-/* Add a string len bytes long. */
-#ifdef DEBUG
-#define ADDNSTR(str, len) { \
- if (addnstr(str, len) == ERR) { \
- int __x, __y; \
- getyx(stdscr, __y, __x); \
- msgq(sp, M_ERR, "Error: %s/%d: addnstr: (%d/%u)", \
- tail(__FILE__), __LINE__, __y, __x); \
- return (1); \
- } \
-}
-#else
-#define ADDNSTR(str, len) (void)addnstr(str, len)
-#endif
-
-/* Add a string. */
-#ifdef DEBUG
-#define ADDSTR(str) { \
- if (addstr(str) == ERR) { \
- int __x, __y; \
- getyx(stdscr, __y, __x); \
- msgq(sp, M_ERR, "Error: %s/%d: addstr: (%d/%u)", \
- tail(__FILE__), __LINE__, __y, __x); \
- return (1); \
- } \
-}
-#else
-#define ADDSTR(str) (void)addstr(str);
-#endif
-
-/* Public routines. */
-void svi_bell __P((SCR *));
-int svi_bg __P((SCR *));
-int svi_busy __P((SCR *, char const *));
-int svi_change __P((SCR *, EXF *, recno_t, enum operation));
-size_t svi_cm_public __P((SCR *, EXF *, recno_t, size_t));
-int svi_column __P((SCR *, EXF *, size_t *));
-enum confirm
- svi_confirm __P((SCR *, EXF *, MARK *, MARK *));
-int svi_clear __P((SCR *));
-int svi_crel __P((SCR *, long));
-int svi_ex_cmd __P((SCR *, EXF *, struct _excmdarg *, MARK *));
-int svi_ex_run __P((SCR *, EXF *, MARK *));
-int svi_ex_write __P((void *, const char *, int));
-int svi_fg __P((SCR *, CHAR_T *));
-int svi_fmap __P((SCR *, enum seqtype, CHAR_T *, size_t, CHAR_T *, size_t));
-enum input
- svi_get __P((SCR *, EXF *, TEXTH *, ARG_CHAR_T, u_int));
-int svi_optchange __P((SCR *, int));
-int svi_rabs __P((SCR *, long, enum adjust));
-size_t svi_rcm __P((SCR *, EXF *, recno_t));
-int svi_refresh __P((SCR *, EXF *));
-int svi_screen_copy __P((SCR *, SCR *));
-int svi_screen_edit __P((SCR *, EXF *));
-int svi_screen_end __P((SCR *));
-int svi_sm_fill __P((SCR *, EXF *, recno_t, enum position));
-int svi_sm_position __P((SCR *, EXF *, MARK *, u_long, enum position));
-int svi_sm_scroll __P((SCR *, EXF *, MARK *, recno_t, enum sctype));
-int svi_split __P((SCR *, ARGS *[], int));
-int svi_suspend __P((SCR *));
-int svi_swap __P((SCR *, SCR **, char *));
-
-/* Private routines. */
-size_t svi_cm_private __P((SCR *, EXF *, recno_t, size_t, size_t));
-int svi_curses_end __P((SCR *));
-int svi_curses_init __P((SCR *));
-void svi_dtoh __P((SCR *, char *));
-int svi_init __P((SCR *));
-int svi_join __P((SCR *, SCR **));
-void svi_keypad __P((SCR *, int));
-int svi_line __P((SCR *, EXF *, SMAP *, size_t *, size_t *));
-int svi_msgflush __P((SCR *));
-int svi_number __P((SCR *, EXF *));
-size_t svi_opt_screens __P((SCR *, EXF *, recno_t, size_t *));
-int svi_paint __P((SCR *, EXF *));
-int svi_sm_1down __P((SCR *, EXF *));
-int svi_sm_1up __P((SCR *, EXF *));
-int svi_sm_cursor __P((SCR *, EXF *, SMAP **));
-int svi_sm_next __P((SCR *, EXF *, SMAP *, SMAP *));
-recno_t svi_sm_nlines __P((SCR *, EXF *, SMAP *, recno_t, size_t));
-int svi_sm_prev __P((SCR *, EXF *, SMAP *, SMAP *));
-int svi_term_end __P((SCR *sp));
-int svi_term_init __P((SCR *sp));
-
-/* Private debugging routines. */
-#ifdef DEBUG
-int svi_gdbrefresh __P((void));
-#endif
diff --git a/usr.bin/vi/svi/svi_smap.c b/usr.bin/vi/svi/svi_smap.c
deleted file mode 100644
index a9205b1..0000000
--- a/usr.bin/vi/svi/svi_smap.c
+++ /dev/null
@@ -1,1216 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_smap.c 8.48 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "svi_screen.h"
-
-static int svi_deleteln __P((SCR *, int));
-static int svi_insertln __P((SCR *, int));
-static int svi_sm_delete __P((SCR *, EXF *, recno_t));
-static int svi_sm_down __P((SCR *, EXF *,
- MARK *, recno_t, enum sctype, SMAP *));
-static int svi_sm_erase __P((SCR *));
-static int svi_sm_insert __P((SCR *, EXF *, recno_t));
-static int svi_sm_reset __P((SCR *, EXF *, recno_t));
-static int svi_sm_up __P((SCR *, EXF *,
- MARK *, recno_t, enum sctype, SMAP *));
-
-/*
- * svi_change --
- * Make a change to the screen.
- */
-int
-svi_change(sp, ep, lno, op)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- enum operation op;
-{
- SMAP *p;
- size_t oldy, oldx;
-
- /* Appending is the same as inserting, if the line is incremented. */
- if (op == LINE_APPEND) {
- ++lno;
- op = LINE_INSERT;
- }
-
- /* Ignore the change if the line is after the map. */
- if (lno > TMAP->lno)
- return (0);
-
- /*
- * If the line is before the map, and it's a decrement, decrement
- * the map. If it's an increment, increment the map. Otherwise,
- * ignore it.
- */
- if (lno < HMAP->lno) {
- switch (op) {
- case LINE_APPEND:
- abort();
- /* NOTREACHED */
- case LINE_DELETE:
- for (p = HMAP; p <= TMAP; ++p)
- --p->lno;
- if (sp->lno >= lno)
- --sp->lno;
- F_SET(sp, S_RENUMBER);
- break;
- case LINE_INSERT:
- for (p = HMAP; p <= TMAP; ++p)
- ++p->lno;
- if (sp->lno >= lno)
- ++sp->lno;
- F_SET(sp, S_RENUMBER);
- break;
- case LINE_RESET:
- break;
- }
- return (0);
- }
-
- F_SET(SVP(sp), SVI_SCREENDIRTY);
-
- /* Invalidate the cursor, if it's on this line. */
- if (sp->lno == lno)
- F_SET(SVP(sp), SVI_CUR_INVALID);
-
- /* Invalidate the line size cache. */
- SVI_SCR_CFLUSH(SVP(sp));
-
- getyx(stdscr, oldy, oldx);
-
- switch (op) {
- case LINE_DELETE:
- if (svi_sm_delete(sp, ep, lno))
- return (1);
- F_SET(sp, S_RENUMBER);
- break;
- case LINE_INSERT:
- if (svi_sm_insert(sp, ep, lno))
- return (1);
- F_SET(sp, S_RENUMBER);
- break;
- case LINE_RESET:
- if (svi_sm_reset(sp, ep, lno))
- return (1);
- break;
- default:
- abort();
- }
-
- MOVEA(sp, oldy, oldx);
-
- return (0);
-}
-
-/*
- * svi_sm_fill --
- * Fill in the screen map, placing the specified line at the
- * right position. There isn't any way to tell if an SMAP
- * entry has been filled in, so this routine had better be
- * called with P_FILL set before anything else is done.
- *
- * !!!
- * Unexported interface: if lno is OOBLNO, P_TOP means that the HMAP
- * slot is already filled in, P_BOTTOM means that the TMAP slot is
- * already filled in, and we just finish up the job.
- */
-int
-svi_sm_fill(sp, ep, lno, pos)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- enum position pos;
-{
- SMAP *p, tmp;
-
- /* Flush all cached information from the SMAP. */
- for (p = HMAP; p <= TMAP; ++p)
- SMAP_FLUSH(p);
-
- /* If the map is filled, the screen must be redrawn. */
- F_SET(sp, S_REDRAW);
-
- switch (pos) {
- case P_FILL:
- tmp.lno = 1;
- tmp.off = 1;
-
- /* See if less than half a screen from the top. */
- if (svi_sm_nlines(sp, ep,
- &tmp, lno, HALFTEXT(sp)) <= HALFTEXT(sp)) {
- lno = 1;
- goto top;
- }
-
- /* See if less than half a screen from the bottom. */
- if (file_lline(sp, ep, &tmp.lno))
- return (1);
- if (!O_ISSET(sp, O_LEFTRIGHT))
- tmp.off = svi_opt_screens(sp, ep, tmp.lno, NULL);
- if (svi_sm_nlines(sp, ep,
- &tmp, lno, HALFTEXT(sp)) <= HALFTEXT(sp)) {
- TMAP->lno = tmp.lno;
- if (!O_ISSET(sp, O_LEFTRIGHT))
- TMAP->off = tmp.off;
- goto bottom;
- }
- goto middle;
- case P_TOP:
- if (lno != OOBLNO) {
-top: HMAP->lno = lno;
- HMAP->off = 1;
- }
- /* If we fail, just punt. */
- for (p = HMAP; p < TMAP; ++p)
- if (svi_sm_next(sp, ep, p, p + 1))
- goto err;
- break;
- case P_MIDDLE:
- /* If we fail, guess that the file is too small. */
-middle: p = HMAP + (TMAP - HMAP) / 2;
- for (p->lno = lno, p->off = 1; p > HMAP; --p)
- if (svi_sm_prev(sp, ep, p, p - 1)) {
- lno = 1;
- goto top;
- }
-
- /* If we fail, just punt. */
- p = HMAP + (TMAP - HMAP) / 2;
- for (; p < TMAP; ++p)
- if (svi_sm_next(sp, ep, p, p + 1))
- goto err;
- break;
- case P_BOTTOM:
- if (lno != OOBLNO) {
- TMAP->lno = lno;
- if (!O_ISSET(sp, O_LEFTRIGHT))
- TMAP->off = svi_opt_screens(sp, ep, lno, NULL);
- }
- /* If we fail, guess that the file is too small. */
-bottom: for (p = TMAP; p > HMAP; --p)
- if (svi_sm_prev(sp, ep, p, p - 1)) {
- lno = 1;
- goto top;
- }
- break;
- default:
- abort();
- }
- return (0);
-
- /*
- * Try and put *something* on the screen. If this fails,
- * we have a serious hard error.
- */
-err: HMAP->lno = 1;
- HMAP->off = 1;
- for (p = HMAP; p < TMAP; ++p)
- if (svi_sm_next(sp, ep, p, p + 1))
- return (1);
- return (0);
-}
-
-/*
- * For the routines svi_sm_reset, svi_sm_delete and svi_sm_insert: if the
- * screen only contains one line, or, if the line is the entire screen, this
- * gets fairly exciting. Skip the fun and simply return if there's only one
- * line in the screen, or just call fill. Fill may not be entirely accurate,
- * i.e. we may be painting the screen with something not even close to the
- * cursor, but it's not like we're into serious performance issues here, and
- * the refresh routine will fix it for us.
- */
-#define TOO_WEIRD { \
- if (cnt_orig >= sp->t_rows) { \
- if (cnt_orig == 1) \
- return (0); \
- if (file_gline(sp, ep, lno, NULL) == NULL) \
- if (file_lline(sp, ep, &lno)) \
- return (1); \
- F_SET(sp, S_REDRAW); \
- return (svi_sm_fill(sp, ep, lno, P_TOP)); \
- } \
-}
-
-/*
- * svi_sm_delete --
- * Delete a line out of the SMAP.
- */
-static int
-svi_sm_delete(sp, ep, lno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
-{
- SMAP *p, *t;
- size_t cnt_orig;
-
- /*
- * Find the line in the map, and count the number of screen lines
- * which display any part of the deleted line.
- */
- for (p = HMAP; p->lno != lno; ++p);
- if (O_ISSET(sp, O_LEFTRIGHT))
- cnt_orig = 1;
- else
- for (cnt_orig = 1, t = p + 1;
- t <= TMAP && t->lno == lno; ++cnt_orig, ++t);
-
- TOO_WEIRD;
-
- /* Delete that many lines from the screen. */
- MOVE(sp, p - HMAP, 0);
- if (svi_deleteln(sp, cnt_orig))
- return (1);
-
- /* Shift the screen map up. */
- memmove(p, p + cnt_orig, (((TMAP - p) - cnt_orig) + 1) * sizeof(SMAP));
-
- /* Decrement the line numbers for the rest of the map. */
- for (t = TMAP - cnt_orig; p <= t; ++p)
- --p->lno;
-
- /* Display the new lines. */
- for (p = TMAP - cnt_orig;;) {
- if (p < TMAP && svi_sm_next(sp, ep, p, p + 1))
- return (1);
- /* svi_sm_next() flushed the cache. */
- if (svi_line(sp, ep, ++p, NULL, NULL))
- return (1);
- if (p == TMAP)
- break;
- }
- return (0);
-}
-
-/*
- * svi_sm_insert --
- * Insert a line into the SMAP.
- */
-static int
-svi_sm_insert(sp, ep, lno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
-{
- SMAP *p, *t;
- size_t cnt_orig, cnt;
-
- /*
- * Find the line in the map, find out how many screen lines
- * needed to display the line.
- */
- for (p = HMAP; p->lno != lno; ++p);
- if (O_ISSET(sp, O_LEFTRIGHT))
- cnt_orig = 1;
- else
- cnt_orig = svi_opt_screens(sp, ep, lno, NULL);
-
- TOO_WEIRD;
-
- /*
- * The lines left in the screen override the number of screen
- * lines in the inserted line.
- */
- cnt = (TMAP - p) + 1;
- if (cnt_orig > cnt)
- cnt_orig = cnt;
-
- /* Push down that many lines. */
- MOVE(sp, p - HMAP, 0);
- if (svi_insertln(sp, cnt_orig))
- return (1);
-
- /* Shift the screen map down. */
- memmove(p + cnt_orig, p, (((TMAP - p) - cnt_orig) + 1) * sizeof(SMAP));
-
- /* Increment the line numbers for the rest of the map. */
- for (t = p + cnt_orig; t <= TMAP; ++t)
- ++t->lno;
-
- /* Fill in the SMAP for the new lines, and display. */
- for (cnt = 1, t = p; cnt <= cnt_orig; ++t, ++cnt) {
- t->lno = lno;
- t->off = cnt;
- SMAP_FLUSH(t);
- if (svi_line(sp, ep, t, NULL, NULL))
- return (1);
- }
- return (0);
-}
-
-/*
- * svi_sm_reset --
- * Reset a line in the SMAP.
- */
-static int
-svi_sm_reset(sp, ep, lno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
-{
- SMAP *p, *t;
- size_t cnt_orig, cnt_new, cnt, diff;
-
- /*
- * See if the number of on-screen rows taken up by the old display
- * for the line is the same as the number needed for the new one.
- * If so, repaint, otherwise do it the hard way.
- */
- for (p = HMAP; p->lno != lno; ++p);
- if (O_ISSET(sp, O_LEFTRIGHT)) {
- t = p;
- cnt_orig = cnt_new = 1;
- } else {
- for (cnt_orig = 0,
- t = p; t <= TMAP && t->lno == lno; ++cnt_orig, ++t);
- cnt_new = svi_opt_screens(sp, ep, lno, NULL);
- }
-
- TOO_WEIRD;
-
- if (cnt_orig == cnt_new) {
- do {
- SMAP_FLUSH(p);
- if (svi_line(sp, ep, p, NULL, NULL))
- return (1);
- } while (++p < t);
- return (0);
- }
-
- if (cnt_orig < cnt_new) {
- /* Get the difference. */
- diff = cnt_new - cnt_orig;
-
- /*
- * The lines left in the screen override the number of screen
- * lines in the inserted line.
- */
- cnt = (TMAP - p) + 1;
- if (diff > cnt)
- diff = cnt;
-
- /* Push down the extra lines. */
- MOVE(sp, p - HMAP, 0);
- if (svi_insertln(sp, diff))
- return (1);
-
- /* Shift the screen map down. */
- memmove(p + diff, p, (((TMAP - p) - diff) + 1) * sizeof(SMAP));
-
- /* Fill in the SMAP for the replaced line, and display. */
- for (cnt = 1, t = p; cnt_new-- && t <= TMAP; ++t, ++cnt) {
- t->lno = lno;
- t->off = cnt;
- SMAP_FLUSH(t);
- if (svi_line(sp, ep, t, NULL, NULL))
- return (1);
- }
- } else {
- /* Get the difference. */
- diff = cnt_orig - cnt_new;
-
- /* Delete that many lines from the screen. */
- MOVE(sp, p - HMAP, 0);
- if (svi_deleteln(sp, diff))
- return (1);
-
- /* Shift the screen map up. */
- memmove(p, p + diff, (((TMAP - p) - diff) + 1) * sizeof(SMAP));
-
- /* Fill in the SMAP for the replaced line, and display. */
- for (cnt = 1, t = p; cnt_new--; ++t, ++cnt) {
- t->lno = lno;
- t->off = cnt;
- SMAP_FLUSH(t);
- if (svi_line(sp, ep, t, NULL, NULL))
- return (1);
- }
-
- /* Display the new lines at the bottom of the screen. */
- for (t = TMAP - diff;;) {
- if (t < TMAP && svi_sm_next(sp, ep, t, t + 1))
- return (1);
- /* svi_sm_next() flushed the cache. */
- if (svi_line(sp, ep, ++t, NULL, NULL))
- return (1);
- if (t == TMAP)
- break;
- }
- }
- return (0);
-}
-
-/*
- * svi_sm_scroll
- * Scroll the SMAP up/down count logical lines. Different
- * semantics based on the vi command, *sigh*.
- */
-int
-svi_sm_scroll(sp, ep, rp, count, scmd)
- SCR *sp;
- EXF *ep;
- MARK *rp;
- recno_t count;
- enum sctype scmd;
-{
- SMAP *smp;
-
- /*
- * Invalidate the cursor. The line is probably going to change,
- * (although for ^E and ^Y it may not). In any case, the scroll
- * routines move the cursor to draw things.
- */
- F_SET(SVP(sp), SVI_CUR_INVALID);
-
- /* Find the cursor in the screen. */
- if (svi_sm_cursor(sp, ep, &smp))
- return (1);
-
- switch (scmd) {
- case CNTRL_B:
- case CNTRL_U:
- case CNTRL_Y:
- case Z_CARAT:
- if (svi_sm_down(sp, ep, rp, count, scmd, smp))
- return (1);
- break;
- case CNTRL_D:
- case CNTRL_E:
- case CNTRL_F:
- case Z_PLUS:
- if (svi_sm_up(sp, ep, rp, count, scmd, smp))
- return (1);
- break;
- default:
- abort();
- }
-
- /*
- * !!!
- * If we're at the start of a line, go for the first non-blank.
- * This makes it look like the old vi, even though we're moving
- * around by logical lines, not physical ones.
- *
- * XXX
- * In the presence of a long line, which has more than a screen
- * width of leading spaces, this code can cause a cursor warp.
- * Live with it.
- */
- if (scmd != CNTRL_E && scmd != CNTRL_Y &&
- rp->cno == 0 && nonblank(sp, ep, rp->lno, &rp->cno))
- return (1);
-
- return (0);
-}
-
-/*
- * svi_sm_up --
- * Scroll the SMAP up count logical lines.
- */
-static int
-svi_sm_up(sp, ep, rp, count, scmd, smp)
- SCR *sp;
- EXF *ep;
- MARK *rp;
- enum sctype scmd;
- recno_t count;
- SMAP *smp;
-{
- int cursor_set, echanged, zset;
- SMAP s1, s2;
-
- /*
- * Check to see if movement is possible.
- *
- * Get the line after the map. If that line is a new one (and if
- * O_LEFTRIGHT option is set, this has to be true), and the next
- * line doesn't exist, and the cursor doesn't move, or the cursor
- * isn't even on the screen, or the cursor is already at the last
- * line in the map, it's an error. If that test succeeded because
- * the cursor wasn't at the end of the map, test to see if the map
- * is mostly empty.
- */
- if (svi_sm_next(sp, ep, TMAP, &s1))
- return (1);
- if (s1.lno > TMAP->lno && !file_gline(sp, ep, s1.lno, NULL)) {
- if (scmd == CNTRL_E || scmd == Z_PLUS || smp == TMAP) {
- v_eof(sp, ep, NULL);
- return (1);
- }
- if (svi_sm_next(sp, ep, smp, &s1))
- return (1);
- if (s1.lno > smp->lno && !file_gline(sp, ep, s1.lno, NULL)) {
- v_eof(sp, ep, NULL);
- return (1);
- }
- }
-
- /*
- * Small screens: see svi/svi_refresh.c:svi_refresh, section 2b.
- *
- * If it's a small screen, and the movement isn't larger than a
- * screen, i.e some context will remain, open up the screen and
- * display by scrolling. In this case, the cursor moves to the
- * first line displayed. Otherwise, erase/compress and repaint,
- * and move the cursor to the first line in the screen. Note,
- * the ^F command is always in the latter case, for historical
- * reasons.
- */
- cursor_set = 0;
- if (ISSMALLSCREEN(sp)) {
- if (count >= sp->t_maxrows || scmd == CNTRL_F) {
- s1 = TMAP[0];
- if (svi_sm_erase(sp))
- return (1);
- for (; count--; s1 = s2) {
- if (svi_sm_next(sp, ep, &s1, &s2))
- return (1);
- if (s2.lno != s1.lno &&
- !file_gline(sp, ep, s2.lno, NULL))
- break;
- }
- TMAP[0] = s2;
- if (svi_sm_fill(sp, ep, OOBLNO, P_BOTTOM))
- return (1);
- return (svi_sm_position(sp, ep, rp, 0, P_TOP));
- }
- for (; count &&
- sp->t_rows != sp->t_maxrows; --count, ++sp->t_rows) {
- if (svi_sm_next(sp, ep, TMAP, &s1))
- return (1);
- if (TMAP->lno != s1.lno &&
- !file_gline(sp, ep, s1.lno, NULL))
- break;
- *++TMAP = s1;
- /* svi_sm_next() flushed the cache. */
- if (svi_line(sp, ep, TMAP, NULL, NULL))
- return (1);
-
- if (scmd != CNTRL_E && !cursor_set) {
- cursor_set = 1;
- rp->lno = TMAP->lno;
- rp->cno = TMAP->c_sboff;
- }
- }
- if (count == 0)
- return (0);
- }
-
- for (echanged = zset = 0; count; --count) {
- /* Decide what would show up on the screen. */
- if (svi_sm_next(sp, ep, TMAP, &s1))
- return (1);
-
- /* If the line doesn't exist, we're done. */
- if (TMAP->lno != s1.lno && !file_gline(sp, ep, s1.lno, NULL))
- break;
-
- /* Scroll the screen cursor up one logical line. */
- if (svi_sm_1up(sp, ep))
- return (1);
- switch (scmd) {
- case CNTRL_E:
- if (smp > HMAP)
- --smp;
- else
- echanged = 1;
- break;
- case Z_PLUS:
- if (zset) {
- if (smp > HMAP)
- --smp;
- } else {
- smp = TMAP;
- zset = 1;
- }
- /* FALLTHROUGH */
- default:
- break;
- }
- }
-
- if (cursor_set)
- return(0);
-
- switch (scmd) {
- case CNTRL_E:
- /*
- * On a ^E that was forced to change lines, try and keep the
- * cursor as close as possible to the last position, but also
- * set it up so that the next "real" movement will return the
- * cursor to the closest position to the last real movement.
- */
- if (echanged) {
- rp->lno = smp->lno;
- rp->cno =
- svi_cm_private(sp, ep, smp->lno, smp->off, sp->rcm);
- }
- return (0);
- case CNTRL_F:
- /*
- * If there are more lines, the ^F command is always
- * positioned at the first line of the screen.
- */
- if (!count) {
- smp = HMAP;
- break;
- }
- /* FALLTHROUGH */
- case CNTRL_D:
- /*
- * The ^D and ^F commands move the cursor towards EOF
- * if there are more lines to move. Check to be sure
- * the lines actually exist. (They may not if the
- * file is smaller than the screen.)
- */
- for (; count; --count, ++smp)
- if (smp == TMAP ||
- !file_gline(sp, ep, smp[1].lno, NULL))
- break;
- break;
- case Z_PLUS:
- /* The z+ command moves the cursor to the first new line. */
- break;
- default:
- abort();
- }
-
- if (!SMAP_CACHE(smp) && svi_line(sp, ep, smp, NULL, NULL))
- return (1);
- rp->lno = smp->lno;
- rp->cno = smp->c_sboff;
- return (0);
-}
-
-/*
- * svi_sm_1up --
- * Scroll the SMAP up one.
- */
-int
-svi_sm_1up(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- /*
- * Delete the top line of the screen. Shift the screen map up.
- * Display a new line at the bottom of the screen.
- */
- MOVE(sp, 0, 0);
- if (svi_deleteln(sp, 1))
- return (1);
-
- /* One-line screens can fail. */
- if (HMAP == TMAP) {
- if (svi_sm_next(sp, ep, TMAP, TMAP))
- return (1);
- } else {
- memmove(HMAP, HMAP + 1, (sp->rows - 1) * sizeof(SMAP));
- if (svi_sm_next(sp, ep, TMAP - 1, TMAP))
- return (1);
- }
- /* svi_sm_next() flushed the cache. */
- if (svi_line(sp, ep, TMAP, NULL, NULL))
- return (1);
- return (0);
-}
-
-/*
- * svi_deleteln --
- * Delete a line a la curses, make sure to put the information
- * line and other screens back.
- */
-static int
-svi_deleteln(sp, cnt)
- SCR *sp;
- int cnt;
-{
- size_t oldy, oldx;
-
- getyx(stdscr, oldy, oldx);
- while (cnt--) {
- deleteln();
- MOVE(sp, INFOLINE(sp) - 1, 0);
- insertln();
- MOVEA(sp, oldy, oldx);
- }
- return (0);
-}
-
-/*
- * svi_sm_down --
- * Scroll the SMAP down count logical lines.
- */
-static int
-svi_sm_down(sp, ep, rp, count, scmd, smp)
- SCR *sp;
- EXF *ep;
- MARK *rp;
- recno_t count;
- SMAP *smp;
- enum sctype scmd;
-{
- SMAP s1, s2;
- int cursor_set, ychanged, zset;
-
- /* Check to see if movement is possible. */
- if (HMAP->lno == 1 && HMAP->off == 1 &&
- (scmd == CNTRL_Y || scmd == Z_CARAT || smp == HMAP)) {
- v_sof(sp, NULL);
- return (1);
- }
-
- /*
- * Small screens: see svi/svi_refresh.c:svi_refresh, section 2b.
- *
- * If it's a small screen, and the movement isn't larger than a
- * screen, i.e some context will remain, open up the screen and
- * display by scrolling. In this case, the cursor moves to the
- * first line displayed. Otherwise, erase/compress and repaint,
- * and move the cursor to the first line in the screen. Note,
- * the ^B command is always in the latter case, for historical
- * reasons.
- */
- cursor_set = scmd == CNTRL_Y;
- if (ISSMALLSCREEN(sp)) {
- if (count >= sp->t_maxrows || scmd == CNTRL_B) {
- s1 = HMAP[0];
- if (svi_sm_erase(sp))
- return (1);
- for (; count--; s1 = s2) {
- if (svi_sm_prev(sp, ep, &s1, &s2))
- return (1);
- if (s2.lno == 1 && s2.off == 1)
- break;
- }
- HMAP[0] = s2;
- if (svi_sm_fill(sp, ep, OOBLNO, P_TOP))
- return (1);
- return (svi_sm_position(sp, ep, rp, 0, P_BOTTOM));
- }
- for (; count &&
- sp->t_rows != sp->t_maxrows; --count, ++sp->t_rows) {
- if (HMAP->lno == 1 || HMAP->off == 1)
- break;
- ++TMAP;
- if (svi_sm_1down(sp, ep))
- return (1);
- if (scmd != CNTRL_Y && !cursor_set) {
- cursor_set = 1;
- if (svi_sm_position(sp, ep, rp, 0, P_BOTTOM))
- return (1);
- }
- }
- if (count == 0)
- return (0);
- }
-
- for (ychanged = zset = 0; count; --count) {
- /* If the line doesn't exist, we're done. */
- if (HMAP->lno == 1 && HMAP->off == 1)
- break;
-
- /* Scroll the screen and cursor down one logical line. */
- if (svi_sm_1down(sp, ep))
- return (1);
- switch (scmd) {
- case CNTRL_Y:
- if (smp < TMAP)
- ++smp;
- else
- ychanged = 1;
- break;
- case Z_CARAT:
- if (zset) {
- if (smp < TMAP)
- ++smp;
- } else {
- smp = HMAP;
- zset = 1;
- }
- /* FALLTHROUGH */
- default:
- break;
- }
- }
-
- if (scmd != CNTRL_Y && cursor_set)
- return(0);
-
- switch (scmd) {
- case CNTRL_B:
- /*
- * If there are more lines, the ^B command is always
- * positioned at the last line of the screen.
- */
- if (!count) {
- smp = TMAP;
- break;
- }
- /* FALLTHROUGH */
- case CNTRL_U:
- /*
- * The ^B and ^U commands move the cursor towards SOF
- * if there are more lines to move.
- */
- if (count < smp - HMAP)
- smp -= count;
- else
- smp = HMAP;
- break;
- case CNTRL_Y:
- /*
- * On a ^Y that was forced to change lines, try and keep the
- * cursor as close as possible to the last position, but also
- * set it up so that the next "real" movement will return the
- * cursor to the closest position to the last real movement.
- */
- if (ychanged) {
- rp->lno = smp->lno;
- rp->cno =
- svi_cm_private(sp, ep, smp->lno, smp->off, sp->rcm);
- }
- return (0);
- case Z_CARAT:
- /* The z^ command moves the cursor to the first new line. */
- break;
- default:
- abort();
- }
-
- if (!SMAP_CACHE(smp) && svi_line(sp, ep, smp, NULL, NULL))
- return (1);
- rp->lno = smp->lno;
- rp->cno = smp->c_sboff;
- return (0);
-}
-
-/*
- * svi_sm_erase --
- * Erase the small screen area for the scrolling functions.
- */
-static int
-svi_sm_erase(sp)
- SCR *sp;
-{
- MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
- for (; sp->t_rows > sp->t_minrows; --sp->t_rows, --TMAP) {
- MOVE(sp, TMAP - HMAP, 0);
- clrtoeol();
- }
- return (0);
-}
-
-/*
- * svi_sm_1down --
- * Scroll the SMAP down one.
- */
-int
-svi_sm_1down(sp, ep)
- SCR *sp;
- EXF *ep;
-{
- /*
- * Clear the bottom line of the screen, insert a line at the top
- * of the screen. Shift the screen map down, display a new line
- * at the top of the screen.
- */
- MOVE(sp, sp->t_rows, 0);
- clrtoeol();
- MOVE(sp, 0, 0);
- if (svi_insertln(sp, 1))
- return (1);
- memmove(HMAP + 1, HMAP, (sp->rows - 1) * sizeof(SMAP));
- if (svi_sm_prev(sp, ep, HMAP + 1, HMAP))
- return (1);
- /* svi_sm_prev() flushed the cache. */
- if (svi_line(sp, ep, HMAP, NULL, NULL))
- return (1);
- return (0);
-}
-
-/*
- * svi_insertln --
- * Insert a line a la curses, make sure to put the information
- * line and other screens back.
- */
-static int
-svi_insertln(sp, cnt)
- SCR *sp;
- int cnt;
-{
- size_t oldy, oldx;
-
- getyx(stdscr, oldy, oldx);
- while (cnt--) {
- MOVE(sp, INFOLINE(sp) - 1, 0);
- deleteln();
- MOVEA(sp, oldy, oldx);
- insertln();
- }
- return (0);
-}
-
-/*
- * svi_sm_next --
- * Fill in the next entry in the SMAP.
- */
-int
-svi_sm_next(sp, ep, p, t)
- SCR *sp;
- EXF *ep;
- SMAP *p, *t;
-{
- size_t lcnt;
-
- SMAP_FLUSH(t);
- if (O_ISSET(sp, O_LEFTRIGHT)) {
- t->lno = p->lno + 1;
- t->off = p->off;
- } else {
- lcnt = svi_opt_screens(sp, ep, p->lno, NULL);
- if (lcnt == p->off) {
- t->lno = p->lno + 1;
- t->off = 1;
- } else {
- t->lno = p->lno;
- t->off = p->off + 1;
- }
- }
- return (0);
-}
-
-/*
- * svi_sm_prev --
- * Fill in the previous entry in the SMAP.
- */
-int
-svi_sm_prev(sp, ep, p, t)
- SCR *sp;
- EXF *ep;
- SMAP *p, *t;
-{
- SMAP_FLUSH(t);
- if (O_ISSET(sp, O_LEFTRIGHT)) {
- t->lno = p->lno - 1;
- t->off = p->off;
- } else if (p->off != 1) {
- t->lno = p->lno;
- t->off = p->off - 1;
- } else {
- t->lno = p->lno - 1;
- t->off = svi_opt_screens(sp, ep, t->lno, NULL);
- }
- return (t->lno == 0);
-}
-
-/*
- * svi_sm_cursor --
- * Return the SMAP entry referenced by the cursor.
- */
-int
-svi_sm_cursor(sp, ep, smpp)
- SCR *sp;
- EXF *ep;
- SMAP **smpp;
-{
- SMAP *p;
-
- /* See if the cursor is not in the map. */
- if (sp->lno < HMAP->lno || sp->lno > TMAP->lno)
- return (1);
-
- /* Find the first occurence of the line. */
- for (p = HMAP; p->lno != sp->lno; ++p);
-
- /* Fill in the map information until we find the right line. */
- for (; p <= TMAP; ++p) {
- /* Short lines are common and easy to detect. */
- if (p != TMAP && (p + 1)->lno != p->lno) {
- *smpp = p;
- return (0);
- }
- if (!SMAP_CACHE(p) && svi_line(sp, ep, p, NULL, NULL))
- return (1);
- if (p->c_eboff >= sp->cno) {
- *smpp = p;
- return (0);
- }
- }
-
- /* It was past the end of the map after all. */
- return (1);
-}
-
-/*
- * svi_sm_position --
- * Return the line/column of the top, middle or last line on the screen.
- * (The vi H, M and L commands.) Here because only the screen routines
- * know what's really out there.
- */
-int
-svi_sm_position(sp, ep, rp, cnt, pos)
- SCR *sp;
- EXF *ep;
- MARK *rp;
- u_long cnt;
- enum position pos;
-{
- SMAP *smp;
- recno_t last;
-
- switch (pos) {
- case P_TOP:
- /*
- * !!!
- * Historically, an invalid count to the H command failed.
- * We do nothing special here, just making sure that H in
- * an empty screen works.
- */
- if (cnt > TMAP - HMAP)
- goto sof;
- smp = HMAP + cnt;
- if (cnt && file_gline(sp, ep, smp->lno, NULL) == NULL) {
-sof: msgq(sp, M_BERR, "Movement past the end-of-screen");
- return (1);
- }
- break;
- case P_MIDDLE:
- /*
- * !!!
- * Historically, a count to the M command was ignored.
- * If the screen isn't filled, find the middle of what's
- * real and move there.
- */
- if (file_gline(sp, ep, TMAP->lno, NULL) == NULL) {
- if (file_lline(sp, ep, &last))
- return (1);
- for (smp = TMAP; smp->lno > last && smp > HMAP; --smp);
- if (smp > HMAP)
- smp -= (smp - HMAP) / 2;
- } else
- smp = (HMAP + (TMAP - HMAP) / 2) + cnt;
- break;
- case P_BOTTOM:
- /*
- * !!!
- * Historically, an invalid count to the L command failed.
- * If the screen isn't filled, find the bottom of what's
- * real and try to offset from there.
- */
- if (cnt > TMAP - HMAP)
- goto eof;
- smp = TMAP - cnt;
- if (file_gline(sp, ep, smp->lno, NULL) == NULL) {
- if (file_lline(sp, ep, &last))
- return (1);
- for (; smp->lno > last && smp > HMAP; --smp);
- if (cnt > smp - HMAP) {
-eof: msgq(sp, M_BERR,
- "Movement past the beginning-of-screen");
- return (1);
- }
- smp -= cnt;
- }
- break;
- default:
- abort();
- }
-
- /* Make sure that the cached information is valid. */
- if (!SMAP_CACHE(smp) && svi_line(sp, ep, smp, NULL, NULL))
- return (1);
- rp->lno = smp->lno;
- rp->cno = smp->c_sboff;
-
- return (0);
-}
-
-/*
- * svi_sm_nlines --
- * Return the number of screen lines from an SMAP entry to the
- * start of some file line, less than a maximum value.
- */
-recno_t
-svi_sm_nlines(sp, ep, from_sp, to_lno, max)
- SCR *sp;
- EXF *ep;
- SMAP *from_sp;
- recno_t to_lno;
- size_t max;
-{
- recno_t lno, lcnt;
-
- if (O_ISSET(sp, O_LEFTRIGHT))
- return (from_sp->lno > to_lno ?
- from_sp->lno - to_lno : to_lno - from_sp->lno);
-
- if (from_sp->lno == to_lno)
- return (from_sp->off - 1);
-
- if (from_sp->lno > to_lno) {
- lcnt = from_sp->off - 1; /* Correct for off-by-one. */
- for (lno = from_sp->lno; --lno >= to_lno && lcnt <= max;)
- lcnt += svi_opt_screens(sp, ep, lno, NULL);
- } else {
- lno = from_sp->lno;
- lcnt = (svi_opt_screens(sp, ep, lno, NULL) - from_sp->off) + 1;
- for (; ++lno < to_lno && lcnt <= max;)
- lcnt += svi_opt_screens(sp, ep, lno, NULL);
- }
- return (lcnt);
-}
diff --git a/usr.bin/vi/svi/svi_split.c b/usr.bin/vi/svi/svi_split.c
deleted file mode 100644
index dbf151c..0000000
--- a/usr.bin/vi/svi/svi_split.c
+++ /dev/null
@@ -1,635 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_split.c 8.49 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "svi_screen.h"
-
-/*
- * svi_split --
- * Split the screen.
- */
-int
-svi_split(sp, argv, argc)
- SCR *sp;
- ARGS *argv[];
- int argc;
-{
- MSG *mp, *next;
- SCR *tsp, saved_sp;
- SVI_PRIVATE saved_svp;
- SMAP *smp;
- size_t cnt, half;
- int issmallscreen, splitup;
- char **ap;
-
- /* Check to see if it's possible. */
- half = sp->rows / 2;
- if (half < MINIMUM_SCREEN_ROWS) {
- msgq(sp, M_ERR, "Screen must be larger than %d to split",
- MINIMUM_SCREEN_ROWS);
- return (1);
- }
-
- /* Get a new screen. */
- if (screen_init(sp, &tsp, 0))
- return (1);
- CALLOC(sp, _HMAP(tsp), SMAP *, SIZE_HMAP(sp), sizeof(SMAP));
- if (_HMAP(tsp) == NULL)
- return (1);
-
- /*
- * We're about to modify the current screen. Save the contents
- * in case something goes horribly, senselessly wrong.
- */
- saved_sp = *sp;
- saved_svp = *SVP(sp);
-
-/* INITIALIZED AT SCREEN CREATE. */
-
-/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
- /*
- * Small screens: see svi/svi_refresh.c:svi_refresh, section 3b.
- * Set a flag so we know to fix the screen up later.
- */
- issmallscreen = ISSMALLSCREEN(sp);
-
- /*
- * Split the screen, and link the screens together. If the cursor
- * is in the top half of the current screen, the new screen goes
- * under the current screen. Else, it goes above the current screen.
- *
- * The columns in the screen don't change.
- */
- tsp->cols = sp->cols;
-
- cnt = svi_sm_cursor(sp, sp->ep, &smp) ? 0 : smp - HMAP;
- if (cnt <= half) { /* Parent is top half. */
- /* Child. */
- tsp->rows = sp->rows - half;
- tsp->woff = sp->woff + half;
- tsp->t_maxrows = tsp->rows - 1;
-
- /* Parent. */
- sp->rows = half;
- sp->t_maxrows = sp->rows - 1;
-
- splitup = 0;
- } else { /* Parent is bottom half. */
- /* Child. */
- tsp->rows = sp->rows - half;
- tsp->woff = sp->woff;
- tsp->t_maxrows = tsp->rows - 1;
-
- /* Parent. */
- sp->rows = half;
- sp->woff += tsp->rows;
- sp->t_maxrows = sp->rows - 1;
-
- /* Shift the parent's map down. */
- memmove(_HMAP(sp),
- _HMAP(sp) + tsp->rows, sp->t_maxrows * sizeof(SMAP));
-
- splitup = 1;
- }
-
- /*
- * Small screens: see svi/svi_refresh.c:svi_refresh, section 3b.
- *
- * The child may have different screen options sizes than the
- * parent, so use them. Make sure that the text counts aren't
- * larger than the new screen sizes.
- */
- if (issmallscreen) {
- /* Fix the text line count for the parent. */
- if (splitup)
- sp->t_rows -= tsp->rows;
-
- /* Fix the parent screen. */
- if (sp->t_rows > sp->t_maxrows)
- sp->t_rows = sp->t_maxrows;
- if (sp->t_minrows > sp->t_maxrows)
- sp->t_minrows = sp->t_maxrows;
-
- /* Fix the child screen. */
- tsp->t_minrows = tsp->t_rows = O_VAL(sp, O_WINDOW);
- if (tsp->t_rows > tsp->t_maxrows)
- tsp->t_rows = tsp->t_maxrows;
- if (tsp->t_minrows > tsp->t_maxrows)
- tsp->t_minrows = tsp->t_maxrows;
-
- /*
- * If we split up, i.e. the child is on top, lines that
- * were painted in the parent may not be painted in the
- * child. Clear any lines not being used in the child
- * screen.
- *
- */
- if (splitup)
- for (cnt = tsp->t_rows; ++cnt <= tsp->t_maxrows;) {
- MOVE(tsp, cnt, 0);
- clrtoeol();
- }
- } else {
- sp->t_minrows = sp->t_rows = sp->rows - 1;
-
- /*
- * The new screen may be a small screen, even though the
- * parent was not. Don't complain if O_WINDOW is too large,
- * we're splitting the screen so the screen is much smaller
- * than normal. Clear any lines not being used in the child
- * screen.
- */
- tsp->t_minrows = tsp->t_rows = O_VAL(sp, O_WINDOW);
- if (tsp->t_rows > tsp->rows - 1)
- tsp->t_minrows = tsp->t_rows = tsp->rows - 1;
- else
- for (cnt = tsp->t_rows; ++cnt <= tsp->t_maxrows;) {
- MOVE(tsp, cnt, 0);
- clrtoeol();
- }
- }
-
- /* Adjust the ends of both maps. */
- _TMAP(sp) = _HMAP(sp) + (sp->t_rows - 1);
- _TMAP(tsp) = _HMAP(tsp) + (tsp->t_rows - 1);
-
- /* Reset the length of the default scroll. */
- sp->defscroll = sp->t_maxrows / 2;
- tsp->defscroll = tsp->t_maxrows / 2;
-
- /*
- * If files specified, build the file list, else, link to the
- * current file.
- */
- if (argv == NULL) {
- if ((tsp->frp = file_add(tsp, sp->frp->name)) == NULL)
- goto err;
- } else {
- /* Create a new argument list. */
- CALLOC(sp, tsp->argv, char **, argc + 1, sizeof(char *));
- if (tsp->argv == NULL)
- goto err;
- for (ap = tsp->argv, argv; argv[0]->len != 0; ++ap, ++argv)
- if ((*ap =
- v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
- goto err;
- *ap = NULL;
-
- /* Switch to the first one. */
- tsp->cargv = tsp->argv;
- if ((tsp->frp = file_add(tsp, *tsp->cargv)) == NULL)
- goto err;
- }
-
- /*
- * Copy the file state flags, start the file. Fill the child's
- * screen map. If the file is unchanged, keep the screen and
- * cursor the same.
- */
- if (argv == NULL) {
- tsp->ep = sp->ep;
- ++sp->ep->refcnt;
-
- tsp->frp->flags = sp->frp->flags;
- tsp->frp->lno = sp->lno;
- tsp->frp->cno = sp->cno;
- F_SET(tsp->frp, FR_CURSORSET);
-
- /* Copy the parent's map into the child's map. */
- memmove(_HMAP(tsp), _HMAP(sp), tsp->t_rows * sizeof(SMAP));
- } else {
- if (file_init(tsp, tsp->frp, NULL, 0))
- goto err;
- (void)svi_sm_fill(tsp, tsp->ep, 1, P_TOP);
- }
-
- /* Everything's initialized, put the screen on the displayed queue.*/
- SIGBLOCK(sp->gp);
- if (splitup) {
- /* Link in before the parent. */
- CIRCLEQ_INSERT_BEFORE(&sp->gp->dq, sp, tsp, q);
- } else {
- /* Link in after the parent. */
- CIRCLEQ_INSERT_AFTER(&sp->gp->dq, sp, tsp, q);
- }
- SIGUNBLOCK(sp->gp);
-
- /* Clear the current information lines in both screens. */
- MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
- MOVE(tsp, INFOLINE(tsp), 0);
- clrtoeol();
-
- /* Redraw the status line for the parent screen. */
- (void)msg_status(sp, sp->ep, sp->lno, 0);
-
- /* Save the parent screen's cursor information. */
- sp->frp->lno = sp->lno;
- sp->frp->cno = sp->cno;
- F_SET(sp->frp, FR_CURSORSET);
-
- /* Completely redraw the child screen. */
- F_SET(tsp, S_REDRAW);
-
- /* Switch screens. */
- sp->nextdisp = tsp;
- F_SET(sp, S_SSWITCH);
- return (0);
-
- /* Recover the original screen. */
-err: *sp = saved_sp;
- *SVP(sp) = saved_svp;
-
- /* Copy any (probably error) messages in the new screen. */
- for (mp = tsp->msgq.lh_first; mp != NULL; mp = next) {
- if (!F_ISSET(mp, M_EMPTY))
- msg_app(sp->gp, sp,
- mp->flags & M_INV_VIDEO, mp->mbuf, mp->len);
- next = mp->q.le_next;
- if (mp->mbuf != NULL)
- free(mp->mbuf);
- free(mp);
- }
-
- /* Free the new screen. */
- if (tsp->argv != NULL) {
- for (ap = tsp->argv; *ap != NULL; ++ap)
- free(*ap);
- free(tsp->argv);
- }
- free(_HMAP(tsp));
- free(SVP(tsp));
- FREE(tsp, sizeof(SCR));
- return (1);
-}
-
-/*
- * svi_bg --
- * Background the screen, and switch to the next one.
- */
-int
-svi_bg(csp)
- SCR *csp;
-{
- SCR *sp;
-
- /* Try and join with another screen. */
- if ((svi_join(csp, &sp)))
- return (1);
- if (sp == NULL) {
- msgq(csp, M_ERR,
- "You may not background your only displayed screen");
- return (1);
- }
-
- /* Move the old screen to the hidden queue. */
- SIGBLOCK(csp->gp);
- CIRCLEQ_REMOVE(&csp->gp->dq, csp, q);
- CIRCLEQ_INSERT_TAIL(&csp->gp->hq, csp, q);
- SIGUNBLOCK(csp->gp);
-
- /* Switch screens. */
- csp->nextdisp = sp;
- F_SET(csp, S_SSWITCH);
-
- return (0);
-}
-
-/*
- * svi_join --
- * Join the screen into a related screen, if one exists,
- * and return that screen.
- */
-int
-svi_join(csp, nsp)
- SCR *csp, **nsp;
-{
- SCR *sp;
- size_t cnt;
-
- /*
- * If a split screen, add space to parent/child. Make no effort
- * to clean up the screen's values. If it's not exiting, we'll
- * get it when the user asks to show it again.
- */
- if ((sp = csp->q.cqe_prev) == (void *)&csp->gp->dq) {
- if ((sp = csp->q.cqe_next) == (void *)&csp->gp->dq) {
- *nsp = NULL;
- return (0);
- }
- sp->woff = csp->woff;
- }
- sp->rows += csp->rows;
- if (ISSMALLSCREEN(sp)) {
- sp->t_maxrows += csp->rows;
- for (cnt = sp->t_rows; ++cnt <= sp->t_maxrows;) {
- MOVE(sp, cnt, 0);
- clrtoeol();
- }
- TMAP = HMAP + (sp->t_rows - 1);
- } else {
- sp->t_maxrows += csp->rows;
- sp->t_rows = sp->t_minrows = sp->t_maxrows;
- TMAP = HMAP + (sp->t_rows - 1);
- if (svi_sm_fill(sp, sp->ep, sp->lno, P_FILL))
- return (1);
- F_SET(sp, S_REDRAW);
- }
-
- /* Reset the length of the default scroll. */
- sp->defscroll = sp->t_maxrows / 2;
-
- /*
- * Save the old screen's cursor information.
- *
- * XXX
- * If called after file_end(), if the underlying file was a tmp
- * file it may have gone away.
- */
- if (csp->frp != NULL) {
- csp->frp->lno = csp->lno;
- csp->frp->cno = csp->cno;
- F_SET(csp->frp, FR_CURSORSET);
- }
-
- *nsp = sp;
- return (0);
-}
-
-/*
- * svi_fg --
- * Background the current screen, and foreground a new one.
- */
-int
-svi_fg(csp, name)
- SCR *csp;
- CHAR_T *name;
-{
- SCR *sp;
-
- if (svi_swap(csp, &sp, name))
- return (1);
- if (sp == NULL) {
- if (name == NULL)
- msgq(csp, M_ERR, "There are no background screens");
- else
- msgq(csp, M_ERR,
- "There's no background screen editing a file named %s",
- name);
- return (1);
- }
-
- /* Move the old screen to the hidden queue. */
- SIGBLOCK(csp->gp);
- CIRCLEQ_REMOVE(&csp->gp->dq, csp, q);
- CIRCLEQ_INSERT_TAIL(&csp->gp->hq, csp, q);
- SIGUNBLOCK(csp->gp);
-
- return (0);
-}
-
-/*
- * svi_swap --
- * Swap the current screen with a hidden one.
- */
-int
-svi_swap(csp, nsp, name)
- SCR *csp, **nsp;
- char *name;
-{
- SCR *sp;
- int issmallscreen;
-
- /* Find the screen, or, if name is NULL, the first screen. */
- for (sp = csp->gp->hq.cqh_first;
- sp != (void *)&csp->gp->hq; sp = sp->q.cqe_next)
- if (name == NULL || !strcmp(sp->frp->name, name))
- break;
- if (sp == (void *)&csp->gp->hq) {
- *nsp = NULL;
- return (0);
- }
- *nsp = sp;
-
- /*
- * Save the old screen's cursor information.
- *
- * XXX
- * If called after file_end(), if the underlying file was a tmp
- * file it may have gone away.
- */
- if (csp->frp != NULL) {
- csp->frp->lno = csp->lno;
- csp->frp->cno = csp->cno;
- F_SET(csp->frp, FR_CURSORSET);
- }
-
- /* Switch screens. */
- csp->nextdisp = sp;
- F_SET(csp, S_SSWITCH);
-
- /* Initialize terminal information. */
- SVP(sp)->srows = SVP(csp)->srows;
-
- issmallscreen = ISSMALLSCREEN(sp);
-
- /* Initialize screen information. */
- sp->rows = csp->rows;
- sp->cols = csp->cols;
- sp->woff = csp->woff;
-
- /*
- * Small screens: see svi/svi_refresh.c:svi_refresh, section 3b.
- *
- * The new screens may have different screen options sizes than the
- * old one, so use them. Make sure that text counts aren't larger
- * than the new screen sizes.
- */
- if (issmallscreen) {
- sp->t_minrows = sp->t_rows = O_VAL(sp, O_WINDOW);
- if (sp->t_rows > csp->t_maxrows)
- sp->t_rows = sp->t_maxrows;
- if (sp->t_minrows > csp->t_maxrows)
- sp->t_minrows = sp->t_maxrows;
- } else
- sp->t_rows = sp->t_maxrows = sp->t_minrows = sp->rows - 1;
-
- /* Reset the length of the default scroll. */
- sp->defscroll = sp->t_maxrows / 2;
-
- /*
- * Don't change the screen's cursor information other than to
- * note that the cursor is wrong.
- */
- F_SET(SVP(sp), SVI_CUR_INVALID);
-
- /*
- * The HMAP may be NULL, if the screen got resized and
- * a bunch of screens had to be hidden.
- */
- if (HMAP == NULL)
- CALLOC_RET(sp, HMAP, SMAP *, SIZE_HMAP(sp), sizeof(SMAP));
- TMAP = HMAP + (sp->t_rows - 1);
-
- /* Fill the map. */
- if (svi_sm_fill(sp, sp->ep, sp->lno, P_FILL))
- return (1);
-
- /*
- * The new screen replaces the old screen in the parent/child list.
- * We insert the new screen after the old one. If we're exiting,
- * the exit will delete the old one, if we're foregrounding, the fg
- * code will move the old one to the hidden queue.
- */
- SIGBLOCK(sp->gp);
- CIRCLEQ_REMOVE(&sp->gp->hq, sp, q);
- CIRCLEQ_INSERT_AFTER(&csp->gp->dq, csp, sp, q);
- SIGUNBLOCK(sp->gp);
-
- F_SET(sp, S_REDRAW);
- return (0);
-}
-
-/*
- * svi_rabs --
- * Change the absolute size of the current screen.
- */
-int
-svi_rabs(sp, count, adj)
- SCR *sp;
- long count;
- enum adjust adj;
-{
- SCR *g, *s;
-
- /*
- * Figure out which screens will grow, which will shrink, and
- * make sure it's possible.
- */
- if (count == 0)
- return (0);
- if (adj == A_SET) {
- if (sp->t_maxrows == count)
- return (0);
- if (sp->t_maxrows > count) {
- adj = A_DECREASE;
- count = sp->t_maxrows - count;
- } else {
- adj = A_INCREASE;
- count = count - sp->t_maxrows;
- }
- }
- if (adj == A_DECREASE) {
- if (count < 0)
- count = -count;
- s = sp;
- if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count)
- goto toosmall;
- if ((g = sp->q.cqe_prev) == (void *)&sp->gp->dq) {
- if ((g = sp->q.cqe_next) == (void *)&sp->gp->dq)
- goto toobig;
- g->woff -= count;
- } else
- s->woff += count;
- } else {
- g = sp;
- if ((s = sp->q.cqe_next) != (void *)&sp->gp->dq)
- if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count)
- s = NULL;
- else
- s->woff += count;
- else
- s = NULL;
- if (s == NULL) {
- if ((s = sp->q.cqe_prev) == (void *)&sp->gp->dq) {
-toobig: msgq(sp, M_BERR, "The screen cannot %s",
- adj == A_DECREASE ? "shrink" : "grow");
- return (1);
- }
- if (s->t_maxrows < MINIMUM_SCREEN_ROWS + count) {
-toosmall: msgq(sp, M_BERR,
- "The screen can only shrink to %d rows",
- MINIMUM_SCREEN_ROWS);
- return (1);
- }
- g->woff -= count;
- }
- }
-
- /*
- * Update the screens; we could optimize the reformatting of the
- * screen, but this isn't likely to be a common enough operation
- * to make it worthwhile.
- */
- g->rows += count;
- g->t_rows += count;
- if (g->t_minrows == g->t_maxrows)
- g->t_minrows += count;
- g->t_maxrows += count;
- _TMAP(g) += count;
- (void)msg_status(g, g->ep, g->lno, 0);
- F_SET(g, S_REFORMAT);
-
- s->rows -= count;
- s->t_rows -= count;
- s->t_maxrows -= count;
- if (s->t_minrows > s->t_maxrows)
- s->t_minrows = s->t_maxrows;
- _TMAP(s) -= count;
- (void)msg_status(s, s->ep, s->lno, 0);
- F_SET(s, S_REFORMAT);
-
- return (0);
-}
diff --git a/usr.bin/vi/svi/svi_term.c b/usr.bin/vi/svi/svi_term.c
deleted file mode 100644
index a6ff7bd..0000000
--- a/usr.bin/vi/svi/svi_term.c
+++ /dev/null
@@ -1,310 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_term.c 8.7 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "excmd.h"
-#include "svi_screen.h"
-
-/*
- * XXX
- * THIS REQUIRES THAT ALL SCREENS SHARE A TERMINAL TYPE.
- */
-typedef struct _tklist {
- char *ts; /* Key's termcap string. */
- char *output; /* Corresponding vi command. */
- char *name; /* Name. */
- u_char value; /* Special value (for lookup). */
-} TKLIST;
-static TKLIST const c_tklist[] = { /* Command mappings. */
-#ifdef SYSV_CURSES
- {"kil1", "O", "insert line"},
- {"kdch1", "x", "delete character"},
- {"kcud1", "j", "cursor down"},
- {"kel", "D", "delete to eol"},
- {"kind", "\004", "scroll down"},
- {"kll", "$", "go to eol"},
- {"khome", "^", "go to sol"},
- {"kich1", "i", "insert at cursor"},
- {"kdl1", "dd", "delete line"},
- {"kcub1", "h", "cursor left"},
- {"knp", "\006", "page down"},
- {"kpp", "\002", "page up"},
- {"kri", "\025", "scroll up"},
- {"ked", "dG", "delete to end of screen"},
- {"kcuf1", "l", "cursor right"},
- {"kcuu1", "k", "cursor up"},
-#else
- {"kA", "O", "insert line"},
- {"kD", "x", "delete character"},
- {"kd", "j", "cursor down"},
- {"kE", "D", "delete to eol"},
- {"kF", "\004", "scroll down"},
- {"kH", "$", "go to eol"},
- {"kh", "^", "go to sol"},
- {"kI", "i", "insert at cursor"},
- {"kL", "dd", "delete line"},
- {"kl", "h", "cursor left"},
- {"kN", "\006", "page down"},
- {"kP", "\002", "page up"},
- {"kR", "\025", "scroll up"},
- {"kS", "dG", "delete to end of screen"},
- {"kr", "l", "cursor right"},
- {"ku", "k", "cursor up"},
-#endif
- {NULL},
-};
-static TKLIST const m1_tklist[] = { /* Input mappings (lookup). */
- {NULL},
-};
-static TKLIST const m2_tklist[] = { /* Input mappings (set or delete). */
-#ifdef SYSV_CURSES
- {"kcud1", "\033ja", "cursor down"},
- {"kcub1", "\033ha", "cursor left"},
- {"kcuu1", "\033ka", "cursor up"},
- {"kcuf1", "\033la", "cursor right"},
-#else
- {"kd", "\033ja", "cursor down"},
- {"kl", "\033ha", "cursor left"},
- {"ku", "\033ka", "cursor up"},
- {"kr", "\033la", "cursor right"},
-#endif
- {NULL},
-};
-
-/*
- * svi_term_init --
- * Initialize the special keys defined by the termcap/terminfo entry.
- */
-int
-svi_term_init(sp)
- SCR *sp;
-{
- KEYLIST *kp;
- SEQ *qp;
- TKLIST const *tkp;
- size_t len;
- char *sbp, *s, *t, sbuf[1024];
-
- /* Command mappings. */
- for (tkp = c_tklist; tkp->name != NULL; ++tkp) {
-#ifdef SYSV_CURSES
- if ((t = tigetstr(tkp->ts)) == NULL || t == (char *)-1)
- continue;
-#else
- sbp = sbuf;
- if ((t = tgetstr(tkp->ts, &sbp)) == NULL)
- continue;
-#endif
- if (seq_set(sp, tkp->name, strlen(tkp->name), t, strlen(t),
- tkp->output, strlen(tkp->output), SEQ_COMMAND, SEQ_SCREEN))
- return (1);
- }
-
- /* Input mappings needing to be looked up. */
- for (tkp = m1_tklist; tkp->name != NULL; ++tkp) {
-#ifdef SYSV_CURSES
- if ((t = tigetstr(tkp->ts)) == NULL || t == (char *)-1)
- continue;
-#else
- sbp = sbuf;
- if ((t = tgetstr(tkp->ts, &sbp)) == NULL)
- continue;
-#endif
- for (kp = keylist;; ++kp)
- if (kp->value == tkp->value)
- break;
- if (kp == NULL)
- continue;
- if (seq_set(sp, tkp->name, strlen(tkp->name),
- t, strlen(t), &kp->ch, 1, SEQ_INPUT, SEQ_SCREEN))
- return (1);
- }
-
- /* Input mappings that are already set or are text deletions. */
- for (tkp = m2_tklist; tkp->name != NULL; ++tkp) {
-#ifdef SYSV_CURSES
- if ((t = tigetstr(tkp->ts)) == NULL || t == (char *)-1)
- continue;
-#else
- sbp = sbuf;
- if ((t = tgetstr(tkp->ts, &sbp)) == NULL)
- continue;
-#endif
- /*
- * !!!
- * Some terminals' <cursor_left> keys send single <backspace>
- * characters. This is okay in command mapping, but not okay
- * in input mapping. That combination is the only one we'll
- * ever see, hopefully, so kluge it here for now.
- */
- if (!strcmp(t, "\b"))
- continue;
- if (tkp->output == NULL) {
- if (seq_set(sp, tkp->name, strlen(tkp->name),
- t, strlen(t), NULL, 0, SEQ_INPUT, SEQ_SCREEN))
- return (1);
- } else
- if (seq_set(sp, tkp->name, strlen(tkp->name),
- t, strlen(t), tkp->output, strlen(tkp->output),
- SEQ_INPUT, SEQ_SCREEN))
- return (1);
- }
-
- /* Rework any function key mappings. */
- for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) {
- if (!F_ISSET(qp, SEQ_FUNCMAP))
- continue;
- (void)svi_fmap(sp, qp->stype,
- qp->input, qp->ilen, qp->output, qp->olen);
- }
-
- /* Set up the visual bell information. */
- t = sbuf;
- if (tgetstr("vb", &t) != NULL && (len = t - sbuf) != 0) {
- MALLOC_RET(sp, s, char *, len);
- memmove(s, sbuf, len);
- if (SVP(sp)->VB != NULL)
- free(SVP(sp)->VB);
- SVP(sp)->VB = s;
- return (0);
- }
-
- return (0);
-}
-
-/*
- * svi_term_end --
- * End the special keys defined by the termcap/terminfo entry.
- */
-int
-svi_term_end(sp)
- SCR *sp;
-{
- SEQ *qp, *nqp;
-
- /* Delete screen specific mappings. */
- for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = nqp) {
- nqp = qp->q.le_next;
- if (!F_ISSET(qp, SEQ_SCREEN))
- continue;
- (void)seq_mdel(qp);
- }
- return (0);
-}
-
-/*
- * svi_fmap --
- * Map a function key.
- */
-int
-svi_fmap(sp, stype, from, flen, to, tlen)
- SCR *sp;
- enum seqtype stype;
- CHAR_T *from, *to;
- size_t flen, tlen;
-{
- char *t, keyname[64];
- size_t nlen;
-
- /* If the terminal isn't initialized, there's nothing to do. */
- if (!F_ISSET(SVP(sp), SVI_CURSES_INIT))
- return (0);
-
-#ifdef SYSV_CURSES
- (void)snprintf(keyname, sizeof(keyname), "kf%d", atoi(from + 1));
- if ((t = tigetstr(keyname)) == NULL || t == (char *)-1)
- t = NULL;
-#else
- /*
- * !!!
- * Historically, the 4BSD termcap code didn't support functions keys
- * greater than 9. This was silently enforced -- asking for key k12
- * returned the value for k1. We try and get around this by using
- * the tables specified in the terminfo(TI_ENV) man page from the 3rd
- * Edition SVID. This assumes that the implementors of any System V
- * compatibility code or an extended termcap used those codes.
- */
- { int n; char *sbp, sbuf[1024];
- static const char codes[] = {
-/* 0-10 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';',
-/* 11-19 */ '1', '2', '3', '4', '5', '6', '7', '8', '9',
-/* 20-63 */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- };
- if ((n = atoi(from + 1)) > 63) {
- msgq(sp, M_ERR,
- "Termcap has no code for the %s function key",
- from);
- return (1);
- }
- (void)snprintf(keyname, sizeof(keyname),
- "%c%c", n <= 10 ? 'k' : 'F', codes[n]);
- sbp = sbuf;
- t = tgetstr(keyname, &sbp);
- }
-#endif
- if (t == NULL) {
- msgq(sp, M_ERR, "This terminal has no %s key", from);
- return (1);
- }
- nlen = snprintf(keyname,
- sizeof(keyname), "function key %d", atoi(from + 1));
- return (seq_set(sp, keyname, nlen, t, strlen(t),
- to, tlen, stype, SEQ_SCREEN | SEQ_USERDEF));
-}
diff --git a/usr.bin/vi/svi/svi_util.c b/usr.bin/vi/svi/svi_util.c
deleted file mode 100644
index 65422ed..0000000
--- a/usr.bin/vi/svi/svi_util.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)svi_util.c 8.55 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <curses.h>
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "../vi/vcmd.h"
-#include "excmd.h"
-#include "svi_screen.h"
-#include "../sex/sex_screen.h"
-
-/*
- * svi_bell --
- * Ring the bell.
- */
-void
-svi_bell(sp)
- SCR *sp;
-{
-#ifdef SYSV_CURSES
- if (O_ISSET(sp, O_FLASH))
- flash();
- else
- beep();
-#else
- if (O_ISSET(sp, O_FLASH) && SVP(sp)->VB != NULL) {
- (void)tputs(SVP(sp)->VB, 1, vi_putchar);
- (void)fflush(stdout);
- } else
- (void)write(STDOUT_FILENO, "\007", 1); /* '\a' */
-#endif
- F_CLR(sp, S_BELLSCHED);
-}
-
-/*
- * svi_optchange --
- * Screen specific "option changed" routine.
- */
-int
-svi_optchange(sp, opt)
- SCR *sp;
- int opt;
-{
- switch (opt) {
- case O_TERM:
- /* Toss any saved visual bell information. */
- if (SVP(sp)->VB != NULL) {
- FREE(SVP(sp)->VB, strlen(SVP(sp)->VB) + 1);
- SVP(sp)->VB = NULL;
- }
-
- /* Reset the screen size. */
- if (sp->s_window(sp, 0))
- return (1);
- F_SET(sp, S_RESIZE);
- break;
- case O_WINDOW:
- if (svi_crel(sp, O_VAL(sp, O_WINDOW)))
- return (1);
- break;
- }
-
- (void)v_optchange(sp, opt);
- (void)ex_optchange(sp, opt);
-
- return (0);
-}
-
-/*
- * svi_busy --
- * Put the cursor somewhere so the user will think we're busy.
- */
-int
-svi_busy(sp, msg)
- SCR *sp;
- char const *msg;
-{
- /*
- * search.c:f_search() is called from ex/ex_tag.c:ex_tagfirst(),
- * which runs before the screen really exists. Make sure we don't
- * step on anything.
- *
- * If the terminal isn't initialized, there's nothing to do.
- */
- if (!F_ISSET(SVP(sp), SVI_CURSES_INIT))
- return (0);
-
- MOVE(sp, INFOLINE(sp), 0);
- if (msg) {
- ADDSTR(msg);
- clrtoeol();
- }
- refresh();
- F_SET(SVP(sp), SVI_CUR_INVALID);
- return (0);
-}
-
-/*
- * svi_keypad --
- * Put the keypad/cursor arrows into or out of application mode.
- */
-void
-svi_keypad(sp, on)
- SCR *sp;
- int on;
-{
-#ifdef SYSV_CURSES
- keypad(stdscr, on ? TRUE : FALSE);
-#else
- char *sbp, *t, sbuf[128];
-
- sbp = sbuf;
- if ((t = tgetstr(on ? "ks" : "ke", &sbp)) == NULL)
- return;
- (void)tputs(t, 0, vi_putchar);
- (void)fflush(stdout);
-#endif
-}
-
-/*
- * svi_clear --
- * Clear from the row down to the end of the screen.
- */
-int
-svi_clear(sp)
- SCR *sp;
-{
- size_t oldy, oldx, row;
-
- getyx(stdscr, oldy, oldx);
- for (row = SVP(sp)->srows - 1; row >= oldy; --row) {
- MOVEA(sp, row, 0);
- clrtoeol();
- }
- MOVEA(sp, oldy, oldx);
- refresh();
- return (0);
-}
-
-/*
- * svi_suspend --
- * Suspend an svi screen.
- *
- * See signal.c for a long discussion of what's going on here. Let
- * me put it this way, it's NOT my fault.
- */
-int
-svi_suspend(sp)
- SCR *sp;
-{
- struct termios sv_term;
- sigset_t set;
- int oldx, oldy, rval;
- char *sbp, *t, sbuf[128];
-
- rval = 0;
-
- /*
- * Block SIGALRM, because vi uses timers to decide when to paint
- * busy messages on the screen.
- */
- (void)sigemptyset(&set);
- (void)sigaddset(&set, SIGALRM);
- if (sigprocmask(SIG_BLOCK, &set, NULL)) {
- msgq(sp, M_SYSERR, "suspend: sigblock");
- return (1);
- }
-
- /* Save the current cursor position. */
- getyx(stdscr, oldy, oldx);
-
- /*
- * Move the cursor to the bottom of the screen.
- *
- * XXX
- * Some curses implementations don't turn off inverse video when
- * standend() is called, waiting to see what the next character is
- * going to be, instead. Write a character to force inverse video
- * off, and then clear the line.
- */
- MOVE(sp, INFOLINE(sp), 0);
- ADDCH('.');
- refresh();
- MOVE(sp, INFOLINE(sp), 0);
- clrtoeol();
- refresh();
-
- /* Restore the cursor keys to normal mode. */
- svi_keypad(sp, 0);
-
- /* Send VE/TE. */
-#ifdef SYSV_CURSES
- if ((t = tigetstr("cnorm")) != NULL && t != (char *)-1)
- (void)tputs(t, 0, vi_putchar);
- if ((t = tigetstr("rmcup")) != NULL && t != (char *)-1)
- (void)tputs(t, 0, vi_putchar);
-#else
- sbp = sbuf;
- if ((t = tgetstr("ve", &sbp)) != NULL)
- (void)tputs(t, 0, vi_putchar);
- sbp = sbuf;
- if ((t = tgetstr("te", &sbp)) != NULL)
- (void)tputs(t, 0, vi_putchar);
-#endif
- (void)fflush(stdout);
-
- /* Save current terminal settings, and restore the original ones. */
- if (tcgetattr(STDIN_FILENO, &sv_term)) {
- msgq(sp, M_SYSERR, "suspend: tcgetattr");
- return (1);
- }
- if (tcsetattr(STDIN_FILENO,
- TCSASOFT | TCSADRAIN, &sp->gp->original_termios)) {
- msgq(sp, M_SYSERR, "suspend: tcsetattr original");
- return (1);
- }
-
- /* Push out any waiting messages. */
- (void)write(STDOUT_FILENO, "\n", 1);
- (void)sex_refresh(sp, sp->ep);
-
- /* Stop the process group. */
- if (kill(0, SIGTSTP)) {
- msgq(sp, M_SYSERR, "suspend: kill");
- rval = 1;
- }
-
- /* Time passes ... */
-
- /* Restore current terminal settings. */
- if (tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &sv_term)) {
- msgq(sp, M_SYSERR, "suspend: tcsetattr current");
- rval = 1;
- }
-
- /* Send TI/VS. */
-#ifdef SYSV_CURSES
- if ((t = tigetstr("smcup")) != NULL && t != (char *)-1)
- (void)tputs(t, 0, vi_putchar);
- if ((t = tigetstr("cvvis")) != NULL && t != (char *)-1)
- (void)tputs(t, 0, vi_putchar);
-#else
- sbp = sbuf;
- if ((t = tgetstr("ti", &sbp)) != NULL)
- (void)tputs(t, 0, vi_putchar);
- sbp = sbuf;
- if ((t = tgetstr("vs", &sbp)) != NULL)
- (void)tputs(t, 0, vi_putchar);
-#endif
- (void)fflush(stdout);
-
- /* Put the cursor keys into application mode. */
- svi_keypad(sp, 1);
-
- /*
- * If the screen changed size, do a full refresh. Otherwise,
- * System V has curses repaint it. 4BSD curses will repaint
- * it in the wrefresh() call below.
- */
- if (!sp->s_window(sp, 1))
- (void)sp->s_refresh(sp, sp->ep);
-#ifdef SYSV_CURSES
- else
- redrawwin(stdscr);
-#endif
-
- /*
- * Restore the cursor.
- *
- * !!!
- * Don't use MOVE/MOVEA, we don't want to return without resetting
- * the signals, regardless.
- */
- (void)move(oldy, oldx);
- (void)wrefresh(curscr);
-
- /* Reset the signals. */
- if (sigprocmask(SIG_UNBLOCK, &set, NULL)) {
- msgq(sp, M_SYSERR, "suspend: sigblock");
- rval = 1;
- }
- return (rval);
-}
-
-/*
- * svi_gdbrefresh --
- * Stub routine so can flush out screen changes using gdb.
- */
-#ifdef DEBUG
-int
-svi_gdbrefresh()
-{
- refresh();
- return (0);
-}
-#endif
diff --git a/usr.bin/vi/vi/getc.c b/usr.bin/vi/vi/getc.c
deleted file mode 100644
index 388994d..0000000
--- a/usr.bin/vi/vi/getc.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.11 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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. */
- break;
- 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)
- if (csp->cs_lno == 1)
- csp->cs_flags = CS_SOF;
- else
- csp->cs_flags = CS_EOL;
- else
- csp->cs_ch = csp->cs_bp[--csp->cs_cno];
- break;
- case CS_SOF: /* SOF. */
- break;
- 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/vi/v_ch.c b/usr.bin/vi/vi/v_ch.c
deleted file mode 100644
index 514efc6..0000000
--- a/usr.bin/vi/vi/v_ch.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.15 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static void notfound __P((SCR *, ARG_CHAR_T));
-static void noprev __P((SCR *));
-
-/*
- * v_chrepeat -- [count];
- * Repeat the last F, f, T or t search.
- */
-int
-v_chrepeat(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- vp->character = VIP(sp)->lastckey;
-
- switch (VIP(sp)->csearchdir) {
- case CNOTSET:
- noprev(sp);
- return (1);
- case FSEARCH:
- return (v_chF(sp, ep, vp));
- case fSEARCH:
- return (v_chf(sp, ep, vp));
- case TSEARCH:
- return (v_chT(sp, ep, vp));
- case tSEARCH:
- return (v_cht(sp, ep, vp));
- 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- enum cdirection savedir;
- int rval;
-
- vp->character = VIP(sp)->lastckey;
- savedir = VIP(sp)->csearchdir;
-
- switch (VIP(sp)->csearchdir) {
- case CNOTSET:
- noprev(sp);
- return (1);
- case FSEARCH:
- rval = v_chf(sp, ep, vp);
- break;
- case fSEARCH:
- rval = v_chF(sp, ep, vp);
- break;
- case TSEARCH:
- rval = v_cht(sp, ep, vp);
- break;
- case tSEARCH:
- rval = v_chT(sp, ep, vp);
- break;
- default:
- abort();
- }
- VIP(sp)->csearchdir = savedir;
- return (rval);
-}
-
-/*
- * v_cht -- [count]tc
- * Search forward in the line for the character before the next
- * occurrence of the specified character.
- */
-int
-v_cht(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- if (v_chf(sp, ep, vp))
- return (1);
-
- /*
- * v_chf places the cursor on the character, where the 't'
- * command wants it to its left. We know this is safe since
- * we had to move right for v_chf() to have succeeded.
- */
- --vp->m_stop.cno;
-
- /*
- * Make any necessary correction to the motion decision made
- * by the v_chf routine.
- */
- if (!ISMOTION(vp))
- vp->m_final = vp->m_stop;
-
- VIP(sp)->csearchdir = tSEARCH;
- return (0);
-}
-
-/*
- * v_chf -- [count]fc
- * Search forward in the line for the next occurrence of the
- * specified character.
- */
-int
-v_chf(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- 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))
- VIP(sp)->lastckey = key;
- VIP(sp)->csearchdir = fSEARCH;
-
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0) {
- notfound(sp, key);
- return (1);
- }
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- if (len == 0) {
- notfound(sp, key);
- return (1);
- }
-
- endp = (startp = p) + len;
- p += vp->m_start.cno;
- for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- while (++p < endp && *p != key);
- if (p == endp) {
- notfound(sp, key);
- return (1);
- }
- }
-
- vp->m_stop.cno = p - startp;
-
- /*
- * Non-motion commands move to the end of the range. VC_D
- * and VC_Y stay at the start. Ignore VC_C and VC_DEF.
- */
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- return (0);
-}
-
-/*
- * v_chT -- [count]Tc
- * Search backward in the line for the character after the next
- * occurrence of the specified character.
- */
-int
-v_chT(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- if (v_chF(sp, ep, vp))
- return (1);
-
- /*
- * v_chF places the cursor on the character, where the 'T'
- * command wants it to its right. We know this is safe since
- * we had to move left for v_chF() to have succeeded.
- */
- ++vp->m_stop.cno;
-
- /*
- * Make any necessary correction to the motion decision made
- * by the v_chF routine.
- *
- * XXX
- * If you change this, notice that v_chF changes vp->m_start
- * AFTER setting vp->m_final.
- */
- if (!F_ISSET(vp, VC_Y))
- vp->m_final = vp->m_stop;
-
- VIP(sp)->csearchdir = TSEARCH;
- return (0);
-}
-
-/*
- * v_chF -- [count]Fc
- * Search backward in the line for the next occurrence of the
- * specified character.
- */
-int
-v_chF(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t len;
- u_long cnt;
- int key;
- char *endp, *p;
-
- /*
- * !!!
- * 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))
- VIP(sp)->lastckey = key;
- VIP(sp)->csearchdir = FSEARCH;
-
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0) {
- notfound(sp, key);
- return (1);
- }
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- if (len == 0) {
- notfound(sp, key);
- return (1);
- }
-
- endp = p - 1;
- p += vp->m_start.cno;
- for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- while (--p > endp && *p != key);
- if (p == endp) {
- notfound(sp, key);
- return (1);
- }
- }
-
- vp->m_stop.cno = (p - endp) - 1;
-
- /*
- * VC_D and non-motion commands move to the end of the range,
- * VC_Y stays at the start. Ignore VC_C and VC_DEF. Motion
- * commands adjust the starting point to the character before
- * the current one.
- */
- vp->m_final = F_ISSET(vp, VC_Y) ? vp->m_start : vp->m_stop;
- if (ISMOTION(vp))
- --vp->m_start.cno;
- return (0);
-}
-
-static void
-noprev(sp)
- SCR *sp;
-{
- msgq(sp, M_BERR, "No previous F, f, T or t search");
-}
-
-static void
-notfound(sp, ch)
- SCR *sp;
- ARG_CHAR_T ch;
-{
- msgq(sp, M_BERR, "%s not found", KEY_NAME(sp, ch));
-}
diff --git a/usr.bin/vi/vi/v_delete.c b/usr.bin/vi/vi/v_delete.c
deleted file mode 100644
index 83eb961..0000000
--- a/usr.bin/vi/vi/v_delete.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.16 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_Delete -- [buffer][count]D
- * Delete line command.
- */
-int
-v_Delete(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t len;
-
- if (file_gline(sp, ep, vp->m_start.lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- return (0);
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- if (len == 0)
- return (0);
-
- vp->m_stop.lno = vp->m_start.lno;
- vp->m_stop.cno = len - 1;
-
- /* Yank the lines. */
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, CUT_NUMOPT))
- return (1);
- if (delete(sp, ep, &vp->m_start, &vp->m_stop, 0))
- return (1);
-
- vp->m_final.lno = vp->m_start.lno;
- vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
- return (0);
-}
-
-/*
- * v_delete -- [buffer][count]d[count]motion
- * Delete a range of text.
- */
-int
-v_delete(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t nlines;
- size_t len;
- int lmode;
-
- lmode = F_ISSET(vp, VM_LMODE) ? CUT_LINEMODE : 0;
-
- /* Yank the lines. */
- if (cut(sp, ep, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop,
- lmode | (F_ISSET(vp, VM_CUTREQ) ? CUT_NUMREQ : CUT_NUMOPT)))
- return (1);
-
- /* Delete the lines. */
- if (delete(sp, ep, &vp->m_start, &vp->m_stop, lmode))
- return (1);
-
- /*
- * Check for deletion of the entire file. Try to check a close
- * by line so we don't go to the end of the file unnecessarily.
- */
- if (file_gline(sp, ep, vp->m_final.lno + 1, &len) == NULL) {
- if (file_lline(sp, ep, &nlines))
- return (1);
- if (nlines == 0) {
- vp->m_final.lno = 1;
- vp->m_final.cno = 0;
- return (0);
- }
- }
-
- /*
- * One special correction, in case we've deleted the current line or
- * character. We check it here instead of checking in every command
- * that can be a motion component.
- */
- if (file_gline(sp, ep, vp->m_final.lno, &len) == NULL) {
- if (file_gline(sp, ep, nlines, &len) == NULL) {
- GETLINE_ERR(sp, nlines);
- return (1);
- }
- vp->m_final.lno = nlines;
- }
- if (vp->m_final.cno >= len)
- vp->m_final.cno = len ? len - 1 : 0;
-
- /*
- * !!!
- * The "dd" command moved to the first non-blank; "d<motion>" didn't.
- */
- if (F_ISSET(vp, VM_LDOUBLE)) {
- F_CLR(vp, VM_RCM_MASK);
- F_SET(vp, VM_RCM_SETFNB);
- }
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_ex.c b/usr.bin/vi/vi/v_ex.c
deleted file mode 100644
index 99d36bf..0000000
--- a/usr.bin/vi/vi/v_ex.c
+++ /dev/null
@@ -1,352 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-static void excmd __P((EXCMDARG *,
- int, int, recno_t, recno_t, int, ARGS *[], ARGS *, char *));
-
-/*
- * v_again -- &
- * Repeat the previous substitution.
- */
-int
-v_again(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
- excmd(&cmd, C_SUBAGAIN,
- 2, vp->m_start.lno, vp->m_start.lno, 1, ap, &a, "");
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_at -- @
- * Execute a buffer.
- */
-int
-v_at(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
- excmd(&cmd, C_AT, 0, OOBLNO, OOBLNO, 0, ap, &a, NULL);
- if (F_ISSET(vp, VC_BUFFER)) {
- F_SET(&cmd, E_BUFFER);
- cmd.buffer = vp->buffer;
- }
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_ex -- :
- * Execute a colon command line.
- */
-int
-v_ex(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (sp->s_ex_run(sp, ep, &vp->m_final));
-}
-
-/*
- * v_exmode -- Q
- * Switch the editor into EX mode.
- */
-int
-v_exmode(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /* Save the current line/column number. */
- sp->frp->lno = sp->lno;
- sp->frp->cno = sp->cno;
- F_SET(sp->frp, FR_CURSORSET);
-
- /* Switch to ex mode. */
- 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);
-}
-
-/*
- * v_filter -- [count]!motion command(s)
- * Run range through shell commands, replacing text.
- */
-int
-v_filter(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
- TEXT *tp;
-
- /*
- * !!!
- * Historical vi permitted "!!" in an empty file, and it's 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.
- *
- * !!!
- * Historical vi did not permit the '!' command to be associated with
- * a non-line oriented motion command, in general, although it did
- * with search commands. So, !f; and !w would fail, but !/;<CR>
- * would succeed, even if they all moved to the same location in the
- * current line. I don't see any reason to disallow '!' using any of
- * the possible motion commands.
- */
- excmd(&cmd, C_BANG,
- 2, vp->m_start.lno, vp->m_stop.lno, 0, ap, &a, 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->tiqp,
- '!', 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->tiqp->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, &vp->m_final));
-}
-
-/*
- * v_join -- [count]J
- * Join lines together.
- */
-int
-v_join(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- 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 = vp->m_start.lno + 1;
- if (F_ISSET(vp, VC_C1SET) && vp->count > 2)
- lno = vp->m_start.lno + (vp->count - 1);
-
- excmd(&cmd, C_JOIN, 2, vp->m_start.lno, lno, 0, ap, &a, NULL);
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_shiftl -- [count]<motion
- * Shift lines left.
- */
-int
-v_shiftl(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
- excmd(&cmd, C_SHIFTL,
- 2, vp->m_start.lno, vp->m_stop.lno, 0, ap, &a, "<");
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_shiftr -- [count]>motion
- * Shift lines right.
- */
-int
-v_shiftr(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
- excmd(&cmd, C_SHIFTR,
- 2, vp->m_start.lno, vp->m_stop.lno, 0, ap, &a, ">");
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_switch -- ^^
- * Switch to the previous file.
- */
-int
-v_switch(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- 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 ((name = sp->alt_name) == NULL) {
- msgq(sp, M_ERR, "No previous file to edit");
- return (1);
- }
-
- /* If autowrite is set, write out the file. */
- if (file_m1(sp, ep, 0, FS_ALL))
- return (1);
-
- excmd(&cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0, ap, &a, name);
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_tagpush -- ^[
- * Do a tag search on a the cursor keyword.
- */
-int
-v_tagpush(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
- excmd(&cmd, C_TAG, 0, OOBLNO, 0, 0, ap, &a, vp->keyword);
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * v_tagpop -- ^T
- * Pop the tags stack.
- */
-int
-v_tagpop(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
- excmd(&cmd, C_TAGPOP, 0, OOBLNO, 0, 0, ap, &a, NULL);
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-}
-
-/*
- * excmd --
- * Build an EX command structure.
- */
-static void
-excmd(cmdp, cmd_id, naddr, lno1, lno2, force, ap, a, arg)
- EXCMDARG *cmdp;
- int cmd_id, force, naddr;
- recno_t lno1, lno2;
- ARGS *ap[2], *a;
- char *arg;
-{
- memset(cmdp, 0, sizeof(EXCMDARG));
- cmdp->cmd = &cmds[cmd_id];
- cmdp->addrcnt = naddr;
- cmdp->addr1.lno = lno1;
- cmdp->addr2.lno = lno2;
- cmdp->addr1.cno = cmdp->addr2.cno = 1;
- if (force)
- cmdp->flags |= E_FORCE;
- if ((a->bp = arg) == NULL) {
- cmdp->argc = 0;
- a->len = 0;
- } else {
- cmdp->argc = 1;
- a->len = strlen(arg);
- }
- ap[0] = a;
- ap[1] = NULL;
- cmdp->argv = ap;
-}
diff --git a/usr.bin/vi/vi/v_increment.c b/usr.bin/vi/vi/v_increment.c
deleted file mode 100644
index e24f496..0000000
--- a/usr.bin/vi/vi/v_increment.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.11 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- 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, vp->m_start.lno, &len)) == NULL) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- GET_SPACE_RET(sp, bp, blen, len + nlen);
- memmove(bp, p, vp->m_start.cno);
- memmove(bp + vp->m_start.cno, nbuf, nlen);
- memmove(bp + vp->m_start.cno + nlen,
- p + vp->m_start.cno + vp->klen, len - vp->m_start.cno - vp->klen);
- len = len - vp->klen + nlen;
-
- rval = file_sline(sp, ep, vp->m_start.lno, bp, len);
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
diff --git a/usr.bin/vi/vi/v_init.c b/usr.bin/vi/vi/v_init.c
deleted file mode 100644
index e39f06b..0000000
--- a/usr.bin/vi/vi/v_init.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.28 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "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;
- nvip->csearchdir = CNOTSET;
- } 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->ps != NULL &&
- (nvip->ps = strdup(ovip->ps)) == NULL) {
- msgq(sp, M_SYSERR, NULL);
- return (1);
- }
-
- nvip->lastckey = ovip->lastckey;
- nvip->csearchdir = ovip->csearchdir;
- }
- 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);
-
- if (vip->ps != NULL)
- free(vip->ps);
-
- /* 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;
-
- if (F_ISSET(sp->frp, FR_FNONBLANK)) {
- sp->cno = 0;
- if (nonblank(sp, ep, sp->lno, &sp->cno))
- return (1);
-
- /* Reset strange attraction. */
- sp->rcm = 0;
- sp->rcm_last = 0;
- }
- } else {
- sp->lno = 1;
- sp->cno = 0;
-
- if (O_ISSET(sp, O_COMMENT) && v_comment(sp, ep))
- return (1);
-
- /* Vi always starts up on the first non-<blank>. */
- if (nonblank(sp, ep, sp->lno, &sp->cno))
- return (1);
-
- /* Reset strange attraction. */
- sp->rcm = 0;
- sp->rcm_last = 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 (msg_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_buildps(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/vi/v_left.c b/usr.bin/vi/vi/v_left.c
deleted file mode 100644
index 69741dd..0000000
--- a/usr.bin/vi/vi/v_left.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.11 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_left -- [count]^H, [count]h
- * Move left by columns.
- */
-int
-v_left(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t cnt;
-
- /*
- * !!!
- * The ^H and h commands always failed in the first column.
- */
- if (vp->m_start.cno == 0) {
- v_sol(sp);
- return (1);
- }
-
- /* Find the end of the range. */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if (vp->m_start.cno > cnt)
- vp->m_stop.cno = vp->m_start.cno - cnt;
- else
- vp->m_stop.cno = 0;
-
- /*
- * VC_D and non-motion commands move to the end of the range,
- * VC_Y stays at the start. Ignore VC_C and VC_DEF. Motion
- * commands adjust the starting point to the character before
- * the current one.
- */
- vp->m_final = F_ISSET(vp, VC_Y) ? vp->m_start : vp->m_stop;
- if (ISMOTION(vp))
- --vp->m_start.cno;
- return (0);
-}
-
-/*
- * v_cfirst -- [count]_
- * Move to the first non-blank character in a line.
- */
-int
-v_cfirst(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t cnt;
-
- /*
- * !!!
- * If the _ is a motion component, it makes the command a line motion
- * e.g. "d_" deletes the line. It also means that the cursor doesn't
- * move.
- *
- * The _ command never failed in the first column.
- */
- if (ISMOTION(vp))
- F_SET(vp, VM_LMODE);
- /*
- * !!!
- * Historically a specified count makes _ move down count - 1
- * rows, so, "3_" is the same as "2j_".
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if (cnt != 1) {
- --vp->count;
- return (v_down(sp, ep, vp));
- }
-
- /*
- * Move to the first non-blank.
- *
- * Can't just use RCM_SET_FNB, in case _ is used as the motion
- * component of another command.
- */
- vp->m_stop.cno = 0;
- if (nonblank(sp, ep, vp->m_stop.lno, &vp->m_stop.cno))
- return (1);
-
- /*
- * VC_D and non-motion commands move to the end of the range,
- * VC_Y stays at the start. Ignore VC_C and VC_DEF.
- */
- vp->m_final = F_ISSET(vp, VC_Y) ? vp->m_start : vp->m_stop;
- return (0);
-}
-
-/*
- * v_first -- ^
- * Move to the first non-blank character in this line.
- */
-int
-v_first(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * !!!
- * 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.
- */
-
- /*
- * Move to the first non-blank.
- *
- * Can't just use RCM_SET_FNB, in case ^ is used as the motion
- * component of another command.
- */
- vp->m_stop.cno = 0;
- if (nonblank(sp, ep, vp->m_stop.lno, &vp->m_stop.cno))
- return (1);
-
- /*
- * !!!
- * The ^ command succeeded if used as a command without a whitespace
- * character preceding the cursor in the line, but failed if used as
- * a motion component in the same situation.
- */
- if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno) {
- v_sol(sp);
- return (1);
- }
-
- /*
- * VC_D and non-motion commands move to the end of the range,
- * VC_Y stays at the start. Ignore VC_C and VC_DEF. Motion
- * commands adjust the starting point to the character before
- * the current one.
- */
- vp->m_final = F_ISSET(vp, VC_Y) ? vp->m_start : vp->m_stop;
- if (ISMOTION(vp))
- --vp->m_start.cno;
- 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- if (F_ISSET(vp, VC_C1SET) && vp->count > 1) {
- --vp->count;
- vp->m_stop.cno =
- sp->s_colpos(sp, ep, vp->m_start.lno, (size_t)vp->count);
- /*
- * !!!
- * The | command succeeded if used as a command and the cursor
- * didn't move, but failed if used as a motion component in the
- * same situation.
- */
- if (ISMOTION(vp) && vp->m_stop.cno == vp->m_start.cno) {
- v_nomove(sp);
- return (1);
- }
- } else {
- /*
- * !!!
- * The | command succeeded if used as a command in column 0
- * without a count, but failed if used as a motion component
- * in the same situation.
- */
- if (ISMOTION(vp) && vp->m_start.cno == 0) {
- v_sol(sp);
- return (1);
- }
- vp->m_stop.cno = 0;
- }
-
- /*
- * If moving right, non-motion commands move to the end of the range.
- * VC_D and VC_Y stay at the start. If moving left, non-motion and
- * VC_D commands move to the end of the range. VC_Y remains at the
- * start. Ignore VC_C and VC_DEF. Motion left commands adjust the
- * starting point to the character before the current one.
- */
- if (vp->m_start.cno < vp->m_stop.cno)
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- else {
- vp->m_final = vp->m_stop;
- if (ISMOTION(vp)) {
- if (F_ISSET(vp, VC_Y))
- vp->m_final = vp->m_start;
- --vp->m_start.cno;
- }
- }
- return (0);
-}
-
-/*
- * v_zero -- 0
- * Move to the first column on this line.
- */
-int
-v_zero(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * !!!
- * The 0 command succeeded if used as a command in the first column
- * but failed if used as a motion component in the same situation.
- */
- if (ISMOTION(vp) && vp->m_start.cno == 0) {
- v_sol(sp);
- return (1);
- }
-
- /*
- * VC_D and non-motion commands move to the end of the range,
- * VC_Y stays at the start. Ignore VC_C and VC_DEF. Motion
- * commands adjust the starting point to the character before
- * the current one.
- */
- vp->m_stop.cno = 0;
- vp->m_final = F_ISSET(vp, VC_Y) ? vp->m_start : vp->m_stop;
- if (ISMOTION(vp))
- --vp->m_start.cno;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_mark.c b/usr.bin/vi/vi/v_mark.c
deleted file mode 100644
index 973430c..0000000
--- a/usr.bin/vi/vi/v_mark.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.10 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_mark -- m[a-z]
- * Set a mark.
- */
-int
-v_mark(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (mark_set(sp, ep, vp->character, &vp->m_start, 1));
-}
-
-enum which {BMARK, FMARK};
-static int mark __P((SCR *, EXF *, VICMDARG *, enum which));
-
-
-/*
- * v_bmark -- `['`a-z]
- * Move to a mark.
- *
- * Moves to a mark, setting both row and column.
- *
- * !!!
- * 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_bmark(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (mark(sp, ep, vp, BMARK));
-}
-
-/*
- * v_fmark -- '['`a-z]
- * Move to a mark.
- *
- * Move to the first nonblank character of the line containing the mark.
- */
-int
-v_fmark(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (mark(sp, ep, vp, FMARK));
-}
-
-static int
-mark(sp, ep, vp, cmd)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- enum which cmd;
-{
- MARK m;
- size_t len;
- enum direction dir;
-
- if (mark_get(sp, ep, vp->character, &vp->m_stop))
- return (1);
-
- /* Forward marks move to the first non-blank. */
- if (cmd == FMARK) {
- vp->m_stop.cno = 0;
- if (nonblank(sp, ep, vp->m_stop.lno, &vp->m_stop.cno))
- return (1);
- }
-
- /* Non-motion commands move to the end of the range. */
- if (!ISMOTION(vp)) {
- vp->m_final = vp->m_stop;
- return (0);
- }
-
- /*
- * !!!
- * If a motion component, the cursor has to move.
- */
- if (vp->m_stop.lno == vp->m_start.lno &&
- vp->m_stop.cno == vp->m_start.cno) {
- v_nomove(sp);
- return (1);
- }
-
- /*
- * If the motion is in the reverse direction, switch the start and
- * stop MARK's so that it's in a forward direction. (There's no
- * reason for this other than to make the tests below easier. The
- * code in vi.c:vi() would have done the switch.) Both forward
- * and backward motions can happen for either kind of mark command.
- */
- if (vp->m_start.lno > vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno > vp->m_stop.cno) {
- dir = BACKWARD;
- m = vp->m_start;
- vp->m_start = vp->m_stop;
- vp->m_stop = m;
- } else
- dir = FORWARD;
-
- /*
- * BACKWARD:
- * VC_D commands move to the end of the range. VC_Y stays at
- * the start unless the end of the range is on a different line,
- * when it moves to the end of the range. Ignore VC_C and
- * VC_DEF.
- *
- * FORWARD:
- * VC_D and VC_Y commands don't move. Ignore VC_C and VC_DEF.
- */
- if (dir == BACKWARD)
- if (F_ISSET(vp, VC_D) ||
- F_ISSET(vp, VC_Y) && vp->m_start.lno != vp->m_stop.lno)
- vp->m_final = vp->m_start;
- else
- vp->m_final = vp->m_stop;
- else
- vp->m_final = vp->m_start;
-
- if (cmd == FMARK)
- return (0);
-
- /*
- * Forward marks are always line oriented, and it's set in the
- * vcmd.c table. Backward marks that start and stop at column
- * 0 of the line are also line mode commands.
- */
- if (vp->m_start.cno == 0 && vp->m_stop.cno == 0)
- F_SET(vp, VM_LMODE);
-
- /*
- * BMARK'S that move backward and start at column 0, or move forward
- * and end at column 0 are corrected to the last column of the previous
- * line. Else, adjust the starting/ending point to the character
- * before the current one (this is safe because we know the command had
- * to move to succeed).
- */
- if (vp->m_start.lno < vp->m_stop.lno && vp->m_stop.cno == 0) {
- if (file_gline(sp, ep, --vp->m_stop.lno, &len) == NULL) {
- GETLINE_ERR(sp, vp->m_stop.lno);
- return (1);
- }
- vp->m_stop.cno = len ? len - 1 : 0;
- } else
- --vp->m_stop.cno;
-
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_match.c b/usr.bin/vi/vi/v_match.c
deleted file mode 100644
index 3df887c..0000000
--- a/usr.bin/vi/vi/v_match.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.16 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_match -- %
- * Search to matching character.
- */
-int
-v_match(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- VCS cs;
- MARK *mp;
- recno_t lno;
- size_t cno, len, off;
- int cnt, matchc, startc, (*gc)__P((SCR *, EXF *, VCS *));
- char *p;
-
- /*
- * !!!
- * Historic practice; ignore the count.
- */
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- goto nomatch;
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- /*
- * !!!
- * Historical practice was to search for the initial character
- * in the forward direction only.
- */
- for (off = vp->m_start.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 = vp->m_start.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);
- }
-
- vp->m_stop.lno = cs.cs_lno;
- vp->m_stop.cno = cs.cs_cno;
-
- /*
- * If moving right, non-motion commands move to the end of the range.
- * VC_D and VC_Y stay at the start. If moving left, non-motion and
- * VC_D commands move to the end of the range. VC_Y remains at the
- * start. Ignore VC_C and VC_DEF.
- *
- * !!!
- * Don't correct for leftward movement -- historic vi deleted the
- * starting cursor position when deleting to a match.
- */
- if (vp->m_start.lno < vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno < vp->m_stop.cno)
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- else
- vp->m_final = ISMOTION(vp) &&
- F_ISSET(vp, VC_Y) ? vp->m_start : vp->m_stop;
-
- /*
- * !!!
- * If the motion is across lines, and the earliest cursor position
- * is at or before any non-blank characters in the line, i.e. the
- * movement is cutting all of the line's text, and the later cursor
- * position has nothing other than whitespace characters between it
- * and the end of its line, the buffer is in line mode.
- */
- if (!ISMOTION(vp) || vp->m_start.lno == vp->m_stop.lno)
- return (0);
- mp = vp->m_start.lno < vp->m_stop.lno ? &vp->m_start : &vp->m_stop;
- if (mp->cno != 0) {
- cno = 0;
- if (nonblank(sp, ep, mp->lno, &cno))
- return (1);
- if (cno < mp->cno)
- return (0);
- }
- mp = vp->m_start.lno < vp->m_stop.lno ? &vp->m_stop : &vp->m_start;
- if ((p = file_gline(sp, ep, mp->lno, &len)) == NULL) {
- GETLINE_ERR(sp, mp->lno);
- return (1);
- }
- for (p += mp->cno + 1, len -= mp->cno; --len; ++p)
- if (!isblank(*p))
- return (0);
- F_SET(vp, VM_LMODE);
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_ntext.c b/usr.bin/vi/vi/v_ntext.c
deleted file mode 100644
index d4b26c5..0000000
--- a/usr.bin/vi/vi/v_ntext.c
+++ /dev/null
@@ -1,1899 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.122 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-#include "excmd.h"
-
-static int txt_abbrev __P((SCR *, TEXT *, 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 *));
-static int txt_indent __P((SCR *, TEXT *));
-static int txt_margin __P((SCR *,
- TEXT *, CHAR_T *, TEXT *, u_int, int *));
-static int txt_outdent __P((SCR *, TEXT *));
-static void txt_Rcleanup __P((SCR *,
- TEXTH *, TEXT *, const char *, const size_t));
-static int txt_resolve __P((SCR *, EXF *, TEXTH *, u_int));
-static void txt_showmatch __P((SCR *, EXF *));
-static void txt_unmap __P((SCR *, TEXT *, u_int *));
-
-/* Cursor character (space is hard to track on the screen). */
-#if defined(DEBUG) && 0
-#undef CH_CURSOR
-#define CH_CURSOR '+'
-#endif
-
-/*
- * v_ntext --
- * Read in text from the user.
- *
- * !!!
- * 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. */
- ARG_CHAR_T 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_NOTWORD, A_INWORD } 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;
- enum input tval;
- struct termios t; /* Terminal characteristics. */
- CH ikey; /* Input character structure. */
- CHAR_T ch; /* Input character. */
- TEXT *tp, *ntp, ait; /* Input and autoindent text structures. */
- TEXT wmt; /* Wrapmargin text structure. */
- size_t owrite, insert; /* Temporary copies of TEXT fields. */
- 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 sig_ix, sig_reset; /* Signal information. */
- int testnr; /* Test first character for nul replay. */
- int max, tmp;
- int unmap_tst; /* Input map needs testing. */
- int wmset, wmskip; /* Wrapmargin happened, blank skip flags. */
- 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;
-
- /*
- * 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
- * CH_ENDMARK
- */
- if (len) {
- if (LF_ISSET(TXT_OVERWRITE)) {
- tp->owrite = (tm->cno - sp->cno) + 1;
- tp->insert = (len - tm->cno) - 1;
- } else
- tp->insert = len - sp->cno;
-
- if (LF_ISSET(TXT_EMARK))
- tp->lb[tm->cno] = CH_ENDMARK;
- }
-
- /*
- * 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 beggars the
- * imagination. Note also, "^^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] = CH_CURSOR;
- ++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.
- *
- * !!!/XXX
- * Replay commands were not affected by the wrapmargin option in the
- * historic 4BSD vi. What I found surprising was that people 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
- *
- * Other historic versions of vi, notably Sun's, applied wrapmargin
- * to replay lines as well.
- *
- * 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.
- *
- * !!!
- * One more special case. If an inserted <blank> character causes
- * wrapmargin to split the line, the next user entered character is
- * discarded if it's a <space> character.
- */
- if (LF_ISSET(TXT_REPLAY) || !LF_ISSET(TXT_WRAPMARGIN))
- margin = 0;
- else if ((margin = O_VAL(sp, O_WRAPMARGIN)) != 0)
- margin = sp->cols - margin;
- wmset = wmskip = 0;
-
- /* Initialize abbreviations checks. */
- if (F_ISSET(sp->gp, G_ABBREV) && LF_ISSET(TXT_MAPINPUT)) {
- abb = A_INWORD;
- 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, CH_NOMAP))
- return (1);
- testnr = 0;
- abb = A_NOTSET;
- LF_CLR(TXT_RECORD);
- } else
- testnr = 1;
-
- unmap_tst = LF_ISSET(TXT_MAPINPUT) && LF_ISSET(TXT_INFOLINE);
- iflags = LF_ISSET(TXT_MAPCOMMAND | TXT_MAPINPUT);
- for (showmatch = 0, sig_reset = 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: tval = term_key(sp, &ikey, quoted == Q_THISCHAR ?
- iflags & ~(TXT_MAPCOMMAND | TXT_MAPINPUT) : iflags);
- ch = ikey.ch;
-
- /* Restore the terminal state if it was modified. */
- if (sig_reset && !tcgetattr(STDIN_FILENO, &t)) {
- t.c_lflag |= ISIG;
- t.c_iflag |= sig_ix;
- sig_reset = 0;
- (void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);
- }
-
- /*
- * !!!
- * Historically, <interrupt> exited the user from text input
- * mode or cancelled a colon command, and returned to command
- * mode. It also beeped the terminal, but that seems a bit
- * excessive.
- */
- if (tval != INP_OK) {
- if (tval == INP_INTR)
- goto k_escape;
- goto err;
- }
-
- /* Abbreviation check. See comment in txt_abbrev(). */
-#define MAX_ABBREVIATION_EXPANSION 256
- if (ikey.flags & CH_ABBREVIATED) {
- if (++ab_cnt > MAX_ABBREVIATION_EXPANSION) {
- term_flush(sp,
- "Abbreviation exceeded maximum number of characters",
- CH_ABBREVIATED);
- ab_cnt = 0;
- continue;
- }
- } else
- ab_cnt = 0;
-
- /* Wrapmargin check. */
- if (wmskip) {
- wmskip = 0;
- if (ch == ' ')
- goto next_ch;
- }
-
- /*
- * !!!
- * 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)) {
- BINC_GOTO(sp, VIP(sp)->rep, VIP(sp)->rep_len, rcol + 1);
- VIP(sp)->rep[rcol++] = ch;
- }
- BINC_GOTO(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.
- */
- if (ikey.flags & CH_QUOTED)
- goto insq_ch;
- if (quoted == Q_THISCHAR) {
- --sp->cno;
- ++tp->owrite;
- quoted = Q_NOTSET;
- goto insq_ch;
- }
- /*
- * !!!
- * Extension. If the user enters "<CH_HEX>[isxdigit()]*" we
- * will try to use the value as a character. Anything else
- * inserts the <CH_HEX> character, and resets hex mode.
- */
- if (hex == H_INHEX && !isxdigit(ch)) {
- if (txt_hex(sp, tp))
- goto err;
- hex = H_NOTSET;
- }
-
- switch (ikey.value) {
- case K_CR: /* Carriage return. */
- case K_NL: /* New line. */
- /* Return in script windows and the command line. */
-k_cr: if (LF_ISSET(TXT_CR)) {
- /*
- * If this was a map, we may have not displayed
- * the line. Display it, just in case.
- *
- * If a script window and not the colon line,
- * push a <cr> so it gets executed.
- */
- if (LF_ISSET(TXT_INFOLINE)) {
- if (sp->s_change(sp,
- ep, tp->lno, LINE_RESET))
- goto err;
- } else if (F_ISSET(sp, S_SCRIPT))
- (void)term_push(sp, "\r", 1, CH_NOMAP);
- goto k_escape;
- }
-
-#define LINE_RESOLVE { \
- /* \
- * Handle abbreviations. If there was one, \
- * discard the replay characters. \
- */ \
- if (abb == A_INWORD && !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_NOTWORD; \
- if (unmap_tst) \
- txt_unmap(sp, tp, &iflags); \
- /* Delete any appended cursor. */ \
- if (LF_ISSET(TXT_APPENDEOL)) { \
- --tp->len; \
- --tp->insert; \
- } \
-}
- LINE_RESOLVE;
-
- /*
- * Save the current line information for restoration
- * in txt_backup(). Set the new line length.
- */
- tp->sv_len = tp->len;
- tp->sv_cno = sp->cno;
- tp->len = sp->cno;
-
- /* Update the old line. */
- if (sp->s_change(sp, ep, tp->lno, LINE_RESET))
- goto err;
-
- /*
- * Historic practice was to delete <blank> characters
- * following the inserted newline. This affected the
- * 'R', 'c', and 's' commands; 'c' and 's' retained
- * the insert characters only, 'R' moved overwrite and
- * insert characters into the next TEXT structure.
- * All other commands simply deleted the overwrite
- * characters. We have to keep track of the number of
- * characters erased for the 'R' command so that we
- * can get the final resolution of the line correct.
- */
- tp->R_erase = 0;
- owrite = tp->owrite;
- insert = tp->insert;
- if (LF_ISSET(TXT_REPLACE) && owrite != 0) {
- for (p = tp->lb + sp->cno;
- owrite > 0 && isblank(*p);
- ++p, --owrite, ++tp->R_erase);
- if (owrite == 0)
- for (; insert > 0 && isblank(*p);
- ++p, ++tp->R_erase, --insert);
- } else {
- for (p = tp->lb + sp->cno + owrite;
- insert > 0 && isblank(*p); ++p, --insert);
- owrite = 0;
- }
-
- /* Set up bookkeeping for the new line. */
- if ((ntp = text_init(sp, p,
- insert + owrite, insert + owrite + 32)) == NULL)
- goto err;
- ntp->insert = insert;
- ntp->owrite = owrite;
- ntp->lno = tp->lno + 1;
-
- /*
- * 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)) {
- 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;
- }
-
- /* Reset the cursor. */
- sp->lno = ntp->lno;
- sp->cno = ntp->ai;
-
- /*
- * If we're here because wrapmargin was set and we've
- * broken a line, there may be additional information
- * (i.e. the start of a line) in the wmt structure.
- */
- if (wmset) {
- if (wmt.len != 0 ||
- wmt.insert != 0 || wmt.owrite != 0) {
- BINC_GOTO(sp, ntp->lb, ntp->lb_len,
- ntp->len + wmt.len + 32);
- memmove(ntp->lb + sp->cno, wmt.lb,
- wmt.len + wmt.insert + wmt.owrite);
- ntp->len +=
- wmt.len + wmt.insert + wmt.owrite;
- ntp->insert = wmt.insert;
- ntp->owrite = wmt.owrite;
- sp->cno += wmt.len;
- }
- wmset = 0;
- }
-
- /* New lines are TXT_APPENDEOL. */
- if (ntp->owrite == 0 && ntp->insert == 0) {
- BINC_GOTO(sp,
- ntp->lb, ntp->lb_len, ntp->len + 1);
- LF_SET(TXT_APPENDEOL);
- ntp->lb[sp->cno] = CH_CURSOR;
- ++ntp->insert;
- ++ntp->len;
- }
-
- /*
- * 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);
-
- /* 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))
- if (sp->s_refresh(sp, ep))
- goto err;
- goto next_ch;
- case K_ESCAPE: /* Escape. */
- if (!LF_ISSET(TXT_ESCAPE))
- goto ins_ch;
-k_escape: LINE_RESOLVE;
-
- /*
- * Clean up for the 'R' command, restoring overwrite
- * characters, and making them into insert characters.
- */
- if (LF_ISSET(TXT_REPLACE))
- txt_Rcleanup(sp, tiqh, tp, lp, len);
-
- /*
- * If there are any overwrite characters, copy down
- * any insert characters, and decrement the length.
- */
- if (tp->owrite) {
- if (tp->insert)
- memmove(tp->lb + sp->cno,
- tp->lb + sp->cno + tp->owrite,
- tp->insert);
- tp->len -= tp->owrite;
- }
-
- /*
- * Optionally resolve the lines into the file. Clear
- * the input flag, the look-aside buffer is no longer
- * valid. 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, flags))
- goto err;
- F_CLR(sp, S_INPUT);
- } else {
- BINC_GOTO(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_CNTRLD: /* 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)
- 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;
- BINC_GOTO(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_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;
-#ifdef HISTORIC_PRACTICE_IS_TO_INSERT_NOT_SUSPEND
- case K_CNTRLZ:
- /*
- * XXX
- * Note, historically suspend triggered an autowrite.
- * That needs to be done to make this work correctly.
- */
- (void)sp->s_suspend(sp);
- break;
-#endif
-#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. */
- ch = '^';
- quoted = Q_NEXTCHAR;
- /*
- * If there are no keys in the queue, reset the tty
- * so that the user can enter a ^C, ^Q, ^S. There's
- * an obvious race here, if the user entered the ^C
- * already. There's nothing that we can do to fix
- * that problem.
- */
- if (!KEYS_WAITING(sp) && !tcgetattr(STDIN_FILENO, &t)) {
- t.c_lflag &= ~ISIG;
- sig_ix = t.c_iflag & (IXON | IXOFF);
- t.c_iflag &= ~(IXON | IXOFF);
- sig_reset = 1;
- (void)tcsetattr(STDIN_FILENO,
- TCSASOFT | TCSADRAIN, &t);
- }
- /*
- * XXX
- * Pass the tests for abbreviations, so ":ab xa XA",
- * "ixa^V<space>" works. Historic vi did something
- * weird here: ":ab x y", "ix\<space>" resulted in
- * "<space>x\", for some unknown reason. Had to be
- * a bug.
- */
- goto insl_ch;
- case K_HEXCHAR:
- hex = H_NEXTCHAR;
- goto insq_ch;
- default: /* Insert the character. */
-ins_ch: /*
- * Historically, vi eliminated nul's out of hand. If
- * the beautify option was set, it also deleted any
- * unknown ASCII value less than space (040) and the
- * del character (0177), except for tabs. Unknown is
- * a key word here. Most vi documentation claims that
- * it deleted everything but <tab>, <nl> and <ff>, as
- * that's what the original 4BSD documentation said.
- * This is obviously wrong, however, as <esc> would be
- * included in that list. What we do is eliminate any
- * unquoted, iscntrl() character that wasn't a replay
- * and wasn't handled specially, except <tab> or <ff>.
- */
- if (LF_ISSET(TXT_BEAUTIFY) && iscntrl(ch) &&
- ikey.value != K_FORMFEED && ikey.value != K_TAB) {
- msgq(sp, M_BERR,
- "Illegal character; quote to enter");
- break;
- }
-insq_ch: /*
- * If entering a non-word character after a word, check
- * for abbreviations. If there was one, discard the
- * replay characters. If entering a blank character,
- * check for unmap commands, as well.
- */
- if (!inword(ch)) {
- if (abb == A_INWORD && !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 (isblank(ch) && unmap_tst)
- txt_unmap(sp, tp, &iflags);
- }
- if (abb != A_NOTSET)
- abb = inword(ch) ? A_INWORD : A_NOTWORD;
-
-insl_ch: 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;
-
- /* 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, &ch, &wmt, flags, &tmp))
- goto err;
- if (tmp) {
- if (isblank(ch))
- wmskip = 1;
- wmset = 1;
- goto k_cr;
- }
- }
- }
-
- /*
- * 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) {
- BINC_GOTO(sp, tp->lb, tp->lb_len, tp->len + 1);
- LF_SET(TXT_APPENDEOL);
- tp->lb[sp->cno] = CH_CURSOR;
- ++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);
-
-err: /* Error jumps. */
-binc_err:
- eval = 1;
- txt_err(sp, ep, tiqh);
- goto ret;
-}
-
-/*
- * txt_abbrev --
- * Handle abbreviations.
- */
-static int
-txt_abbrev(sp, tp, pushcp, isinfoline, didsubp, turnoffp)
- SCR *sp;
- TEXT *tp;
- CHAR_T *pushcp;
- int isinfoline, *didsubp, *turnoffp;
-{
- CHAR_T ch;
- SEQ *qp;
- size_t len, off;
- char *p;
-
- /*
- * Find the start of the "word". Historically, abbreviations
- * could be preceded by any non-word character or the beginning
- * of the entry, .e.g inserting an abbreviated string in the
- * middle of another string triggered the replacement.
- */
- for (off = sp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
- if (!inword(*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
- * unabbreviate "foo1", and the commands:
- * :ab foo bar
- * :ab bar baz
- * unabbreviate "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. Note also, minor trickiness, so that if
- * the user erases the line and starts another command, we turn the
- * 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 = *pushcp;
- if (term_push(sp, &ch, 1, CH_ABBREVIATED))
- return (1);
- if (term_push(sp, qp->output, qp->olen, CH_ABBREVIATED))
- return (1);
-
- /* Move 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);
-}
-
-/*
- * txt_unmap --
- * Handle the unmap command.
- */
-static void
-txt_unmap(sp, tp, iflagsp)
- SCR *sp;
- TEXT *tp;
- u_int *iflagsp;
-{
- 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 input mappings on the command line. See the
- * txt_abbrev() routine for an explanation of the problems inherent
- * in this.
- *
- * We make this work as follows. 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 unmap command. If it is, we return that the input
- * mapping should be turned off. Note also, minor trickiness, so that
- * if the user erases the line and starts another command, we go ahead
- * an turn mapping back on.
- */
- if ((off == tp->ai || off == tp->offset) && ex_is_unmap(p, len))
- *iflagsp &= ~TXT_MAPINPUT;
- else
- *iflagsp |= TXT_MAPINPUT;
-}
-
-/*
- * 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;
-
- /*
- * If the length is less than or equal to the autoindent
- * characters, delete them.
- */
- if (tp->len <= tp->ai) {
- tp->len = tp->ai = 0;
- if (tp->lno == sp->lno)
- sp->cno = 0;
- 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);
- tp->len -= del;
-
- /* If the cursor was on this line, adjust it as well. */
- if (sp->lno == tp->lno)
- sp->cno -= 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 the ex append command is executed with an address of 0,
- * it's possible to get here with a line number of 0. Return
- * an indent of 0.
- */
- if (lno == 0) {
- tp->ai = 0;
- return (0);
- }
- if ((t = file_gline(sp, ep, lno, &len)) == NULL)
- return (1);
- } else
- t = aitp->lb;
-
- /* Count whitespace characters. */
- for (p = t; len > 0; ++p, --len)
- if (!isblank(*p))
- break;
-
- /* Set count, check for no indentation. */
- if ((nlen = (p - t)) == 0)
- return (0);
-
- /* Make sure the buffer's big enough. */
- BINC_RET(sp, tp->lb, tp->lb_len, tp->len + nlen);
-
- /* Copy the buffer's current contents up. */
- if (tp->len != 0)
- memmove(tp->lb + nlen, tp->lb, tp->len);
- tp->len += nlen;
-
- /* Copy the indentation into the new buffer. */
- memmove(tp->lb, t, nlen);
-
- /* Set the autoindent count. */
- tp->ai = nlen;
- return (0);
-}
-
-/*
- * txt_backup --
- * Back up to the previously edited line.
- */
-static TEXT *
-txt_backup(sp, ep, tiqh, tp, flagsp)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
- TEXT *tp;
- u_int *flagsp;
-{
- TEXT *ntp;
- u_int flags;
-
- /* 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);
- }
-
- /* Reset the cursor, bookkeeping. */
- sp->lno = ntp->lno;
- sp->cno = ntp->sv_cno;
- ntp->len = ntp->sv_len;
-
- /* Handle appending to the line. */
- flags = *flagsp;
- if (ntp->owrite == 0 && ntp->insert == 0) {
- ntp->lb[ntp->len] = CH_CURSOR;
- ++ntp->insert;
- ++ntp->len;
- LF_SET(TXT_APPENDEOL);
- } else
- LF_CLR(TXT_APPENDEOL);
- *flagsp = flags;
-
- /* Release the current TEXT. */
- CIRCLEQ_REMOVE(tiqh, tp, q);
- text_free(tp);
-
- /* Update the old line on the screen. */
- if (sp->s_change(sp, ep, ntp->lno + 1, LINE_DELETE))
- return (NULL);
-
- /* Return the new/current TEXT. */
- 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 "^X[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)
- SCR *sp;
- TEXT *tp;
-{
- CHAR_T 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 CH_HEX character. */
- for (off = sp->cno - 1, p = tp->lb + off, len = 0;; --p, --off, ++len) {
- if (*p == CH_HEX) {
- wp = p + 1;
- break;
- }
- /* Not on this line? Shouldn't happen. */
- if (off == tp->ai || off == tp->offset)
- goto nothex;
- }
-
- /* If length of 0, then it wasn't a hex value. */
- if (len == 0)
- goto nothex;
-
- /* Get the value. */
- errno = 0;
- value = strtol(wp, NULL, 16);
- if (errno || value > MAX_CHAR_T) {
-nothex: tp->lb[sp->cno] = savec;
- return (0);
- }
-
- /* Restore the original character. */
- tp->lb[sp->cno] = savec;
-
- /* Adjust the bookkeeping. */
- sp->cno -= len;
- tp->len -= len;
- tp->lb[sp->cno - 1] = value;
-
- /* Copy down any overwrite characters. */
- if (tp->owrite)
- memmove(tp->lb + sp->cno,
- tp->lb + sp->cno + len, tp->owrite);
-
- /* Copy down any insert characters. */
- if (tp->insert)
- memmove(tp->lb + sp->cno + tp->owrite,
- tp->lb + sp->cno + tp->owrite + len, tp->insert);
-
- 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, flags)
- SCR *sp;
- EXF *ep;
- TEXTH *tiqh;
- u_int flags;
-{
- TEXT *tp;
- recno_t lno;
-
- /*
- * The first line replaces a current line, and all subsequent lines
- * are appended into the file. Resolve autoindented characters for
- * each line before committing it.
- */
- tp = tiqh->cqh_first;
- if (LF_ISSET(TXT_AUTOINDENT))
- txt_ai_resolve(sp, tp);
- if (file_sline(sp, ep, tp->lno, tp->lb, tp->len))
- return (1);
-
- for (lno = tp->lno; (tp = tp->q.cqe_next) != (void *)sp->tiqp; ++lno) {
- if (LF_ISSET(TXT_AUTOINDENT))
- txt_ai_resolve(sp, tp);
- 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.
- */
-static int
-txt_margin(sp, tp, chp, wmtp, flags, didbreak)
- SCR *sp;
- TEXT *tp, *wmtp;
- CHAR_T *chp;
- int *didbreak;
- u_int flags;
-{
- size_t len, off;
- char *p, *wp;
-
- /* Find the nearest previous blank. */
- for (off = sp->cno - 1, p = tp->lb + off, len = 0;; --off, --p, ++len) {
- if (isblank(*p)) {
- wp = p + 1;
- break;
- }
-
- /*
- * If reach the start of the line, there's nowhere to break.
- *
- * !!!
- * Historic vi belled 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 as it tends to wake the
- * cats.
- */
- if (off == tp->ai || off == tp->offset) {
- *didbreak = 0;
- return (0);
- }
- }
-
- /*
- * Store saved information about the rest of the line in the
- * wrapmargin TEXT structure.
- */
- wmtp->lb = p + 1;
- wmtp->len = len;
- wmtp->insert = LF_ISSET(TXT_APPENDEOL) ? tp->insert - 1 : tp->insert;
- wmtp->owrite = tp->owrite;
-
- /* Correct current bookkeeping information. */
- sp->cno -= len;
- if (LF_ISSET(TXT_APPENDEOL)) {
- tp->len -= len + tp->owrite + (tp->insert - 1);
- tp->insert = 1;
- } else {
- tp->len -= len + tp->owrite + tp->insert;
- tp->insert = 0;
- }
- tp->owrite = 0;
-
- /*
- * !!!
- * Delete any trailing whitespace from the current line.
- */
- for (;; --p, --off) {
- if (!isblank(*p))
- break;
- --sp->cno;
- --tp->len;
- if (off == tp->ai || off == tp->offset)
- break;
- }
- *didbreak = 1;
- return (0);
-}
-
-/*
- * txt_Rcleanup --
- * Resolve the input line for the 'R' command.
- */
-static void
-txt_Rcleanup(sp, tiqh, tp, lp, olen)
- SCR *sp;
- TEXTH *tiqh;
- TEXT *tp;
- const char *lp;
- const size_t olen;
-{
- TEXT *ttp;
- size_t ilen, tmp;
-
- /*
- * Check to make sure that the cursor hasn't moved beyond
- * the end of the line.
- */
- if (tp->owrite == 0)
- return;
-
- /*
- * Calculate how many characters the user has entered,
- * plus the blanks erased by <carriage-return>/<newline>s.
- */
- for (ttp = tiqh->cqh_first, ilen = 0;;) {
- ilen += ttp == tp ? sp->cno : ttp->len + ttp->R_erase;
- if ((ttp = ttp->q.cqe_next) == (void *)sp->tiqp)
- break;
- }
-
- /*
- * If the user has entered less characters than the original line
- * was long, restore any overwriteable characters to the original
- * characters, and make them insert characters. We don't copy them
- * anywhere, because the 'R' command doesn't have insert characters.
- */
- if (ilen < olen) {
- tmp = MIN(tp->owrite, olen - ilen);
- memmove(tp->lb + sp->cno, lp + ilen, tmp);
- tp->owrite -= tmp;
- tp->insert += tmp;
- }
-}
diff --git a/usr.bin/vi/vi/v_paragraph.c b/usr.bin/vi/vi/v_paragraph.c
deleted file mode 100644
index de417ec..0000000
--- a/usr.bin/vi/vi/v_paragraph.c
+++ /dev/null
@@ -1,370 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.20 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-#define INTEXT_CHECK { \
- if (len == 0 || v_isempty(p, len)) { \
- if (!--cnt) \
- goto found; \
- pstate = P_INBLANK; \
- } \
- /* \
- * !!! \
- * Historic documentation (USD:15-11, 4.2) said that formfeed \
- * characters (^L) in the first column delimited paragraphs. \
- * The historic vi code mentions formfeed characters, but never \
- * implements them. It seems reasonable, do it. \
- */ \
- if (p[0] == '\014') { \
- if (!--cnt) \
- goto found; \
- continue; \
- } \
- if (p[0] != '.' || len < 2) \
- continue; \
- for (lp = VIP(sp)->ps; *lp != '\0'; lp += 2) \
- if (lp[0] == p[1] && \
- (lp[1] == ' ' && len == 2 || lp[1] == p[2]) && \
- !--cnt) \
- goto found; \
-}
-
-/*
- * v_paragraphf -- [count]}
- * Move forward count paragraphs.
- *
- * Paragraphs are empty lines after text, formfeed characters, or values
- * from the paragraph or section options.
- */
-int
-v_paragraphf(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- enum { P_INTEXT, P_INBLANK } pstate;
- size_t lastlen, len;
- recno_t cnt, lastlno, lno;
- char *p, *lp;
-
- /*
- * !!!
- * If the starting cursor position is at or before any non-blank
- * characters in the line, i.e. the movement is cutting all of the
- * line's text, the buffer is in line mode. It's a lot easier to
- * check here, because we know that the end is going to be the start
- * or end of a line.
- *
- * This was historical practice in vi, with a single exception. If
- * the paragraph movement was from the start of the last line to EOF,
- * then all the characters were deleted from the last line, but the
- * line itself remained. If somebody complains, don't pause, don't
- * hesitate, just hit them.
- */
- if (ISMOTION(vp))
- if (vp->m_start.cno == 0)
- F_SET(vp, VM_LMODE);
- else {
- vp->m_stop = vp->m_start;
- vp->m_stop.cno = 0;
- if (nonblank(sp, ep, vp->m_stop.lno, &vp->m_stop.cno))
- return (1);
- if (vp->m_start.cno <= vp->m_stop.cno)
- F_SET(vp, VM_LMODE);
- }
-
- /* Figure out what state we're currently in. */
- lno = vp->m_start.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:
- INTEXT_CHECK;
- break;
- case P_INBLANK:
- if (len == 0 || v_isempty(p, len))
- break;
- if (--cnt) {
- pstate = P_INTEXT;
- break;
- }
- /*
- * !!!
- * Non-motion commands move to the end of the range,
- * VC_D and VC_Y stay at the start. Ignore VC_C and
- * VC_DEF. Adjust the end of the range for motion
- * commands; historically, a motion component was to
- * the end of the previous line, whereas the movement
- * command was to the start of the new "paragraph".
- */
-found: if (ISMOTION(vp)) {
- vp->m_stop.lno = lastlno;
- vp->m_stop.cno = lastlen ? lastlen - 1 : 0;
- vp->m_final = vp->m_start;
- } else {
- vp->m_stop.lno = lno;
- vp->m_stop.cno = 0;
- vp->m_final = vp->m_stop;
- }
- return (0);
- default:
- abort();
- }
- }
-
- /*
- * !!!
- * Adjust end of the range for motion commands; EOF is a movement
- * sink. The } command historically moved to the end of the last
- * line, not the beginning, from any position before the end of the
- * last line. It also historically worked on empty files, so we
- * have to make it okay.
- */
-eof: if (vp->m_start.lno == lno || vp->m_start.lno == lno - 1) {
- if (file_gline(sp, ep, vp->m_start.lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (vp->m_start.lno != 1 || lno != 0) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- vp->m_start.cno = 0;
- return (0);
- }
- if (vp->m_start.cno == (len ? len - 1 : 0)) {
- v_eof(sp, ep, NULL);
- return (1);
- }
- }
- /*
- * !!!
- * Non-motion commands move to the end of the range, VC_D
- * and VC_Y stay at the start. Ignore VC_C and VC_DEF.
- *
- * If deleting the line (which happens if deleting to EOF), then
- * cursor movement is to the first nonblank.
- */
- if (F_ISSET(vp, VC_D)) {
- F_CLR(vp, VM_RCM_MASK);
- F_SET(vp, VM_RCM_SETFNB);
- }
- vp->m_stop.lno = lno - 1;
- vp->m_stop.cno = len ? len - 1 : 0;
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- return (0);
-}
-
-/*
- * v_paragraphb -- [count]{
- * Move backward count paragraphs.
- */
-int
-v_paragraphb(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- enum { P_INTEXT, P_INBLANK } pstate;
- size_t len;
- recno_t cnt, lno;
- char *p, *lp;
-
- /*
- * !!!
- * Check for SOF. The historic vi didn't complain if users hit SOF
- * repeatedly, unless it was part of a motion command. There is no
- * question but that Emerson's editor of choice was vi.
- *
- * The { command historically moved to the beginning of the first
- * line if invoked on the first line.
- *
- * !!!
- * If the starting cursor position is in the first column (backward
- * paragraph movements did NOT historically pay attention to non-blank
- * characters) i.e. the movement is cutting the entire line, the buffer
- * is in line mode. Cuts from the beginning of the line also did not
- * cut the current line, but started at the previous EOL.
- *
- * Correct for a left motion component while we're thinking about it.
- */
- lno = vp->m_start.lno;
-
- if (ISMOTION(vp))
- if (vp->m_start.cno == 0) {
- if (vp->m_start.lno == 1) {
- v_sof(sp, &vp->m_start);
- return (1);
- } else
- --vp->m_start.lno;
- F_SET(vp, VM_LMODE);
- } else
- --vp->m_start.cno;
-
- if (vp->m_start.lno <= 1)
- goto sof;
-
- /* Figure out what state we're currently in. */
- 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;
-
- /*
- * !!!
- * If the starting cursor is past the first column,
- * the current line is checked for a paragraph.
- */
- if (vp->m_start.cno > 0)
- ++lno;
- }
-
- for (;;) {
- if ((p = file_gline(sp, ep, --lno, &len)) == NULL)
- goto sof;
- switch (pstate) {
- case P_INTEXT:
- INTEXT_CHECK;
- break;
- case P_INBLANK:
- if (len != 0 && !v_isempty(p, len)) {
- if (!--cnt)
- goto found;
- pstate = P_INTEXT;
- }
- break;
- default:
- abort();
- }
- }
-
- /* SOF is a movement sink. */
-sof: lno = 1;
-
-found: vp->m_stop.lno = lno;
- vp->m_stop.cno = 0;
-
- /*
- * All commands move to the end of the range. (We already
- * adjusted the start of the range for motion commands).
- */
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_buildps --
- * Build the paragraph command search pattern.
- */
-int
-v_buildps(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->ps != NULL)
- free(vip->ps);
-
- 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->ps = p;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_put.c b/usr.bin/vi/vi/v_put.c
deleted file mode 100644
index af7fcc5..0000000
--- a/usr.bin/vi/vi/v_put.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.11 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- u_long cnt;
-
- if (F_ISSET(vp, VC_ISDOT))
- inc_buf(sp, vp);
-
- /*
- * !!!
- * Historic vi did not support a count with the 'p' and 'P'
- * commands. It's useful, so we do.
- */
- for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- if (put(sp, ep, NULL,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_final, 0))
- return (1);
- vp->m_start = vp->m_final;
- }
- return (0);
-}
-
-/*
- * v_put -- [buffer]p
- * Insert the contents of the buffer after the cursor.
- */
-int
-v_put(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- u_long cnt;
-
- if (F_ISSET(vp, VC_ISDOT))
- inc_buf(sp, vp);
-
- /*
- * !!!
- * Historic vi did not support a count with the 'p' and 'P'
- * commands. It's useful, so we do.
- */
- for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
- if (put(sp, ep, NULL,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_final, 1))
- return (1);
- vp->m_start = vp->m_final;
- }
- return (0);
-}
-
-/*
- * !!!
- * 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/vi/v_redraw.c b/usr.bin/vi/vi/v_redraw.c
deleted file mode 100644
index f028111..0000000
--- a/usr.bin/vi/vi/v_redraw.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.6 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_redraw -- ^R
- * Redraw the screen.
- */
-int
-v_redraw(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- F_SET(sp, S_REFRESH);
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_replace.c b/usr.bin/vi/vi/v_replace.c
deleted file mode 100644
index 40d0bbc..0000000
--- a/usr.bin/vi/vi/v_replace.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.20 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- 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, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, vp->m_start.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 append replacement characters
- * to the line, but I see no compelling reason to do so.
- */
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- vp->m_stop.lno = vp->m_start.lno;
- vp->m_stop.cno = vp->m_start.cno + cnt - 1;
- if (vp->m_stop.cno > len - 1) {
- v_eol(sp, ep, &vp->m_start);
- return (1);
- }
-
- /*
- * Get the character. Literal escapes escape any character,
- * single escapes return.
- */
- if (F_ISSET(vp, VC_ISDOT)) {
- ikey.ch = VIP(sp)->rlast;
- ikey.value = KEY_VAL(sp, ikey.ch);
- } else {
- sp->showmode = "Replace char";
- (void)sp->s_refresh(sp, ep);
-
- if (term_key(sp, &ikey, 0) != INP_OK)
- return (1);
- switch (ikey.value) {
- case K_ESCAPE:
- 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. */
- vp->m_stop.lno = vp->m_start.lno + cnt;
- vp->m_stop.cno = 0;
-
- /* The first part of the current line. */
- if (file_sline(sp, ep, vp->m_start.lno, p, vp->m_start.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 += vp->m_start.cno + cnt, len -= vp->m_start.cno + cnt;
- len && isblank(*p); --len, ++p);
-
- if ((tp = text_init(sp, p, len, len)) == NULL)
- goto err_ret;
- if (txt_auto(sp, ep, vp->m_start.lno, NULL, 0, tp))
- goto err_ret;
- vp->m_stop.cno = tp->ai ? tp->ai - 1 : 0;
- if (file_aline(sp, ep, 1, vp->m_start.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, vp->m_start.lno, "", 0)) {
-err_ret: rval = 1;
- break;
- }
- } else {
- memset(bp + vp->m_start.cno, ikey.ch, cnt);
- rval = file_sline(sp, ep, vp->m_start.lno, bp, len);
- }
- FREE_SPACE(sp, bp, blen);
-
- vp->m_final = vp->m_stop;
- return (rval);
-}
diff --git a/usr.bin/vi/vi/v_right.c b/usr.bin/vi/vi/v_right.c
deleted file mode 100644
index b71f40f..0000000
--- a/usr.bin/vi/vi/v_right.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.10 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_right -- [count]' ', [count]l
- * Move right by columns.
- */
-int
-v_right(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t len;
-
- if (file_gline(sp, ep, vp->m_start.lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_eol(sp, ep, NULL);
- else
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- /* It's always illegal to move right on empty lines. */
- if (len == 0) {
- v_eol(sp, ep, NULL);
- return (1);
- }
-
- /*
- * Non-motion commands move to the end of the range. VC_D and
- * VC_Y stay at the start. Ignore VC_C and VC_DEF. Adjust the
- * end of the range for motion commands.
- *
- * !!!
- * Historically, "[cdsy]l" worked at the end of a line. Also,
- * EOL is a count sink.
- */
- vp->m_stop.cno = vp->m_start.cno +
- (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
- if (vp->m_start.cno == len - 1 && !ISMOTION(vp)) {
- v_eol(sp, ep, NULL);
- return (1);
- }
- if (vp->m_stop.cno >= len) {
- vp->m_stop.cno = len - 1;
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- } else if (ISMOTION(vp)) {
- --vp->m_stop.cno;
- vp->m_final = vp->m_start;
- } else
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_dollar -- [count]$
- * Move to the last column.
- */
-int
-v_dollar(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t len;
-
- /*
- * !!!
- * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
- */
- if ((F_ISSET(vp, VC_C1SET) ? vp->count : 1) != 1) {
- /*
- * !!!
- * 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.
- */
- vp->m_stop.cno = 0;
- if (nonblank(sp, ep, vp->m_start.lno, &vp->m_stop.cno))
- return (1);
- if (ISMOTION(vp) && vp->m_start.cno <= vp->m_stop.cno)
- F_SET(vp, VM_LMODE);
-
- --vp->count;
- if (v_down(sp, ep, vp))
- return (1);
- }
-
- if (file_gline(sp, ep, vp->m_stop.lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- v_eol(sp, ep, NULL);
- else
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
-
- /*
- * Non-motion commands move to the end of the range. VC_D
- * and VC_Y stay at the start. Ignore VC_C and VC_DEF.
- */
- vp->m_stop.cno = len ? len - 1 : 0;
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_screen.c b/usr.bin/vi/vi/v_screen.c
deleted file mode 100644
index 83cccb9..0000000
--- a/usr.bin/vi/vi/v_screen.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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.14 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_screen -- ^W
- * Switch screens.
- */
-int
-v_screen(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * 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)msg_status(sp, ep, vp->m_start.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/vi/v_scroll.c b/usr.bin/vi/vi/v_scroll.c
deleted file mode 100644
index e188865..0000000
--- a/usr.bin/vi/vi/v_scroll.c
+++ /dev/null
@@ -1,486 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.22 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-static void goto_adjust __P((VICMDARG *));
-
-/*
- * 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.
- *
- * 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.
- *
- * 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.
- */
-
-/*
- * 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t nlines;
-
- if (F_ISSET(vp, VC_C1SET)) {
- if (file_gline(sp, ep, vp->count, NULL) == NULL) {
- v_eof(sp, ep, &vp->m_start);
- return (1);
- }
- vp->m_stop.lno = vp->count;
- } else {
- if (file_lline(sp, ep, &nlines))
- return (1);
- vp->m_stop.lno = nlines ? nlines : 1;
- }
- goto_adjust(vp);
- return (0);
-}
-
-/*
- * v_home -- [count]H
- * Move to the first non-blank character of the logical line
- * count - 1 from the top of the screen, 0 by default.
- */
-int
-v_home(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- if (sp->s_position(sp, ep, &vp->m_stop,
- F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0, P_TOP))
- return (1);
- goto_adjust(vp);
- return (0);
-}
-
-/*
- * 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * 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.
- */
- if (sp->s_position(sp, ep, &vp->m_stop, 0, P_MIDDLE))
- return (1);
- goto_adjust(vp);
- return (0);
-}
-
-/*
- * v_bottom -- [count]L
- * Move to the first non-blank character of the logical line
- * count - 1 from the bottom of the screen, 0 by default.
- */
-int
-v_bottom(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- if (sp->s_position(sp, ep, &vp->m_stop,
- F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0, P_BOTTOM))
- return (1);
- goto_adjust(vp);
- return (0);
-}
-
-static void
-goto_adjust(vp)
- VICMDARG *vp;
-{
- /* Guess that it's the end of the range. */
- vp->m_final = vp->m_stop;
-
- /*
- * Non-motion commands move the cursor to the end of the range, and
- * then to the NEXT nonblank of the line. Historic vi always moved
- * to the first nonblank in the line; since the H, M, and L commands
- * are logical motions in this implementation, we do the next nonblank
- * so that it looks approximately the same to the user. To make this
- * happen, the VM_RCM_SETNNB flag is set in the vcmd.c command table.
- *
- * If it's a motion, it's more complicated. The best possible solution
- * is probably to display the first nonblank of the line the cursor
- * will eventually rest on. This is tricky, particularly given that if
- * the associated command is a delete, we don't yet know what line that
- * will be. So, we clear the VM_RCM_SETNNB flag, and set the first
- * nonblank flag (VM_RCM_SETFNB). Note, if the lines are sufficiently
- * long, this can cause the cursor to warp out of the screen. It's too
- * hard to fix.
- *
- * XXX
- * The G command is always first nonblank, so it's okay to reset it.
- */
- if (ISMOTION(vp)) {
- F_CLR(vp, VM_RCM_MASK);
- F_SET(vp, VM_RCM_SETFNB);
- } else
- return;
-
- /*
- * If moving backward in the file, VC_D and VC_Y move to the end
- * of the range, unless the line didn't change, in which case VC_Y
- * doesn't move. If moving forward in the file, VC_D and VC_Y stay
- * at the start of the range. Ignore VC_C and VC_DEF.
- */
- if (vp->m_stop.lno < vp->m_start.lno ||
- vp->m_stop.lno == vp->m_start.lno &&
- vp->m_stop.cno < vp->m_start.cno) {
- if (F_ISSET(vp, VC_Y) && vp->m_stop.lno == vp->m_start.lno)
- vp->m_final = vp->m_start;
- } else
- vp->m_final = vp->m_start;
-}
-
-/*
- * v_up -- [count]^P, [count]k, [count]-
- * Move up by lines.
- */
-int
-v_up(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
-
- lno = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if (vp->m_start.lno <= lno) {
- v_sof(sp, &vp->m_start);
- return (1);
- }
- vp->m_stop.lno = vp->m_start.lno - lno;
- vp->m_final = vp->m_stop;
- 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * 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, vp->m_start.lno) : v_down(sp, ep, vp));
-}
-
-/*
- * v_down -- [count]^J, [count]^N, [count]j, [count]^M, [count]+
- * Move down by lines.
- */
-int
-v_down(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
-
- lno = vp->m_start.lno + (F_ISSET(vp, VC_C1SET) ? vp->count : 1);
- if (file_gline(sp, ep, lno, NULL) == NULL) {
- v_eof(sp, ep, &vp->m_start);
- return (1);
- }
- vp->m_stop.lno = lno;
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- return (0);
-}
-
-/*
- * v_hpageup -- [count]^U
- * Page up half screens.
- */
-int
-v_hpageup(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * Half screens always succeed unless already at SOF.
- *
- * !!!
- * Half screens set the scroll value, even if the command
- * ultimately failed, in historic vi. Probably a don't care.
- */
- if (F_ISSET(vp, VC_C1SET))
- sp->defscroll = vp->count;
- if (sp->s_scroll(sp, ep, &vp->m_stop, sp->defscroll, CNTRL_U))
- return (1);
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_hpagedown -- [count]^D
- * Page down half screens.
- */
-int
-v_hpagedown(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * Half screens always succeed unless already at EOF.
- *
- * !!!
- * Half screens set the scroll value, even if the command
- * ultimately failed, in historic vi. Probably a don't care.
- */
- if (F_ISSET(vp, VC_C1SET))
- sp->defscroll = vp->count;
- if (sp->s_scroll(sp, ep, &vp->m_stop, sp->defscroll, CNTRL_D))
- return (1);
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t offset;
-
- /*
- * !!!
- * The calculation in IEEE Std 1003.2-1992 (POSIX) is:
- *
- * top_line = top_line + count * (window - 2);
- *
- * which was historically wrong. The correct one is:
- *
- * top_line = top_line + count * window - 2;
- *
- * i.e. the two line "overlap" was only subtracted once. Which
- * makes no sense, but then again, an overlap makes no sense for
- * any screen but the "next" one anyway. We do it the historical
- * was as there's no good reason to change it.
- *
- * If the screen has been split, use the smaller of the current
- * window size and the window option value.
- *
- * Given a one-line screen with the cursor on line 1, it would be
- * possible for this to fail, i.e. "1 + 1 * 1 - 2 = 0". Move at
- * least one line.
- */
-#define IS_SPLIT_SCREEN(sp) \
- ((sp)->q.cqe_prev != (void *)&(sp)->gp->dq || \
- (sp)->q.cqe_next != (void *)&(sp)->gp->dq)
-
- offset = (F_ISSET(vp, VC_C1SET) ? vp->count : 1) *
- (IS_SPLIT_SCREEN(sp) ?
- MIN(sp->t_maxrows, O_VAL(sp, O_WINDOW)) : O_VAL(sp, O_WINDOW)) - 2;
- if (offset == 0)
- offset = 1;
- if (sp->s_scroll(sp, ep, &vp->m_stop, offset, CNTRL_F))
- return (1);
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t offset;
-
- /*
- * !!!
- * The calculation in IEEE Std 1003.2-1992 (POSIX) is:
- *
- * top_line = top_line - count * (window - 2);
- *
- * which was historically wrong. The correct one is:
- *
- * top_line = (top_line - count * window) + 2;
- *
- * A simpler expression is that, as with ^F, we scroll exactly:
- *
- * count * window - 2
- *
- * lines.
- *
- * Bizarre. As with ^F, an overlap makes no sense for anything
- * but the first screen. We do it the historical way as there's
- * no good reason to change it.
- *
- * If the screen has been split, use the smaller of the current
- * window size and the window option value.
- *
- * Given a one-line screen with the cursor on line 1, it would be
- * possible for this to fail, i.e. "1 + 1 * 1 - 2 = 0". Move at
- * least one line.
- */
- offset = (F_ISSET(vp, VC_C1SET) ? vp->count : 1) *
- (IS_SPLIT_SCREEN(sp) ?
- MIN(sp->t_maxrows, O_VAL(sp, O_WINDOW)) : O_VAL(sp, O_WINDOW)) - 2;
- if (offset == 0)
- offset = 1;
- if (sp->s_scroll(sp, ep, &vp->m_stop, offset, CNTRL_B))
- return (1);
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_lineup -- [count]^Y
- * Page up by lines.
- */
-int
-v_lineup(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * The cursor moves down, staying with its original line, unless it
- * reaches the bottom of the screen.
- */
- if (sp->s_scroll(sp, ep,
- &vp->m_stop, F_ISSET(vp, VC_C1SET) ? vp->count : 1, CNTRL_Y))
- return (1);
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_linedown -- [count]^E
- * Page down by lines.
- */
-int
-v_linedown(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * The cursor moves up, staying with its original line, unless it
- * reaches the top of the screen.
- */
- if (sp->s_scroll(sp, ep,
- &vp->m_stop, F_ISSET(vp, VC_C1SET) ? vp->count : 1, CNTRL_E))
- return (1);
- vp->m_final = vp->m_stop;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_search.c b/usr.bin/vi/vi/v_search.c
deleted file mode 100644
index ad0b0ca..0000000
--- a/usr.bin/vi/vi/v_search.c
+++ /dev/null
@@ -1,414 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.34 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static int correct __P((SCR *, EXF *, VICMDARG *, u_int));
-static int getptrn __P((SCR *, EXF *, ARG_CHAR_T, char **, size_t *));
-static int search __P((SCR *,
- EXF *, VICMDARG *, char *, size_t, u_int, enum direction));
-
-/*
- * v_searchn -- n
- * Repeat last search.
- */
-int
-v_searchn(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (search(sp, ep, vp, NULL, 0, SEARCH_MSG, sp->searchdir));
-}
-
-/*
- * v_searchN -- N
- * Reverse last search.
- */
-int
-v_searchN(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- enum direction dir;
-
- switch (sp->searchdir) {
- case BACKWARD:
- dir = FORWARD;
- break;
- case FORWARD:
- dir = BACKWARD;
- break;
- default: /* NOTSET handled in search(). */
- dir = sp->searchdir;
- break;
- }
- return (search(sp, ep, vp, NULL, 0, SEARCH_MSG, dir));
-}
-
-/*
- * v_searchb -- [count]?RE[? offset]
- * Search backward.
- */
-int
-v_searchb(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- size_t len;
- char *ptrn;
-
- if (F_ISSET(vp, VC_ISDOT))
- ptrn = NULL;
- else {
- if (getptrn(sp, ep, CH_BSEARCH, &ptrn, &len))
- return (1);
- if (len == 0) {
- F_SET(vp, VM_NOMOTION);
- return (0);
- }
- }
- return (search(sp, ep, vp, ptrn, len,
- SEARCH_MSG | SEARCH_PARSE | SEARCH_SET, BACKWARD));
-}
-
-/*
- * v_searchf -- [count]/RE[/ offset]
- * Search forward.
- */
-int
-v_searchf(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- size_t len;
- char *ptrn;
-
- if (F_ISSET(vp, VC_ISDOT))
- ptrn = NULL;
- else {
- if (getptrn(sp, ep, CH_FSEARCH, &ptrn, &len))
- return (1);
- if (len == 0) {
- F_SET(vp, VM_NOMOTION);
- return (0);
- }
- }
- return (search(sp, ep, vp, ptrn, len,
- SEARCH_MSG | SEARCH_PARSE | SEARCH_SET, FORWARD));
-}
-
-/*
- * v_searchw -- [count]^A
- * Search for the word under the cursor.
- */
-int
-v_searchw(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- size_t blen, len;
- 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);
-
- rval = search(sp, ep, vp, bp, 0, SEARCH_MSG | SEARCH_TERM, FORWARD);
-
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
-
-static int
-search(sp, ep, vp, ptrn, len, flags, dir)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- u_int flags;
- char *ptrn;
- size_t len;
- enum direction dir;
-{
- char *eptrn;
-
- if (ISMOTION(vp))
- flags |= SEARCH_EOL;
-
- for (;;) {
- switch (dir) {
- case BACKWARD:
- if (b_search(sp, ep,
- &vp->m_start, &vp->m_stop, ptrn, &eptrn, &flags))
- return (1);
- break;
- case FORWARD:
- if (f_search(sp, ep,
- &vp->m_start, &vp->m_stop, ptrn, &eptrn, &flags))
- return (1);
- break;
- case NOTSET:
- msgq(sp, M_ERR, "No previous search pattern");
- return (1);
- default:
- abort();
- }
-
- /*
- * !!!
- * Historically, vi permitted trailing <blank>'s, multiple
- * search strings (separated by semi-colons) and full-blown
- * z commands after / and ? search strings. In the case of
- * multiple search strings, leading <blank>'s on the second
- * and subsequent strings was eaten as well.
- *
- * !!!
- * However, the command "/STRING/; " failed, apparently it
- * confused the parser. We're not *that* compatible.
- *
- * The N, n, and ^A commands also get to here, but they've
- * set ptrn to NULL, len to 0, or the SEARCH_TERM flag, or
- * some combination thereof.
- */
- if (ptrn == NULL || len == 0)
- break;
- len -= eptrn - ptrn;
- for (; len > 0 && isblank(*eptrn); ++eptrn, --len);
- if (len == 0)
- break;
-
- switch (*eptrn) {
- case ';':
- for (++eptrn; --len > 0 && isblank(*eptrn); ++eptrn);
- ptrn = eptrn;
- switch (*eptrn) {
- case '/':
- dir = FORWARD;
- break;
- case '?':
- dir = BACKWARD;
- break;
- default:
- goto usage;
- }
- ptrn = eptrn;
- vp->m_start = vp->m_stop;
- continue;
- case 'z':
- if (term_push(sp, eptrn, len, CH_NOMAP | CH_QUOTED))
- return (1);
- goto ret;
- default:
-usage: msgq(sp, M_ERR,
- "Characters after search string and/or delta");
- return (1);
- }
- }
-
- /* Non-motion commands move to the end of the range. */
-ret: if (ISMOTION(vp)) {
- if (correct(sp, ep, vp, flags))
- return (1);
- } else
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * getptrn --
- * Get the search pattern.
- */
-static int
-getptrn(sp, ep, prompt, ptrnp, lenp)
- SCR *sp;
- EXF *ep;
- ARG_CHAR_T prompt;
- char **ptrnp;
- size_t *lenp;
-{
- TEXT *tp;
-
- if (sp->s_get(sp, ep, sp->tiqp, 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->tiqp->cqh_first;
- *ptrnp = tp->lb;
- *lenp = tp->len;
- return (0);
-}
-
-/*
- * correct --
- * Handle command with a search as the motion.
- *
- * !!!
- * Historically, commands didn't affect the line searched to/from if the
- * motion command was a search and the final position was the start/end
- * of the line. There were some special cases and vi was not consistent;
- * 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 going to exactly match historic practice.
- */
-static int
-correct(sp, ep, vp, flags)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- u_int flags;
-{
- enum direction dir;
- MARK m;
- size_t len;
-
- /*
- * !!!
- * We may have wrapped if wrapscan was set, and we may have returned
- * to the position where the cursor started. Historic vi didn't cope
- * with this well. Yank wouldn't beep, but the first put after the
- * yank would move the cursor right one column (without adding any
- * text) and the second would put a copy of the current line. The
- * change and delete commands would beep, but would leave the cursor
- * on the colon command line. I believe that there are macros that
- * depend on delete, at least, failing. For now, commands that use
- * search as a motion component fail when the search returns to the
- * original cursor position.
- */
- if (vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno == vp->m_stop.cno) {
- msgq(sp, M_BERR, "Search wrapped to original position");
- return (1);
- }
-
- /*
- * !!!
- * Searches become line mode operations if there was a delta
- * specified to the search pattern.
- */
- if (LF_ISSET(SEARCH_DELTA))
- F_SET(vp, VM_LMODE);
-
- /*
- * If the motion is in the reverse direction, switch the start and
- * stop MARK's so that it's in a forward direction. (There's no
- * reason for this other than to make the tests below easier. The
- * code in vi.c:vi() would have done the switch.) Both forward
- * and backward motions can happen for any kind of search command
- * because of the wrapscan option.
- */
- if (vp->m_start.lno > vp->m_stop.lno ||
- vp->m_start.lno == vp->m_stop.lno &&
- vp->m_start.cno > vp->m_stop.cno) {
- dir = BACKWARD;
- m = vp->m_start;
- vp->m_start = vp->m_stop;
- vp->m_stop = m;
- } else
- dir = FORWARD;
-
- /*
- * BACKWARD:
- * VC_D commands move to the end of the range. VC_Y stays at
- * the start unless the end of the range is on a different line,
- * when it moves to the end of the range. Ignore VC_C and
- * VC_DEF.
- *
- * FORWARD:
- * VC_D and VC_Y commands don't move. Ignore VC_C and VC_DEF.
- */
- if (dir == BACKWARD)
- if (F_ISSET(vp, VC_D) ||
- F_ISSET(vp, VC_Y) && vp->m_start.lno != vp->m_stop.lno)
- vp->m_final = vp->m_start;
- else
- vp->m_final = vp->m_stop;
- else
- vp->m_final = vp->m_start;
-
- /*
- * !!!
- * Backward searches starting at column 0, and forward searches ending
- * at column 0 are corrected to the last column of the previous line.
- * Otherwise, adjust the starting/ending point to the character before
- * the current one (this is safe because we know the search had to move
- * to succeed).
- *
- * Searches become line mode operations if they start at column 0 and
- * end at column 0 of another line.
- */
- if (vp->m_start.lno < vp->m_stop.lno && vp->m_stop.cno == 0) {
- if (file_gline(sp, ep, --vp->m_stop.lno, &len) == NULL) {
- GETLINE_ERR(sp, vp->m_stop.lno);
- return (1);
- }
- if (vp->m_start.cno == 0)
- F_SET(vp, VM_LMODE);
- vp->m_stop.cno = len ? len - 1 : 0;
- } else
- --vp->m_stop.cno;
-
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_section.c b/usr.bin/vi/vi/v_section.c
deleted file mode 100644
index a22773a..0000000
--- a/usr.bin/vi/vi/v_section.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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 behavior to match the paragraph commands.
- *
- * In historic vi, a section was defined as the first character(s) of the
- * line matching, which could be followed by anything. This implementation
- * follows that historic practice.
- *
- * !!!
- * The historic vi documentation (USD:15-10) claimed:
- * The section commands interpret a preceding count as a different
- * window size in which to redraw the screen at the new location,
- * and this window size is the base size for newly drawn windows
- * until another size is specified. This is very useful if you are
- * on a slow terminal ...
- *
- * I can't get the 4BSD vi to do this, it just beeps at me. For now, a
- * count to the section commands simply repeats the command.
- */
-
-/*
- * v_sectionf -- [count]]]
- * Move forward count sections/functions.
- *
- * !!!
- * Using ]] as a motion command was a bit special, historically. It could
- * match } as well as the usual { and section values. If it matched a { or
- * a section, it did NOT include the matched line. If it matched a }, it
- * did include the line. No clue why.
- */
-int
-v_sectionf(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t cnt, lno;
- size_t len;
- char *p, *list, *lp;
-
- /* Get the macro list. */
- if ((list = O_STR(sp, O_SECTIONS)) == NULL)
- return (1);
-
- /*
- * !!!
- * If the starting cursor position is at or before any non-blank
- * characters in the line, i.e. the movement is cutting all of the
- * line's text, the buffer is in line mode. It's a lot easier to
- * check here, because we know that the end is going to be the start
- * or end of a line.
- */
- if (ISMOTION(vp))
- if (vp->m_start.cno == 0)
- F_SET(vp, VM_LMODE);
- else {
- vp->m_stop = vp->m_start;
- vp->m_stop.cno = 0;
- if (nonblank(sp, ep, vp->m_stop.lno, &vp->m_stop.cno))
- return (1);
- if (vp->m_start.cno <= vp->m_stop.cno)
- F_SET(vp, VM_LMODE);
- }
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- for (lno = vp->m_start.lno;
- (p = file_gline(sp, ep, ++lno, &len)) != NULL;) {
- if (len == 0)
- continue;
- if (p[0] == '{' || ISMOTION(vp) && p[0] == '}') {
- if (!--cnt) {
- if (p[0] == '{')
- goto adjust1;
- goto adjust2;
- }
- continue;
- }
- /*
- * !!!
- * Historic documentation (USD:15-11, 4.2) said that formfeed
- * characters (^L) in the first column delimited sections.
- * The historic code mentions formfeed characters, but never
- * implements them. Seems reasonable, do it.
- */
- if (p[0] == '\014') {
- if (!--cnt)
- goto adjust1;
- continue;
- }
- if (p[0] != '.' || len < 2)
- continue;
- for (lp = list; *lp != '\0'; lp += 2 * sizeof(*lp))
- if (lp[0] == p[1] &&
- (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&
- !--cnt) {
- /*
- * !!!
- * If not cutting this line, adjust to the end
- * of the previous one. Otherwise, position to
- * column 0.
- */
-adjust1: if (ISMOTION(vp))
- goto ret1;
-
-adjust2: vp->m_stop.lno = lno;
- vp->m_stop.cno = 0;
- goto ret2;
- }
- }
-
- /* If moving forward, reached EOF, check to see if we started there. */
- if (vp->m_start.lno == lno - 1) {
- v_eof(sp, ep, NULL);
- return (1);
- }
-
-ret1: if (file_gline(sp, ep, --lno, &len) == NULL)
- return (1);
- vp->m_stop.lno = lno;
- vp->m_stop.cno = len ? len - 1 : 0;
-
- /*
- * Non-motion commands go to the end of the range. VC_D and
- * VC_Y stay at the start of the range. Ignore VC_C and VC_DEF.
- */
-ret2: if (ISMOTION(vp)) {
- vp->m_final = vp->m_start;
- if (F_ISSET(vp, VM_LMODE))
- vp->m_final.cno = 0;
- } else
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_sectionb -- [count][[
- * Move backward count sections/functions.
- */
-int
-v_sectionb(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- size_t len;
- recno_t cnt, lno;
- char *p, *list, *lp;
-
- /* An empty file or starting from line 1 is always illegal. */
- if (vp->m_start.lno <= 1) {
- v_sof(sp, NULL);
- return (1);
- }
-
- /* Get the macro list. */
- if ((list = O_STR(sp, O_SECTIONS)) == NULL)
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- for (lno = vp->m_start.lno;
- (p = file_gline(sp, ep, --lno, &len)) != NULL;) {
- if (len == 0)
- continue;
- if (p[0] == '{') {
- if (!--cnt)
- goto adjust1;
- continue;
- }
- /*
- * !!!
- * Historic documentation (USD:15-11, 4.2) said that formfeed
- * characters (^L) in the first column delimited sections.
- * The historic code mentions formfeed characters, but never
- * implements them. Seems reasonable, do it.
- */
- if (p[0] == '\014') {
- if (!--cnt)
- goto adjust1;
- continue;
- }
- if (p[0] != '.' || len < 2)
- continue;
- for (lp = list; *lp != '\0'; lp += 2 * sizeof(*lp))
- if (lp[0] == p[1] &&
- (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&
- !--cnt) {
-adjust1: vp->m_stop.lno = lno;
- vp->m_stop.cno = 0;
- goto ret1;
- }
- }
-
- /*
- * If moving backward, reached SOF, which is a movement sink.
- * We already checked for starting there.
- */
- vp->m_stop.lno = 1;
- vp->m_stop.cno = 0;
-
- /*
- * All commands move to the end of the range.
- *
- * !!!
- * Historic practice is the section cut was in line mode if it started
- * from column 0 and was in the backward direction. Otherwise, left
- * motion commands adjust the starting point to the character before
- * the current one. What makes this worse is that if it cut to line
- * mode it also went to the first non-<blank>.
- */
-ret1: if (vp->m_start.cno == 0) {
- F_CLR(vp, VM_RCM_MASK);
- F_SET(vp, VM_RCM_SETFNB);
-
- --vp->m_start.lno;
- F_SET(vp, VM_LMODE);
- } else
- --vp->m_start.cno;
-
- vp->m_final = vp->m_stop;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_sentence.c b/usr.bin/vi/vi/v_sentence.c
deleted file mode 100644
index 0b7543a..0000000
--- a/usr.bin/vi/vi/v_sentence.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.17 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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.
- * Finally, tabs are eaten (along with spaces) when skipping to the start
- * of the text following a "sentence".
- */
-
-/*
- * v_sentencef -- [count])
- * Move forward count sentences.
- */
-int
-v_sentencef(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- enum { BLANK, NONE, PERIOD } state;
- VCS cs;
- size_t len;
- u_long cnt;
-
- cs.cs_lno = vp->m_start.lno;
- cs.cs_cno = vp->m_start.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 (vp->m_start.lno != cs.cs_lno ||
- vp->m_start.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, but it's an error not to have moved. */
- if (vp->m_start.lno == cs.cs_lno && vp->m_start.cno == cs.cs_cno) {
- v_eof(sp, ep, NULL);
- return (1);
- }
-
-okret: vp->m_stop.lno = cs.cs_lno;
- vp->m_stop.cno = cs.cs_cno;
-
- /*
- * !!!
- * Historic, uh, features, yeah, that's right, call 'em features.
- * If the ending cursor position is at the first column in the
- * line, i.e. the movement is cutting an entire line, the buffer
- * is in line mode, and the ending position is the last character
- * of the previous line.
- *
- * Non-motion commands move to the end of the range. VC_D and
- * VC_Y stay at the start. Ignore VC_C and VC_DEF. Adjust the
- * end of the range for motion commands.
- */
- if (ISMOTION(vp)) {
- if (vp->m_start.cno == 0 &&
- (cs.cs_flags != 0 || vp->m_stop.cno == 0)) {
- if (file_gline(sp, ep,
- --vp->m_stop.lno, &len) == NULL) {
- GETLINE_ERR(sp, vp->m_stop.lno);
- return (1);
- }
- vp->m_stop.cno = len ? len - 1 : 0;
- F_SET(vp, VM_LMODE);
- } else
- --vp->m_stop.cno;
- vp->m_final = vp->m_start;
- } else
- vp->m_final = vp->m_stop;
- return (0);
-}
-
-/*
- * v_sentenceb -- [count](
- * Move backward count sentences.
- */
-int
-v_sentenceb(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- VCS cs;
- recno_t slno;
- size_t len, scno;
- u_long cnt;
- int last;
-
- /*
- * !!!
- * Historic vi permitted the user to hit SOF repeatedly.
- */
- if (vp->m_start.lno == 1 && vp->m_start.cno == 0)
- return (0);
-
- cs.cs_lno = vp->m_start.lno;
- cs.cs_cno = vp->m_start.cno;
- if (cs_init(sp, ep, &cs))
- return (1);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-
- /*
- * !!!
- * In empty lines, skip to the previous non-white-space character.
- * If in text, skip to the prevous white-space character. Believe
- * it or not, in the paragraph:
- * ab cd.
- * AB CD.
- * if the cursor is on the 'A' or 'B', ( moves to the 'a'. If it
- * is on the ' ', 'C' or 'D', it moves to the 'A'. Yes, Virginia,
- * Berkeley was once a major center of drug activity.
- */
- if (cs.cs_flags == CS_EMP) {
- if (cs_bblank(sp, ep, &cs))
- return (1);
- for (;;) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags != CS_EOL)
- break;
- }
- } else if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
- for (;;) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- break;
- }
-
- for (last = 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) {
- last = 1;
- continue;
- }
- if (cs.cs_flags == CS_EMP) {
- if (--cnt == 0)
- goto ret;
- if (cs_bblank(sp, ep, &cs))
- return (1);
- last = 0;
- continue;
- }
- switch (cs.cs_ch) {
- case '.':
- case '?':
- case '!':
- if (!last || --cnt != 0) {
- last = 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 (vp->m_start.lno != cs.cs_lno ||
- vp->m_start.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;
- last = 0;
- break;
- case '\t':
- last = 1;
- break;
- default:
- last =
- cs.cs_flags == CS_EOL || isblank(cs.cs_ch) ||
- cs.cs_ch == ')' || cs.cs_ch == ']' ||
- cs.cs_ch == '"' || cs.cs_ch == '\'' ? 1 : 0;
- }
- }
-
-okret: vp->m_stop.lno = cs.cs_lno;
- vp->m_stop.cno = cs.cs_cno;
-
- /*
- * !!!
- * If the starting and stopping cursor positions are at the first
- * columns in the line, i.e. the movement is cutting an entire line,
- * the buffer is in line mode, and the starting position is the last
- * character of the previous line.
- *
- * All commands move to the end of the range. Adjust the start of
- * the range for motion commands.
- */
- if (ISMOTION(vp))
- if (vp->m_start.cno == 0 &&
- (cs.cs_flags != 0 || vp->m_stop.cno == 0)) {
- if (file_gline(sp, ep,
- --vp->m_start.lno, &len) == NULL) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- vp->m_start.cno = len ? len - 1 : 0;
- F_SET(vp, VM_LMODE);
- } else
- --vp->m_start.cno;
- vp->m_final = vp->m_stop;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_status.c b/usr.bin/vi/vi/v_status.c
deleted file mode 100644
index 16e6c2b..0000000
--- a/usr.bin/vi/vi/v_status.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.18 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_status -- ^G
- * Show the file status.
- */
-int
-v_status(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
-
- /*
- * ^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 (msg_status(sp, ep, vp->m_start.lno, 1));
-}
diff --git a/usr.bin/vi/vi/v_stop.c b/usr.bin/vi/vi/v_stop.c
deleted file mode 100644
index 6a4cd72..0000000
--- a/usr.bin/vi/vi/v_stop.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.9 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_stop -- ^Z
- * Suspend vi.
- */
-int
-v_stop(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /* 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/vi/v_text.c b/usr.bin/vi/vi/v_text.c
deleted file mode 100644
index 5ad042c..0000000
--- a/usr.bin/vi/vi/v_text.c
+++ /dev/null
@@ -1,886 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.43 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "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.
- *
- * !!!
- * 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.) We also check for mapped keys waiting, i.e. if we're in the
- * middle of a map, don't bother logging the cursor.
- */
-#define LOG_CORRECT { \
- if (!MAPPED_KEYS_WAITING(sp)) \
- (void)log_cursor(sp, ep); \
-}
-#define LOG_CORRECT_FIRST { \
- if (first == 1) { \
- LOG_CORRECT; \
- first = 0; \
- } \
-}
-
-static u_int set_txt_std __P((SCR *, VICMDARG *, u_int));
-static int v_CS __P((SCR *, EXF *, VICMDARG *, u_int));
-
-/*
- * v_iA -- [count]A
- * Append text to the end of the line.
- */
-int
-v_iA(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- int first;
- char *p;
-
- sp->showmode = "Append";
- flags = set_txt_std(sp, vp, TXT_APPENDEOL);
- for (first = 1, lno = vp->m_start.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. */
- if (first == 1) {
- sp->cno = len == 0 ? 0 : len - 1;
- LOG_CORRECT;
- first = 0;
- }
-
- /* Start the change after the line. */
- sp->cno = len;
- }
-
- if (v_ntext(sp, ep,
- sp->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))
- return (1);
-
- flags = set_txt_std(sp, vp, TXT_APPENDEOL | TXT_REPLAY);
- sp->lno = lno = vp->m_final.lno;
- sp->cno = vp->m_final.cno;
- }
- return (0);
-}
-
-/*
- * v_ia -- [count]a
- * Append text to the cursor position.
- */
-int
-v_ia(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- u_long cnt;
- u_int flags;
- size_t len;
- char *p;
-
- sp->showmode = "Append";
- flags = set_txt_std(sp, vp, 0);
- for (lno = vp->m_start.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->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))
- return (1);
-
- flags = set_txt_std(sp, vp, TXT_REPLAY);
- sp->lno = lno = vp->m_final.lno;
- sp->cno = vp->m_final.cno;
- }
- return (0);
-}
-
-/*
- * v_iI -- [count]I
- * Insert text at the first non-blank character in the line.
- */
-int
-v_iI(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- int first;
- char *p;
-
- sp->showmode = "Insert";
- flags = set_txt_std(sp, vp, 0);
- for (first = 1, lno = vp->m_start.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. */
- LOG_CORRECT_FIRST;
- }
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
-
- if (v_ntext(sp, ep,
- sp->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))
- return (1);
-
- flags = set_txt_std(sp, vp, TXT_REPLAY);
- sp->lno = lno = vp->m_final.lno;
- sp->cno = vp->m_final.cno;
- }
- return (0);
-}
-
-/*
- * v_ii -- [count]i
- * Insert text at the cursor position.
- */
-int
-v_ii(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- char *p;
-
- sp->showmode = "Insert";
- flags = set_txt_std(sp, vp, 0);
- for (lno = vp->m_start.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, vp->m_start.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->tiqp, NULL, p, len, &vp->m_final, 0, OOBLNO, flags))
- return (1);
-
- /*
- * On replay, if the line isn't empty, advance the insert
- * by one (make it an append).
- */
- flags = set_txt_std(sp, vp, TXT_REPLAY);
- sp->lno = lno = vp->m_final.lno;
- if ((sp->cno = vp->m_final.cno) != 0)
- ++sp->cno;
- }
- return (0);
-}
-
-/*
- * v_iO -- [count]O
- * Insert text above this line.
- */
-int
-v_iO(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t ai_line, lno;
- size_t len;
- u_long cnt;
- u_int flags;
- int first;
- char *p;
-
- sp->showmode = "Insert";
- flags = set_txt_std(sp, vp, TXT_APPENDEOL);
- 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. */
- LOG_CORRECT_FIRST;
-
- 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->tiqp, NULL, p, len, &vp->m_final, 0, ai_line, flags))
- return (1);
-
- flags = set_txt_std(sp, vp, TXT_APPENDEOL | TXT_REPLAY);
- sp->lno = lno = vp->m_final.lno;
- sp->cno = vp->m_final.cno;
- }
- return (0);
-}
-
-/*
- * v_io -- [count]o
- * Insert text after this line.
- */
-int
-v_io(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t ai_line, lno;
- size_t len;
- u_long cnt;
- u_int flags;
- int first;
- char *p;
-
- sp->showmode = "Insert";
- flags = set_txt_std(sp, vp, TXT_APPENDEOL);
- 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. */
- LOG_CORRECT_FIRST;
-
- 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->tiqp, NULL, p, len, &vp->m_final, 0, ai_line, flags))
- return (1);
-
- flags = set_txt_std(sp, vp, TXT_APPENDEOL | TXT_REPLAY);
- sp->lno = lno = vp->m_final.lno;
- sp->cno = vp->m_final.cno;
- }
- return (0);
-}
-
-/*
- * v_Change -- [buffer][count]C
- * Change line command.
- */
-int
-v_Change(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (v_CS(sp, ep, vp, 0));
-}
-
-/*
- * v_Subst -- [buffer][count]S
- * Line substitute command.
- */
-int
-v_Subst(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- 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)) {
- vp->m_start.cno = 0;
- if (nonblank(sp, ep, vp->m_start.lno, &vp->m_start.cno))
- return (1);
- LF_SET(TXT_AICHARS);
- } else
- vp->m_start.cno = 0;
- sp->cno = vp->m_start.cno;
- return (v_CS(sp, ep, vp, flags));
-}
-
-/*
- * v_CS --
- * C and S commands.
- */
-static int
-v_CS(sp, ep, vp, iflags)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- u_int iflags;
-{
- MARK *tm;
- recno_t lno;
- size_t len;
- char *p;
- u_int flags;
-
- sp->showmode = "Change";
- flags = set_txt_std(sp, vp, iflags);
-
- /*
- * 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.
- */
- vp->m_stop.lno =
- vp->m_start.lno + (F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0);
- if (vp->m_start.lno != vp->m_stop.lno) {
- /* Make sure that the to line is real. */
- if (file_gline(sp, ep,
- vp->m_stop.lno, &vp->m_stop.cno) == NULL) {
- v_eof(sp, ep, &vp->m_start);
- return (1);
- }
- if (vp->m_stop.cno != 0)
- --vp->m_stop.cno;
-
- /*
- * Cut the lines.
- *
- * !!!
- * Historic practice, C and S did not cut into the numeric
- * buffers, only the unnamed one.
- */
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, CUT_LINEMODE))
- return (1);
-
- /* Insert a line while we still can... */
- if (file_iline(sp, ep, vp->m_start.lno, "", 0))
- return (1);
- ++vp->m_start.lno;
- ++vp->m_stop.lno;
-
- /* Delete the lines. */
- if (delete(sp, ep, &vp->m_start, &vp->m_stop, 1))
- return (1);
-
- /* Get the inserted line. */
- if ((p = file_gline(sp, ep, --vp->m_start.lno, &len)) == NULL) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- tm = NULL;
- sp->lno = vp->m_start.lno;
- sp->cno = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- /* The line may be empty, but that's okay. */
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- vp->m_stop.cno = len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (len == 0) {
- vp->m_stop.cno = 0;
- LF_SET(TXT_APPENDEOL);
- } else
- vp->m_stop.cno = len - 1;
- /*
- * !!!
- * Historic practice, C and S did not cut into the
- * numeric buffers, only the unnamed one.
- */
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, CUT_LINEMODE))
- return (1);
- LF_SET(TXT_EMARK | TXT_OVERWRITE);
- }
- tm = &vp->m_stop;
- }
-
- /* Correct logging for implied cursor motion. */
- LOG_CORRECT;
-
- return (v_ntext(sp, ep,
- sp->tiqp, tm, p, len, &vp->m_final, 0, OOBLNO, flags));
-}
-
-/*
- * v_change -- [buffer][count]c[count]motion
- * Change command.
- */
-int
-v_change(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t blen, len;
- u_int flags;
- int lmode, rval;
- char *bp, *p;
-
- sp->showmode = "Change";
- flags = set_txt_std(sp, vp, 0);
-
- /*
- * 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, VM_LMODE) ? CUT_LINEMODE : 0;
- if (lmode) {
- vp->m_start.cno = 0;
- if (O_ISSET(sp, O_AUTOINDENT)) {
- if (nonblank(sp, ep, vp->m_start.lno, &vp->m_start.cno))
- return (1);
- LF_SET(TXT_AICHARS);
- }
- }
- sp->lno = vp->m_start.lno;
- sp->cno = vp->m_start.cno;
-
- /* Correct logging for implied cursor motion. */
- LOG_CORRECT;
-
- /*
- * 'c' can be combined with motion commands that set the resulting
- * cursor position, i.e. "cG". Clear the VM_RCM flags and make the
- * resulting cursor position stick, inserting text has its own rules
- * for cursor positioning.
- */
- F_CLR(vp, VM_RCM_MASK);
- F_SET(vp, VM_RCM_SET);
-
- /*
- * If not in line mode and changing within a single line, the line
- * either currently has text or it doesn't. If it doesn't, insert
- * some. Otherwise, copy it and overwrite it.
- */
- if (!lmode && vp->m_start.lno == vp->m_stop.lno) {
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (p == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- }
- vp->m_stop.cno = len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- /*
- * !!!
- * Historic practice, c cut into the numeric buffers,
- * as well as the unnamed one.
- */
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, lmode | CUT_NUMOPT))
- return (1);
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_EMARK | TXT_OVERWRITE);
- }
- return (v_ntext(sp, ep, sp->tiqp,
- &vp->m_stop, p, len, &vp->m_final, 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.
- *
- * !!!
- * Historic practice, c cut into the numeric buffers, as well as the
- * unnamed one.
- *
- * Copy the text.
- */
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, lmode | CUT_NUMOPT))
- return (1);
-
- /* If replacing entire lines and there's leading text. */
- if (lmode && vp->m_start.cno) {
- /* Get a copy of the first line changed. */
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- /* Copy the leading text elsewhere. */
- GET_SPACE_RET(sp, bp, blen, vp->m_start.cno);
- memmove(bp, p, vp->m_start.cno);
- } else
- bp = NULL;
-
- /* Delete the text. */
- if (delete(sp, ep, &vp->m_start, &vp->m_stop, lmode))
- return (1);
-
- /* If replacing entire lines, insert a replacement line. */
- if (lmode) {
- if (file_iline(sp, ep, vp->m_start.lno, bp, vp->m_start.cno))
- return (1);
- sp->lno = vp->m_start.lno;
- len = sp->cno = vp->m_start.cno;
- }
-
- /* Get the line we're editing. */
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- len = 0;
- }
-
- /* Check to see if we're appending to the line. */
- if (vp->m_start.cno >= len)
- LF_SET(TXT_APPENDEOL);
-
- rval = v_ntext(sp, ep,
- sp->tiqp, NULL, p, len, &vp->m_final, 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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- u_long cnt;
- size_t len;
- u_int flags;
- char *p;
-
- sp->showmode = "Replace";
- flags = set_txt_std(sp, vp, 0);
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_OVERWRITE | TXT_REPLACE);
- }
- vp->m_stop.lno = vp->m_start.lno;
- vp->m_stop.cno = len ? len - 1 : 0;
- if (v_ntext(sp, ep, sp->tiqp,
- &vp->m_stop, p, len, &vp->m_final, 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 vp->m_final.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, vp->m_final.lno, &len)) == NULL)
- GETLINE_ERR(sp, vp->m_final.lno);
- flags = set_txt_std(sp, vp, TXT_REPLAY);
-
- sp->lno = vp->m_final.lno;
-
- if (len == 0 || vp->m_final.cno == len - 1) {
- sp->cno = len;
- LF_SET(TXT_APPENDEOL);
- } else {
- sp->cno = vp->m_final.cno;
- if (vp->m_final.cno != 0)
- ++sp->cno;
- LF_SET(TXT_OVERWRITE | TXT_REPLACE);
- }
-
- vp->m_stop.lno = sp->lno;
- vp->m_stop.cno = sp->cno;
- if (v_ntext(sp, ep, sp->tiqp,
- &vp->m_stop, p, len, &vp->m_final, 0, OOBLNO, flags))
- return (1);
- }
- return (0);
-}
-
-/*
- * v_subst -- [buffer][count]s
- * Substitute characters.
- */
-int
-v_subst(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t len;
- u_int flags;
- char *p;
-
- sp->showmode = "Change";
- flags = set_txt_std(sp, vp, 0);
- if ((p = file_gline(sp, ep, vp->m_start.lno, &len)) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno != 0) {
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- len = 0;
- LF_SET(TXT_APPENDEOL);
- } else {
- if (len == 0)
- LF_SET(TXT_APPENDEOL);
- LF_SET(TXT_EMARK | TXT_OVERWRITE);
- }
-
- vp->m_stop.lno = vp->m_start.lno;
- vp->m_stop.cno =
- vp->m_start.cno + (F_ISSET(vp, VC_C1SET) ? vp->count - 1 : 0);
- if (vp->m_stop.cno > len - 1)
- vp->m_stop.cno = len - 1;
-
- if (p != NULL && cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, 0))
- return (1);
-
- return (v_ntext(sp, ep, sp->tiqp,
- &vp->m_stop, p, len, &vp->m_final, 0, OOBLNO, flags));
-}
-
-/*
- * set_txt_std --
- * Initialize text processing flags.
- */
-static u_int
-set_txt_std(sp, vp, init)
- SCR *sp;
- VICMDARG *vp;
- u_int init;
-{
- u_int flags;
-
- /* Text operations are all interruptible. */
- F_SET(sp, S_INTERRUPTIBLE);
-
- LF_INIT(init);
- LF_SET(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_BEAUTIFY))
- LF_SET(TXT_BEAUTIFY);
- 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);
- if (F_ISSET(vp, VC_ISDOT))
- LF_SET(TXT_REPLAY);
- return (flags);
-}
diff --git a/usr.bin/vi/vi/v_ulcase.c b/usr.bin/vi/vi/v_ulcase.c
deleted file mode 100644
index 684a7f5..0000000
--- a/usr.bin/vi/vi/v_ulcase.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.10 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static int ulcase __P((SCR *, EXF *,
- recno_t, CHAR_T *, size_t, size_t, size_t));
-
-/*
- * v_ulcase -- [count]~
- * Toggle upper & lower case letters.
- *
- * !!!
- * Historic vi didn't permit ~ to cross newline boundaries. I can
- * think of no reason why it shouldn't, which at least lets the user
- * auto-repeat through a paragraph.
- *
- * !!!
- * 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 make
- * that the default now.
- */
-int
-v_ulcase(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t cno, lcnt, len;
- u_long cnt;
- char *p;
-
- len = 0;
- lno = vp->m_start.lno;
- cno = vp->m_start.cno;
-
- /* EOF is an infinite count sink. */
- for (cnt =
- F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt > 0; cno = 0, ++lno) {
- if ((p = file_gline(sp, ep, lno, &len)) == NULL)
- break;
-
- /* Empty lines decrement the count by one. */
- if (len == 0) {
- --cnt;
- vp->m_final.lno = lno + 1;
- vp->m_final.cno = 0;
- } else {
- if (cno + cnt >= len) {
- lcnt = len - 1;
- cnt -= len - cno;
-
- vp->m_final.lno = lno + 1;
- vp->m_final.cno = 0;
- } else {
- lcnt = cno + cnt - 1;
- cnt = 0;
-
- vp->m_final.lno = lno;
- vp->m_final.cno = lcnt + 1;
- }
-
- if (ulcase(sp, ep, lno, p, len, cno, lcnt))
- return (1);
- }
- }
-
- /* Check to see if we tried to move past EOF. */
- if (file_gline(sp, ep, vp->m_final.lno, &len) == NULL) {
- /* line number start with 1, lno zero is illegal */
- if (vp->m_final.lno > 1)
- --vp->m_final.lno;
- (void)file_gline(sp, ep, vp->m_final.lno, &len);
- vp->m_final.cno = len == 0 ? 0 : len - 1;
- }
- return (0);
-}
-
-/*
- * v_mulcase -- [count]~[count]motion
- * Toggle upper & lower case letters over a range.
- */
-int
-v_mulcase(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- CHAR_T *p;
- size_t len;
- recno_t lno;
-
- for (lno = vp->m_start.lno;;) {
- if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
- GETLINE_ERR(sp, lno);
- return (1);
- }
- if (len != 0 &&
- ulcase(sp, ep, lno, p, len,
- lno == vp->m_start.lno ? vp->m_start.cno : 0,
- !F_ISSET(vp, VM_LMODE) &&
- lno == vp->m_stop.lno ? vp->m_stop.cno : len))
- return (1);
-
- if (++lno > vp->m_stop.lno)
- break;
- }
-
- /*
- * XXX
- * I didn't create a new motion command when I added motion semantics
- * for ~. While that's the correct way to do it, that choice would
- * have required changes all over the vi directory for little gain.
- * Instead, we pretend it's a yank command. Note, this means that we
- * follow the cursor motion rules for yank commands, but that seems
- * reasonable to me.
- */
- return (0);
-}
-
-/*
- * ulcase --
- * Change part of a line's case.
- */
-static int
-ulcase(sp, ep, lno, lp, len, scno, ecno)
- SCR *sp;
- EXF *ep;
- recno_t lno;
- CHAR_T *lp;
- size_t len, scno, ecno;
-{
- size_t blen;
- int change, rval;
- CHAR_T ch, *p, *t;
- char *bp;
-
- GET_SPACE_RET(sp, bp, blen, len);
- memmove(bp, lp, len);
-
- change = rval = 0;
- for (p = bp + scno, t = bp + ecno + 1; p < t; ++p) {
- ch = *(u_char *)p;
- if (islower(ch)) {
- *p = toupper(ch);
- change = 1;
- } else if (isupper(ch)) {
- *p = tolower(ch);
- change = 1;
- }
- }
-
- if (change && file_sline(sp, ep, lno, bp, len))
- rval = 1;
-
- FREE_SPACE(sp, bp, blen);
- return (rval);
-}
diff --git a/usr.bin/vi/vi/v_undo.c b/usr.bin/vi/vi/v_undo.c
deleted file mode 100644
index 52e502c..0000000
--- a/usr.bin/vi/vi/v_undo.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_Undo -- U
- * Undo changes to this line.
- */
-int
-v_Undo(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /*
- * 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.
- */
- vp->m_final.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)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /* 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.
- *
- * !!!
- * There is change to historic practice for the final cursor position
- * in this implementation. In historic vi, if an undo was isolated to
- * a single line, the cursor moved to the start of the change, and
- * then, subsequent 'u' commands would not move it again. (It has been
- * pointed out that users used multiple undo commands to get the cursor
- * to the start of the changed text.) Nvi toggles between the cursor
- * position before and after the change was made. One final issue is
- * that historic vi only did this if the user had not moved off of the
- * line before entering the undo command; otherwise, vi would move the
- * cursor to the most attractive position on the changed line.
- *
- * It would be difficult to match historic practice in this area. You
- * not only have to know that the changes were isolated to one line,
- * but whether it was the first or second undo command as well. And,
- * to completely match historic practice, we'd have to track users line
- * changes, too. This isn't worth the effort.
- */
- 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, &vp->m_final));
- case FORWARD:
- return (log_forward(sp, ep, &vp->m_final));
- default:
- abort();
- }
- /* NOTREACHED */
-}
diff --git a/usr.bin/vi/vi/v_util.c b/usr.bin/vi/vi/v_util.c
deleted file mode 100644
index cd20c6d..0000000
--- a/usr.bin/vi/vi/v_util.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.12 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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;
-{
- recno_t 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_nomove --
- * Vi no cursor movement error.
- */
-void
-v_nomove(sp)
- SCR *sp;
-{
- msgq(sp, M_BERR, "No cursor movement made");
-}
-
-/*
- * 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_sol --
- * Vi start-of-line error.
- */
-void
-v_sol(sp)
- SCR *sp;
-{
- msgq(sp, M_BERR, "Already in the first column");
-}
-
-/*
- * 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/vi/v_word.c b/usr.bin/vi/vi/v_word.c
deleted file mode 100644
index 95d960e..0000000
--- a/usr.bin/vi/vi/v_word.c
+++ /dev/null
@@ -1,570 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.23 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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" -- in particular, single character words, and commands that
- * began in whitespace were almost always handled incorrectly. 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, or, if you did it from the start of the line as part of a motion
- * command, go absolutely nuts. If the lines contained only white-space
- * characters, the 'w' and 'W' commands would just beep at you, and the 'B',
- * 'b', 'E' and 'e' commands would treat the group as a single word, and
- * the 'B' and 'b' commands will treat the lines as individual words. This
- * implementation treats all of these cases as a single white-space word.
- */
-
-enum which {BIGWORD, LITTLEWORD};
-
-static int bword __P((SCR *, EXF *, VICMDARG *, enum which));
-static int eword __P((SCR *, EXF *, VICMDARG *, enum which));
-static int fword __P((SCR *, EXF *, VICMDARG *, enum which));
-
-/*
- * v_wordW -- [count]W
- * Move forward a bigword at a time.
- */
-int
-v_wordW(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (fword(sp, ep, vp, BIGWORD));
-}
-
-/*
- * v_wordw -- [count]w
- * Move forward a word at a time.
- */
-int
-v_wordw(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (fword(sp, ep, vp, LITTLEWORD));
-}
-
-/*
- * fword --
- * Move forward by words.
- */
-static int
-fword(sp, ep, vp, type)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- enum which type;
-{
- enum { INWORD, NOTWORD } state;
- VCS cs;
- u_long cnt;
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- cs.cs_lno = vp->m_start.lno;
- cs.cs_cno = vp->m_start.cno;
- if (cs_init(sp, ep, &cs))
- return (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))
- return (0);
- if (F_ISSET(vp, VC_D | VC_Y)) {
- if (cs_fspace(sp, ep, &cs))
- return (1);
- goto ret;
- }
- }
- 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 ret;
- 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 && ISMOTION(vp)) {
- 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 ret;
- }
- 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 ret;
- 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 && ISMOTION(vp)) {
- 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 ret;
- }
-
- /*
- * If we didn't move, we must be at EOF.
- *
- * !!!
- * That's okay for motion commands, however.
- */
-ret: if (!ISMOTION(vp) &&
- cs.cs_lno == vp->m_start.lno && cs.cs_cno == vp->m_start.cno) {
- v_eof(sp, ep, &vp->m_start);
- return (1);
- }
-
- /* Adjust the end of the range for motion commands. */
- vp->m_stop.lno = cs.cs_lno;
- vp->m_stop.cno = cs.cs_cno;
- if (ISMOTION(vp) && cs.cs_flags == 0)
- --vp->m_stop.cno;
-
- /*
- * Non-motion commands move to the end of the range. VC_D
- * and VC_Y stay at the start. Ignore VC_C and VC_DEF.
- */
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- return (0);
-}
-
-/*
- * v_wordE -- [count]E
- * Move forward to the end of the bigword.
- */
-int
-v_wordE(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (eword(sp, ep, vp, BIGWORD));
-}
-
-/*
- * v_worde -- [count]e
- * Move forward to the end of the word.
- */
-int
-v_worde(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (eword(sp, ep, vp, LITTLEWORD));
-}
-
-/*
- * eword --
- * Move forward to the end of the word.
- */
-static int
-eword(sp, ep, vp, type)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- enum which type;
-{
- enum { INWORD, NOTWORD } state;
- VCS cs;
- u_long cnt;
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- cs.cs_lno = vp->m_start.lno;
- cs.cs_cno = vp->m_start.cno;
- if (cs_init(sp, ep, &cs))
- return (1);
-
- /*
- * !!!
- * If in whitespace, or the next character is whitespace, move past
- * it. (This doesn't count as a word move.) Stay at the character
- * past the current one, it sets word "state" for the 'e' command.
- */
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch)) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
- goto start;
- }
- if (cs_fblank(sp, ep, &cs))
- return (1);
-
- /*
- * Cyclically move to the next word -- this involves skipping
- * over word characters and then any trailing non-word characters.
- * Note, for the 'e' command, the definition of a word keeps
- * switching.
- */
-start: if (type == BIGWORD)
- while (cnt--) {
- for (;;) {
- if (cs_next(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- break;
- }
- /*
- * When we reach the start of the word after the last
- * word, we're done. If we changed state, back up one
- * to the end of the previous word.
- */
- if (cnt == 0) {
- if (cs.cs_flags == 0 && cs_prev(sp, ep, &cs))
- return (1);
- break;
- }
-
- /* Eat whitespace characters. */
- if (cs_fblank(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_EOF)
- goto ret;
- }
- 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 ret;
- 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) {
- if (cs.cs_flags == 0 && cs_prev(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 ret;
- }
-
- /*
- * If we didn't move, we must be at EOF.
- *
- * !!!
- * That's okay for motion commands, however.
- */
-ret: if (!ISMOTION(vp) &&
- cs.cs_lno == vp->m_start.lno && cs.cs_cno == vp->m_start.cno) {
- v_eof(sp, ep, &vp->m_start);
- return (1);
- }
-
- /* Set the end of the range for motion commands. */
- vp->m_stop.lno = cs.cs_lno;
- vp->m_stop.cno = cs.cs_cno;
-
- /*
- * Non-motion commands move to the end of the range. VC_D
- * and VC_Y stay at the start. Ignore VC_C and VC_DEF.
- */
- vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
- return (0);
-}
-
-/*
- * v_WordB -- [count]B
- * Move backward a bigword at a time.
- */
-int
-v_wordB(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (bword(sp, ep, vp, BIGWORD));
-}
-
-/*
- * v_wordb -- [count]b
- * Move backward a word at a time.
- */
-int
-v_wordb(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- return (bword(sp, ep, vp, LITTLEWORD));
-}
-
-/*
- * bword --
- * Move backward by words.
- */
-static int
-bword(sp, ep, vp, type)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
- enum which type;
-{
- enum { INWORD, NOTWORD } state;
- VCS cs;
- u_long cnt;
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- cs.cs_lno = vp->m_start.lno;
- cs.cs_cno = vp->m_start.cno;
- if (cs_init(sp, ep, &cs))
- return (1);
-
- /*
- * !!!
- * If in whitespace, or the previous character is whitespace, move
- * past it. (This doesn't count as a word move.) Stay at the
- * character before the current one, it sets word "state" for the
- * 'b' command.
- */
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch)) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == 0 && !isblank(cs.cs_ch))
- goto start;
- }
- if (cs_bblank(sp, ep, &cs))
- return (1);
-
- /*
- * Cyclically move to the beginning of the previous word -- this
- * involves skipping over word characters and then any trailing
- * non-word characters. Note, for the 'b' command, the definition
- * of a word keeps switching.
- */
-start: if (type == BIGWORD)
- while (cnt--) {
- for (;;) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_SOF)
- goto ret;
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- break;
- }
- /*
- * When we reach the end of the word before the last
- * word, we're done. If we changed state, move forward
- * one to the end of the next word.
- */
- if (cnt == 0) {
- if (cs.cs_flags == 0 && cs_next(sp, ep, &cs))
- return (1);
- break;
- }
-
- /* Eat whitespace characters. */
- if (cs_bblank(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_SOF)
- goto ret;
- }
- else
- while (cnt--) {
- state = cs.cs_flags == 0 &&
- inword(cs.cs_ch) ? INWORD : NOTWORD;
- for (;;) {
- if (cs_prev(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_SOF)
- goto ret;
- 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) {
- if (cs.cs_flags == 0 && cs_next(sp, ep, &cs))
- return (1);
- break;
- }
-
- /* Eat whitespace characters. */
- if (cs.cs_flags != 0 || isblank(cs.cs_ch))
- if (cs_bblank(sp, ep, &cs))
- return (1);
- if (cs.cs_flags == CS_SOF)
- goto ret;
- }
-
- /* If we didn't move, we must be at SOF. */
-ret: if (cs.cs_lno == vp->m_start.lno && cs.cs_cno == vp->m_start.cno) {
- v_sof(sp, &vp->m_start);
- return (1);
- }
-
- /* Set the end of the range for motion commands. */
- vp->m_stop.lno = cs.cs_lno;
- vp->m_stop.cno = cs.cs_cno;
-
- /*
- * All commands move to the end of the range. Motion commands
- * adjust the starting point to the character before the current
- * one.
- *
- * !!!
- * The historic vi didn't get this right -- the `yb' command yanked
- * the right stuff and even updated the cursor value, but the cursor
- * was not actually updated on the screen.
- */
- vp->m_final = vp->m_stop;
- if (ISMOTION(vp))
- --vp->m_start.cno;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_xchar.c b/usr.bin/vi/vi/v_xchar.c
deleted file mode 100644
index 7ecc1b5..0000000
--- a/usr.bin/vi/vi/v_xchar.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.10 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_xchar -- [count]x
- * Deletes the character(s) on which the cursor sits.
- */
-int
-v_xchar(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- recno_t lno;
- size_t len;
-
- if (file_gline(sp, ep, vp->m_start.lno, &len) == NULL) {
- if (file_lline(sp, ep, &lno))
- return (1);
- if (lno == 0)
- goto nodel;
- GETLINE_ERR(sp, vp->m_start.lno);
- return (1);
- }
- if (len == 0) {
-nodel: msgq(sp, M_BERR, "No characters to delete");
- return (1);
- }
-
- /*
- * Delete 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.
- */
- if (F_ISSET(vp, VC_C1SET))
- vp->m_stop.cno += vp->count - 1;
- if (vp->m_stop.cno >= len - 1) {
- vp->m_stop.cno = len - 1;
- vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0;
- } else
- vp->m_final.cno = vp->m_start.cno;
-
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, 0))
- return (1);
- return (delete(sp, ep, &vp->m_start, &vp->m_stop, 0));
-}
-
-/*
- * v_Xchar -- [count]X
- * Deletes the character(s) immediately before the current cursor
- * position.
- */
-int
-v_Xchar(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- u_long cnt;
-
- if (vp->m_start.cno == 0) {
- v_sol(sp);
- return (1);
- }
-
- cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
- if (cnt >= vp->m_start.cno)
- vp->m_start.cno = 0;
- else
- vp->m_start.cno -= cnt;
- --vp->m_stop.cno;
- vp->m_final.cno = vp->m_start.cno;
-
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, 0))
- return (1);
- return (delete(sp, ep, &vp->m_start, &vp->m_stop, 0));
-}
diff --git a/usr.bin/vi/vi/v_yank.c b/usr.bin/vi/vi/v_yank.c
deleted file mode 100644
index 762ece6..0000000
--- a/usr.bin/vi/vi/v_yank.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.16 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_yank -- [buffer][count]Y
- * [buffer][count]y[count][motion]
- * Yank text (or lines of text) into a cut buffer.
- *
- * !!!
- * Historic vi moved the cursor to the from MARK if it was before the current
- * cursor and on a different line, e.g., "yj" moves the cursor but "yk" and
- * "yh" do 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. Hopefully, the motion component code
- * got it right... Unlike delete, we make no adjustments here.
- */
-int
-v_yank(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- int lmode;
-
- /* The line may not exist in line mode cuts, check to be sure. */
- if (F_ISSET(vp, VM_LMODE)) {
- if (file_gline(sp, ep, vp->m_stop.lno, NULL) == NULL) {
- v_eof(sp, ep, &vp->m_start);
- return (1);
- }
- lmode = CUT_LINEMODE;
- } else
- lmode = 0;
- if (cut(sp, ep,
- F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
- &vp->m_start, &vp->m_stop, lmode))
- return (1);
-
- sp->rptlines[L_YANKED] += (vp->m_stop.lno - vp->m_start.lno) + 1;
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_z.c b/usr.bin/vi/vi/v_z.c
deleted file mode 100644
index 5c6fdd0..0000000
--- a/usr.bin/vi/vi/v_z.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.18 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-/*
- * v_z -- [count]z[count][-.+^<CR>]
- * Move the screen.
- */
-int
-v_z(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- 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 = vp->m_start.lno;
-
- /* Set default return cursor values. */
- vp->m_final.lno = lno;
- vp->m_final.cno = vp->m_start.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_crel(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;
- case '+':
- /*
- * If the user specified a line number, put that line at the
- * top and move the cursor to it. Otherwise, scroll forward
- * a screen from the current screen.
- */
- if (F_ISSET(vp, VC_C1SET)) {
- if (sp->s_fill(sp, ep, lno, P_TOP))
- return (1);
- if (sp->s_position(sp, ep, &vp->m_final, 0, P_TOP))
- return (1);
- } else
- if (sp->s_scroll(sp, ep,
- &vp->m_final, sp->t_rows, Z_PLUS))
- return (1);
- break;
- case '^':
- /*
- * If the user specified a line number, put that line at the
- * bottom, move the cursor to it, and then display the screen
- * before that one. Otherwise, scroll backward a screen from
- * the current screen.
- *
- * !!!
- * Note, we match the off-by-one characteristics of historic
- * vi, here.
- */
- if (F_ISSET(vp, VC_C1SET)) {
- if (sp->s_fill(sp, ep, lno, P_BOTTOM))
- return (1);
- if (sp->s_position(sp, ep, &vp->m_final, 0, P_TOP))
- return (1);
- if (sp->s_fill(sp, ep, vp->m_final.lno, P_BOTTOM))
- return (1);
- } else
- if (sp->s_scroll(sp, ep,
- &vp->m_final, sp->t_rows, Z_CARAT))
- return (1);
- break;
- default: /* Put the line at the top for <cr>. */
- value = KEY_VAL(sp, vp->character);
- if (value != K_CR && value != K_NL) {
- msgq(sp, M_ERR, "usage: %s", vp->kp->usage);
- return (1);
- }
- if (sp->s_fill(sp, ep, lno, P_TOP))
- return (1);
- break;
- }
-
-
- return (0);
-}
diff --git a/usr.bin/vi/vi/v_zexit.c b/usr.bin/vi/vi/v_zexit.c
deleted file mode 100644
index d699db3..0000000
--- a/usr.bin/vi/vi/v_zexit.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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_zexit.c 8.13 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "excmd.h"
-#include "vcmd.h"
-
-/*
- * v_zexit -- ZZ
- * Save the file and exit.
- */
-int
-v_zexit(sp, ep, vp)
- SCR *sp;
- EXF *ep;
- VICMDARG *vp;
-{
- /* Write back any modifications. */
- if (F_ISSET(ep, F_MODIFIED) &&
- file_write(sp, ep, NULL, NULL, NULL, FS_ALL))
- return (1);
-
- /* Check to make sure it's not a temporary file. */
- if (file_m3(sp, ep, 0))
- return (1);
-
- /* Check for more files to edit. */
- if (ex_ncheck(sp, 0))
- return (1);
-
- F_SET(sp, S_EXIT);
- return (0);
-}
diff --git a/usr.bin/vi/vi/vcmd.c b/usr.bin/vi/vi/vcmd.c
deleted file mode 100644
index f82aeb5..0000000
--- a/usr.bin/vi/vi/vcmd.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.41 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.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|VM_CUTREQ|VM_RCM_SET,
- "[count]^A",
- "^A search forward for cursor word"},
-/* 002 ^B */
- {v_pageup, V_CNT|VM_RCM_SET,
- "[count]^B",
- "^B scroll up by screens"},
-/* 003 ^C */
- {NULL, 0,
- "^C",
- "^C interrupt an operation (e.g. read, write, search)"},
-/* 004 ^D */
- {v_hpagedown, V_CNT|VM_RCM_SET,
- "[count]^D",
- "^D scroll down by half screens (setting count)"},
-/* 005 ^E */
- {v_linedown, V_CNT,
- "[count]^E",
- "^E scroll down by lines"},
-/* 006 ^F */
- {v_pagedown, V_CNT|VM_RCM_SET,
- "[count]^F",
- "^F scroll down by screens"},
-/* 007 ^G */
- {v_status, 0,
- "^G",
- "^G file status"},
-/* 010 ^H */
- {v_left, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]^H",
- "^H move left by characters"},
-/* 011 ^I */
- {NULL},
-/* 012 ^J */
- {v_down, V_CNT|V_MOVE|VM_LMODE|VM_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_MOVE|VM_LMODE|VM_RCM_SETFNB,
- "[count]^M",
- "^M move down by lines (to first non-blank)"},
-/* 016 ^N */
- {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
- "[count]^N",
- "^N move down by lines"},
-/* 017 ^O */
- {NULL},
-/* 020 ^P */
- {v_up, V_CNT|V_MOVE|VM_LMODE|VM_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_ABS|VM_RCM_SET,
- "^T",
- "^T tag pop"},
-/* 025 ^U */
- {v_hpageup, V_CNT|VM_RCM_SET,
- "[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 ^\ */
- {v_exmode, 0,
- "^\\",
- " ^\\ switch to ex mode"},
-/* 035 ^] */
- {v_tagpush, V_ABS|V_KEYW|VM_RCM_SET,
- "^]",
- "^] tag push cursor word"},
-/* 036 ^^ */
- {v_switch, 0,
- "^^",
- "^^ switch to previous file"},
-/* 037 ^_ */
- {NULL},
-/* 040 ' ' */
- {v_right, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]' '",
- " <space> move right by columns"},
-/* 041 ! */
- {v_filter, V_CNT|V_DOT|V_MOTION|VC_DEF|VM_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|VM_RCM_SET,
- "[count]#[#+-]",
- " # number increment/decrement"},
-/* 044 $ */
- {v_dollar, V_CNT|V_MOVE|VM_RCM_SETLAST,
- " [count]$",
- " $ move to last column"},
-/* 045 % */
- {v_match, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "%",
- " % move to match"},
-/* 046 & */
- {v_again, 0,
- "&",
- " & repeat substitution"},
-/* 047 ' */
- {v_fmark, V_ABS_L|V_CHAR|V_MOVE|VM_LMODE,
- "'['a-z]",
- " ' move to mark (to first non-blank)"},
-/* 050 ( */
- {v_sentenceb, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "[count](",
- " ( move back sentence"},
-/* 051 ) */
- {v_sentencef, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "[count])",
- " ) move forward sentence"},
-/* 052 * */
- {NULL},
-/* 053 + */
- {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
- "[count]+",
- " + move down by lines (to first non-blank)"},
-/* 054 , */
- {v_chrrepeat, V_CNT|V_MOVE|VM_RCM_SET,
- "[count],",
- " , reverse last F, f, T or t search"},
-/* 055 - */
- {v_up, V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
- "[count]-",
- " - move up by lines (to first non-blank)"},
-/* 056 . */
- {NULL, 0,
- ".",
- " . repeat the last command"},
-/* 057 / */
- {v_searchf, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "/RE[/ offset]",
- " / search forward"},
-/* 060 0 */
- {v_zero, V_MOVE|VM_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|VM_RCM_SET,
- "[count];",
- " ; repeat last F, f, T or t search"},
-/* 074 < */
- {v_shiftl, V_CNT|V_DOT|V_MOTION|VC_DEF|VM_RCM_SET,
- "[count]<[count]motion",
- " < shift lines left to motion"},
-/* 075 = */
- {NULL},
-/* 076 > */
- {v_shiftr, V_CNT|V_DOT|V_MOTION|VC_DEF|VM_RCM_SET,
- "[count]>[count]motion",
- " > shift lines right to motion"},
-/* 077 ? */
- {v_searchb, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "?RE[? offset]",
- " ? search backward"},
-/* 100 @ */
- {v_at, V_RBUF|VM_RCM_SET,
- "@buffer",
- " @ execute buffer"},
-/* 101 A */
- {v_iA, V_CNT|V_DOT|VM_RCM_SET,
- "[count]A",
- " A append to the line"},
-/* 102 B */
- {v_wordB, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]B",
- " B move back bigword"},
-/* 103 C */
- {v_Change, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
- "[buffer][count]C",
- " C change to end-of-line"},
-/* 104 D */
- {v_Delete, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
- "[buffer][count]D",
- " D delete to end-of-line"},
-/* 105 E */
- {v_wordE, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]E",
- " E move to end of bigword"},
-/* 106 F */
- {v_chF, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
- "[count]F character",
- " F character in line backward search"},
-/* 107 G */
- {v_lgoto, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
- "[count]G",
- " G move to line"},
-/* 110 H */
- {v_home, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
- "[count]H",
- " H move to count lines from screen top"},
-/* 111 I */
- {v_iI, V_CNT|V_DOT|VM_RCM_SET,
- "[count]I",
- " I insert at line beginning"},
-/* 112 J */
- {v_join, V_CNT|V_DOT|VM_RCM_SET,
- "[count]J",
- " J join lines"},
-/* 113 K */
- {NULL},
-/* 114 L */
- {v_bottom, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
- "[count]L",
- " L move to screen bottom"},
-/* 115 M */
- {v_middle, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
- "M",
- " M move to screen middle"},
-/* 116 N */
- {v_searchN, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "n",
- " N reverse last search"},
-/* 117 O */
- {v_iO, V_CNT|V_DOT|VM_RCM_SET,
- "[count]O",
- " O insert above line"},
-/* 120 P */
- {v_Put, V_CNT|V_DOT|V_OBUF|VM_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|VM_RCM_SET,
- "[count]R",
- " R replace characters"},
-/* 123 S */
- {v_Subst, V_CNT|V_DOT|V_OBUF|VM_LMODE|VM_RCM_SET,
- "[buffer][count]S",
- " S substitute for the line(s)"},
-/* 124 T */
- {v_chT, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
- "[count]T character",
- " T before character in line backward search"},
-/* 125 U */
- {v_Undo, VM_RCM_SET,
- "U",
- " U Restore the current line"},
-/* 126 V */
- {NULL},
-/* 127 W */
- {v_wordW, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]W",
- " W move to next bigword"},
-/* 130 X */
- {v_Xchar, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
- "[buffer][count]X",
- " X delete character before cursor"},
-/* 131 Y */
- {v_yank, V_CNT|VM_LMODE|V_OBUF,
- "[buffer][count]Y",
- " Y copy line"},
-/* 132 Z */
- {v_zexit, 0,
- "ZZ",
- "ZZ save file and exit"},
-/* 133 [ */
- {v_sectionb, V_ABS|V_CNT|V_MOVE|VM_RCM_SET,
- "[[",
- "[[ move back section"},
-/* 134 \ */
- {NULL},
-/* 135 ] */
- {v_sectionf, V_ABS|V_CNT|V_MOVE|VM_RCM_SET,
- "]]",
- "]] move forward section"},
-/* 136 ^ */
- /*
- * DON'T set the VM_RCM_SETFNB flag, the function has to do the work
- * anyway, in case it's a motion component. DO set VM_RCM_SET, so
- * that any motion that's part of a command is preserved.
- */
- {v_first, V_CNT|V_MOVE|VM_RCM_SET,
- "^",
- " ^ move to first non-blank"},
-/* 137 _ */
- /*
- * Needs both to set the VM_RCM_SETFNB flag, and to do the work
- * in the function, in case it's a delete.
- */
- {v_cfirst, V_CNT|V_MOVE|VM_RCM_SETFNB,
- "_",
- " _ move to first non-blank"},
-/* 140 ` */
- {v_bmark, V_ABS_C|V_CHAR|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "`[`a-z]",
- " ` move to mark"},
-/* 141 a */
- {v_ia, V_CNT|V_DOT|VM_RCM_SET,
- "[count]a",
- " a append after cursor"},
-/* 142 b */
- {v_wordb, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]b",
- " b move back word"},
-/* 143 c */
- {v_change, V_CNT|V_DOT|V_MOTION|V_OBUF|VC_C|VM_RCM_SET,
- "[buffer][count]c[count]motion",
- " c change to motion"},
-/* 144 d */
- {v_delete, V_CNT|V_DOT|V_MOTION|V_OBUF|VC_D|VM_RCM_SET,
- "[buffer][count]d[count]motion",
- " d delete to motion"},
-/* 145 e */
- {v_worde, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]e",
- " e move to end of word"},
-/* 146 f */
- {v_chf, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
- "[count]f character",
- " f character in line forward search"},
-/* 147 g */
- {NULL},
-/* 150 h */
- {v_left, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]h",
- " h move left by columns"},
-/* 151 i */
- {v_ii, V_CNT|V_DOT|VM_RCM_SET,
- "[count]i",
- " i insert before cursor"},
-/* 152 j */
- {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
- "[count]j",
- " j move down by lines"},
-/* 153 k */
- {v_up, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
- "[count]k",
- " k move up by lines"},
-/* 154 l */
- {v_right, V_CNT|V_MOVE|VM_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_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "n",
- " n repeat last search"},
-/* 157 o */
- {v_io, V_CNT|V_DOT|VM_RCM_SET,
- "[count]o",
- " o append after line"},
-/* 160 p */
- {v_put, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
- "[buffer]p",
- " p insert after cursor from buffer"},
-/* 161 q */
- {NULL},
-/* 162 r */
- {v_replace, V_CNT|V_DOT|VM_RCM_SET,
- "[count]r character",
- " r replace character"},
-/* 163 s */
- {v_subst, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
- "[buffer][count]s",
- " s substitute character"},
-/* 164 t */
- {v_cht, V_CHAR|V_CNT|V_MOVE|VM_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, VM_RCM_SET,
- "u",
- " u undo last change"},
-/* 166 v */
- {NULL},
-/* 167 w */
- {v_wordw, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]w",
- " w move to next word"},
-/* 170 x */
- {v_xchar, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
- "[buffer][count]x",
- " x delete character"},
-/* 171 y */
- {v_yank, V_CNT|V_MOTION|V_OBUF|VC_Y|VM_RCM_SET,
- "[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_ABS_L|V_CNT|VM_RCM_SET,
- "[line]z[window_size][-|.|+|^|<CR>]",
- " z redraw window"},
-/* 173 { */
- {v_paragraphb, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "[count]{",
- " { move back paragraph"},
-/* 174 | */
- {v_ncol, V_CNT|V_MOVE|VM_RCM_SET,
- "[count]|",
- " | move to column"},
-/* 175 } */
- {v_paragraphf, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
- "[count]}",
- " } move forward paragraph"},
-/* 176 ~ */
- {v_ulcase, V_CNT|V_DOT|VM_RCM_SET,
- "[count]~",
- " ~ reverse case"},
-};
diff --git a/usr.bin/vi/vi/vcmd.h b/usr.bin/vi/vi/vcmd.h
deleted file mode 100644
index 758c97b..0000000
--- a/usr.bin/vi/vi/vcmd.h
+++ /dev/null
@@ -1,346 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.40 (Berkeley) 8/5/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 key; /* Command key. */
- CHAR_T buffer; /* Buffer. */
- CHAR_T character; /* Character. */
- u_long count; /* Count. */
- u_long count2; /* Second count (only used by z). */
- VIKEYS const *kp; /* VIKEYS 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, while "d/b" 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. The special cases are handled
- * by setting flags per command so that the underlying command and
- * motion routines know what's really going on.
- *
- * The VC_* and VM_* flags are set in the vikeys array, and the VM_*
- * flags may be set by the underlying functions (motion component or
- * command) as well. For this reason, the flags in the VICMDARG and
- * VIKEYS structures live in the same name space.
- */
-#define VC_C 0x00000001 /* The 'c' command. */
-#define VC_D 0x00000002 /* The 'd' command. */
-#define VC_DEF 0x00000004 /* The '<', '>' and '!' commands. */
-#define VC_Y 0x00000008 /* The 'y' command. */
-#define VC_COMMASK 0x0000000f /* Mask for VC flags. */
-#define ISMOTION(vp) F_ISSET(vp, VC_COMMASK)
-
-#define VM_CUTREQ 0x00000010 /* Always cut into numeric buffers. */
-#define VM_LDOUBLE 0x00000020 /* Doubled command for line mode. */
-#define VM_LMODE 0x00000040 /* Motion is line oriented. */
-#define VM_NOMOTION 0x00000080 /* Motion command not entered. */
-#define VM_COMMASK 0x000000f0 /* Mask for VM flags. */
-
- /*
- * The VM_RCM_* flags are single usage, i.e. if you set one, you have
- * to clear the others.
- */
-#define VM_RCM 0x00000100 /* Use relative cursor movment (RCM). */
-#define VM_RCM_SET 0x00000200 /* RCM: set to current position. */
-#define VM_RCM_SETFNB 0x00000400 /* RCM: set to first non-blank (FNB). */
-#define VM_RCM_SETLAST 0x00000800 /* RCM: set to last character. */
-#define VM_RCM_SETNNB 0x00001000 /* RCM: set to next non-blank. */
-#define VM_RCM_MASK 0x00001f00 /* Mask for RCM flags. */
-
- /* Flags for the underlying function. */
-#define VC_BUFFER 0x00002000 /* The buffer was set. */
-#define VC_C1RESET 0x00004000 /* Reset C1SET flag for dot commands. */
-#define VC_C1SET 0x00008000 /* Count 1 was set. */
-#define VC_C2SET 0x00010000 /* Count 2 was set. */
-#define VC_ISDOT 0x00020000 /* Command was the dot command. */
- u_int32_t flags;
-
-#define vp_endzero keyword /* END ZERO OUT. */
- char *keyword; /* Keyword. */
- size_t kbuflen; /* Keyword buffer length. */
- /*
- * There are four cursor locations that we worry about: the initial
- * cursor position, the start of the range, the end of the range,
- * and the final cursor position. The initial cursor position and
- * the start of the range are both m_start, and are always the same.
- * All locations are initialized to the starting cursor position by
- * the main vi routines, and the underlying functions depend on this.
- *
- * Commands that can be motion components set the end of the range
- * cursor position, m_stop. All commands must set the ending cursor
- * position, m_final. The reason that m_stop isn't the same as m_final
- * is that there are situations where the final position of the cursor
- * is outside of the cut/delete range (e.g. 'd[[' from the first column
- * of a line). The final cursor position often varies based on the
- * direction of the movement, as well as the command. The only special
- * case that the delete code handles is that it will make adjustments
- * if the final cursor position is deleted.
- *
- * The reason for all of this is that the historic vi semantics were
- * defined command-by-command. Every function has to roll its own
- * starting and stopping positions, and adjust them if it's being used
- * as a motion component. The general rules are as follows:
- * 1: If not a motion component, the final cursor is at the end
- * of the range.
- * 2: If moving backward in the file:
- * a: VC_D moves to the end of the range.
- * b: If the line hasn't changed, VC_Y doesn't move, else it
- * moves to the end of the range.
- * 3: If moving forward in the file, VC_D and VC_Y stay at the
- * start of the range.
- *
- * Usually, if moving backward in the file and it's a motion component,
- * the starting cursor is decremented by a single character (or, in a
- * few cases, to the end of the previous line) so that the starting
- * cursor character isn't cut or deleted. No cursor adjustment is
- * needed for moving forward, because the cut/delete routines handle
- * m_stop inclusively, i.e. the last character in the range is cut or
- * deleted. This makes cutting to the EOF/EOL reasonable.
- *
- * The 'c', '<', '>', and '!' commands are special cases. We ignore
- * the final cursor position for all of them: for 'c', the text input
- * routines set the cursor to the last character inserted; for '<',
- * '>' and '!', the underlying ex commands that do the operation will
- * set the cursor for us. We still need a VC_C flag because there are
- * special motion semantics that are associated with the 'c' command.
- * We don't need VC_ flags for the others, because, as far as I know,
- * there are no special semantics associated with their motions. So,
- * we group them under a single VC_ flag so that the standard motion
- * adjustments get done.
- */
- MARK m_start; /* mark: initial cursor, range start. */
- MARK m_stop; /* mark: range end. */
- MARK m_final; /* mark: final cursor position. */
-} VICMDARG;
-
-/* Vi command structure. */
-struct _vikeys { /* Underlying function. */
- int (*func) __P((SCR *, EXF *, VICMDARG *));
-#define V_ABS 0x00040000 /* Absolute movement, set '' mark. */
-#define V_ABS_C 0x00080000 /* V_ABS: if the line/column changed. */
-#define V_ABS_L 0x00100000 /* V_ABS: if the line changed. */
-#define V_CHAR 0x00200000 /* Character (required, trailing). */
-#define V_CNT 0x00400000 /* Count (optional, leading). */
-#define V_DOT 0x00800000 /* On success, sets dot command. */
-#define V_KEYNUM 0x01000000 /* Cursor referenced number. */
-#define V_KEYW 0x02000000 /* Cursor referenced word. */
-#define V_MOTION 0x04000000 /* Motion (required, trailing). */
-#define V_MOVE 0x08000000 /* Command defines movement. */
-#define V_OBUF 0x10000000 /* Buffer (optional, leading). */
-#define V_RBUF 0x20000000 /* Buffer (required, trailing). */
- u_int32_t flags;
- char *usage; /* Usage line. */
- char *help; /* Help line. */
-};
-#define MAXVIKEY 126 /* List of vi commands. */
-extern VIKEYS const vikeys[MAXVIKEY + 1];
-extern VIKEYS const tmotion; /* XXX Hacked ~ command. */
-
-/* Definition of a vi "word". */
-#define inword(ch) (isalnum(ch) || (ch) == '_')
-
-/* Offset to next column of stop size. */
-#define STOP_OFF(c, stop) (stop - (c) % stop)
-
-/* Character stream structure, prototypes. */
-typedef struct _vcs {
- recno_t cs_lno; /* Line. */
- size_t cs_cno; /* Column. */
- CHAR_T *cs_bp; /* Buffer. */
- size_t cs_len; /* Length. */
- CHAR_T 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 *));
-
- /* Character search information. */
-enum cdirection { CNOTSET, FSEARCH, fSEARCH, TSEARCH, tSEARCH };
-
-/* 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 *ps; /* Paragraph plus section list. */
-
- u_long u_ccnt; /* Undo command count. */
-
- CHAR_T lastckey; /* Last search character. */
- enum cdirection csearchdir; /* Character search direction. */
-} 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_buildps __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 *));
-void v_nomove __P((SCR *));
-int v_ntext __P((SCR *, EXF *, TEXTH *, MARK *,
- const char *, const size_t, MARK *, ARG_CHAR_T, 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 *));
-void v_sol __P((SCR *));
-int vi __P((SCR *, EXF *));
-
-#define VIPROTO(name) int name __P((SCR *, EXF *, VICMDARG *))
-VIPROTO(v_again);
-VIPROTO(v_at);
-VIPROTO(v_bmark);
-VIPROTO(v_bottom);
-VIPROTO(v_cfirst);
-VIPROTO(v_Change);
-VIPROTO(v_change);
-VIPROTO(v_chF);
-VIPROTO(v_chf);
-VIPROTO(v_chrepeat);
-VIPROTO(v_chrrepeat);
-VIPROTO(v_chT);
-VIPROTO(v_cht);
-VIPROTO(v_cr);
-VIPROTO(v_Delete);
-VIPROTO(v_delete);
-VIPROTO(v_dollar);
-VIPROTO(v_down);
-VIPROTO(v_ex);
-VIPROTO(v_exmode);
-VIPROTO(v_filter);
-VIPROTO(v_first);
-VIPROTO(v_fmark);
-VIPROTO(v_home);
-VIPROTO(v_hpagedown);
-VIPROTO(v_hpageup);
-VIPROTO(v_iA);
-VIPROTO(v_ia);
-VIPROTO(v_iI);
-VIPROTO(v_ii);
-VIPROTO(v_increment);
-VIPROTO(v_iO);
-VIPROTO(v_io);
-VIPROTO(v_join);
-VIPROTO(v_left);
-VIPROTO(v_lgoto);
-VIPROTO(v_linedown);
-VIPROTO(v_lineup);
-VIPROTO(v_mark);
-VIPROTO(v_match);
-VIPROTO(v_middle);
-VIPROTO(v_mulcase);
-VIPROTO(v_ncol);
-VIPROTO(v_pagedown);
-VIPROTO(v_pageup);
-VIPROTO(v_paragraphb);
-VIPROTO(v_paragraphf);
-VIPROTO(v_Put);
-VIPROTO(v_put);
-VIPROTO(v_redraw);
-VIPROTO(v_Replace);
-VIPROTO(v_replace);
-VIPROTO(v_right);
-VIPROTO(v_screen);
-VIPROTO(v_searchb);
-VIPROTO(v_searchf);
-VIPROTO(v_searchN);
-VIPROTO(v_searchn);
-VIPROTO(v_searchw);
-VIPROTO(v_sectionb);
-VIPROTO(v_sectionf);
-VIPROTO(v_sentenceb);
-VIPROTO(v_sentencef);
-VIPROTO(v_shiftl);
-VIPROTO(v_shiftr);
-VIPROTO(v_status);
-VIPROTO(v_stop);
-VIPROTO(v_Subst);
-VIPROTO(v_subst);
-VIPROTO(v_switch);
-VIPROTO(v_tagpop);
-VIPROTO(v_tagpush);
-VIPROTO(v_ulcase);
-VIPROTO(v_Undo);
-VIPROTO(v_undo);
-VIPROTO(v_up);
-VIPROTO(v_wordB);
-VIPROTO(v_wordb);
-VIPROTO(v_wordE);
-VIPROTO(v_worde);
-VIPROTO(v_wordW);
-VIPROTO(v_wordw);
-VIPROTO(v_Xchar);
-VIPROTO(v_xchar);
-VIPROTO(v_Yank);
-VIPROTO(v_yank);
-VIPROTO(v_z);
-VIPROTO(v_zero);
-VIPROTO(v_zexit);
diff --git a/usr.bin/vi/vi/vi.c b/usr.bin/vi/vi/vi.c
deleted file mode 100644
index 40ed3e7..0000000
--- a/usr.bin/vi/vi/vi.c
+++ /dev/null
@@ -1,937 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993, 1994
- * 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.91 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-#include "vcmd.h"
-
-static int getcmd __P((SCR *, EXF *,
- VICMDARG *, VICMDARG *, VICMDARG *, int *, 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 *, int *));
-
-/*
- * 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;
- VICMDARG cmd, *vp;
- u_int flags, saved_mode;
- int comcount, eval, mapped;
-
- /* Start vi and paint the screen. */
- if (v_init(sp, ep))
- return (1);
-
- /* Command initialization. */
- memset(&cmd, 0, sizeof(VICMDARG));
-
- for (eval = 0, vp = &cmd;;) {
- /* Refresh the screen. */
- sp->showmode = "Command";
- if (sp->s_refresh(sp, ep)) {
- eval = 1;
- break;
- }
-
- /* Set the new favorite position. */
- if (F_ISSET(vp, VM_RCM_SET | VM_RCM_SETFNB | VM_RCM_SETNNB)) {
- sp->rcm_last = 0;
- (void)sp->s_column(sp, ep, &sp->rcm);
- }
-
- /*
- * If not currently in a map, log the cursor position,
- * and set a flag so that this command can become the
- * DOT command.
- */
- if (MAPPED_KEYS_WAITING(sp))
- mapped = 1;
- else {
- if (log_cursor(sp, ep))
- goto err;
- mapped = 0;
- }
-
- /*
- * 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, &mapped))
- 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;
-
- /* Copy the key flags into the local structure. */
- F_SET(vp, vp->kp->flags);
-
- /* Get any associated keyword. */
- if (F_ISSET(vp, V_KEYNUM | V_KEYW) &&
- getkeyword(sp, ep, vp, vp->flags))
- goto err;
-
- /* Prepare to set the previous context. */
- if (F_ISSET(vp, V_ABS | V_ABS_C | V_ABS_L)) {
- abs.lno = sp->lno;
- abs.cno = sp->cno;
- }
-
- /*
- * Set the three cursor locations to the current cursor. The
- * underlying routines don't bother if the cursor doesn't move.
- * This also handles line commands (e.g. Y) defaulting to the
- * current line.
- */
- vp->m_start.lno = vp->m_stop.lno = vp->m_final.lno = sp->lno;
- vp->m_start.cno = vp->m_stop.cno = vp->m_final.cno = sp->cno;
-
- /*
- * Do any required motion; getmotion sets the from MARK and the
- * line mode flag. We save off the RCM mask and only restore
- * it if it no RCM flags are set by the motion command. This
- * means that the motion command is expected to determine where
- * the cursor ends up!
- */
- if (F_ISSET(vp, V_MOTION)) {
- flags = F_ISSET(vp, VM_RCM_MASK);
- F_CLR(vp, VM_RCM_MASK);
- if (getmotion(sp, ep, DOTMOTION, vp, &mapped))
- goto err;
- if (F_ISSET(vp, VM_NOMOTION))
- goto err;
- if (!F_ISSET(vp, VM_RCM_MASK))
- F_SET(vp, flags);
- }
-
- /*
- * If a count is set and the command is line oriented, set the
- * to MARK here relative to the cursor/from MARK. This is for
- * commands that take both counts and motions, i.e. "4yy" and
- * "y%". As there's no way the command can know which the user
- * did, we have to do it here. (There are commands that are
- * line oriented and that take counts ("#G", "#H"), for which
- * this calculation is either completely meaningless or wrong.
- * Each command must validate the value for itself.
- */
- if (F_ISSET(vp, VC_C1SET) && F_ISSET(vp, VM_LMODE))
- vp->m_stop.lno += vp->count - 1;
-
- /* Increment the command count. */
- ++sp->ccnt;
-
- /* Save the mode and call the function. */
- saved_mode = F_ISSET(sp, S_SCREENS | S_MAJOR_CHANGE);
- if ((vp->kp->func)(sp, ep, vp))
- 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 dot command structure.
- *
- * !!!
- * Historically, no command which used any mapped keys became
- * the dot command.
- */
- if (F_ISSET(vp, V_DOT) && !mapped) {
- *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);
-
- /* VM flags aren't retained. */
- F_CLR(DOT, VM_COMMASK | VM_RCM_MASK);
- }
-
- /*
- * Some vi row movements are "attracted" to the last position
- * set, i.e. the VM_RCM commands are moths to the VM_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 VM_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 (F_ISSET(vp, VM_RCM_MASK)) {
- case 0:
- case VM_RCM_SET:
- break;
- case VM_RCM:
- vp->m_final.cno = sp->s_rcm(sp, ep, vp->m_final.lno);
- break;
- case VM_RCM_SETLAST:
- sp->rcm_last = 1;
- break;
- case VM_RCM_SETFNB:
- vp->m_final.cno = 0;
- /* FALLTHROUGH */
- case VM_RCM_SETNNB:
- if (nonblank(sp, ep, vp->m_final.lno, &vp->m_final.cno))
- goto err;
- break;
- default:
- abort();
- }
-
- /* Update the cursor. */
- sp->lno = vp->m_final.lno;
- sp->cno = vp->m_final.cno;
-
- /*
- * Set the absolute mark -- set even if a tags or similar
- * command, since the tag may be moving to the same file.
- */
- if ((F_ISSET(vp, V_ABS) ||
- F_ISSET(vp, V_ABS_L) && sp->lno != abs.lno ||
- F_ISSET(vp, V_ABS_C) &&
- (sp->lno != abs.lno || sp->cno != abs.cno)) &&
- mark_set(sp, ep, ABSMARK1, &abs, 1))
- goto err;
-
- if (!MAPPED_KEYS_WAITING(sp))
- (void)msg_rpt(sp, 1);
-
- /*
- * Check and clear the interrupts. There's an obvious race,
- * but it's not worth cleaning up. This is done after the
- * err: lable, so that if the "error" was an interupt it gets
- * cleaned up.
- *
- * !!!
- * Previous versions of nvi cleared mapped characters on error,
- * even if it wasn't an interrupt. This feature was removed as
- * users complained that it wasn't historic practice and that
- * they used leading (illegal) <escape> characters in the map
- * to clean up vi state before the map was interpreted.
- */
-err: if (INTERRUPTED(sp))
- term_flush(sp, "Interrupted", CH_MAPPED);
- CLR_INTERRUPT(sp);
- }
-
- /* Free allocated keyword memory. */
- if (cmd.keyword != NULL)
- free(cmd.keyword);
-
- return (v_end(sp) || eval);
-}
-
-#define KEY(key, map) { \
- if (getkey(sp, &ikey, map)) \
- return (1); \
- if (ikey.value == K_ESCAPE) \
- goto esc; \
- if (F_ISSET(&ikey, CH_MAPPED)) \
- *mappedp = 1; \
- key = ikey.ch; \
-}
-
-/*
- * The O_TILDEOP option makes the ~ command take a motion instead
- * of a straight count. This is the replacement structure we use
- * instead of the one currently in the VIKEYS table.
- *
- * XXX
- * Note, I used VC_Y instead of creating a new motion command, it's
- * a lot easier.
- */
-VIKEYS const tmotion = {
- v_mulcase, V_CNT|V_DOT|V_MOTION|VC_Y|VM_RCM_SET,
- "[count]~[count]motion",
- " ~ change case to motion"
-};
-
-/*
- * 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, mappedp)
- SCR *sp;
- EXF *ep;
- VICMDARG *dp, *vp;
- VICMDARG *ismotion; /* Previous key if getting motion component. */
- int *comcountp, *mappedp;
-{
- enum { COMMANDMODE, ISPARTIAL, NOTPARTIAL } cpart;
- VIKEYS const *kp;
- u_int flags;
- CH ikey;
- CHAR_T key;
- char *s;
-
- /* Refresh the command structure. */
- memset(&vp->vp_startzero, 0,
- (char *)&vp->vp_endzero - (char *)&vp->vp_startzero);
-
- /*
- * Get a key.
- *
- * <escape> cancels partial commands, i.e. a command where at least
- * one non-numeric character has been entered. Otherwise, it beeps
- * the terminal.
- *
- * !!!
- * POSIX 1003.2-1992 explicitly disallows cancelling commands where
- * all that's been entered is a number, requiring that the terminal
- * be alerted.
- */
- cpart = ismotion == NULL ? COMMANDMODE : ISPARTIAL;
- KEY(key, TXT_MAPCOMMAND);
- if (ismotion == NULL)
- cpart = NOTPARTIAL;
-
- /* Pick up optional buffer. */
- if (key == '"') {
- cpart = ISPARTIAL;
- if (ismotion != NULL) {
- msgq(sp, M_BERR,
- "Buffers should be specified before the command");
- return (1);
- }
- 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 == '"') {
- cpart = ISPARTIAL;
- if (F_ISSET(vp, VC_BUFFER)) {
- msgq(sp, M_ERR, "Only one buffer can be specified");
- return (1);
- }
- if (ismotion != NULL) {
- msgq(sp, M_BERR,
- "Buffers should be specified before the command");
- return (1);
- }
- KEY(vp->buffer, 0);
- F_SET(vp, VC_BUFFER);
-
- KEY(key, TXT_MAPCOMMAND);
- }
-
- /* Check for an OOB command key. */
- cpart = ISPARTIAL;
- if (key > MAXVIKEY) {
- msgq(sp, M_BERR, "%s isn't a vi command", KEY_NAME(sp, key));
- return (1);
- }
- kp = &vikeys[vp->key = key];
-
- /* The tildeop option makes the ~ command take a motion. */
- if (key == '~' && O_ISSET(sp, O_TILDEOP))
- kp = &tmotion;
-
- vp->kp = kp;
-
- /*
- * Find the command. The only legal command with no underlying
- * function is dot. It's historic practice that <escape> doesn't
- * just erase the preceding number, it beeps the terminal as well.
- * It's a common problem, so just beep the terminal unless verbose
- * was set.
- */
- if (kp->func == NULL) {
- if (key != '.') {
- msgq(sp, ikey.value == K_ESCAPE ? M_BERR : M_ERR,
- "%s isn't a vi command", KEY_NAME(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);
- }
-
- /* Set the flags based on the command flags. */
- 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);
- F_SET(vp, VC_BUFFER);
- }
- }
-
- /*
- * 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') {
- /*
- * Historically, half entered [[, ]] or Z commands weren't
- * cancelled by <escape>, the terminal was beeped instead.
- * POSIX.2-1992 probably didn't notice, and requires that
- * they be cancelled instead of beeping. Seems fine to me.
- */
- KEY(key, TXT_MAPCOMMAND);
-
- if (vp->key != key) {
-usage: if (ismotion == NULL)
- s = kp->usage;
- else if (ismotion->key == '~' && O_ISSET(sp, O_TILDEOP))
- s = tmotion.usage;
- else
- s = vikeys[ismotion->key].usage;
- msgq(sp, M_ERR, "Usage: %s", s);
- return (1);
- }
- }
- /* 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.
- */
- if (ismotion != NULL && ismotion->key != key && !LF_ISSET(V_MOVE)) {
- msgq(sp, M_ERR, "%s may not be used as a motion command",
- KEY_NAME(sp, key));
- return (1);
- }
-
- /* Required character. */
- if (LF_ISSET(V_CHAR))
- KEY(vp->character, 0);
-
- return (0);
-
-esc: switch (cpart) {
- case COMMANDMODE:
- msgq(sp, M_BERR, "Already in command mode");
- break;
- case ISPARTIAL:
- break;
- case NOTPARTIAL:
- (void)sp->s_bell(sp);
- break;
- }
- return (1);
-}
-
-/*
- * getmotion --
- *
- * Get resulting motion mark.
- */
-static int
-getmotion(sp, ep, dm, vp, mappedp)
- SCR *sp;
- EXF *ep;
- VICMDARG *dm, *vp;
- int *mappedp;
-{
- MARK m;
- VICMDARG motion;
- size_t len;
- u_long cnt;
- int notused;
-
- /*
- * If '.' command, use the dot motion, else get the motion command.
- * Clear any line motion flags, the subsequent motion isn't always
- * the same, i.e. "/aaa" may or may not be a line motion.
- */
- if (F_ISSET(vp, VC_ISDOT)) {
- motion = *dm;
- F_SET(&motion, VC_ISDOT);
- F_CLR(&motion, VM_COMMASK);
- } else if (getcmd(sp, ep, NULL, &motion, vp, &notused, mappedp))
- 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, VM_LDOUBLE | VM_LMODE);
-
- /* Set the origin of the command. */
- vp->m_start.lno = sp->lno;
- vp->m_start.cno = 0;
-
- /*
- * Set the end of the command.
- *
- * If the current line is missing, i.e. the file is empty,
- * historic vi permitted a "cc" or "!!" command to insert
- * text.
- */
- vp->m_stop.lno = sp->lno + motion.count - 1;
- if (file_gline(sp, ep, vp->m_stop.lno, &len) == NULL) {
- if (vp->m_stop.lno != 1 ||
- vp->key != 'c' && vp->key != '!') {
- m.lno = sp->lno;
- m.cno = sp->cno;
- v_eof(sp, ep, &m);
- return (1);
- }
- vp->m_stop.cno = 0;
- } else
- vp->m_stop.cno = len ? len - 1 : 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);
-
- /*
- * Copy the key flags into the local structure, except for
- * the RCM flags, the motion command will set the RCM flags
- * in the vp structure as necessary.
- */
- F_SET(&motion, motion.kp->flags & ~VM_RCM_MASK);
-
- /*
- * Set the three cursor locations to the current cursor. 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.
- */
- motion.m_final.lno =
- motion.m_stop.lno = motion.m_start.lno = sp->lno;
- motion.m_final.cno =
- motion.m_stop.cno = motion.m_start.cno = sp->cno;
-
- /* Run the function. */
- if ((motion.kp->func)(sp, ep, &motion))
- return (1);
-
- /*
- * Copy cut buffer, line mode and cursor position information
- * from the motion command structure, i.e. anything that the
- * motion command can set for us. The commands can flag the
- * movement as a line motion (see v_sentence) as well as set
- * the VM_RCM_* flags explicitly.
- */
- F_SET(vp, F_ISSET(&motion, VM_COMMASK | VM_RCM_MASK));
-
- /*
- * Motion commands can reset all of the cursor information.
- * If the motion is in the reverse direction, switch the
- * from and to MARK's so that it's in a forward direction.
- * Motions are from the from MARK to the to MARK (inclusive).
- */
- if (motion.m_start.lno > motion.m_stop.lno ||
- motion.m_start.lno == motion.m_stop.lno &&
- motion.m_start.cno > motion.m_stop.cno) {
- vp->m_start = motion.m_stop;
- vp->m_stop = motion.m_start;
- } else {
- vp->m_start = motion.m_start;
- vp->m_stop = motion.m_stop;
- }
- vp->m_final = motion.m_final;
- }
-
- /*
- * 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;
- }
- 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);
- }
-
- /*
- * !!!
- * Historically, tag commands skipped over any leading whitespace
- * characters.
- */
- for (beg = sp->cno; beg < len && isspace(p[beg]); ++beg);
-
- if (beg >= len ||
- LF_ISSET(V_KEYW) && !inword(p[beg]) ||
- LF_ISSET(V_KEYNUM) && !innum(p[beg]) &&
- p[beg] != '-' && p[beg] != '+')
- goto noword;
-
- /*
- * !!!
- * 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 the 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 = beg; ++end < len && inword(p[end]););
- --end;
- } else {
- for (end = beg; ++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] == '-')) {
-noword: msgq(sp, M_BERR, "Cursor not in a %s",
- LF_ISSET(V_KEYW) ? "word" : "number");
- return (1);
- }
- --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_EOF:
- case INP_ERR:
- F_SET(sp, S_EXIT_FORCE);
- return (1);
- case INP_INTR:
- /*
- * !!!
- * Historically, vi beeped on command level interrupts.
- *
- * Historically, vi exited to ex mode if no file was named
- * on the command line, and two interrupts were generated
- * in a row. (Just figured you might want to know that.)
- */
- (void)sp->s_bell(sp);
- return (1);
- case INP_OK:
- return (0);
- }
- /* NOTREACHED */
-}
diff --git a/usr.bin/vi/xaw/xaw_screen.c b/usr.bin/vi/xaw/xaw_screen.c
deleted file mode 100644
index 0e78619..0000000
--- a/usr.bin/vi/xaw/xaw_screen.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- * 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[] = "@(#)xaw_screen.c 8.8 (Berkeley) 8/17/94";
-#endif /* not lint */
-
-#include <sys/queue.h>
-#include <sys/time.h>
-
-#include <bitstring.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include "compat.h"
-#include <db.h>
-#include <regex.h>
-
-#include "vi.h"
-
-/*
- * xaw_init --
- * Athena widget screen initialization.
- */
-int
-xaw_screen_init(sp)
- SCR *sp;
-{
- msgq(sp, M_ERR, "The Athena widget screen not yet implemented");
- return (1);
-}
-
-/*
- * xaw_screen_copy --
- * Copy to a new screen.
- */
-int
-xaw_screen_copy(orig, sp)
- SCR *orig, *sp;
-{
- return (0);
-}
-
-/*
- * xaw_screen_end --
- * End a screen.
- */
-int
-xaw_screen_end(sp)
- SCR *sp;
-{
- return (0);
-}
-
-/*
- * xaw --
- * Main vi Athena widget screen loop.
- */
-int
-xaw(sp, ep, spp)
- SCR *sp, **spp;
- EXF *ep;
-{
- *spp = NULL;
- return (0);
-}
OpenPOWER on IntegriCloud