[mod.sources] v07i006: Vi front-end for remote editing, Part04/04

sources-request@mirror.UUCP (08/28/86)

Submitted by: Alan Klietz <ihnp4!dicome!mn-at1!alan>
Mod.sources: Volume 7, Issue 6
Archive-name: rvi/Part04

#!/bin/sh
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
# Wrapped by mirror!rs on Wed Aug 27 00:12:10 EDT 1986

# Exit status; set to 1 on "wc" errors or if would overwrite.
STATUS=0
# Contents:  rv_where.c rv_word.c rv_xmit.c rv_yank.c rvi.1 rvtest.c
#	todo zero.c MANIFEST
 
echo x - rv_where.c
if test -f rv_where.c ; then
    echo rv_where.c exists, putting output in $$rv_where.c
    OUT=$$rv_where.c
    STATUS=1
else
    OUT=rv_where.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F rv_where.c//'
XX#include "rv.h"
XX#include <ctype.h>

XXvoid
XXread_where_mod(cmd, specified_count, cmd_count)
XX/*
XX * Read in where modifier, override old count if specified
XX */
XXINT	cmd;              /* Previous cmd_character */
XXboolean	specified_count;  /* TRUE if count was specified  */
XXINT	cmd_count;	  /* Command count, default 1 */
XX{
XX	INT	c;
XX	INT	count;
XX	void	where_mod();

XX	if (read_cmd(&c, &count)) {
XX		specified_count = TRUE;
XX		cmd_count = count;
XX	}
XX	/*
XX	 * Doubled character means single line (internally stored as '\0')
XX	 */
XX	if (c == cmd)
XX		c = '\0';
XX	where_mod(c, specified_count, cmd_count, FALSE);
XX}


