Termcap update, replacing elvis by nvi.

Removing elvis, importing nvi, ctags, updating libedit.

Change-Id: I881eb04d2dc64cf112facd992de1114e1a59107f
This commit is contained in:
2013-01-22 12:03:53 +01:00
committed by Lionel Sambuc
parent f9f6c9251a
commit 3e1db26a5a
491 changed files with 192709 additions and 28905 deletions

View File

@@ -4,24 +4,33 @@
.include <bsd.own.mk>
SUBDIR= \
\
\
bzip2 bzip2recover \
chpass cksum \
\
du \
chpass cksum \
ctags \
du \
\
\
genassym \
indent join \
ldd \
login lorder m4 \
make man \
mkdep mktemp \
nbperf newgrp \
\
nbperf newgrp nvi \
passwd \
\
\
\
sed seq \
sort stat su \
tic \
tsort \
uniq \
\
\
\
xinstall
.if !defined(__MINIX)

573
usr.bin/ctags/C.c Normal file
View File

@@ -0,0 +1,573 @@
/* $NetBSD: C.c,v 1.19 2009/07/13 19:05:40 roy Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: C.c,v 1.19 2009/07/13 19:05:40 roy Exp $");
#endif
#endif /* not lint */
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "ctags.h"
static int func_entry(void);
static void hash_entry(void);
static void skip_string(int);
static int str_entry(int);
/*
* c_entries --
* read .c and .h files and call appropriate routines
*/
void
c_entries(void)
{
int c; /* current character */
int level; /* brace level */
int token; /* if reading a token */
int t_def; /* if reading a typedef */
int t_level; /* typedef's brace level */
char *sp; /* buffer pointer */
char tok[MAXTOKEN]; /* token buffer */
lineftell = ftell(inf);
sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
while (GETC(!=, EOF)) {
switch (c) {
/*
* Here's where it DOESN'T handle: {
* foo(a)
* {
* #ifdef notdef
* }
* #endif
* if (a)
* puts("hello, world");
* }
*/
case '{':
++level;
goto endtok;
case '}':
/*
* if level goes below zero, try and fix
* it, even though we've already messed up
*/
if (--level < 0)
level = 0;
goto endtok;
case '\n':
SETLINE;
/*
* the above 3 cases are similar in that they
* are special characters that also end tokens.
*/
endtok: if (sp > tok) {
*sp = EOS;
token = YES;
sp = tok;
}
else
token = NO;
continue;
/*
* We ignore quoted strings and character constants
* completely.
*/
case '"':
case '\'':
(void)skip_string(c);
break;
/*
* comments can be fun; note the state is unchanged after
* return, in case we found:
* "foo() XX comment XX { int bar; }"
*/
case '/':
if (GETC(==, '*')) {
skip_comment(c);
continue;
} else if (c == '/') {
skip_comment(c);
continue;
}
(void)ungetc(c, inf);
c = '/';
goto storec;
/* hash marks flag #define's. */
case '#':
if (sp == tok) {
hash_entry();
break;
}
goto storec;
/*
* if we have a current token, parenthesis on
* level zero indicates a function.
*/
case '(':
do c = getc(inf);
while (c != EOF && iswhite(c));
if (c == '*')
break;
if (c != EOF)
ungetc(c, inf);
if (!level && token) {
int curline;
if (sp != tok)
*sp = EOS;
/*
* grab the line immediately, we may
* already be wrong, for example,
* foo\n
* (arg1,
*/
get_line();
curline = lineno;
if (func_entry()) {
++level;
pfnote(tok, curline);
}
break;
}
goto storec;
/*
* semi-colons indicate the end of a typedef; if we find a
* typedef we search for the next semi-colon of the same
* level as the typedef. Ignoring "structs", they are
* tricky, since you can find:
*
* "typedef long time_t;"
* "typedef unsigned int u_int;"
* "typedef unsigned int u_int [10];"
*
* If looking at a typedef, we save a copy of the last token
* found. Then, when we find the ';' we take the current
* token if it starts with a valid token name, else we take
* the one we saved. There's probably some reasonable
* alternative to this...
*/
case ';':
if (t_def && level == t_level) {
t_def = NO;
get_line();
if (sp != tok)
*sp = EOS;
pfnote(tok, lineno);
break;
}
goto storec;
/*
* store characters until one that can't be part of a token
* comes along; check the current token against certain
* reserved words.
*/
default:
storec: if (c == EOF)
break;
if (!intoken(c)) {
if (sp == tok)
break;
*sp = EOS;
if (tflag) {
/* no typedefs inside typedefs */
if (!t_def &&
!memcmp(tok, "typedef",8)) {
t_def = YES;
t_level = level;
break;
}
/* catch "typedef struct" */
if ((!t_def || t_level <= level)
&& (!memcmp(tok, "struct", 7)
|| !memcmp(tok, "union", 6)
|| !memcmp(tok, "enum", 5))) {
/*
* get line immediately;
* may change before '{'
*/
get_line();
if (str_entry(c))
++level;
break;
/* } */
}
}
sp = tok;
}
else if (sp != tok || begtoken(c)) {
if (sp < tok + sizeof tok)
*sp++ = c;
token = YES;
}
continue;
}
sp = tok;
token = NO;
}
}
/*
* func_entry --
* handle a function reference
*/
static int
func_entry(void)
{
int c; /* current character */
int level = 0; /* for matching '()' */
static char attribute[] = "__attribute__";
char maybe_attribute[sizeof attribute + 1],
*anext;
/*
* Find the end of the assumed function declaration.
* Note that ANSI C functions can have type definitions so keep
* track of the parentheses nesting level.
*/
while (GETC(!=, EOF)) {
switch (c) {
case '\'':
case '"':
/* skip strings and character constants */
skip_string(c);
break;
case '/':
/* skip comments */
if (GETC(==, '*'))
skip_comment(c);
else if (c == '/')
skip_comment(c);
break;
case '(':
level++;
break;
case ')':
if (level == 0)
goto fnd;
level--;
break;
case '\n':
SETLINE;
}
}
return (NO);
fnd:
/*
* we assume that the character after a function's right paren
* is a token character if it's a function and a non-token
* character if it's a declaration. Comments don't count...
*/
for (anext = maybe_attribute;;) {
while (GETC(!=, EOF) && iswhite(c))
if (c == '\n')
SETLINE;
if (c == EOF)
return NO;
/*
* Recognize the gnu __attribute__ extension, which would
* otherwise make the heuristic test DTWT
*/
if (anext == maybe_attribute) {
if (intoken(c)) {
*anext++ = c;
continue;
}
} else {
if (intoken(c)) {
if (anext - maybe_attribute
< (ptrdiff_t)(sizeof attribute - 1))
*anext++ = c;
else break;
continue;
} else {
*anext++ = '\0';
if (strcmp(maybe_attribute, attribute) == 0) {
(void)ungetc(c, inf);
return NO;
}
break;
}
}
if (intoken(c) || c == '{')
break;
if (c == '/' && GETC(==, '*'))
skip_comment(c);
else if (c == '/')
skip_comment(c);
else { /* don't ever "read" '/' */
(void)ungetc(c, inf);
return (NO);
}
}
if (c != '{')
(void)skip_key('{');
return (YES);
}
/*
* hash_entry --
* handle a line starting with a '#'
*/
static void
hash_entry(void)
{
int c; /* character read */
int curline; /* line started on */
char *sp; /* buffer pointer */
char tok[MAXTOKEN]; /* storage buffer */
curline = lineno;
do if (GETC(==, EOF))
return;
while(c != '\n' && iswhite(c));
ungetc(c, inf);
for (sp = tok;;) { /* get next token */
if (GETC(==, EOF))
return;
if (iswhite(c))
break;
if (sp < tok + sizeof tok)
*sp++ = c;
}
if(sp >= tok + sizeof tok)
--sp;
*sp = EOS;
if (memcmp(tok, "define", 6)) /* only interested in #define's */
goto skip;
for (;;) { /* this doesn't handle "#define \n" */
if (GETC(==, EOF))
return;
if (!iswhite(c))
break;
}
for (sp = tok;;) { /* get next token */
if(sp < tok + sizeof tok)
*sp++ = c;
if (GETC(==, EOF))
return;
/*
* this is where it DOESN'T handle
* "#define \n"
*/
if (!intoken(c))
break;
}
if(sp >= tok + sizeof tok)
--sp;
*sp = EOS;
if (dflag || c == '(') { /* only want macros */
get_line();
pfnote(tok, curline);
}
skip: if (c == '\n') { /* get rid of rest of define */
SETLINE
if (*(sp - 1) != '\\')
return;
}
(void)skip_key('\n');
}
/*
* str_entry --
* handle a struct, union or enum entry
*/
static int
str_entry(int c /* current character */)
{
int curline; /* line started on */
char *sp; /* buffer pointer */
char tok[LINE_MAX]; /* storage buffer */
curline = lineno;
while (iswhite(c))
if (GETC(==, EOF))
return (NO);
if (c == '{') /* it was "struct {" */
return (YES);
for (sp = tok;;) { /* get next token */
*sp++ = c;
if (GETC(==, EOF))
return (NO);
if (!intoken(c))
break;
}
switch (c) {
case '{': /* it was "struct foo{" */
--sp;
break;
case '\n': /* it was "struct foo\n" */
SETLINE;
/*FALLTHROUGH*/
default: /* probably "struct foo " */
while (GETC(!=, EOF))
if (!iswhite(c))
break;
if (c != '{') {
(void)ungetc(c, inf);
return (NO);
}
}
*sp = EOS;
pfnote(tok, curline);
return (YES);
}
/*
* skip_comment --
* skip over comment
*/
void
skip_comment(int commenttype)
{
int c; /* character read */
int star; /* '*' flag */
for (star = 0; GETC(!=, EOF);)
switch(c) {
/* comments don't nest, nor can they be escaped. */
case '*':
star = YES;
break;
case '/':
if (commenttype == '*' && star)
return;
break;
case '\n':
if (commenttype == '/') {
/*
* we don't really parse C, so sometimes it
* is necessary to see the newline
*/
ungetc(c, inf);
return;
}
SETLINE;
/*FALLTHROUGH*/
default:
star = NO;
break;
}
}
/*
* skip_string --
* skip to the end of a string or character constant.
*/
void
skip_string(int key)
{
int c,
skip;
for (skip = NO; GETC(!=, EOF); )
switch (c) {
case '\\': /* a backslash escapes anything */
skip = !skip; /* we toggle in case it's "\\" */
break;
case '\n':
SETLINE;
/*FALLTHROUGH*/
default:
if (c == key && !skip)
return;
skip = NO;
}
}
/*
* skip_key --
* skip to next char "key"
*/
int
skip_key(int key)
{
int c,
skip,
retval;
for (skip = retval = NO; GETC(!=, EOF);)
switch(c) {
case '\\': /* a backslash escapes anything */
skip = !skip; /* we toggle in case it's "\\" */
break;
case ';': /* special case for yacc; if one */
case '|': /* of these chars occurs, we may */
retval = YES; /* have moved out of the rule */
break; /* not used by C */
case '\'':
case '"':
/* skip strings and character constants */
skip_string(c);
break;
case '/':
/* skip comments */
if (GETC(==, '*')) {
skip_comment(c);
break;
} else if (c == '/') {
skip_comment(c);
break;
}
(void)ungetc(c, inf);
c = '/';
goto norm;
case '\n':
SETLINE;
/*FALLTHROUGH*/
default:
norm:
if (c == key && !skip)
return (retval);
skip = NO;
}
return (retval);
}

