head	1.6;
access;
symbols
	perseant-exfatfs-base-20250801:1.6
	perseant-exfatfs-base-20240630:1.6
	perseant-exfatfs:1.6.0.46
	perseant-exfatfs-base:1.6
	cjep_sun2x:1.6.0.44
	cjep_sun2x-base:1.6
	cjep_staticlib_x-base1:1.6
	cjep_staticlib_x:1.6.0.42
	cjep_staticlib_x-base:1.6
	phil-wifi-20200421:1.6
	phil-wifi-20200411:1.6
	phil-wifi-20200406:1.6
	pgoyette-compat-merge-20190127:1.6
	pgoyette-compat-20190127:1.6
	pgoyette-compat-20190118:1.6
	pgoyette-compat-1226:1.6
	pgoyette-compat-1126:1.6
	pgoyette-compat-1020:1.6
	pgoyette-compat-0930:1.6
	pgoyette-compat-0906:1.6
	pgoyette-compat-0728:1.6
	pgoyette-compat-0625:1.6
	pgoyette-compat-0521:1.6
	pgoyette-compat-0502:1.6
	pgoyette-compat-0422:1.6
	pgoyette-compat-0415:1.6
	pgoyette-compat-0407:1.6
	pgoyette-compat-0330:1.6
	pgoyette-compat-0322:1.6
	pgoyette-compat-0315:1.6
	pgoyette-compat:1.6.0.40
	pgoyette-compat-base:1.6
	perseant-stdc-iso10646:1.6.0.38
	perseant-stdc-iso10646-base:1.6
	prg-localcount2-base3:1.6
	prg-localcount2-base2:1.6
	prg-localcount2-base1:1.6
	prg-localcount2:1.6.0.36
	prg-localcount2-base:1.6
	pgoyette-localcount-20170426:1.6
	bouyer-socketcan-base1:1.6
	pgoyette-localcount-20170320:1.6
	bouyer-socketcan:1.6.0.34
	bouyer-socketcan-base:1.6
	pgoyette-localcount-20170107:1.6
	pgoyette-localcount-20161104:1.6
	localcount-20160914:1.6
	pgoyette-localcount-20160806:1.6
	pgoyette-localcount-20160726:1.6
	pgoyette-localcount:1.6.0.32
	pgoyette-localcount-base:1.6
	netbsd-5-2-3-RELEASE:1.6
	netbsd-5-1-5-RELEASE:1.6
	yamt-pagecache-base9:1.6
	yamt-pagecache-tag8:1.6
	tls-earlyentropy:1.6.0.28
	tls-earlyentropy-base:1.6
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.6
	riastradh-drm2-base3:1.6
	netbsd-5-2-2-RELEASE:1.6
	netbsd-5-1-4-RELEASE:1.6
	netbsd-5-2-1-RELEASE:1.6
	netbsd-5-1-3-RELEASE:1.6
	agc-symver:1.6.0.30
	agc-symver-base:1.6
	tls-maxphys-base:1.6
	yamt-pagecache-base8:1.6
	netbsd-5-2:1.6.0.26
	yamt-pagecache-base7:1.6
	netbsd-5-2-RELEASE:1.6
	netbsd-5-2-RC1:1.6
	yamt-pagecache-base6:1.6
	yamt-pagecache-base5:1.6
	yamt-pagecache-base4:1.6
	netbsd-5-1-2-RELEASE:1.6
	netbsd-5-1-1-RELEASE:1.6
	yamt-pagecache-base3:1.6
	yamt-pagecache-base2:1.6
	yamt-pagecache:1.6.0.24
	yamt-pagecache-base:1.6
	bouyer-quota2-nbase:1.6
	bouyer-quota2:1.6.0.22
	bouyer-quota2-base:1.6
	matt-nb5-pq3:1.6.0.20
	matt-nb5-pq3-base:1.6
	netbsd-5-1:1.6.0.18
	netbsd-5-1-RELEASE:1.6
	netbsd-5-1-RC4:1.6
	netbsd-5-1-RC3:1.6
	netbsd-5-1-RC2:1.6
	netbsd-5-1-RC1:1.6
	netbsd-5-0-2-RELEASE:1.6
	netbsd-5-0-1-RELEASE:1.6
	jym-xensuspend-nbase:1.6
	netbsd-5-0:1.6.0.16
	netbsd-5-0-RELEASE:1.6
	netbsd-5-0-RC4:1.6
	netbsd-5-0-RC3:1.6
	netbsd-5-0-RC2:1.6
	jym-xensuspend:1.6.0.14
	jym-xensuspend-base:1.6
	netbsd-5-0-RC1:1.6
	netbsd-5:1.6.0.12
	netbsd-5-base:1.6
	mjf-devfs2:1.6.0.10
	mjf-devfs2-base:1.6
	yamt-pf42-base4:1.6
	yamt-pf42-base3:1.6
	hpcarm-cleanup-nbase:1.6
	yamt-pf42-base2:1.6
	yamt-pf42:1.6.0.8
	yamt-pf42-base:1.6
	keiichi-mipv6-nbase:1.6
	keiichi-mipv6:1.6.0.6
	keiichi-mipv6-base:1.6
	cube-autoconf:1.6.0.4
	cube-autoconf-base:1.6
	hpcarm-cleanup:1.6.0.2
	hpcarm-cleanup-base:1.6
	netbsd-1-0-base:1.5
	nvi-1-11b:1.1.1.2
	nvi-1-03:1.1.1.1
	bostic-nvi:1.1.1;