XXvoid
XXwhere_mod(c, specified_count, cmd_count, cmdflag)
XX/*
XX * Set the (row,col) pairs to cover the range of text specified by
XX * the where modifier.  The caller gets the pairs via the screen structure.
XX *
XX * Screen structure,
XX *
XX *	sc->sc_firstline	First line # of range
XX *	sc->sc_firstcol		First column # of range
XX *
XX *	sc->sc_lastline		Last line # of range
XX *	sc->sc_lastcol		Last column # of range
XX *
XX *	sc->sc_validcol		If column # if valid (otherwise
XX *				the range covers whole lines)
XX */
XXINT	c;			/* Command character */
XXboolean	specified_count;	/* TRUE if count was specified */
XXINT	cmd_count;		/* Command count, default 1*/
XXboolean	cmdflag;		/* TRUE if this is a cursor movement command */
XX{
XX	register struct	sc_screen *sc;
XX	boolean forward_back(), word_search(), search();
XX	static	INT	last_searchdir = 1;

XX	sc = &screen;
XX	sc->sc_firstline = sc->sc_lineno;
XX	sc->sc_firstcol = sc->sc_column;
XX	sc->sc_lastline = sc->sc_lineno;
XX	sc->sc_lastcol = sc->sc_column;
XX	sc->sc_validcol = TRUE;

XX	switch (c) {

XXcase 'h':
XXcase '\b':
XX#ifdef USG
XXcase KEY_LEFT:
XX#endif
XX	/*
XX	 * Left cursor
XX	 */
XX	sc->sc_firstcol -= cmd_count;
XX	sc->sc_lastcol--;
XX	break;

XXcase 'l':
XXcase ' ':
XX#ifdef USG
XXcase KEY_RIGHT:
XX#endif
XX	/*
XX	 * Right cursor
XX	 */
XX	sc->sc_lastcol += cmd_count-1;
XX	break;


XXcase 'k':
XXcase '-':
XXcase CTRL(P):
XX#ifdef USG
XXcase KEY_UP:
XX#endif
XX	/*
XX	 * Up cursor
XX	 */
XX	sc->sc_validcol = FALSE;
XX	sc->sc_firstline -= cmd_count;
XX	break;

XXcase 'j':
XXcase '\n':
XXcase '\r':
XXcase '+':
XXcase CTRL(N):
XX#ifdef USG
XXcase KEY_DOWN:
XX#endif
XX	/*
XX	 * Down cursor
XX	 */
XX	sc->sc_validcol = FALSE;
XX	sc->sc_lastline += cmd_count;
XX	break;

XXcase '\0':
XX	/*
XX	 * Repeated character (line count)
XX	 */
XX	sc->sc_validcol = FALSE;
XX	sc->sc_lastline += cmd_count-1;
XX	break;

XXcase '0':
XX	/*
XX	 * Beginning of line
XX	 */
XX	sc->sc_lastcol--;
XX	sc->sc_firstcol = 0;
XX	break;

XXcase '^':
XXcase '_':
XX	/*
XX	 * First nonwhite char
XX	 */
XX	sc->sc_lastcol--;
XX	sc->sc_firstcol = 0;
XX	while (isspace(sc->sc_curline->li_text[sc->sc_firstcol]) &&
XX			sc->sc_firstcol != sc->sc_lastcol)
XX		sc->sc_firstcol++;
XX	if (sc->sc_firstcol > sc->sc_lastcol)
XX		sc->sc_lastcol = sc->sc_firstcol;
XX	break;

XXcase '$':
XX	/*
XX	 * End of line
XX	 */
XX	sc->sc_lastcol = sc->sc_curline->li_width-1;
XX	break;

XXcase ',': 
XXcase ';':
XXcase 'f':
XXcase 'F':
XXcase 't':
XXcase 'T':
XX	/*
XX	 * Search for character forward and backward
XX	 */
XX	if (!forward_back(c, cmd_count))
XX		goto error;
XX	break;
XX	
XXcase 'w':
XXcase 'W':
XXcase 'b':
XXcase 'B':
XXcase 'e':
XXcase 'E':
XX	/*
XX	 * Go to the next word
XX	 */
XX	if (!word_search(c, cmd_count, cmdflag))
XX		goto error;
XX	break;

XXcase 'H':
XX#ifdef USG
XXcase KEY_HOME:
XX#endif
XX	/*
XX	 * Home line
XX	 */
XX	sc->sc_validcol = FALSE;
XX	sc->sc_firstline = sc->sc_lineno - (sc->sc_curline-sc->sc_topline) +
XX		cmd_count-1;
XX	break;

XXcase 'L':
XX#ifdef USG
XXcase KEY_LL:
XX#endif
XX	/*
XX	 * Last line
XX	 */
XX	sc->sc_validcol = FALSE;
XX	sc->sc_lastline = sc->sc_lineno + (sc->sc_botline-sc->sc_curline) -
XX		cmd_count+1;
XX	break;

XXcase 'G':
XX	/*
XX	 * Goto line #
XX	 */
XX	sc->sc_validcol = FALSE;
XX	if (!specified_count)
XX		cmd_count = file.fi_numlines;
XX	if (cmd_count < sc->sc_lineno)
XX		sc->sc_firstline = cmd_count;
XX	else
XX		sc->sc_lastline = cmd_count;
XX	break;

XXcase '|':
XX	/*
XX	 * Goto column #
XX	 */
XX	cmd_count = file_column(sc->sc_curline->li_text, cmd_count-1);
XX	if (cmd_count == sc->sc_column)
XX		goto error;
XX	if (cmd_count < sc->sc_column)
XX		sc->sc_firstcol = cmd_count;
XX	else
XX		sc->sc_lastcol = cmd_count;
XX	break;

XXcase '\'':
XX	/*
XX	 * Goto mark
XX	 */
XX	c = getch();
XX	xmit_ed("'%c\n", c);
XX	xmit_sync();
XX	xmit_ed(".=\n");
XX	if (recv_sync(FALSE)) {
XX		char buf[32];

XX		sc->sc_validcol = FALSE;
XX		fgets(buf, 31, file.fi_fpin);
XX		if ((c = atoi(buf)) > 0)
XX			if (c < sc->sc_lineno)
XX				sc->sc_firstline = c;
XX			else
XX				sc->sc_lastline = c;
XX	} else
XX		goto error;
XX	break;
XX	
XXcase '/':
XX	/*
XX	 * Search forward
XX	 */
XX	mvaddch(LINES-1, 0, '/');
XX	last_searchdir = 1;
XX	if (!search(1, rv_getline(), cmdflag)) {
XX		errflag = 1;
XX		return;
XX	}
XX	errflag = cmdflag;
XX	break;

XXcase '?':
XX	/*
XX	 * Search backward
XX	 */
XX	mvaddch(LINES-1, 0, '?');
XX	last_searchdir = -1;
XX	if (!search(-1, rv_getline(), cmdflag)) {
XX		errflag = 1;
XX		return;
XX	}
XX	errflag = cmdflag;
XX	break;

XXcase 'N':
XX	/*
XX	 * Reverse last search
XX	 */
XX	if (!search(last_searchdir > 0 ? -1 : 1, "", cmdflag)) {
XX		errflag = 1;
XX		return;
XX	}
XX	errflag = cmdflag;
XX	break;

XXcase 'n':
XX	/*
XX	 * Repeat last search
XX	 */
XX	if (!search(last_searchdir, "", cmdflag)) {
XX		errflag = 1;
XX		return;
XX	}
XX	errflag = cmdflag;
XX	break;

XXcase '[':
XX	/*
XX	 * Search backward for C function
XX	 */
XX	if (getch() != '[' || !search(-1, "^{", cmdflag)) {
XX		move(LINES-1, 0);
XX		clrtoeol();
XX		move_cursor(sc->sc_lineno, sc->sc_column);
XX		goto error;
XX	}
XX	errflag = cmdflag;
XX	break;

XXcase ']':
XX	/*
XX	 * Search forward for C function
XX	 */
XX	if (getch() != ']' || !search(1, "^{", cmdflag)) {
XX		move(LINES-1, 0);
XX		clrtoeol();
XX		move_cursor(sc->sc_lineno, sc->sc_column);
XX		goto error;
XX	}
XX	errflag = cmdflag;
XX	break;


XXdefault:
XX	/*
XX	 * Unknown where modifier
XX	 */
XX	goto error;


XX	}  /* End of switch */

XX	if (errflag)
XX		return;
XX	/*
XX	 * Consistency checks
XX	 */
XX	if (sc->sc_validcol) {
XX		if (sc->sc_firstcol < 0) {
XX			if (sc->sc_column == 0)
XX				goto error;
XX			sc->sc_firstcol = 0;
XX		}
XX		if (sc->sc_lastcol < 0) 
XX			goto error;
XX		if (sc->sc_firstline == sc->sc_lineno)
XX			if (sc->sc_firstcol >= sc->sc_curline->li_width)
XX				goto error;
XX		if (sc->sc_lastline == sc->sc_lineno)
XX			if (sc->sc_lastcol >= sc->sc_curline->li_width) {
XX				if (sc->sc_column == sc->sc_curline->li_width)
XX					goto error;
XX				sc->sc_lastcol = sc->sc_curline->li_width;
XX			}
XX	}
XX	if (sc->sc_firstline > 0 && sc->sc_firstline <= file.fi_numlines &&
XX	    sc->sc_lastline > 0 &&  sc->sc_lastline <= file.fi_numlines)
XX		return;

XXerror:
XX	errflag = 1;
XX	flash();
XX	return;
XX}
@//E*O*F rv_where.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - rv_word.c
if test -f rv_word.c ; then
    echo rv_word.c exists, putting output in $$rv_word.c
    OUT=$$rv_word.c
    STATUS=1