12
usr.bin/ctags/Makefile Normal file
View File

@@ -0,0 +1,12 @@
# $NetBSD: Makefile,v 1.13 2012/08/10 12:10:27 joerg Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= ctags
CPPFLAGS+=-I${.CURDIR}
SRCS= C.c ctags.c fortran.c lisp.c print.c tree.c yacc.c
.if !defined(HOSTPROGNAME)
COPTS.ctags.c+= -Wno-pointer-sign
.endif
.include <bsd.prog.mk>

226
usr.bin/ctags/ctags.1 Normal file
View File

@@ -0,0 +1,226 @@
.\" $NetBSD: ctags.1,v 1.16 2010/05/14 16:48:36 joerg Exp $
.\"
.\" Copyright (c) 1987, 1990, 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. 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.
.\"
.\" @(#)ctags.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt CTAGS 1
.Os
.Sh NAME
.Nm ctags
.Nd create a tags file
.Sh SYNOPSIS
.Nm
.Op Fl BFadtuwvx
.Op Fl f Ar tagsfile
.Ar name ...
.Sh DESCRIPTION
.Nm
makes a tags file for
.Xr ex 1
from the specified C,
Pascal, Fortran,
.Tn YACC ,
lex, and lisp sources.
A tags file gives the locations of specified objects in a group of files.
Each line of the tags file contains the object name, the file in which it
is defined, and a search pattern for the object definition, separated by
white-space.
Using the
.Ar tags
file,
.Xr ex 1
can quickly locate these object definitions.
Depending upon the options provided to
.Nm ,
objects will consist of subroutines, typedefs, defines, structs,
enums and unions.
.Bl -tag -width Ds
.It Fl B
use backward searching patterns
.Pq Li ?...? .
.It Fl F
use forward searching patterns
.Pq Li /.../
(the default).
.It Fl a
append to
.Ar tags
file.
.It Fl d
create tags for
.Li #defines
that don't take arguments;
.Li #defines
that take arguments are tagged automatically.
.It Fl f
Places the tag descriptions in a file called
.Ar tagsfile .
The default behaviour is to place them in a file called
.Ar tags .
.It Fl t
create tags for typedefs, structs, unions, and enums.
.It Fl u
update the specified files in the
.Ar tags
file, that is, all
references to them are deleted, and the new values are appended to the
file.
(Beware: this option is implemented in a way which is rather
slow; it is usually faster to simply rebuild the
.Ar tags
file.)
.It Fl v
An index of the form expected by
.Xr vgrind 1
is produced on the standard output.
This listing
contains the object name, file name, and page number (assuming 64
line pages).
Since the output will be sorted into lexicographic order,
it may be desired to run the output through
.Xr sort 1 .
Sample use:
.Bd -literal -offset indent
ctags \-v files \&| sort \-f \*[Gt] index
vgrind \-x index
.Ed
.It Fl w
suppress warning diagnostics.
.It Fl x
.Nm
produces a list of object
names, the line number and file name on which each is defined, as well
as the text of that line and prints this on the standard output.
This
is a simple index which can be printed out as an off-line readable
function index.
.El
.Pp
Files whose names end in
.Sq \&.c
or
.Sq \&.h
are assumed to be C
source files and are searched for C style routine and macro definitions.
Files whose names end in
.Sq \&.y
are assumed to be
.Tn YACC
source files.
Files whose names end in
.Sq \&.l
are assumed to be lisp files if their
first non-blank character is
.Sq \&; ,
.Sq \&( ,
or
.Sq \&[ ,
otherwise, they are
treated as lex files.
Other files are first examined to see if they
contain any Pascal or Fortran routine definitions, and, if not, are
searched for C style definitions.
.Pp
The tag
.Li main
is treated specially in C programs.
The tag formed
is created by prepending
.Ar M
to the name of the file, with the
trailing
.Sq \&.c
and any leading pathname components removed.
This
makes use of
.Nm
practical in directories with more than one
program.
.Pp
Yacc and lex files each have a special tag.
.Ar Yyparse
is the start
of the second section of the yacc file, and
.Ar yylex
is the start of
the second section of the lex file.
.Sh FILES
.Bl -tag -width tags -compact
.It Pa tags
default output tags file
.El
.Sh EXIT STATUS
.Nm
exits with a value of 1 if an error occurred, 0 otherwise.
Duplicate objects are not considered errors.
.Sh SEE ALSO
.Xr ex 1 ,
.Xr vi 1
.Sh HISTORY
The
.Nm
command appeared in
.Bx 3.0 .
.Sh BUGS
Recognition of
.Em functions ,
.Em subroutines
and
.Em procedures
for
.Tn FORTRAN
and Pascal is done in a very simpleminded way.
No attempt
is made to deal with block structure; if you have two Pascal procedures
in different blocks with the same name you lose.
.Nm
doesn't
understand about Pascal types.
.Pp
The method of deciding whether to look for C, Pascal or
.Tn FORTRAN
functions is a hack.
.Pp
.Nm
relies on the input being well formed, and any syntactical
errors will completely confuse it.
It also finds some legal syntax
confusing; for example, since it doesn't understand
.Li #ifdef Ns 's
(incidentally, that's a feature, not a bug), any code with unbalanced
braces inside
.Li #ifdef Ns 's
will cause it to become somewhat disoriented.
In a similar fashion, multiple line changes within a definition will
cause it to enter the last line of the object, rather than the first, as
the searching pattern.
The last line of multiple line
.Li typedef Ns 's
will similarly be noted.

275
usr.bin/ctags/ctags.c Normal file
View File

@@ -0,0 +1,275 @@
/* $NetBSD: ctags.c,v 1.12 2008/07/21 14:19:22 lukem Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
* 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__COPYRIGHT) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994, 1995\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)ctags.c 8.4 (Berkeley) 2/7/95";
#endif
__RCSID("$NetBSD: ctags.c,v 1.12 2008/07/21 14:19:22 lukem Exp $");
#endif /* not lint */
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "ctags.h"
/*
* ctags: create a tags file
*/
NODE *head; /* head of the sorted binary tree */
/* boolean "func" (see init()) */
bool _wht[256], _etk[256], _itk[256], _btk[256], _gd[256];
FILE *inf; /* ioptr for current input file */
FILE *outf; /* ioptr for tags file */
long lineftell; /* ftell after getc( inf ) == '\n' */
int lineno; /* line number of current line */
int dflag; /* -d: non-macro defines */
int tflag; /* -t: create tags for typedefs */
int vflag; /* -v: vgrind style index output */
int wflag; /* -w: suppress warnings */
int xflag; /* -x: cxref style output */
char *curfile; /* current input file name */
char searchar = '/'; /* use /.../ searches by default */
char lbuf[LINE_MAX];
void init(void);
void find_entries(char *);
int
main(int argc, char **argv)
{
static const char *outfile = "tags"; /* output file */
int aflag; /* -a: append to tags */
int uflag; /* -u: update tags */
int exit_val; /* exit value */
int step; /* step through args */
int ch; /* getopts char */
char cmd[100]; /* too ugly to explain */
aflag = uflag = NO;
while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1)
switch(ch) {
case 'B':
searchar = '?';
break;
case 'F':
searchar = '/';
break;
case 'a':
aflag++;
break;
case 'd':
dflag++;
break;
case 'f':
outfile = optarg;
break;
case 't':
tflag++;
break;
case 'u':
uflag++;
break;
case 'w':
wflag++;
break;
case 'v':
vflag++;
case 'x':
xflag++;
break;
case '?':
default:
goto usage;
}
argv += optind;
argc -= optind;
if (!argc) {
usage: (void)fprintf(stderr,
"usage: ctags [-BFadtuwvx] [-f tagsfile] file ...\n");
exit(1);
}
init();
for (exit_val = step = 0; step < argc; ++step)
if (!(inf = fopen(argv[step], "r"))) {
warn("%s", argv[step]);
exit_val = 1;
}
else {
curfile = argv[step];
find_entries(argv[step]);
(void)fclose(inf);
}
if (head) {
if (xflag)
put_entries(head);
else {
if (uflag) {
for (step = 0; step < argc; step++) {
(void)snprintf(cmd, sizeof(cmd),
"mv %s OTAGS; fgrep -v '\t%s\t' OTAGS >%s; rm OTAGS",
outfile, argv[step],
outfile);
system(cmd);
}
++aflag;
}
if (!(outf = fopen(outfile, aflag ? "a" : "w")))
err(exit_val, "%s", outfile);
put_entries(head);
(void)fclose(outf);
if (uflag) {
(void)snprintf(cmd, sizeof(cmd),
"sort -o %s %s", outfile, outfile);
system(cmd);
}
}
}
exit(exit_val);
}
/*
* init --
* this routine sets up the boolean psuedo-functions which work by
* setting boolean flags dependent upon the corresponding character.
* Every char which is NOT in that string is false with respect to
* the pseudo-function. Therefore, all of the array "_wht" is NO
* by default and then the elements subscripted by the chars in
* CWHITE are set to YES. Thus, "_wht" of a char is YES if it is in
* the string CWHITE, else NO.
*/
void
init(void)
{
int i;
unsigned const char *sp;
for (i = 0; i < 256; i++) {
_wht[i] = _etk[i] = _itk[i] = _btk[i] = NO;
_gd[i] = YES;
}
#define CWHITE " \f\t\n"
for (sp = CWHITE; *sp; sp++) /* white space chars */
_wht[*sp] = YES;
#define CTOKEN " \t\n\"'#()[]{}=-+%*/&|^~!<>;,.:?"
for (sp = CTOKEN; *sp; sp++) /* token ending chars */
_etk[*sp] = YES;
#define CINTOK "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789"
for (sp = CINTOK; *sp; sp++) /* valid in-token chars */
_itk[*sp] = YES;
#define CBEGIN "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
for (sp = CBEGIN; *sp; sp++) /* token starting chars */
_btk[*sp] = YES;
#define CNOTGD ",;"
for (sp = CNOTGD; *sp; sp++) /* invalid after-function chars */
_gd[*sp] = NO;
}
/*
* find_entries --
* this routine opens the specified file and calls the function
* which searches the file.
*/
void
find_entries(char *file)
{
char *cp;
lineno = 0; /* should be 1 ?? KB */
if ((cp = strrchr(file, '.')) != NULL) {
if (cp[1] == 'l' && !cp[2]) {
int c;
for (;;) {
if (GETC(==, EOF))
return;
if (!iswhite(c)) {
rewind(inf);
break;
}
}
#define LISPCHR ";(["
/* lisp */ if (strchr(LISPCHR, c)) {
l_entries();
return;
}
/* lex */ else {
/*
* we search all 3 parts of a lex file
* for C references. This may be wrong.
*/
toss_yysec();
(void)strlcpy(lbuf, "%%$", sizeof(lbuf));
pfnote("yylex", lineno);
rewind(inf);
}
}
/* yacc */ else if (cp[1] == 'y' && !cp[2]) {
/*
* we search only the 3rd part of a yacc file
* for C references. This may be wrong.
*/
toss_yysec();
(void)strlcpy(lbuf, "%%$", sizeof(lbuf));
pfnote("yyparse", lineno);
y_entries();
}
/* fortran */ else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) {
if (PF_funcs())
return;
rewind(inf);
}
}
/* C */ c_entries();
}

92
usr.bin/ctags/ctags.h Normal file
View File

@@ -0,0 +1,92 @@
/* $NetBSD: ctags.h,v 1.9 2009/07/13 19:05:40 roy Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*
* @(#)ctags.h 8.3 (Berkeley) 4/2/94
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#define bool char
#define YES 1
#define NO 0
#define EOS '\0'
#define ENDLINE 50 /* max length of pattern */
#define MAXTOKEN 250 /* max size of single token */
#define SETLINE {++lineno;lineftell = ftell(inf);}
#define GETC(op,exp) ((c = getc(inf)) op (int)exp)
#define iswhite(arg) (_wht[(unsigned)arg]) /* T if char is white */
#define begtoken(arg) (_btk[(unsigned)arg]) /* T if char can start token */
#define intoken(arg) (_itk[(unsigned)arg]) /* T if char can be in token */
#define endtoken(arg) (_etk[(unsigned)arg]) /* T if char ends tokens */
#define isgood(arg) (_gd[(unsigned)arg]) /* T if char can be after ')' */
typedef struct nd_st { /* sorting structure */
struct nd_st *left,
*right; /* left and right sons */
char *entry, /* function or type name */
*file, /* file name */
*pat; /* search pattern */
int lno; /* for -x option */
bool been_warned; /* set if noticed dup */
} NODE;
extern char *curfile; /* current input file name */
extern NODE *head; /* head of the sorted binary tree */
extern FILE *inf; /* ioptr for current input file */
extern FILE *outf; /* ioptr for current output file */
extern long lineftell; /* ftell after getc( inf ) == '\n' */
extern int lineno; /* line number of current line */
extern int dflag; /* -d: non-macro defines */
extern int tflag; /* -t: create tags for typedefs */
extern int vflag; /* -v: vgrind style index output */
extern int wflag; /* -w: suppress warnings */
extern int xflag; /* -x: cxref style output */
extern bool _wht[], _etk[], _itk[], _btk[], _gd[];
extern char lbuf[LINE_MAX];
extern char *lbp;
extern char searchar; /* ex search character */
extern int cicmp(const char *);
extern void get_line(void);
extern void pfnote(const char *, int);
extern int skip_key(int);
extern void put_entries(NODE *);
extern void toss_yysec(void);
extern void l_entries(void);
extern void y_entries(void);
extern int PF_funcs(void);
extern void c_entries(void);
extern void skip_comment(int);

174
usr.bin/ctags/fortran.c Normal file
View File

@@ -0,0 +1,174 @@
/* $NetBSD: fortran.c,v 1.11 2009/07/13 19:05:40 roy Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)fortran.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: fortran.c,v 1.11 2009/07/13 19:05:40 roy Exp $");
#endif
#endif /* not lint */
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "ctags.h"
static void takeprec(void);
char *lbp; /* line buffer pointer */
int
PF_funcs(void)
{
bool pfcnt; /* pascal/fortran functions found */
char *cp;
char tok[MAXTOKEN];
for (pfcnt = NO;;) {
lineftell = ftell(inf);
if (!fgets(lbuf, sizeof(lbuf), inf))
return (pfcnt);
++lineno;
lbp = lbuf;
if (*lbp == '%') /* Ratfor escape to fortran */
++lbp;
for (; isspace((unsigned char)*lbp); ++lbp)
continue;
if (!*lbp)
continue;
switch (*lbp | ' ') { /* convert to lower-case */
case 'c':
if (cicmp("complex") || cicmp("character"))
takeprec();
break;
case 'd':
if (cicmp("double")) {
for (; isspace((unsigned char)*lbp); ++lbp)
continue;
if (!*lbp)
continue;
if (cicmp("precision"))
break;
continue;
}
break;
case 'i':
if (cicmp("integer"))
takeprec();
break;
case 'l':
if (cicmp("logical"))
takeprec();
break;
case 'r':
if (cicmp("real"))
takeprec();
break;
}
for (; isspace((unsigned char)*lbp); ++lbp)
continue;
if (!*lbp)
continue;
switch (*lbp | ' ') {
case 'f':
if (cicmp("function"))
break;
continue;
case 'p':
if (cicmp("program") || cicmp("procedure"))
break;
continue;
case 's':
if (cicmp("subroutine"))
break;
default:
continue;
}
for (; isspace((unsigned char)*lbp); ++lbp)
continue;
if (!*lbp)
continue;
for (cp = lbp + 1; *cp && intoken(*cp); ++cp)
continue;
if ((cp = lbp + 1) != NULL)
continue;
*cp = EOS;
(void)strlcpy(tok, lbp, sizeof(tok));
get_line(); /* process line for ex(1) */
pfnote(tok, lineno);
pfcnt = YES;
}
/*NOTREACHED*/
}
/*
* cicmp --
* do case-independent strcmp
*/
int
cicmp(const char *cp)
{
int len;
char *bp;
for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' ');
++cp, ++len)
continue;
if (!*cp) {
lbp += len;
return (YES);
}
return (NO);
}
static void
takeprec(void)
{
for (; isspace((unsigned char)*lbp); ++lbp)
continue;
if (*lbp == '*') {
for (++lbp; isspace((unsigned char)*lbp); ++lbp)
continue;
if (!isdigit((unsigned char)*lbp))
--lbp; /* force failure */
else
while (isdigit((unsigned char)*++lbp))
continue;
}
}