locks; strict;
comment	@ * @;


1.6
date	95.03.01.00.00.00;	author mycroft;	state dead;
branches;
next	1.5;

1.5
date	94.03.28.04.28.05;	author cgd;	state Exp;
branches;
next	1.4;

1.4
date	94.03.02.01.54.11;	author cgd;	state Exp;
branches;
next	1.3;

1.3
date	94.02.09.07.06.11;	author cgd;	state Exp;
branches;
next	1.2;

1.2
date	94.01.24.06.39.21;	author cgd;	state Exp;
branches;
next	1.1;

1.1
date	94.01.24.05.53.00;	author cgd;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	94.01.24.05.53.01;	author cgd;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	94.03.28.02.52.49;	author cgd;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Clean up deleted files.
@
text
@/*-
 * Copyright (c) 1991, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef lint
static char sccsid[] = "@@(#)util.c	8.44 (Berkeley) 3/15/94";
#endif /* not lint */

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <sys/time.h>

#include <bitstring.h>
#include <ctype.h>
#include <curses.h>
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif

#include "compat.h"
#include <db.h>
#include <regex.h>

#include "vi.h"

/*
 * msgq --
 *	Display a message.
 */
void
#ifdef __STDC__
msgq(SCR *sp, enum msgtype mt, const char *fmt, ...)
#else
msgq(sp, mt, fmt, va_alist)
	SCR *sp;
	enum msgtype mt;
        char *fmt;
        va_dcl