else
    OUT=rv_word.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F rv_word.c//'
XX#include "rv.h"
XX#include <ctype.h>

XXextern boolean change_flag;	/* The current command is a change cmd */

XXstatic INT matchtype;

XXstatic boolean
XXisword(c, bigflag)
XX/*
XX * Return TRUE if c is part of a word
XX */
XXINT c;
XXboolean bigflag;
XX{
XX	INT oldmatchtype;

XX	if (bigflag)
XX		return (!isspace(c));
XX	oldmatchtype = matchtype;
XX	if (isalpha(c) || isdigit(c) || c == '_') {
XX		matchtype = 1;
XX		return (oldmatchtype != 2);
XX	}
XX	if (!isspace(c)) {
XX		matchtype = 2;
XX		return (oldmatchtype != 1);
XX	}
XX	matchtype = 0;
XX	return FALSE;
XX}
XX	


XXboolean
XXword_search(c, cmd_count, cmdflag)
XX/*
XX * Scan forward and backward for words
XX */
XXINT c;
XXINT cmd_count;
XXboolean cmdflag;	/* TRUE if this is a cursor movement command */
XX{
XX	register INT i, len, method;
XX	register char *s;
XX	register struct sc_screen *sc;
XX	INT	direction = 1;
XX	boolean big_word = FALSE, end_word = FALSE, newline_flag = FALSE;

XX	sc = &screen;

XX	switch (c) {
XXcase 'w':
XX	/*
XX	 * Scan forward for a word
XX	 */
XX	direction = 1;
XX	big_word = FALSE;
XX	break;

XXcase 'W':
XX	/*
XX	 * Scan forward for a big word
XX	 */
XX	direction = 1;
XX	big_word = TRUE;
XX	break;

XXcase 'b':
XX	/*
XX	 * Scan backward for a word
XX	 */
XX	direction = -1;
XX	big_word = FALSE;
XX	break;

XXcase 'B':
XX	/*
XX	 * Scan backward for a big word
XX	 */
XX	direction = -1;
XX	big_word = TRUE;
XX	break;

XXcase 'e':
XX	/*
XX	 * Scan forward for the end of a word
XX	 */
XX	direction = 1;
XX	big_word = FALSE;
XX	end_word = TRUE;
XX	break;

XXcase 'E':
XX	/*
XX	 * Scan forward for the end of a big word
XX	 */
XX	direction = 1;
XX	big_word = TRUE;
XX	end_word = TRUE;
XX	break;

XXdefault:
XX	return FALSE;

XX	} /* End switch */


XX	s = sc->sc_curline->li_text;
XX	len = sc->sc_curline->li_width;
XX	sc->sc_validcol = TRUE;
XX	i = sc->sc_column;
XX	for (; cmd_count > 0; --cmd_count) {
XX		/*
XX		 * Build a search algorithm
XX		 */
XX		matchtype = 0;
XX		if (len <= 0)
XX			goto beyondline;
XX		if (newline_flag) {
XX			method = isword(s[i], big_word) ? 1 : 0;
XX			newline_flag = FALSE;
XX		} else {
XX			INT temptype;

XX			method = isword(s[i], big_word) ? 2 : 0;
XX			temptype = matchtype;
XX			if (direction > 0 && i < len-1 ||
XX					direction < 0 && i > 0)
XX				method |= isword(s[i+direction], big_word) ?
XX					1 : 0;
XX			matchtype = temptype;
XX		}
XX		if (direction < 0 || end_word)
XX			method |= 4;
XX		if (method < 4 && change_flag)
XX			method = 4;  /* Emulating a vi kludge.. */
XX		else
XX			switch (method) {
XX	case 0:
XX	case 1:			method = 2;
XX				break;
XX	case 2:
XX	case 3:			method = 3;
XX				break;
XX	case 7:			method = 4;
XX				break;
XX	case 4:
XX	case 5:			method = 6;
XX				break;
XX	case 6:			method = 7;
XX				break;
XX			}
XX		/*
XX		 * Execute the search algorithm 
XX		 */
XX		if (method & 1)
XX			while (isword(s[i], big_word)) {
XX				i += direction;
XX				if (i < 0 || i >= len)
XX					goto beyondline;
XX			}
XX		if (method & 2)
XX			while (!isword(s[i], big_word)) {
XX				i += direction;
XX				if (i < 0 || i >= len)
XX					goto beyondline;
XX			}
XX		if (method & 4)
XX			for (;;) {
XX				i += direction;
XX				if (i < 0 || i >= len ||
XX						!isword(s[i], big_word)) {
XX					i -= direction;
XX					break;
XX				}
XX			}
XX		continue;
XXbeyondline:
XX		if (cmdflag) {
XX			move_abs_cursor(sc->sc_lineno+direction, 0);
XX			s = sc->sc_curline->li_text;
XX			len = sc->sc_curline->li_width;
XX			sc->sc_firstline = sc->sc_lineno;
XX			sc->sc_lastline = sc->sc_lineno;
XX			if (errflag)
XX				break;
XX			if (len == 0 || direction > 0)
XX				i = 0;
XX			else
XX				i = len-1;
XX			sc->sc_column = sc->sc_firstcol = sc->sc_lastcol = i;
XX			sc->sc_validcol = TRUE;
XX			++cmd_count;
XX			newline_flag = TRUE;
XX		} else
XX			break;
XX	}
XX	if (direction >= 0) {
XX		sc->sc_lastcol = i;
XX		if (!cmdflag && method < 4 && !change_flag)
XX			sc->sc_lastcol--;
XX	} else {
XX		if (!cmdflag)
XX			sc->sc_lastcol--;
XX		sc->sc_firstcol = i;
XX	}
XX	return (sc->sc_firstcol <= sc->sc_lastcol);
XX}
@//E*O*F rv_word.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - rv_xmit.c
if test -f rv_xmit.c ; then
    echo rv_xmit.c exists, putting output in $$rv_xmit.c
    OUT=$$rv_xmit.c
    STATUS=1