112
usr.bin/ctags/lisp.c Normal file
View File

@@ -0,0 +1,112 @@
/* $NetBSD: lisp.c,v 1.11 2009/07/13 19:05:40 roy Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)lisp.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: lisp.c,v 1.11 2009/07/13 19:05:40 roy Exp $");
#endif
#endif /* not lint */
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "ctags.h"
/*
* lisp tag functions
* just look for (def or (DEF
*/
void
l_entries(void)
{
int special;
char *cp;
char savedc;
char tok[MAXTOKEN];
for (;;) {
lineftell = ftell(inf);
if (!fgets(lbuf, sizeof(lbuf), inf))
return;
++lineno;
lbp = lbuf;
if (!cicmp("(def"))
continue;
special = NO;
switch(*lbp | ' ') {
case 'm':
if (cicmp("method"))
special = YES;
break;
case 'w':
if (cicmp("wrapper") || cicmp("whopper"))
special = YES;
}
for (; !isspace((unsigned char)*lbp); ++lbp)
continue;
for (; isspace((unsigned char)*lbp); ++lbp)
continue;
for (cp = lbp; *cp && *cp != '\n'; ++cp)
continue;
*cp = EOS;
if (special) {
if (!(cp = strchr(lbp, ')')))
continue;
for (; cp >= lbp && *cp != ':'; --cp)
continue;
if (cp < lbp)
continue;
lbp = cp;
for (; *cp && *cp != ')' && *cp != ' '; ++cp)
continue;
}
else
for (cp = lbp + 1;
*cp && *cp != '(' && *cp != ' '; ++cp)
continue;
savedc = *cp;
*cp = EOS;
(void)strlcpy(tok, lbp, sizeof(tok));
*cp = savedc;
get_line();
pfnote(tok, lineno);
}
/*NOTREACHED*/
}