#endif
{
        va_list ap;
	int len;
	char msgbuf[1024];

#ifdef __STDC__
        va_start(ap, fmt);
#else
        va_start(ap);
#endif
	/*
	 * It's possible to enter msg when there's no screen to hold
	 * the message.  Always check sp before using it, and, if it's
	 * NULL, use __global_list.
	 */
	switch (mt) {
	case M_BERR:
		if (sp != NULL && !F_ISSET(sp, S_EXSILENT) &&
		    F_ISSET(sp->gp, G_STDIN_TTY) && !O_ISSET(sp, O_VERBOSE)) {
			F_SET(sp, S_BELLSCHED);
			return;
		}
		mt = M_ERR;
		break;
	case M_VINFO:
		if (sp == NULL || !O_ISSET(sp, O_VERBOSE))
			return;
		mt = M_INFO;
		/* FALLTHROUGH */
	case M_INFO:
		if (F_ISSET(sp, S_EXSILENT))
			return;
		break;
	case M_ERR:
	case M_SYSERR:
		break;
	default:
		abort();
	}

	/* Length is the min length of the message or the buffer. */
	if (mt == M_SYSERR)
		if (sp->if_name != NULL)
			len = snprintf(msgbuf, sizeof(msgbuf),
			    "Error: %s, %d: %s%s%s.", sp->if_name, sp->if_lno,
			    fmt == NULL ? "" : fmt, fmt == NULL ? "" : ": ",
			    strerror(errno));
		else
			len = snprintf(msgbuf, sizeof(msgbuf),
			    "Error: %s%s%s.",
			    fmt == NULL ? "" : fmt, fmt == NULL ? "" : ": ",
			    strerror(errno));
	else {
		len = sp->if_name == NULL ? 0 : snprintf(msgbuf, sizeof(msgbuf),
		        "%s, %d: ", sp->if_name, sp->if_lno);
		len += vsnprintf(msgbuf + len, sizeof(msgbuf) - len, fmt, ap);
	}

	/*
	 * If len >= the size, some characters were discarded.
	 * Ignore trailing nul.
	 */
	if (len >= sizeof(msgbuf))
		len = sizeof(msgbuf) - 1;

	msg_app(__global_list, sp, mt == M_ERR ? 1 : 0, msgbuf, len);
}

/*
 * msg_app --
 *	Append a message into the queue.  This can fail, but there's
 *	nothing we can do if it does.
 */
void
msg_app(gp, sp, inv_video, p, len)
	GS *gp;
	SCR *sp;
	int inv_video;
	char *p;
	size_t len;
{
	static int reenter;		/* STATIC: Re-entrancy check. */
	MSG *mp, *nmp;

	/*
	 * It's possible to reenter msg when it allocates space.
	 * We're probably dead anyway, but no reason to drop core.
	 */
	if (reenter)
		return;
	reenter = 1;

	/*
	 * Find an empty structure, or allocate a new one.  Use the
	 * screen structure if possible, otherwise the global one.
	 */
	if (sp != NULL) {
		if ((mp = sp->msgq.lh_first) == NULL) {
			CALLOC(sp, mp, MSG *, 1, sizeof(MSG));
			if (mp == NULL)
				goto ret;
			LIST_INSERT_HEAD(&sp->msgq, mp, q);
			goto store;
		}
	} else if ((mp = gp->msgq.lh_first) == NULL) {
		CALLOC(sp, mp, MSG *, 1, sizeof(MSG));
		if (mp == NULL)
			goto ret;
		LIST_INSERT_HEAD(&gp->msgq, mp, q);
		goto store;
	}
	while (!F_ISSET(mp, M_EMPTY) && mp->q.le_next != NULL)
		mp = mp->q.le_next;
	if (!F_ISSET(mp, M_EMPTY)) {
		CALLOC(sp, nmp, MSG *, 1, sizeof(MSG));
		if (nmp == NULL)
			goto ret;
		LIST_INSERT_AFTER(mp, nmp, q);
		mp = nmp;
	}

	/* Get enough memory for the message. */
store:	if (len > mp->blen && binc(sp, &mp->mbuf, &mp->blen, len))
		goto ret;

	/* Store the message. */
	memmove(mp->mbuf, p, len);
	mp->len = len;
	mp->flags = inv_video ? M_INV_VIDEO : 0;

ret:	reenter = 0;
}

/*
 * msgrpt --
 *	Report on the lines that changed.
 *
 * !!!
 * Historic vi documentation (USD:15-8) claimed that "The editor will also
 * always tell you when a change you make affects text which you cannot see."
 * This isn't true -- edit a large file and do "100d|1".  We don't implement
 * this semantic as it would require that we track each line that changes
 * during a command instead of just keeping count.
 *
 * Line counts weren't right in historic vi, either.  For example, given the
 * file:
 *	abc
 *	def
 * the command 2d}, from the 'b' would report that two lines were deleted,
 * not one.
 */