else
    OUT=rv_xmit.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F rv_xmit.c//'
XX#include "rv.h"

XXvoid
XXxmit_curline()
XX/*
XX * Transmit the current line, if modified
XX */
XX{
XX	register struct sc_screen *sc;
XX	register struct li_line  *line;

XX	sc = &screen;
XX	if (sc->sc_origline.li_text != NULL) {
XX		free(sc->sc_origline.li_text);
XX		sc->sc_origline.li_text = NULL;
XX		line = sc->sc_curline;
XX		xmit_ed("%dc\n", sc->sc_lineno);
XX		if (strcmp(line->li_text, ".") == 0)
XX			fputs("\\.", file.fi_fpout);
XX		else
XX			fputs(line->li_text, file.fi_fpout);
XX		fputs("\n.\n", file.fi_fpout);
XX		file.fi_modified = TRUE;
XX		if (set_debug > 1)
XX			fputs("\007", stderr);
XX	}
XX}


XX/*VARARGS1*/
XXvoid
XXxmit_ed(txt, arg1, arg2, arg3, arg4, arg5)
XX/*
XX * Printf the string to ed
XX */
XXchar *txt, *arg1, *arg2, *arg3, *arg4, *arg5;
XX{
XX	char buf[512];

XX	sprintf(buf, txt, arg1, arg2, arg3, arg4, arg5);
XX	fputs(buf, file.fi_fpout);
XX}
@//E*O*F rv_xmit.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - rv_yank.c
if test -f rv_yank.c ; then
    echo rv_yank.c exists, putting output in $$rv_yank.c
    OUT=$$rv_yank.c
    STATUS=1