121
usr.bin/ctags/print.c Normal file
View File

@@ -0,0 +1,121 @@
/* $NetBSD: print.c,v 1.10 2009/07/13 19:05:40 roy Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: print.c,v 1.10 2009/07/13 19:05:40 roy Exp $");
#endif
#endif /* not lint */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ctags.h"
/*
* get_line --
* get the line the token of interest occurred on,
* prepare it for printing.
*/
void
get_line(void)
{
long saveftell;
int c;
int cnt;
char *cp;
saveftell = ftell(inf);
(void)fseek(inf, lineftell, SEEK_SET);
if (xflag)
for (cp = lbuf; GETC(!=, '\n'); *cp++ = c)
continue;
/*
* do all processing here, so we don't step through the
* line more than once; means you don't call this routine
* unless you're sure you've got a keeper.
*/
else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) {
if (c == '\\') { /* backslashes */
if (cnt > ENDLINE - 2)
break;
*cp++ = '\\'; *cp++ = '\\';
++cnt;
}
else if (c == (int)searchar) { /* search character */
if (cnt > ENDLINE - 2)
break;
*cp++ = '\\'; *cp++ = c;
++cnt;
}
else if (c == '\n') { /* end of keep */
*cp++ = '$'; /* can find whole line */
break;
}
else
*cp++ = c;
}
*cp = EOS;
(void)fseek(inf, saveftell, SEEK_SET);
}
/*
* put_entries --
* write out the tags
*/
void
put_entries(NODE *node)
{
if (node->left)
put_entries(node->left);
if (vflag)
printf("%s %s %d\n",
node->entry, node->file, (node->lno + 63) / 64);
else if (xflag)
printf("%-16s%4d %-16s %s\n",
node->entry, node->lno, node->file, node->pat);
else
fprintf(outf, "%s\t%s\t%c^%s%c\n",
node->entry, node->file, searchar, node->pat, searchar);
if (node->right)
put_entries(node->right);
}

View File

@@ -0,0 +1,69 @@
/* $NetBSD: ctags.test,v 1.2 1995/03/26 20:14:14 glass Exp $ */
int bar = (1 + 5);
FOO("here is a #define test: ) {");
char sysent[20];
int nsysent = sizeof (sysent) / sizeof (sysent[0]);
/*
* now is the time for a comment.
* four lines in length...
*/struct struct_xtra{int list;};r4(x,y){};typedef struct{int bar;}struct_xxe;
#define FOO BAR
struct struct_three {
int list;
};
#define SINGLE
int BAD();
enum color {red, green, gold, brown};
char qq[] = " quote(one,two) {int bar;} ";
typedef struct {
int bar;
struct struct_two {
int foo;
union union_3 {
struct struct_three entry;
char size[25];
};
struct last {
struct struct_three xentry;
char list[34];
};
};
} struct_one;
#define TWOLINE ((MAXLIST + FUTURE + 15) \
/ (time_to_live ? 3 : 4))
#if (defined(BAR))
int bar;
#endif
#define MULTIPLE {\
multiple(one,two); \
lineno++; \
callroute(one,two); \
}
#if defined(BAR)
int bar;
#endif
union union_one {
struct struct_three s3;
char foo[25];
};
#define XYZ(A,B) (A + B / 2) * (3 - 26 + l_lineno)
routine1(one,two) /* comments here are fun... */
struct {
int entry;
char bar[34];
} *one;
char two[10];
{
typedef unsigned char u_char;
register struct buf *bp;
five(one,two);
}
routine2 (one,two) { puts("hello\n"); }
routine3
(one,
two) { puts("world\n"); }
routine4(int one, char (*two)(void)) /* test ANSI arguments */
{
}

145
usr.bin/ctags/tree.c Normal file
View File

@@ -0,0 +1,145 @@
/* $NetBSD: tree.c,v 1.12 2006/04/05 19:38:47 dsl Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)tree.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: tree.c,v 1.12 2006/04/05 19:38:47 dsl Exp $");
#endif
#endif /* not lint */
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ctags.h"
static void add_node(NODE *, NODE *);
static void free_tree(NODE *);
/*
* pfnote --
* enter a new node in the tree
*/
void
pfnote(const char *name, int ln)
{
NODE *np;
char *fp;
char nbuf[MAXTOKEN];
/*NOSTRICT*/
if (!(np = (NODE *)malloc(sizeof(NODE)))) {
warnx("too many entries to sort");
put_entries(head);
free_tree(head);
/*NOSTRICT*/
if (!(head = np = (NODE *)malloc(sizeof(NODE))))
err(1, "out of space");
}
if (!xflag && !strcmp(name, "main")) {
if (!(fp = strrchr(curfile, '/')))
fp = curfile;
else
++fp;
(void)snprintf(nbuf, sizeof(nbuf), "M%s", fp);
fp = strrchr(nbuf, '.');
if (fp && !fp[2])
*fp = EOS;
name = nbuf;
}
if (!(np->entry = strdup(name)))
err(1, "strdup");
np->file = curfile;
np->lno = ln;
np->left = np->right = 0;
if (!(np->pat = strdup(lbuf)))
err(1, "strdup");
if (!head)
head = np;
else
add_node(np, head);
}
static void
add_node(NODE *node, NODE *cur_node)
{
int dif;
dif = strcmp(node->entry, cur_node->entry);
if (!dif) {
if (node->file == cur_node->file) {
if (!wflag)
fprintf(stderr, "Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n", node->file, lineno, node->entry);
return;
}
if (!cur_node->been_warned)
if (!wflag)
fprintf(stderr, "Duplicate entry in files %s and %s: %s (Warning only)\n", node->file, cur_node->file, node->entry);
cur_node->been_warned = YES;
}
else if (dif < 0) {
if (cur_node->left)
add_node(node, cur_node->left);
else
cur_node->left = node;
} else {
if (cur_node->right)
add_node(node, cur_node->right);
else
cur_node->right = node;
}
}
static void
free_tree(NODE *node)
{
NODE *nnode;
for (; node != NULL; node = nnode) {
nnode = node->left;
if (node->right) {
if (nnode == NULL)
nnode = node->right;
else
free_tree(node->right);
}
free(node);
}
}

160
usr.bin/ctags/yacc.c Normal file
View File

@@ -0,0 +1,160 @@
/* $NetBSD: yacc.c,v 1.12 2009/07/13 19:05:40 roy Exp $ */
/*
* Copyright (c) 1987, 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. 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: yacc.c,v 1.12 2009/07/13 19:05:40 roy Exp $");
#endif
#endif /* not lint */
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "ctags.h"
/*
* y_entries:
* find the yacc tags and put them in.
*/
void
y_entries(void)
{
int c;
char *sp;
bool in_rule;
char tok[MAXTOKEN];
in_rule = NO;
while (GETC(!=, EOF))
switch (c) {
case '\n':
SETLINE;
/* FALLTHROUGH */
case ' ':
case '\f':
case '\r':
case '\t':
break;
case '{':
if (skip_key('}'))
in_rule = NO;
break;
case '\'':
case '"':
if (skip_key(c))
in_rule = NO;
break;
case '%':
if (GETC(==, '%'))
return;
(void)ungetc(c, inf);
break;
case '/':
if (GETC(==, '*'))
skip_comment('*');
else
(void)ungetc(c, inf);
break;
case '|':
case ';':
in_rule = NO;
break;
default:
if (in_rule || (!isalpha(c) && c != '.' && c != '_'))
break;
sp = tok;
*sp++ = c;
while (GETC(!=, EOF) && (intoken(c) || c == '.'))
*sp++ = c;
*sp = EOS;
get_line(); /* may change before ':' */
if (c == EOF)
return;
while (iswhite(c)) {
if (c == '\n')
SETLINE;
if (GETC(==, EOF))
return;
}
if (c == ':') {
pfnote(tok, lineno);
in_rule = YES;
}
else
(void)ungetc(c, inf);
}
}
/*
* toss_yysec --
* throw away lines up to the next "\n%%\n"
*/
void
toss_yysec(void)
{
int c; /* read character */
int state;
/*
* state == 0 : waiting
* state == 1 : received a newline
* state == 2 : received first %
* state == 3 : received second %
*/
lineftell = ftell(inf);
for (state = 0; GETC(!=, EOF);)
switch (c) {
case '\n':
++lineno;
lineftell = ftell(inf);
if (state == 3) /* done! */
return;
state = 1; /* start over */
break;
case '%':
if (state) /* if 1 or 2 */
++state; /* goto 3 */
break;
default:
state = 0; /* reset */
break;
}
}

21
usr.bin/nvi/Makefile Normal file
View File

@@ -0,0 +1,21 @@
# $NetBSD: Makefile,v 1.3 2008/10/13 18:11:54 dyoung Exp $
.include "Makefile.inc"
.include <bsd.own.mk>
.if defined(__MINIX)
SUBDIR+= build
.else
.if ${MKSHARE} != "no"
SUBDIR+= catalog
.endif
SUBDIR+= build recover
.if ${MKDOC} != "no"
SUBDIR+= docs
.endif
.endif # defined(__MINIX)
.include <bsd.subdir.mk>

6
usr.bin/nvi/Makefile.inc Normal file
View File

@@ -0,0 +1,6 @@
# $NetBSD: Makefile.inc,v 1.2 2008/07/13 03:44:41 christos Exp $
.include <bsd.own.mk>
DIST= ${NETBSDSRCDIR}/dist/nvi
.PATH: ${DIST}

View File