int
msg_rpt(sp, is_message)
	SCR *sp;
	int is_message;
{
	static const char *const action[] = {
		"added", "changed", "copied", "deleted", "joined", "moved",
		"put", "left shifted", "right shifted", "yanked", NULL,
	};
	recno_t total;
	u_long rval;
	int first, cnt;
	size_t blen, len;
	const char *const *ap;
	char *bp, *p, number[40];

	if (F_ISSET(sp, S_EXSILENT))
		return (0);

	if ((rval = O_VAL(sp, O_REPORT)) == 0)
		goto norpt;

	GET_SPACE_RET(sp, bp, blen, 512);
	p = bp;

	total = 0;
	for (ap = action, cnt = 0, first = 1; *ap != NULL; ++ap, ++cnt)
		if (sp->rptlines[cnt] != 0) {
			total += sp->rptlines[cnt];
			len = snprintf(number, sizeof(number),
			    "%s%lu line%s %s", first ? "" : "; ",
			    sp->rptlines[cnt],
			    sp->rptlines[cnt] > 1 ? "s" : "", *ap);
			memmove(p, number, len);
			p += len;
			first = 0;
		}

	/*
	 * If nothing to report, return.  Note that the number of lines
	 * must be > than the user's value, not >=.  This is historic
	 * practice and means that users cannot report on single line
	 * changes.
	 */
	if (total > rval) {
		*p = '\0';

		if (is_message)
			msgq(sp, M_INFO, "%s", bp);
		else
			ex_printf(EXCOOKIE, "%s\n", bp);
	}

	FREE_SPACE(sp, bp, blen);

	/* Clear after each report. */
norpt:	memset(sp->rptlines, 0, sizeof(sp->rptlines));
	return (0);
}

/*
 * binc --
 *	Increase the size of a buffer.
 */
int
binc(sp, argp, bsizep, min)
	SCR *sp;			/* sp MAY BE NULL!!! */
	void *argp;
	size_t *bsizep, min;
{
	size_t csize;
	void *bpp;

	/* If already larger than the minimum, just return. */
	if (min && *bsizep >= min)
		return (0);

	/*
	 * If the initial pointer is null, use calloc (for non-ANSI
	 * C realloc implementations).
	 */
	bpp = *(char **)argp;
	csize = *bsizep + MAX(min, 256);
	if (bpp == NULL) {
		MALLOC(sp, bpp, void *, csize);
	} else
		REALLOC(sp, bpp, void *, csize);

	if (bpp == NULL) {
		/*
		 * Theoretically, realloc is supposed to leave any already
		 * held memory alone if it can't get more.  Don't trust it.
		 */
		*bsizep = 0;
		return (1);
	}
	/*
	 * Memory is guaranteed to be zero-filled, various parts of
	 * nvi depend on this.
	 */
	memset((char *)bpp + *bsizep, 0, csize - *bsizep);
	*(char **)argp = bpp;
	*bsizep = csize;
	return (0);
}
/*
 * nonblank --
 *	Set the column number of the first non-blank character
 *	including or after the starting column.  On error, set
 *	the column to 0, it's safest.
 */
int
nonblank(sp, ep, lno, cnop)
	SCR *sp;
	EXF *ep;
	recno_t lno;
	size_t *cnop;
{
	char *p;
	size_t cnt, len, off;

	/* Default. */
	off = *cnop;
	*cnop = 0;

	/* Get the line. */
	if ((p = file_gline(sp, ep, lno, &len)) == NULL) {
		if (file_lline(sp, ep, &lno))
			return (1);
		if (lno == 0)
			return (0);
		GETLINE_ERR(sp, lno);
		return (1);
	}

	/* Set the offset. */
	if (len == 0 || off >= len)
		return (0);

	for (cnt = off, p = &p[off],
	    len -= off; len && isblank(*p); ++cnt, ++p, --len);

	/* Set the return. */
	*cnop = len ? cnt : cnt - 1;
	return (0);
}