else
    OUT=rv_yank.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F rv_yank.c//'
XX#include "rv.h"

XXINT	yank_shift = 9;  /* Shift count for numbered yank buffers */
XXINT	yank_cmd;	 /* "x letter */

XXINT
XXchar_to_yank(c)
XX/*
XX * Convert a character to a yank ordinal
XX */
XXregister INT c;
XX{
XX	if (c == ' ')
XX		return 0;
XX	else if (c >= '1' && c <= '9')
XX		c = (yank_shift - (c - '0')) % 9 + 1;
XX	else if (c >= 'a' && c <= 'z')
XX		c = c - 'a' + 10;
XX	else if (c == '.')
XX		return NUM_YANK_BUFS-2;
XX	else {
XX		if (c != '$')
XX			errflag = 1;
XX		return NUM_YANK_BUFS-1;
XX	}
XX	return c;
XX}


XXvoid
XXyank()
XX/*
XX * Yank text between first/last marks. 
XX * If more than 1 line, text is written to a temp file using ed.
XX */
XX{
XX	register struct li_line	  *line;
XX	register struct ya_yank   *yank;
XX	register struct sc_screen *sc;
XX	INT	indx;

XX	sc = &screen;

XX	indx = char_to_yank(yank_cmd);
XX	if (errflag) {
XX		flash();
XX		return;
XX	}
XX	yank = &yank_array[indx];
XX	line = sc->sc_curline;

XX	/*
XX	 * Three cases:  lines, columns, or both
XX	 */
XX	if (sc->sc_validcol) { /* If columns */
XX		if (sc->sc_firstline != sc->sc_lastline) { /* If both */
XX			botprint(TRUE,
XX			    "Cant yank columns within multiple lines yet.\n");
XX			return;
XX		}
XX		yank->ya_type = YANK_COLS;
XX		yank->ya_width = sc->sc_lastcol - sc->sc_firstcol + 1;
XX		yank->ya_numlines = 0;
XX		if (yank->ya_text)
XX			free(yank->ya_text);
XX		yank->ya_text = xalloc(yank->ya_width+1);
XX		strncpy(yank->ya_text, &line->li_text[sc->sc_firstcol], yank->ya_width);
XX		yank->ya_text[yank->ya_width] = '\0';
XX	}
XX	else { /* If lines */
XX		if (sc->sc_firstline == sc->sc_lastline) {
XX			/*
XX			 * Simple case - yank line
XX			 */
XX			yank->ya_type = YANK_SINGLE;
XX			yank->ya_width = 0;
XX			yank->ya_numlines = 1;
XX			if (yank->ya_text)
XX				free(yank->ya_text);
XX			yank->ya_text = xalloc(strlen(line->li_text)+1);
XX			strcpy(yank->ya_text, line->li_text);
XX		}
XX		else {
XX			/*
XX			 * Yank multiple lines
XX			 */
XX			xmit_curline();
XX			yank->ya_type = YANK_LINES;
XX			yank->ya_width = 0;
XX			yank->ya_numlines = sc->sc_lastline-sc->sc_firstline+1;
XX			if (yank->ya_text) {
XX				free(yank->ya_text);
XX				yank->ya_text = NULL;
XX			}
XX			xmit_ed("%d,%dw /tmp/yk%d.%d\n", sc->sc_firstline,
XX				sc->sc_lastline, getpid(), indx);
XX			yank->ya_madefile = TRUE;
XX			if (indx == 0)
XX				xmit_ed("%d,%dw /tmp/yk%d.%d\n",
XX					sc->sc_firstline, sc->sc_lastline,
XX						getpid(), NUM_YANK_BUFS-1);

XX			botprint(FALSE, "%d lines yanked", yank->ya_numlines);
XX			hitcr_continue();
XX		}
XX	}
XX}
@//E*O*F rv_yank.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - rvi.1
if test -f rvi.1 ; then
    echo rvi.1 exists, putting output in $$rvi.1
    OUT=$$rvi.1
    STATUS=1