@@ -0,0 +1,69 @@
# $NetBSD: Makefile,v 1.17 2012/03/21 05:44:39 matt Exp $
.include <bsd.own.mk>
USE_WIDECHAR?=yes
CWARNFLAGS.clang+= -Wno-uninitialized -Wno-format-security
CPPFLAGS+=-I${DIST}/include -I${.CURDIR} -I. -DGTAGS
#DBG=-g
#CWARNFLAGS+=-Wno-parentheses -Wno-unused -Wno-missing-prototypes
#.if defined(HAVE_GCC)
#CWARNFLAGS+=-Wno-pointer-sign
#COPTS+=-fno-strict-aliasing
#.endif
LDADD+= -lcurses -lterminfo
DPADD+= ${LIBCURSES} ${LIBTERMINFO}
PROG= vi
SRCS= api.c cl_bsd.c cl_funcs.c cl_main.c cl_read.c cl_screen.c cl_term.c \
conv.c cut.c db.c db1.c delete.c ex.c ex_abbrev.c ex_append.c \
ex_args.c ex_argv.c ex_at.c ex_bang.c ex_cd.c ex_cmd.c ex_cscope.c \
ex_delete.c ex_display.c ex_edit.c ex_equal.c ex_file.c ex_filter.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_perl.c ex_preserve.c ex_print.c ex_put.c \
ex_quit.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_tcl.c \
ex_txt.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 exf.c getc.c gs.c key.c log.c \
main.c mark.c msg.c nothread.c options.c options_f.c put.c recover.c \
screen.c search.c seq.c util.c v_at.c v_ch.c v_cmd.c v_delete.c \
v_event.c v_ex.c v_increment.c v_init.c v_itxt.c v_left.c v_mark.c \
v_match.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_txt.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 vi.c vs_line.c vs_msg.c vs_refresh.c vs_relative.c \
vs_smap.c vs_split.c
# For wide char support
.if ${USE_WIDECHAR} == "yes"
SRCS+= regcomp.c regerror.c regexec.c regfree.c
CPPFLAGS+=-I${DIST}/regex -D__REGEX_PRIVATE -DUSE_WIDECHAR
.endif
LINKS= ${BINDIR}/vi ${BINDIR}/ex ${BINDIR}/vi ${BINDIR}/view
MLINKS= vi.1 ex.1 vi.1 view.1
DPSRCS+=options_def.h
CLEANFILES+=options_def.h
options_def.h: options.awk options.c
${_MKTARGET_CREATE}
${TOOL_AWK} -f ${.ALLSRC} >${.TARGET}
.include "../Makefile.inc"
.include "../../Makefile.inc"
WARNS= 4
.PATH: ${DIST}/vi ${DIST}/ex ${DIST}/cl
.PATH: ${DIST}/common
.PATH: ${DIST}/regex
.PATH: ${DIST}/docs/vi.man
COPTS.exf.c += -Wno-format-nonliteral
COPTS.msg.c += -Wno-format-nonliteral
.include <bsd.prog.mk>

291
usr.bin/nvi/build/config.h Normal file
View File

@@ -0,0 +1,291 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.in by autoheader. */
/* Id: acconfig.h,v 8.34 2002/01/19 23:01:35 skimo Exp (Berkeley) Date: 2002/01/19 23:01:35 */
/* Define to `int' if <sys/types.h> doesn't define. */
/* #undef ssize_t */
/* Define if you want a debugging version. */
/* #undef DEBUG */
/* Define if you have a System V-style (broken) gettimeofday. */
/* #undef HAVE_BROKEN_GETTIMEOFDAY */
/* Define if you have a Ultrix-style (broken) vdisable. */
/* #undef HAVE_BROKEN_VDISABLE */
/* Define if you have a BSD version of curses. */
/* #undef HAVE_BSD_CURSES */
/* Define if you have wide ncurses(3). */
/* #undef HAVE_NCURSESW */
/* Define if you have the curses(3) waddnwstr function. */
/* #undef HAVE_CURSES_ADDNWSTR */
/* Define if you have the curses(3) waddnstr function. */
#define HAVE_CURSES_WADDNSTR 1
/* Define if you have the curses(3) beep function. */
#define HAVE_CURSES_BEEP 1
/* Define if you have the curses(3) flash function. */
#define HAVE_CURSES_FLASH 1
/* Define if you have the curses(3) idlok function. */
#define HAVE_CURSES_IDLOK 1
/* Define if you have the curses(3) keypad function. */
#define HAVE_CURSES_KEYPAD 1
/* Define if you have the curses(3) newterm function. */
#define HAVE_CURSES_NEWTERM 1
/* Define if you have the curses(3) setupterm function. */
#define HAVE_CURSES_SETUPTERM 1
/* Define if you have the curses(3) tigetstr/tigetnum functions. */
#define HAVE_CURSES_TIGETSTR 1
/* Define if you have the DB __hash_open call in the C library. */
/* #undef HAVE_DB_HASH_OPEN */
/* Define if you have the chsize(2) system call. */
/* #undef HAVE_FTRUNCATE_CHSIZE */
/* Define if you have the ftruncate(2) system call. */
#define HAVE_FTRUNCATE_FTRUNCATE 1
/* Define if you have gcc. */
#define HAVE_GCC 1
/* Define if you have fcntl(2) style locking. */
/* #undef HAVE_LOCK_FCNTL */
/* Define if you have flock(2) style locking. */
#define HAVE_LOCK_FLOCK 1
/* Define is appropriate pango is available */
/* #undef HAVE_PANGO */
/* Define if you want to compile in the Perl interpreter. */
/* #undef HAVE_PERL_INTERP */
/* Define if using pthread. */
/* #undef HAVE_PTHREAD */
#ifndef __minix
/* Define if you have the Berkeley style revoke(2) system call. */
#define HAVE_REVOKE 1
#endif
/* Define if you have the Berkeley style strsep(3) function. */
#define HAVE_STRSEP 1
/* Define if you have <sys/mman.h> */
#define HAVE_SYS_MMAN_H 1
/* Define if you have <sys/select.h> */
#define HAVE_SYS_SELECT_H 1
#ifndef __minix
/* Define if you have the System V style pty calls. */
#define HAVE_SYS5_PTY 1
#endif
/* Define if you want to compile in the Tcl interpreter. */
/* #undef HAVE_TCL_INTERP */
/* Define is appropriate zvt is available */
/* #undef HAVE_ZVT */
/* Define if your sprintf returns a pointer, not a length. */
/* #undef SPRINTF_RET_CHARPNT */
/* Define when using db1 */
#define USE_DB1 1
/* Define when using db4 logging */
/* #undef USE_DB4_LOGGING */
/* Define when dynamically loading DB 3 */
/* #undef USE_DYNAMIC_LOADING */
/* Define when iconv can be used */
#define USE_ICONV 1
/* Define when perl's setenv should be used */
/* #undef USE_PERL_SETENV */
/* Define when using S-Lang */
/* #undef USE_SLANG_CURSES */
/* Define when using wide characters */
/* #undef USE_WIDECHAR */
/* Define if you have <ncurses.h> */
/* #undef HAVE_NCURSES_H */
/* Define when fprintf prototype not in an obvious place */
/* #undef NEED_FPRINTF_PROTO */
/* Define to 1 if you have the `bsearch' function. */
#define HAVE_BSEARCH 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the `fork' function. */
#define HAVE_FORK 1
/* Define to 1 if you have the `gethostname' function. */
#define HAVE_GETHOSTNAME 1
/* Define to 1 if you have the `getpagesize' function. */
#define HAVE_GETPAGESIZE 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `iswblank' function. */
#define HAVE_ISWBLANK 1
/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY 1
/* Define to 1 if you have the `memchr' function. */
#define HAVE_MEMCHR 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the `mkstemp' function. */
#define HAVE_MKSTEMP 1
/* Define to 1 if you have a working `mmap' system call. */
#define HAVE_MMAP 1
/* Define to 1 if you have the <ncursesw/ncurses.h> header file. */
/* #undef HAVE_NCURSESW_NCURSES_H */
/* Define to 1 if you have the <ncurses.h> header file. */
/* #undef HAVE_NCURSES_H */
/* Define to 1 if you have the `select' function. */
#define HAVE_SELECT 1
/* Define to 1 if you have the `setenv' function. */
#define HAVE_SETENV 1
/* Define to 1 if you have the `snprintf' function. */
#define HAVE_SNPRINTF 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `strpbrk' function. */
#define HAVE_STRPBRK 1
/* Define to 1 if you have the `strsep' function. */
#define HAVE_STRSEP 1
/* Define to 1 if `st_blksize' is member of `struct stat'. */
#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
/* Define to 1 if your `struct stat' has `st_blksize'. Deprecated, use
`HAVE_STRUCT_STAT_ST_BLKSIZE' instead. */
#define HAVE_ST_BLKSIZE 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the `unsetenv' function. */
#define HAVE_UNSETENV 1
/* Define to 1 if you have the `vfork' function. */
#define HAVE_VFORK 1
/* Define to 1 if you have the <vfork.h> header file. */
/* #undef HAVE_VFORK_H */
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
/* Define to 1 if `fork' works. */
#define HAVE_WORKING_FORK 1
/* Define to 1 if `vfork' works. */
#define HAVE_WORKING_VFORK 1
/* Name of package */
#define PACKAGE "vi"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME ""
/* Define to the full name and version of this package. */
#define PACKAGE_STRING ""
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""
/* Define to the version of this package. */
#define PACKAGE_VERSION ""
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
/* #undef TM_IN_SYS_TIME */
/* Version number of package */
#define VERSION "1.81.6"
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/* #undef WORDS_BIGENDIAN */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef mode_t */
/* Define to `long int' if <sys/types.h> does not define. */
/* #undef off_t */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef pid_t */
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef ssize_t */
/* Define as `fork' if `vfork' does not work. */
/* #undef vfork */

View File