/*
 * tail --
 *	Return tail of a path.
 */
char *
tail(path)
	char *path;
{
	char *p;

	if ((p = strrchr(path, '/')) == NULL)
		return (path);
	return (p + 1);
}

/*
 * set_window_size --
 *	Set the window size, the row may be provided as an argument.
 */
int
set_window_size(sp, set_row, ign_env)
	SCR *sp;
	u_int set_row;
	int ign_env;
{
	struct winsize win;
	size_t col, row;
	int user_set;
	ARGS *argv[2], a, b;
	char *s, buf[2048];

	/*
	 * Get the screen rows and columns.  If the values are wrong, it's
	 * not a big deal -- as soon as the user sets them explicitly the
	 * environment will be set and the screen package will use the new
	 * values.
	 *
	 * Try TIOCGWINSZ.
	 */
	row = col = 0;
#ifdef TIOCGWINSZ
	if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) != -1) {
		row = win.ws_row;
		col = win.ws_col;
	}
#endif

	/* If TIOCGWINSZ failed, or had entries of 0, try termcap. */
	if (row == 0 || col == 0) {
		s = NULL;
		if (F_ISSET(&sp->opts[O_TERM], OPT_SET))
			s = O_STR(sp, O_TERM);
		else
			s = getenv("TERM");
		if (s != NULL && tgetent(buf, s) == 1) {
			if (row == 0)
				row = tgetnum("li");
			if (col == 0)
				col = tgetnum("co");
		}
	}
	/* If nothing else, well, it's probably a VT100. */
	if (row == 0)
		row = 24;
	if (col == 0)
		col = 80;

	/*
	 * POSIX 1003.2 requires the environment to override, however,
	 * if we're here because of a signal, we don't want to use the
	 * old values.
	 */
	if (!ign_env) {
		if ((s = getenv("LINES")) != NULL)
			row = strtol(s, NULL, 10);
		if ((s = getenv("COLUMNS")) != NULL)
			col = strtol(s, NULL, 10);
	}

	/* But, if we got an argument for the rows, use it. */
	if (set_row)
		row = set_row;

	a.bp = buf;
	b.bp = NULL;
	b.len = 0;
	argv[0] = &a;
	argv[1] = &b;;

	/*
	 * Tell the options code that the screen size has changed.
	 * Since the user didn't do the set, clear the set bits.
	 */
	user_set = F_ISSET(&sp->opts[O_LINES], OPT_SET);
	a.len = snprintf(buf, sizeof(buf), "lines=%u", row);
	if (opts_set(sp, argv))
		return (1);
	if (user_set)
		F_CLR(&sp->opts[O_LINES], OPT_SET);
	user_set = F_ISSET(&sp->opts[O_COLUMNS], OPT_SET);
	a.len = snprintf(buf, sizeof(buf), "columns=%u", col);
	if (opts_set(sp, argv))
		return (1);
	if (user_set)
		F_CLR(&sp->opts[O_COLUMNS], OPT_SET);
	return (0);
}

/*
 * set_alt_name --
 *	Set the alternate file name.
 *
 * Swap the alternate file name.  It's a routine because I wanted some place
 * to hang this comment.  The alternate file name (normally referenced using
 * the special character '#' during file expansion) is set by many
 * operations.  In the historic vi, the commands "ex", and "edit" obviously
 * set the alternate file name because they switched the underlying file.
 * Less obviously, the "read", "file", "write" and "wq" commands set it as
 * well.  In this implementation, some new commands have been added to the
 * list.  Where it gets interesting is that the alternate file name is set
 * multiple times by some commands.  If an edit attempt fails (for whatever
 * reason, like the current file is modified but as yet unwritten), it is
 * set to the file name that the user was unable to edit.  If the edit
 * succeeds, it is set to the last file name that was edited.  Good fun.
 *
 * If the user edits a temporary file, there are time when there isn't an
 * alternative file name.  A name argument of NULL turns it off.
 */