else
    OUT=rvi.1
fi
sed 's/^XX//' > $OUT <<'@//E*O*F rvi.1//'
XX.TH RVI 1 
XX.UC 4
XX.SH NAME
XXrvi \- remote screen editor based on vi
XX.SH SYNOPSIS
XX\fBrvi infd outfd "files"\fR
XX.br
XX.SH DESCRIPTION
XX.I Rvi\^
XXis a screen editor based on
XX.IR vi .
XXIt generates
XX.I ed\^
XXcommands for execution on a remote machine.  The parameters \fBinfd\fR and \fBoutfd\fR are
XXpipe descriptors connecting
XX.I rvi\^
XXto a remote
XX.I ed\^
XXprogram.
XX.PP
XX.SH INVOCATION
XX.I Rvi
XXis invoked via an escape sequence from within a network terminal program.
XXThe actual sequence varies depending on the terminal program used.  For example,
XXthe escape sequence for
XX.I cxint
XXis \fB~v files\fR, while the escape sequence for
XX.I telnet
XXis \fB^]v files\fR.
XX.PP
XX.SH DIFFERENCES
XXEntering the command \fBQ\fR allows the user to communicate directly with
XX.I ed
XXbypassing the
XX.I rvi
XXprogram.
XX(To pass control back to
XX.IR rvi ,
XXsimply type the escape sequence again.)
XX.br
XX.sp
XXPressing the interrupt key is synoymous with \fBQ\fR.
XX.br
XX.sp
XXThe option \fB:set fortran\fR places
XX.I rvi
XXin a mode suitable for editing Fortran source files.  Tabs are expanded
XXto spaces, and the first tabstop is set to column 6.  (Fortran mode is set
XXimplicitly when editing files ending in \fB.f\fR)
XX.br
XX.sp
XXCommands found in the environment variable RVINIT are executed at
XXinitialization time.
XX.br
XX.sp
XX.I Rvi
XXdoes not support the following command keystrokes:
XX\fBz `` = % ( ) { }\fR.
XX.br
XX.sp
XXMacros and tags are not supported.
XX.PP
XX.SH "SEE ALSO"
XXvi (1).
XX.br
XX.sp
XX\f2Vi Quick Reference Card\fR.
XX.br
XX\f2An Introduction to Display Editing with Vi\fR,
XXand
XX\f2Ex Reference Manual\fR
XXin the \f2\s-1UNIX\s+1 System Documentation Workbench\fR.
@//E*O*F rvi.1//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - rvtest.c
if test -f rvtest.c ; then
    echo rvtest.c exists, putting output in $$rvtest.c
    OUT=$$rvtest.c
    STATUS=1