@@ -0,0 +1,49 @@
/* Id: pathnames.h.in,v 8.5 2000/04/21 21:26:21 skimo Exp (Berkeley) Date: 2000/04/21 21:26:21 */
#ifndef _PATH_BSHELL
#define _PATH_BSHELL "/bin/sh"
#endif
#ifndef _PATH_DB3
#define _PATH_DB3 ""
#endif
#ifndef _PATH_EXRC
#define _PATH_EXRC ".exrc"
#endif
#ifndef _PATH_MSGCAT
#define _PATH_MSGCAT "./"
#endif
#ifndef _PATH_NEXRC
#define _PATH_NEXRC ".nexrc"
#endif
#ifndef _PATH_PRESERVE
#define _PATH_PRESERVE "/var/tmp/vi.recover"
#endif
#ifndef _PATH_SYSV_PTY
#define _PATH_SYSV_PTY "/dev/ptmx"
#endif
#ifndef _PATH_SENDMAIL
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#endif
#ifndef _PATH_SYSEXRC
#define _PATH_SYSEXRC "/etc/vi.exrc"
#endif
#ifndef _PATH_TAGS
#define _PATH_TAGS "tags"
#endif
#ifndef _PATH_TMP
#define _PATH_TMP "/tmp"
#endif
#ifndef _PATH_TTY
#define _PATH_TTY "/dev/tty"
#endif

201
usr.bin/nvi/build/port.h Normal file
View File

@@ -0,0 +1,201 @@
/* Id: port.h.in,v 8.15 2001/01/01 20:26:48 skimo Exp (Berkeley) Date: 2001/01/01 20:26:48 */
/*
* Declare the basic types, if they aren't already declared. Named and
* some system's db.h files protect them with __BIT_TYPES_DEFINED__.
*/
#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__
#endif
/*
* XXX
* Handle function prototypes. This steps on name space that vi doesn't
* control, but all of the other solutions are worse.
*/
#undef __P
#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos /* ANSI C prototypes */
#else
#define __P(protos) () /* K&R C preprocessor */
#endif
/*
* XXX
* Some versions of System V changed the number of arguments to gettimeofday
* without changing the name.
*/
#ifdef HAVE_BROKEN_GETTIMEOFDAY
#define gettimeofday(tv, tz) gettimeofday(tv)
#endif
/*
* XXX
* If we don't have mmap, we fake it with read and write, but we'll
* still need the header information.
*/
#ifndef HAVE_SYS_MMAN_H
#define MAP_SHARED 1 /* share changes */
#define MAP_PRIVATE 2 /* changes are private */
#define PROT_READ 0x1 /* pages can be read */
#define PROT_WRITE 0x2 /* pages can be written */
#define PROT_EXEC 0x4 /* pages can be executed */
#endif
/*
* XXX
* POSIX 1003.1 names for file descriptors.
*/
#ifndef STDERR_FILENO
#define STDIN_FILENO 0 /* ANSI C #defines */
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#endif
/*
* XXX
* POSIX 1003.1 names for seek settings.
*/
#ifndef SEEK_END
#define SEEK_SET 0 /* POSIX 1003.1 seek values */
#define SEEK_CUR 1
#define SEEK_END 2
#endif
/*
* Hack _POSIX_VDISABLE to \377 since Ultrix doesn't honor _POSIX_VDISABLE
* (treats it as ^@). The symptom is that the ^@ keystroke immediately
* drops core.
*/
#ifdef HAVE_BROKEN_VDISABLE
#undef _POSIX_VDISABLE
#define _POSIX_VDISABLE ((unsigned char)'\377')
#endif
/*
* XXX
* POSIX 1003.1 tty disabling character.
*/
#ifndef _POSIX_VDISABLE
#define _POSIX_VDISABLE 0 /* Some systems used 0. */
#endif
/*
* XXX
* 4.4BSD extension to only set the software termios bits.
*/
#ifndef TCSASOFT /* 4.4BSD extension. */
#define TCSASOFT 0
#endif
/*
* XXX
* POSIX 1003.1 maximum path length.
*/
#ifndef MAXPATHLEN
#ifdef PATH_MAX
#define MAXPATHLEN PATH_MAX
#else
#define MAXPATHLEN 1024
#endif
#endif
/*
* XXX
* MIN, MAX, historically in <sys/param.h>
*/
#ifndef MAX
#define MAX(_a,_b) ((_a)<(_b)?(_b):(_a))
#endif
#ifndef MIN
#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
#endif
#ifndef USE_DB1
/*
* XXX
* "DB" isn't always portable, and we want the private information.
*/
#define DB L__DB
#undef pgno_t /* IRIX has its own version. */
#define pgno_t L__db_pgno_t
#endif /* USE_DB1 */
/*
* XXX
* 4.4BSD extension to provide lock values in the open(2) call.
*/
#ifndef O_EXLOCK
#define O_EXLOCK 0
#endif
#ifndef O_SHLOCK
#define O_SHLOCK 0
#endif
/*
* XXX
* POSIX 1003.1 bad file format errno.
*/
#ifndef EFTYPE
#define EFTYPE EINVAL
#endif
/*
* XXX
* POSIX 1003.2 RE length limit.
*/
#ifndef _POSIX2_RE_DUP_MAX
#define _POSIX2_RE_DUP_MAX 255
#endif
/*
* XXX
* 4.4BSD extension to determine if a program dropped core from the exit
* status.
*/
#ifndef WCOREDUMP
#define WCOREDUMP(a) 0
#endif
/*
* XXX
* Endian-ness of the machine.
*/
#if !defined(LITTLE_ENDIAN)
#define LITTLE_ENDIAN 1234
#endif
#if !defined(BIG_ENDIAN)
#define BIG_ENDIAN 4321
#endif
#if !defined(BYTE_ORDER)
#if WORDS_BIGENDIAN == 1
#define BYTE_ORDER BIG_ENDIAN
#else
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#endif
#ifndef HAVE_MEMCPY
#define memcpy memmove
#endif
#ifdef NEED_FPRINTF_PROTO
extern int fprintf( FILE *, const char *, ... );
#endif
#ifdef HAVE_PTHREAD
#define VI_DB_THREAD DB_THREAD
#else
#define VI_DB_THREAD 0
#endif

View File