void
set_alt_name(sp, name)
	SCR *sp;
	char *name;
{
	if (sp->alt_name != NULL)
		FREE(sp->alt_name, strlen(sp->alt_name) + 1);
	if (name == NULL)
		sp->alt_name = NULL;
	else if ((sp->alt_name = strdup(name)) == NULL)
		msgq(sp, M_SYSERR, NULL);
}

/*
 * baud_from_bval --
 *	Return the baud rate using the standard defines.
 */
u_long
baud_from_bval(sp)
	SCR *sp;
{
	speed_t v;

	if (!F_ISSET(sp->gp, G_TERMIOS_SET))
		return (9600);

	switch (v = cfgetospeed(&sp->gp->original_termios)) {
	case B50:
		return (50);
	case B75:
		return (75);
	case B110:
		return (110);
	case B134:
		return (134);
	case B150:
		return (150);
	case B200:
		return (200);
	case B300:
		return (300);
	case B600:
		return (600);
	case B1200:
		return (1200);
	case B1800:
		return (1800);
	case B2400:
		return (2400);
	case B4800:
		return (4800);
#ifdef B7200
	case B7200:
		return (7200);
#endif
	case B0:				/* Hangup -- ignore. */
	case B9600:
		return (9600);
#ifdef B14400
	case B14400:
		return (14400);
#endif
	case B19200:
		return (19200);
#ifdef B28800
	case B28800:
		return (28800);
#endif
	case B38400:
		return (38400);
#ifdef B57600
	case B57600:
		return (57600);
#endif
#ifdef B115200
	case B115200:
		return (115200);
#endif
#ifdef B230400
	case B230400:
		return (230400);
#endif
	default:
		/*
		 * EXTA and EXTB aren't required by POSIX 1003.1, and
		 * are almost certainly the same as some of the above
		 * values, so they can't be part of the case statement.
		 */
#ifdef EXTA
		if (v == EXTA)
			return (19200);
#endif
#ifdef EXTB
		if (v == EXTB)
			return (38400);
#endif
		msgq(sp, M_ERR, "Unknown terminal baud rate %u.\n", v);
		return (9600);
	}
}

/*
 * v_strdup --
 *	Strdup for wide character strings with an associated length.
 */
CHAR_T *
v_strdup(sp, str, len)
	SCR *sp;
	CHAR_T *str;
	size_t len;
{
	CHAR_T *copy;

	MALLOC(sp, copy, CHAR_T *, len);
	if (copy == NULL)
		return (NULL);
	memmove(copy, str, len * sizeof(CHAR_T));
	return (copy);
}
@


1.5
log
@nvi 1.11(beta) from bostic.  reconcile conflicts/kill rcsids.
@
text
@@


1.4
log
@fix to misc/130, from Christos Zoulas <christos@@deshaw.com>.  don't do
stuff to the controlling tty if we don't have one!
@
text
@d2 1
a2 1
 * Copyright (c) 1991, 1993