else
    OUT=rvtest.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F rvtest.c//'
XX#include <stdio.h>
XX#include <signal.h>
XX/*
XX * Loopback test.   This program forks a copy of rvi and connects it to
XX * a local ``ed'' program.
XX */

XXmain(argc, argv)
XXint argc;
XXchar **argv;
XX{
XX	int in[2], out[2];
XX	char ibuf[12], obuf[12];

XX	if (argv[1] == NULL)
XX		argv[1] = "";

XX	pipe(in);
XX	pipe(out);

XX	sprintf(ibuf, "%d", in[1]);
XX	sprintf(obuf, "%d", out[0]);
XX	signal(SIGPIPE, SIG_IGN);

XX	if (fork() == 0) {
XX		close(in[0]);
XX		close(out[1]);
XX		execlp("rvi", "rvi", obuf, ibuf, argv[1], "-l", NULL);
XX		execl("/u/aek/bin/rvi", "rvi", obuf, ibuf, argv[1], "-l", NULL);
XX		perror("exec rvi");
XX		_exit(1);
XX	}

XX	close(in[1]);
XX	close(out[0]);

XX	close(0);
XX	dup(in[0]);
XX	close(1);
XX	dup(out[1]);

XX	execlp("ed", "ed", NULL);
XX}
@//E*O*F rvtest.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - todo
if test -f todo ; then
    echo todo exists, putting output in $$todo
    OUT=$$todo
    STATUS=1
else
    OUT=todo