@@ -0,0 +1,101 @@
# $NetBSD: Makefile,v 1.6 2008/10/25 22:27:39 apb Exp $
#
# @(#)Makefile 8.29 (Berkeley) 10/19/96
NOMAN= # defined
.include "../Makefile.inc"
.PATH: ${DIST}/catalog
CATALOG= dutch english french german ru_RU.KOI8-R spanish swedish
VI_FILES= ${DIST}/cl/*.c ${DIST}/common/*.c \
${DIST}/ex/*.c ${DIST}/vi/*.c
FILES= ${CATALOG}
FILESDIR= /usr/share/nvi/catalog
HOSTPROG= dump
SRCS= dump.c
CLEANFILES+= ${CATALOG} english.base *.check __ck1 __ck2
realall: ${CATALOG}
${CATALOG}: ${CATALOG:S/$/.base/}
@echo "... $@"; \
rm -f $@; \
if test -f $@.base; then \
f=$@.base; \
else \
f=${DIST}/catalog/$@.base; \
fi; \
sort -u $$f | \
${TOOL_AWK} '{ \
if ($$1 == 1) { \
print "\nMESSAGE NUMBER 1 IS NOT LEGAL"; \
exit 1; \
} \
if (++nline > $$1) { \
print "DUPLICATE MESSAGE NUMBER " $$1; \
exit 1; \
} \
for (; nline < $$1; ++nline) \
print ""; \
print $0; \
}' | \
${TOOL_SED} -e '1s/^/VI_MESSAGE_CATALOG/' \
-e '/"/s/^[^"]*"//' \
-e '1!s/"$$/X/' > $@; \
if grep DUPLICATE $@ > /dev/null; then \
grep DUPLICATE $@; \
fi; \
if grep 'NOT LEGAL' $@ > /dev/null; then \
grep 'NOT LEGAL' $@; \
fi
CHK= dutch.check english.check french.check german.check \
ru_RU.KOI8-R.check spanish.check swedish.check
check: ${CHK}
${CHK}: ${CATALOG}
@echo "... $@"; \
f=${DIST}/catalog/`basename $@ .check`; \
(echo "Unused message id's (this is okay):"; \
${TOOL_AWK} '{ \
while (++nline < $$1) \
printf "%03d\n", nline; \
}' < ${DIST}/catalog/$$f.base; \
echo =========================; \
echo "MISSING ERROR MESSAGES (Please add!):"; \
${TOOL_AWK} '{print $$1}' < $$f.base | sort -u > __ck1; \
${TOOL_AWK} '{print $$1}' < english.base | sort -u > __ck2; \
comm -13 __ck1 __ck2; \
echo =========================; \
echo "Extra error messages (just delete them):"; \
comm -23 __ck1 __ck2; \
echo =========================; \
echo "MESSAGES WITH THE SAME MESSAGE ID's (FIX!):"; \
for j in \
`${TOOL_SED} '/^$$/d' < $$f.base | sort -u | \
${TOOL_AWK} '{print $$1}' | uniq -d`; do \
egrep $$j $$f.base; \
done; \
echo =========================; \
echo "Duplicate messages, both id and message (this is okay):"; \
${TOOL_SED} '/^$$/d' < $$f.base | sort | uniq -c | \
${TOOL_AWK} '$$1 != 1 { print $$0 }' | sort -n; \
echo =========================; \
echo "Duplicate messages, just message (this is okay):"; \
${TOOL_SED} '/^$$/d' < $$f | sort | uniq -c | \
${TOOL_AWK} '$$1 != 1 { print $$0 }' | sort -n; \
echo =========================) > $@
english.base: dump ${VI_FILES} #Makefile
${_MKTARGET_CREATE}
./dump ${VI_FILES} |\
${TOOL_SED} -e '/|/!d' \
-e 's/|/ "/' \
-e 's/^"//' \
-e 's/\\"/"/g' |\
sort -n > $@
.include <bsd.hostprog.mk>

View File

@@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
SUBDIR= USD.doc info
.include <bsd.subdir.mk>

View File

@@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
SUBDIR= edit exref vi.ref vitut
.include <bsd.subdir.mk>

View File

@@ -0,0 +1,24 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
#
# @(#)Makefile 8.1 (Berkeley) 6/8/93
.include "../../../Makefile.inc"
.PATH: ${DIST}/docs/edit
DIR= usd/11.edit
SRCS= edittut.ms
MACROS= -ms
all: paper.ps
paper.ps: ${SRCS}
${TOOL_TBL} ${.ALLSRC} | ${TOOL_ROFF_PS} ${MACROS} > ${.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:
${TOOL_ROFF_RAW} ${MACROS} -n22 edit.vindex
.include <bsd.doc.mk>

View File

@@ -0,0 +1,113 @@
.\" $NetBSD: edit.vindex,v 1.1 2008/09/02 09:25:39 christos Exp $
.\"
.\" 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. 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

View File

@@ -0,0 +1,21 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
#
# @(#)Makefile 8.8 (Berkeley) 10/10/96
.include "../../../Makefile.inc"
.PATH: ${DIST}/docs/exref
DIR= usd/12.ex
SRCS= ex.rm ex.summary
MACROS= -ms
CLEANFILES= summary.ps
all: paper.ps summary.ps
paper.ps: ex.rm
${TOOL_TBL} ${.ALLSRC} | ${TOOL_ROFF_PS} ${MACROS} > ${.TARGET}
summary.ps: ex.summary
${TOOL_TBL} ${.ALLSRC} | ${TOOL_ROFF_PS} ${MACROS} > ${.TARGET}
.include <bsd.doc.mk>

View File

@@ -0,0 +1,35 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
#
# @(#)Makefile 8.20 (Berkeley) 8/18/96
DIR= usd/13.viref
SRCS= vi.ref ex.cmd.roff set.opt.roff vi.cmd.roff ref.so
MACROS= -me
CLEANFILES+= vi.ref.txt vi.ref.ps index index.so
all: vi.ref.txt vi.ref.ps
vi.ref.txt: vi.ref index.so
${TOOL_SOELIM} vi.ref | ${TOOL_TBL} | ${TOOL_ROFF_ASCII} ${MACROS} > $@
rm -f index
chmod 444 $@
vi.ref.ps: vi.ref index.so
${TOOL_SOELIM} vi.ref | ${TOOL_TBL} | ${TOOL_ROFF_PS} ${MACROS} > $@
rm -f index
chmod 444 $@
index.so: vi.ref
# Build index.so, side-effect of building the paper.
${TOOL_SOELIM} vi.ref | ${TOOL_TBL} | \
${TOOL_ROFF_PS} ${MACROS} > /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' > $@
rm -f index
chmod 444 $@
.include <bsd.doc.mk>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
# $NetBSD: merge.awk,v 1.1 2008/09/02 09:25:39 christos Exp $
#
# @(#)merge.awk 8.3 (Berkeley) 5/25/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"
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
#
# @(#)Makefile 8.7 (Berkeley) 8/18/96
.include "../../../Makefile.inc"
.PATH: ${DIST}/docs/vitut
DIR= usd/12.vi
SRCS= vi.in vi.chars
MACROS= -ms
CLEANFILES+= vitut.ps summary.ps viapwh.ps
all: vitut.ps summary.ps viapwh.ps
vitut.ps: ${SRCS}
${TOOL_TBL} ${.ALLSRC} | ${TOOL_ROFF_PS} ${MACROS} > $@
chmod 444 $@
summary.ps: vi.summary
${TOOL_TBL} ${.ALLSRC} | ${TOOL_ROFF_PS} ${MACROS} > $@
chmod 444 $@
viapwh.ps: vi.apwh.ms
${TOOL_TBL} ${.ALLSRC} | ${TOOL_ROFF_PS} ${MACROS} > $@
chmod 444 $@
.include <bsd.doc.mk>

55
usr.bin/nvi/docs/ev Normal file
View File

@@ -0,0 +1,55 @@
# @(#)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.

230
usr.bin/nvi/docs/help Normal file
View File

@@ -0,0 +1,230 @@
MOVING THE CURSOR:
k - cursor up ^F - page forward /<pattern><CR> - search forward
j - cursor down ^B - page backward ?<pattern><CR> - search backward
h - cursor left w - move forward a "word" n - repeat the last search
l - cursor right b - move backward a "word"
ENTERING TEXT:
a - append after the cursor. Use the <escape> key to return to
i - insert before the cursor. command mode.
o - open a new line below the cursor.
O - open new line above the cursor.
WRITING AND EXITING:
:w<Enter> - write the file
:q<Enter> - exit the file
:q!<Enter> - exit without writing the file
:#<Enter> - move to a line (e.g., :35<Enter> moves to line 35)
MISCELLANEOUS:
^G - display the file name
J - join two lines (use i<Enter><escape> to split a line)
u - undo the last change (enter . after a 'u' to undo more than one change)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
VI COMMANDS:
^A search forward for cursor word
^B scroll up by screens
^C interrupt an operation (e.g. read, write, search)
^D scroll down by half screens (setting count)
^E scroll down by lines
^F scroll down by screens
^G file status
^H move left by characters
^J move down by lines
^L redraw screen
^M move down by lines (to first non-blank)
^N move down by lines
^P move up by lines
^R redraw screen
^T tag pop
^U half page up (set count)
^V input a literal character
^W move to next screen
^Y page up by lines
^Z suspend editor
^[ <escape> exit input mode, cancel partial commands
^\ switch to ex mode
^] tag push cursor word
^^ switch to previous file
<space> move right by columns
! filter through command(s) to motion
# number increment/decrement
$ move to last column
% move to match
& repeat substitution
' move to mark (to first non-blank)
( move back sentence
) move forward sentence
+ move down by lines (to first non-blank)
, reverse last F, f, T or t search
- move up by lines (to first non-blank)
. repeat the last command
/ search forward
0 move to first character
: ex command
; repeat last F, f, T or t search
< shift lines left to motion
> shift lines right to motion
? search backward
@ execute buffer
A append to the line
B move back bigword
C change to end-of-line
D delete to end-of-line
E move to end of bigword
F character in line backward search
G move to line
H move to count lines from screen top
I insert before first nonblank
J join lines
L move to screen bottom
M move to screen middle
N reverse last search
O insert above line
P insert before cursor from buffer
Q switch to ex mode
R replace characters
S substitute for the line(s)
T before character in line backward search
U Restore the current line
W move to next bigword
X delete character before cursor
Y copy line
ZZ save file and exit
[[ move back section
]] move forward section
^ move to first non-blank
_ move to first non-blank
` move to mark
a append after cursor
b move back word
c change to motion
d delete to motion
e move to end of word
f character in line forward search
h move left by columns
i insert before cursor
j move down by lines
k move up by lines
l move right by columns
m set mark
n repeat last search
o append after line
p insert after cursor from buffer
r replace character
s substitute character
t before character in line forward search
u undo last change
w move to next word
x delete character
y copy text to motion into a cut buffer
z reposition the screen
{ move back paragraph
| move to column
} move forward paragraph
~ reverse case
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
EX COMMANDS:
^D: scroll lines
!: filter lines through commands or run commands
#: display numbered lines
&: repeat the last subsitution
*: execute a buffer
<: shift lines left
=: display line number
>: shift lines right
@: execute a buffer
append: append input to a line
abbreviate: specify an input abbreviation
args: display file argument list
bg: background the current screen
change: change lines to input
cd: change the current directory
chdir: change the current directory
copy: copy lines elsewhere in the file
cscope: create a set of tags using a cscope command
delete: delete lines from the file
display: display buffers, screens or tags
[Ee]dit: begin editing another file
[Ee]x: begin editing another file
exusage: display ex command usage statement
file: display (and optionally set) file name
fg: switch the current screen and a backgrounded screen
global: execute a global command on lines matching an RE
help: display help statement
insert: insert input before a line
join: join lines into a single line
k: mark a line position
list: display lines in an unambiguous form
move: move lines elsewhere in the file
mark: mark a line position
map: map input or commands to one or more keys
mkexrc: write a .exrc file
[Nn]ext: edit (and optionally specify) the next file
number: change display to number lines
open: enter "open" mode (not implemented)
print: display lines
perl: run the perl interpreter with the command
perldo: run the perl interpreter with the command, on each line
preserve: preserve an edit session for recovery
[Pp]revious: edit the previous file in the file argument list
put: append a cut buffer to the line
quit: exit ex/vi
read: append input from a command or file to the line
recover: recover a saved file
resize: grow or shrink the current screen
rewind: re-edit all the files in the file argument list
s: substitute on lines matching an RE
script: run a shell in a screen
set: set options (use ":set all" to see all options)
shell: suspend editing and run a shell
source: read a file of ex commands
stop: suspend the edit session
suspend: suspend the edit session
t: copy lines elsewhere in the file
[Tt]ag: edit the file containing the tag
tagnext: move to the next tag
tagpop: return to the previous group of tags
tagprev: move to the previous tag
tagtop: discard all tags
tcl: run the tcl interpreter with the command
undo: undo the most recent change
unabbreviate: delete an abbreviation
unmap: delete an input or command map
v: execute a global command on lines NOT matching an RE
version: display the program version information
visual: enter visual (vi) mode from ex mode
[Vv]isual: edit another file (from vi mode only)
viusage: display vi key usage statement
write: write the file
wn: write the file and switch to the next file
wq: write the file and exit
xit: exit
yank: copy lines to a cut buffer
z: display different screens of the file
~: replace previous RE with previous replacement string,
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Edit options:
noaltwerase filec="" nomodeline scroll=17 notildeop
autoindent flash msgcat="./" nosearchincr timeout
autoprint hardtabs=0 noprint="" nosecure nottywerase
noautowrite noiclower nonumber shiftwidth=8 noverbose
backup="" noignorecase nooctal noshowmatch warn
nobeautify keytime=6 open noshowmode window=35
cedit="" noleftright optimize sidescroll=16 nowindowname
columns=80 lines=36 print="" noslowopen wraplen=0
comment nolisp prompt nosourceany wrapmargin=0
noedcompatible nolist readonly tabstop=8 wrapscan
escapetime=1 lock noredraw taglength=0 nowriteany
noerrorbells magic remap tags="tags"
exrc matchtime=7 report=5 term="xterm"
noextended mesg ruler noterse
cdpath="/usr/src/local/nvi:/tmp"
directory="/tmp"
matchchars="[]{}()<>"
paragraphs="IPLPPPQPP LIpplpipbp"
recdir="/var/tmp/vi.recover"
sections="NHSHH HUnhsh"
shell="/bin/csh"
shellmeta="~{[*?$`'"\"

View File

@@ -0,0 +1,12 @@
# $NetBSD: Makefile,v 1.2 2008/12/09 23:49:42 lukem Exp $
.include "${.CURDIR}/../../Makefile.inc"
.PATH: ${DIST}/docs/vi.ref
TEXINFO= vi.texi
INFOFLAGS= -I${DIST}/doc
vi.info: ref.texi vi.cmd.texi ex.cmd.texi set.opt.texi
.include <bsd.info.mk>

View File

@@ -0,0 +1,88 @@
# @(#)autowrite 8.3 (Berkeley) 2/17/95
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.

View File

@@ -0,0 +1,32 @@
# @(#)context 8.6 (Berkeley) 10/14/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, v
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.

View File

@@ -0,0 +1,76 @@
# @(#)gdb.script 8.5 (Berkeley) 5/4/96
# display the VI screen map
# usage dmap(sp)
define dmap
set $h = ((VI_PRIVATE *)$arg0->vi_private)->h_smap
set $t = ((VI_PRIVATE *)$arg0->vi_private)->t_smap
while ($h <= $t)
printf "lno: %2d; soff %d coff %d ", \
(int)$h->lno, (int)$h->soff, (int)$h->coff
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 VI screen map
define tmap
set $h = ((VI_PRIVATE *)$arg0->vi_private)->h_smap
set $t = ((VI_PRIVATE *)$arg0->vi_private)->t_smap
while ($t >= $h)
printf "lno: %2d; soff %d coff %d ", \
(int)$t->lno, (int)$t->soff, (int)$t->coff
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 clp
print *((CL_PRIVATE *)sp->gp->cl_private)
end
define vip
print *((VI_PRIVATE *)sp->vi_private)
end
define exp
print *((EX_PRIVATE *)sp->ex_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

View File

@@ -0,0 +1,350 @@
# @(#)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 ===
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

View File

@@ -0,0 +1,36 @@
@(#)openmode 8.1 (Berkeley) 10/29/94
Open mode has the following special behaviors:
z, ^F, ^B:
If count is not specified, it shall default to the window
edit option - 2.
Write lines from the edit buffer starting at:
(the current line) - ((count - 2) / 2)
until:
(((count + 1) / 2) * 2) - 1
lines, or the last line in the edit buffer has been written. A
line consisting of the smaller of the number of columns in the
display divided by two or 40 ``-'' characters shall be written
immediately before and after the specified is written. These two
lines shall count against the total number of lines to be written.
A blank line shall be written after the last line is written.
z, ^F and ^B all behave identically.
^D: Display the next scroll value lines, change the current line.
^U: Change the current line, do nothing else.
^E, ^Y: Do nothing.
^L: Clear the screen and redisplay the current line.
H, L, M:
Move to the first nonblank of the current line and do nothing
else.

View File

@@ -0,0 +1,208 @@
# @(#)quoting 5.5 (Berkeley) 11/12/94
QUOTING IN EX/VI:
There are four escape characters in historic ex/vi:
\ (backslashes)
^V
^Q (assuming it wasn't used for IXON/IXOFF)
The terminal literal next character.
Vi did not use the lnext character, it always used ^V (or ^Q).
^V and ^Q were equivalent in all cases for vi.
There are four different areas in ex/vi where escaping characters
is interesting:
1: In vi text input mode.
2: In vi command mode.
3: In ex command and text input modes.
4: In the ex commands themselves.
1: Vi text input mode (a, i, o, :colon commands, etc.):
The set of characters that users might want to escape are as follows.
As ^L and ^Z were not special in input mode, they are not listed.
carriage return (^M)
escape (^[)
autoindents (^D, 0, ^, ^T)
erase (^H)
word erase (^W)
line erase (^U)
newline (^J) (not historic practice)
Historic practice was that ^V was the only way to escape any
of these characters, and that whatever character followed
the ^V was taken literally, e.g. ^V^V is a single ^V. I
don't see any strong reason to make it possible to escape
^J, so I'm going to leave that alone.
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.
Abbreviations were not performed if the non-word character
that triggered the abbreviation was escaped by a ^V. Input
maps were not triggered if any part of the map was escaped
by a ^V.
The historic vi implementation for the 'r' command requires
two leading ^V's to replace a character with a literal
character. This is obviously a bug, and should be fixed.
2: Vi command mode
Command maps were not triggered if the second or later
character of a map was escaped by a ^V.
The obvious extension is that ^V should keep the next command
character from being mapped, so you can do ":map x xxx" and
then enter ^Vx to delete a single character.
3: Ex command and text input modes.
As ex ran in canonical mode, there was little work that it
needed to do for quoting. The notable differences between
ex and vi are that it was possible to escape a <newline> in
the ex command and text input modes, and ex used the "literal
next" character, not control-V/control-Q.
4: The ex commands:
Ex commands are delimited by '|' or newline characters.
Within the commands, whitespace characters delimit the
arguments. Backslash will generally escape any following
character. In the abbreviate, unabbreviate, map and unmap
commands, control-V escapes the next character, instead.
This is historic behavior in vi, although there are special
cases where it's impossible to escape a character, generally
a whitespace character.
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)
Since file names are also subject to word expansion, the
underlying shell had better be doing the correct backslash
escaping. This is NOT historic behavior in vi, making it
impossible to insert a whitespace, newline or carriage return
character into a file name.
4: Escaping characters in non-file arguments in ex commands:
:abbreviate word string (word, string)
* :edit [+cmd] [file] (+cmd)
* :ex [+cmd] [file] (+cmd)
:map word string (word, string)
* :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.

View File

@@ -0,0 +1,68 @@
# @(#)structures 5.4 (Berkeley) 10/4/95
There are three major data structures in this package, plus a single data
structure per screen type. The first is a single global structure (GS)
which contains information common to all files and screens. It hold
global things like the input key queues, and functions as a single place
to hang things. For example, interrupt routines have to be able to find
screen structures, and they can only do this if they have a starting
point. The number of globals in nvi is dependent on the screen type, but
every screen type will have at least one global, __global_list, which
references the GS structure.
The GS structure contains linked lists of screen (SCR) structures.
Each SCR structure normally references a file (EXF) structure.
The GS 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 never goes away. The SCR structure persists over
instances of screens, and the EXF structure persists over references to
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, which usually
references an underlying EXF structure. 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 various ex commands will substitute a new EXF in place of the current
one, and there's no way to detect this.
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.
CL The curses screen private data structure. Everything to
do standalone curses screens.
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.
TK The Tcl/Tk screen private data structure. Everything to
do standalone Tcl/Tk screens.
EXCMD In nvi/ex/ex.h. 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.)
VICMD In nvi/vi/vi.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.)

View File

@@ -0,0 +1,7 @@
# $NetBSD: Makefile,v 1.1 2008/09/02 09:25:39 christos Exp $
SCRIPTS = virecover
SCRIPTSDIR = /usr/libexec
MAN= virecover.8
.include <bsd.prog.mk>

View File

@@ -0,0 +1,49 @@
#!/bin/sh -
#
# $NetBSD: virecover,v 1.1 2008/09/02 09:25:39 christos Exp $
#
# @(#)recover.in 8.8 (Berkeley) 10/10/96
#
# Script to recover nvi edit sessions.
RECDIR="/var/tmp/vi.recover"
SENDMAIL="/usr/sbin/sendmail"
# 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 ! -f $i || 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

View File

@@ -0,0 +1,90 @@
.\" $NetBSD: virecover.8,v 1.1 2008/09/02 09:25:39 christos Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jeremy C. Reed.
.\"
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd October 9, 2006
.Dt VIRECOVER 8
.Os
.Sh NAME
.Nm virecover
.Nd report recovered vi edit sessions
.Sh SYNOPSIS
.Pa /usr/libexec/virecover
.Sh DESCRIPTION
The
.Nm
utility sends emails to users who have
.Xr vi 1
recovery files.
.Pp
This email gives the name of the file that was
saved for recovery and instructions for recovering
most, if not all, of the changes to the file.
This is done by using the
.Fl r
option with
.Xr vi 1 .
See the
.Fl r
option in
.Xr vi 1
for details.
.Pp
If the backup files have the execute bit set or are zero length,
then they have not been modified, so
.Nm
deletes them to clean up.
.Nm
also removes recovery files that are corrupted, zero length,
or do not have a corresponding backup file.
.Pp
.Nm
is normally run automatically at boot time using
.Pa /etc/rc.d/virecover .
.Sh FILES
.Bl -tag -width "/var/tmp/vi.recover/recover.*" -compact
.It Pa /var/tmp/vi.recover/recover.*
.Xr vi 1
recovery files
.It Pa /var/tmp/vi.recover/vi.*
.Xr vi 1
editor backup files
.El
.Sh SEE ALSO
.Xr vi 1 ,
.Xr rc.conf 5
.Sh HISTORY
This script, previously known as
.Nm recover.script ,
is from nvi and was added to
.Nx
in 1996.
It was renamed in 2001.
.Sh AUTHORS
This man page was written by
.An Jeremy C. Reed Aq reed@reedmedia.net .