d35 1
a35 2
/* from: static char sccsid[] = "@@(#)util.c	8.34 (Berkeley) 12/23/93"; */
static char *rcsid = "$Id: util.c,v 1.3 1994/02/09 07:06:11 cgd Exp $";
d40 2
d43 1
d47 3
d52 1
d61 4
d98 2
a99 1
		if (sp != NULL && !O_ISSET(sp, O_VERBOSE)) {
d106 1
a106 1
		if (sp != NULL && !O_ISSET(sp, O_VERBOSE))
d224 7
d238 1
a238 1
		"added", "changed", "copied", "deleted", "joined", "moved",	
d298 1
a298 1
	SCR *sp;			/* MAY BE NULL */
d302 1
a303 1
	size_t csize;
d306 1
a306 2
	csize = *bsizep;
	if (min && csize >= min)
d309 4
a312 1
	csize += MAX(min, 256);
d314 5
a319 5
	/* For non-ANSI C realloc implementations. */
	if (bpp == NULL)
		bpp = malloc(csize * sizeof(CHAR_T));
	else
		bpp = realloc(bpp, csize * sizeof(CHAR_T));
d321 4
a324 1
		msgq(sp, M_SYSERR, NULL);
d328 5
a336 1

d530 1
a530 1
	if (!F_ISSET(sp->gp, G_HAVETTY))
d558 4
d565 4
d571 4
d583 5
a587 1
		return (B115200);
@


1.3
log
@provisional fix to understand 57.6k and 115.2k
@
text
@d36 1
a36 1
static char *rcsid = "$Id: util.c,v 1.2 1994/01/24 06:39:21 cgd Exp $";
d502 3
@


1.2
log
@more Ids than you'll ever want.
@
text
@d36 1
a36 1
static char *rcsid = "$Id$";
d535 8
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)util.c	8.34 (Berkeley) 12/23/93";
@


1.1.1.1
log
@nvi 1.03, from ftp.cs.berkeley.edu, per keith bostic's permission.
@
text
@@


1.1.1.2
log
@nvi/nex 1.11beta from bostic.
@
text
@d2 1
a2 1
 * Copyright (c) 1991, 1993, 1994
d35 1
a35 1
static char sccsid[] = "@@(#)util.c	8.44 (Berkeley) 3/15/94";
a39 2
#include <sys/queue.h>
#include <sys/time.h>
a40 1
#include <bitstring.h>
a43 3
#include <limits.h>
#include <signal.h>
#include <stdio.h>
a45 1
#include <termios.h>
a53 4
#include "compat.h"
#include <db.h>
#include <regex.h>

d87 1
a87 2
		if (sp != NULL && !F_ISSET(sp, S_EXSILENT) &&
		    F_ISSET(sp->gp, G_STDIN_TTY) && !O_ISSET(sp, O_VERBOSE)) {
d94 1
a94 1
		if (sp == NULL || !O_ISSET(sp, O_VERBOSE))
a211 7
 *
 * Line counts weren't right in historic vi, either.  For example, given the
 * file:
 *	abc
 *	def
 * the command 2d}, from the 'b' would report that two lines were deleted,
 * not one.
d219 1
a219 1
		"added", "changed", "copied", "deleted", "joined", "moved",
d279 1
a279 1
	SCR *sp;			/* sp MAY BE NULL!!! */
d283 1
a284 1
	void *bpp;
d287 2
a288 1
	if (min && *bsizep >= min)
d291 1
a291 4
	/*
	 * If the initial pointer is null, use calloc (for non-ANSI
	 * C realloc implementations).
	 */
a292 5
	csize = *bsizep + MAX(min, 256);
	if (bpp == NULL) {
		MALLOC(sp, bpp, void *, csize);
	} else
		REALLOC(sp, bpp, void *, csize);
d294 5
d300 1
a300 4
		/*
		 * Theoretically, realloc is supposed to leave any already
		 * held memory alone if it can't get more.  Don't trust it.
		 */
a303 5
	/*
	 * Memory is guaranteed to be zero-filled, various parts of
	 * nvi depend on this.
	 */
	memset((char *)bpp + *bsizep, 0, csize - *bsizep);
d308 1
a501 3
	if (!F_ISSET(sp->gp, G_TERMIOS_SET))
		return (9600);

a526 4
#ifdef B7200
	case B7200:
		return (7200);
#endif
a529 4
#ifdef B14400
	case B14400:
		return (14400);
#endif
a531 4
#ifdef B28800
	case B28800:
		return (28800);
#endif
a533 12
#ifdef B57600
	case B57600:
		return (57600);
#endif
#ifdef B115200
	case B115200:
		return (115200);
#endif
#ifdef B230400
	case B230400:
		return (230400);
#endif
@