fi
sed 's/^XX//' > $OUT <<'@//E*O*F todo//'
XXAdd heuristic to shut off P (prompt) in ed.

XXStrip off trailing CR's or CR-LF --> LF

XXAdd >> << %
@//E*O*F todo//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - zero.c
if test -f zero.c ; then
    echo zero.c exists, putting output in $$zero.c
    OUT=$$zero.c
    STATUS=1
else
    OUT=zero.c
fi
sed 's/^XX//' > $OUT <<'@//E*O*F zero.c//'
XX/*	zero - zero data structures
XX	84/12/18.  A. E. Klietz.
XX*/

XX#include "rv.h"

XX#ifdef zero
XX#undef zero
XX#endif

XX#ifndef USG
XXvoid
XXzero(ptr, len)
XXchar *ptr;
XXint len;
XX{
XX	for (; len > 0; --len)
XX		*(ptr++) = 0;
XX}
XX#endif
@//E*O*F zero.c//
chmod u=rw,g=rw,o=rw $OUT
 
echo x - MANIFEST
if test -f MANIFEST ; then
    echo MANIFEST exists, putting output in $$MANIFEST
    OUT=$$MANIFEST
    STATUS=1
else
    OUT=MANIFEST
fi
sed 's/^XX//' > $OUT <<'@//E*O*F MANIFEST//'
XXBUGFIX                       1
XXBUGFIX2                      1
XXMANIFEST                     4
XXMakefile.bsd                 1
XXMakefile.usg                 1
XXManifest                     1
XXNEXT_REL                     1
XXREADME                       1
XXbinsearch.c                  1
XXcopy.c                       1
XXcopyright                    1
XXregerror.c                   1
XXregexp.c                     1
XXregexp.h                     1
XXregmagic.h                   1
XXrv.h                         2
XXrv_change.c                  1
XXrv_cmd.c                     2
XXrv_column.c                  1
XXrv_delcol.c                  1
XXrv_delete.c                  2
XXrv_dot.c                     1
XXrv_dummy.c                   2
XXrv_edit.c                    2
XXrv_fast.c                    2
XXrv_fetch.c                   2
XXrv_flash.c                   2
XXrv_forback.c                 2
XXrv_getline.c                 2
XXrv_init.c                    2
XXrv_input.c                   2
XXrv_insert.c                  3
XXrv_join.c                    2
XXrv_linecmd.c                 3
XXrv_main.c                    2
XXrv_mark.c                    2
XXrv_misc.c                    3
XXrv_move.c                    3
XXrv_openline.c                3
XXrv_print_ln.c                2
XXrv_put.c                     3
XXrv_quit.c                    2
XXrv_redraw.c                  3
XXrv_redraw_ln.c               3
XXrv_scroll.c                  3
XXrv_scroll_bk.c               3
XXrv_search.c                  3
XXrv_shell.c                   3
XXrv_sync.c                    3
XXrv_undo.c                    3
XXrv_where.c                   4
XXrv_word.c                    4
XXrv_xmit.c                    4
XXrv_yank.c                    4
XXrvi.1                        4
XXrvtest.c                     4
XXtodo                         4
XXzero.c                       4
@//E*O*F MANIFEST//
chmod u=rw,g=rw,o=rw $OUT
 
echo Inspecting for damage in transit...
temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
     367     866    6288 rv_where.c
     209     594    3669 rv_word.c
      42      98     808 rv_xmit.c
     107     311    2354 rv_yank.c
      72     270    1597 rvi.1
      43      90     711 rvtest.c
       5      21      98 todo
      20      39     213 zero.c
      58     116    1798 MANIFEST
     923    2405   17536 total
!!!
wc $FILES | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if test -s $dtemp ; then
    echo "Ouch [diff of wc output]:"
    cat $dtemp
    STATUS=1
elif test $STATUS = 0 ; then
    echo "No problems found."
else
    echo "WARNING -- PROBLEMS WERE FOUND..."
fi
exit $STATUS