head	1.12;
access;
symbols
	perseant-exfatfs-base-20250801:1.12
	perseant-exfatfs-base-20240630:1.12
	perseant-exfatfs:1.12.0.36
	perseant-exfatfs-base:1.12
	cjep_sun2x:1.12.0.34
	cjep_sun2x-base:1.12
	cjep_staticlib_x-base1:1.12
	cjep_staticlib_x:1.12.0.32
	cjep_staticlib_x-base:1.12
	phil-wifi-20200421:1.12
	phil-wifi-20200411:1.12
	phil-wifi-20200406:1.12
	pgoyette-compat-merge-20190127:1.12
	pgoyette-compat-20190127:1.12
	pgoyette-compat-20190118:1.12
	pgoyette-compat-1226:1.12
	pgoyette-compat-1126:1.12
	pgoyette-compat-1020:1.12
	pgoyette-compat-0930:1.12
	pgoyette-compat-0906:1.12
	pgoyette-compat-0728:1.12
	pgoyette-compat-0625:1.12
	pgoyette-compat-0521:1.12
	pgoyette-compat-0502:1.12
	pgoyette-compat-0422:1.12
	pgoyette-compat-0415:1.12
	pgoyette-compat-0407:1.12
	pgoyette-compat-0330:1.12
	pgoyette-compat-0322:1.12
	pgoyette-compat-0315:1.12
	pgoyette-compat:1.12.0.30
	pgoyette-compat-base:1.12
	perseant-stdc-iso10646:1.12.0.28
	perseant-stdc-iso10646-base:1.12
	prg-localcount2-base3:1.12
	prg-localcount2-base2:1.12
	prg-localcount2-base1:1.12
	prg-localcount2:1.12.0.26
	prg-localcount2-base:1.12
	pgoyette-localcount-20170426:1.12
	bouyer-socketcan-base1:1.12
	pgoyette-localcount-20170320:1.12
	bouyer-socketcan:1.12.0.24
	bouyer-socketcan-base:1.12
	pgoyette-localcount-20170107:1.12
	pgoyette-localcount-20161104:1.12
	localcount-20160914:1.12
	pgoyette-localcount-20160806:1.12
	pgoyette-localcount-20160726:1.12
	pgoyette-localcount:1.12.0.22
	pgoyette-localcount-base:1.12
	netbsd-5-2-3-RELEASE:1.12
	netbsd-5-1-5-RELEASE:1.12
	yamt-pagecache-base9:1.12
	yamt-pagecache-tag8:1.12
	tls-earlyentropy:1.12.0.18
	tls-earlyentropy-base:1.12
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.12
	riastradh-drm2-base3:1.12
	netbsd-5-2-2-RELEASE:1.12
	netbsd-5-1-4-RELEASE:1.12
	netbsd-5-2-1-RELEASE:1.12
	netbsd-5-1-3-RELEASE:1.12
	agc-symver:1.12.0.20
	agc-symver-base:1.12
	tls-maxphys-base:1.12
	yamt-pagecache-base8:1.12
	netbsd-5-2:1.12.0.16
	yamt-pagecache-base7:1.12
	netbsd-5-2-RELEASE:1.12
	netbsd-5-2-RC1:1.12
	yamt-pagecache-base6:1.12
	yamt-pagecache-base5:1.12
	yamt-pagecache-base4:1.12
	netbsd-5-1-2-RELEASE:1.12
	netbsd-5-1-1-RELEASE:1.12
	yamt-pagecache-base3:1.12
	yamt-pagecache-base2:1.12
	yamt-pagecache:1.12.0.14
	yamt-pagecache-base:1.12
	bouyer-quota2-nbase:1.12
	bouyer-quota2:1.12.0.12
	bouyer-quota2-base:1.12
	matt-nb5-pq3:1.12.0.10
	matt-nb5-pq3-base:1.12
	netbsd-5-1:1.12.0.8
	netbsd-5-1-RELEASE:1.12
	netbsd-5-1-RC4:1.12
	netbsd-5-1-RC3:1.12
	netbsd-5-1-RC2:1.12
	netbsd-5-1-RC1:1.12
	netbsd-5-0-2-RELEASE:1.12
	netbsd-5-0-1-RELEASE:1.12
	jym-xensuspend-nbase:1.12
	netbsd-5-0:1.12.0.6
	netbsd-5-0-RELEASE:1.12
	netbsd-5-0-RC4:1.12
	netbsd-5-0-RC3:1.12
	netbsd-5-0-RC2:1.12
	jym-xensuspend:1.12.0.4
	jym-xensuspend-base:1.12
	netbsd-5-0-RC1:1.12
	netbsd-5:1.12.0.2
	netbsd-5-base:1.12
	matt-mips64-base2:1.11
	matt-mips64:1.11.0.32
	mjf-devfs2:1.11.0.30
	mjf-devfs2-base:1.11
	netbsd-4-0-1-RELEASE:1.11
	wrstuden-revivesa-base-3:1.11
	wrstuden-revivesa-base-2:1.11
	wrstuden-fixsa-newbase:1.11
	wrstuden-revivesa-base-1:1.11
	yamt-pf42-base4:1.11
	yamt-pf42-base3:1.11
	hpcarm-cleanup-nbase:1.11
	yamt-pf42-baseX:1.11
	yamt-pf42-base2:1.11
	wrstuden-revivesa:1.11.0.28
	wrstuden-revivesa-base:1.11
	yamt-pf42:1.11.0.26
	yamt-pf42-base:1.11
	keiichi-mipv6-nbase:1.11
	keiichi-mipv6:1.11.0.24
	keiichi-mipv6-base:1.11
	matt-armv6-nbase:1.11
	matt-armv6-prevmlocking:1.11
	wrstuden-fixsa-base-1:1.11
	netbsd-4-0:1.11.0.22
	netbsd-4-0-RELEASE:1.11
	cube-autoconf:1.11.0.20
	cube-autoconf-base:1.11
	netbsd-4-0-RC5:1.11
	netbsd-4-0-RC4:1.11
	netbsd-4-0-RC3:1.11
	netbsd-4-0-RC2:1.11
	netbsd-4-0-RC1:1.11
	matt-armv6:1.11.0.18
	matt-armv6-base:1.11
	matt-mips64-base:1.11
	hpcarm-cleanup:1.11.0.16
	hpcarm-cleanup-base:1.11
	netbsd-3-1-1-RELEASE:1.11
	netbsd-3-0-3-RELEASE:1.11
	wrstuden-fixsa:1.11.0.14
	wrstuden-fixsa-base:1.11
	abandoned-netbsd-4-base:1.11
	abandoned-netbsd-4:1.11.0.8
	netbsd-3-1:1.11.0.10
	netbsd-3-1-RELEASE:1.11
	netbsd-3-0-2-RELEASE:1.11
	netbsd-3-1-RC4:1.11
	netbsd-3-1-RC3:1.11
	netbsd-3-1-RC2:1.11
	netbsd-3-1-RC1:1.11
	netbsd-4:1.11.0.12
	netbsd-4-base:1.11
	chap-midi-nbase:1.11
	netbsd-3-0-1-RELEASE:1.11
	chap-midi:1.11.0.6
	chap-midi-base:1.11
	netbsd-3-0:1.11.0.4
	netbsd-3-0-RELEASE:1.11
	netbsd-3-0-RC6:1.11
	netbsd-3-0-RC5:1.11
	netbsd-3-0-RC4:1.11
	netbsd-3-0-RC3:1.11
	netbsd-3-0-RC2:1.11
	netbsd-3-0-RC1:1.11
	netbsd-2-0-3-RELEASE:1.10.4.2
	netbsd-2-1:1.10.6.1.0.2
	netbsd-2-1-RELEASE:1.10.6.1
	netbsd-2-1-RC6:1.10.6.1
	netbsd-2-1-RC5:1.10.6.1
	netbsd-2-1-RC4:1.10.6.1
	netbsd-2-1-RC3:1.10.6.1
	netbsd-2-1-RC2:1.10.6.1
	netbsd-2-1-RC1:1.10.6.1
	netbsd-2-0-2-RELEASE:1.10.4.2
	netbsd-3:1.11.0.2
	netbsd-3-base:1.11
	netbsd-2-0-1-RELEASE:1.10
	netbsd-2:1.10.0.6
	netbsd-2-base:1.10
	netbsd-2-0-RELEASE:1.10
	netbsd-2-0-RC5:1.10
	netbsd-2-0-RC4:1.10
	netbsd-2-0-RC3:1.10
	netbsd-2-0-RC2:1.10
	netbsd-2-0-RC1:1.10
	netbsd-2-0:1.10.0.4
	netbsd-2-0-base:1.10
	netbsd-1-6-PATCH002-RELEASE:1.10
	netbsd-1-6-PATCH002:1.10
	netbsd-1-6-PATCH002-RC4:1.10
	netbsd-1-6-PATCH002-RC3:1.10
	netbsd-1-6-PATCH002-RC2:1.10
	netbsd-1-6-PATCH002-RC1:1.10
	netbsd-1-6-PATCH001:1.10
	netbsd-1-6-PATCH001-RELEASE:1.10
	netbsd-1-6-PATCH001-RC3:1.10
	netbsd-1-6-PATCH001-RC2:1.10
	netbsd-1-6-PATCH001-RC1:1.10
	fvdl_fs64_base:1.10
	netbsd-1-6-RELEASE:1.10
	netbsd-1-6-RC3:1.10
	netbsd-1-6-RC2:1.10
	netbsd-1-6-RC1:1.10
	netbsd-1-6:1.10.0.2
	netbsd-1-6-base:1.10
	netbsd-1-5-PATCH003:1.7.10.1
	netbsd-1-5-PATCH002:1.7.10.1
	netbsd-1-5-PATCH001:1.7.10.1
	nvi_1_79:1.1.1.5
	netbsd-1-5-RELEASE:1.7.10.1
	netbsd-1-5-BETA2:1.7.10.1
	netbsd-1-5-BETA:1.7.10.1
	netbsd-1-4-PATCH003:1.7.2.1
	netbsd-1-5-ALPHA2:1.7
	netbsd-1-5:1.7.0.10
	netbsd-1-5-base:1.7
	minoura-xpg4dl-base:1.7
	minoura-xpg4dl:1.7.0.8
	netbsd-1-4-PATCH002:1.7
	wrstuden-devbsize-19991221:1.7
	wrstuden-devbsize:1.7.0.6
	wrstuden-devbsize-base:1.7
	comdex-fall-1999:1.7.0.4
	comdex-fall-1999-base:1.7
	netbsd-1-4-PATCH001:1.7
	netbsd-1-4-RELEASE:1.7
	netbsd-1-4:1.7.0.2
	netbsd-1-4-base:1.7
	netbsd-1-3-PATCH003:1.6
	netbsd-1-3-PATCH003-CANDIDATE2:1.6
	netbsd-1-3-PATCH003-CANDIDATE1:1.6
	netbsd-1-3-PATCH003-CANDIDATE0:1.6
	netbsd-1-3-PATCH002:1.6
	netbsd-1-3-PATCH001:1.6
	netbsd-1-3-RELEASE:1.6
	netbsd-1-3-BETA:1.6
	netbsd-1-3:1.6.0.2
	netbsd-1-3-base:1.6
	netbsd-1-2-PATCH001:1.6
	netbsd-1-2-RELEASE:1.6
	netbsd-1-2-BETA:1.6
	netbsd-1-2:1.6.0.4
	netbsd-1-2-base:1.6
	nvi_1_66:1.1.1.5
	BOSTIC:1.1.1
	netbsd-1-1-PATCH001:1.5
	netbsd-1-1-RELEASE:1.5
	netbsd-1-1:1.5.0.4
	netbsd-1-1-base:1.5
	netbsd-1-0-PATCH06:1.5
	netbsd-1-0-PATCH05:1.5
	netbsd-1-0-PATCH04:1.5
	netbsd-1-0-PATCH03:1.5
	netbsd-1-0-PATCH02:1.5
	netbsd-1-0-PATCH1:1.5
	netbsd-1-0-PATCH0:1.5
	netbsd-1-0-RELEASE:1.5
	netbsd-1-0:1.5.0.2
	nvi-1-34b:1.1.1.4
	nvi-1-33b:1.1.1.3
	netbsd-1-0-base:1.3
	nvi-1-11b:1.1.1.2
	nvi-1-03:1.1.1.1
	bostic-nvi:1.1.1;
locks; strict;
comment	@ * @;


1.12
date	2008.10.29.16.49.37;	author christos;	state dead;
branches;
next	1.11;

1.11
date	2005.02.12.12.53.23;	author aymeric;	state Exp;
branches;
next	1.10;

1.10
date	2002.04.09.01.47.33;	author thorpej;	state Exp;
branches
	1.10.4.1
	1.10.6.1;
next	1.9;

1.9
date	2001.03.31.11.37.50;	author aymeric;	state Exp;
branches;
next	1.8;

1.8
date	2000.10.11.14.46.21;	author is;	state Exp;
branches;
next	1.7;

1.7
date	98.01.09.08.07.57;	author perry;	state Exp;
branches
	1.7.2.1
	1.7.10.1;
next	1.6;

1.6
date	96.05.20.03.47.48;	author mrg;	state Exp;
branches;
next	1.5;

1.5
date	94.08.17.20.12.45;	author cgd;	state Exp;
branches
	1.5.2.1;
next	1.4;

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

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

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

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

1.10.4.1
date	2005.02.12.12.24.13;	author aymeric;	state Exp;
branches;
next	1.10.4.2;

1.10.4.2
date	2005.02.12.12.46.26;	author aymeric;	state Exp;
branches;
next	;

1.10.6.1
date	2005.05.06.14.42.05;	author riz;	state Exp;
branches;
next	;

1.7.2.1
date	2000.10.19.16.33.03;	author he;	state Exp;
branches;
next	;

1.7.10.1
date	2000.10.18.01.32.53;	author tv;	state Exp;
branches;
next	;

1.5.2.1
date	94.08.17.20.12.45;	author cgd;	state dead;
branches;
next	1.5.2.2;

1.5.2.2
date	94.08.17.20.12.46;	author cgd;	state Exp;
branches;
next	;

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

1.1.1.2
date	94.03.28.02.54.46;	author cgd;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	94.08.17.16.16.47;	author cgd;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	94.08.17.19.18.18;	author cgd;	state Exp;
branches;
next	1.1.1.5;

1.1.1.5
date	96.05.20.01.56.12;	author mrg;	state Exp;
branches;
next	;


desc
@@


1.12
log
@bye old vi!
@
text
@/*	$NetBSD: ex_print.c,v 1.11 2005/02/12 12:53:23 aymeric Exp $	*/

/*-
 * Copyright (c) 1992, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 * Copyright (c) 1992, 1993, 1994, 1995, 1996
 *	Keith Bostic.  All rights reserved.
 *
 * See the LICENSE file for redistribution information.
 */

#include "config.h"

#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char sccsid[] = "@@(#)ex_print.c	10.18 (Berkeley) 5/12/96";
#else
__RCSID("$NetBSD: ex_print.c,v 1.11 2005/02/12 12:53:23 aymeric Exp $");
#endif
#endif /* not lint */

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

#include <bitstring.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

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

#include "../common/common.h"

static int ex_prchars __P((SCR *, const char *, size_t *, size_t, u_int, int));

/*
 * ex_list -- :[line [,line]] l[ist] [count] [flags]
 *
 *	Display the addressed lines such that the output is unambiguous.
 *
 * PUBLIC: int ex_list __P((SCR *, EXCMD *));
 */
int
ex_list(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	if (ex_print(sp, cmdp,
	    &cmdp->addr1, &cmdp->addr2, cmdp->iflags | E_C_LIST))
		return (1);
	sp->lno = cmdp->addr2.lno;
	sp->cno = cmdp->addr2.cno;
	return (0);
}

/*
 * ex_number -- :[line [,line]] nu[mber] [count] [flags]
 *
 *	Display the addressed lines with a leading line number.
 *
 * PUBLIC: int ex_number __P((SCR *, EXCMD *));
 */
int
ex_number(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	if (ex_print(sp, cmdp,
	    &cmdp->addr1, &cmdp->addr2, cmdp->iflags | E_C_HASH))
		return (1);
	sp->lno = cmdp->addr2.lno;
	sp->cno = cmdp->addr2.cno;
	return (0);
}

/*
 * ex_pr -- :[line [,line]] p[rint] [count] [flags]
 *
 *	Display the addressed lines.
 *
 * PUBLIC: int ex_pr __P((SCR *, EXCMD *));
 */
int
ex_pr(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	if (ex_print(sp, cmdp, &cmdp->addr1, &cmdp->addr2, cmdp->iflags))
		return (1);
	sp->lno = cmdp->addr2.lno;
	sp->cno = cmdp->addr2.cno;
	return (0);
}

/*
 * ex_print --
 *	Print the selected lines.
 *
 * PUBLIC: int ex_print __P((SCR *, EXCMD *, MARK *, MARK *, u_int32_t));
 */
int
ex_print(sp, cmdp, fp, tp, flags)
	SCR *sp;
	EXCMD *cmdp;
	MARK *fp, *tp;
	u_int32_t flags;
{
	GS *gp;
	recno_t from, to;
	size_t col, len;
	char *p, buf[10];

	NEEDFILE(sp, cmdp);

	gp = sp->gp;
	for (from = fp->lno, to = tp->lno; from <= to; ++from) {
		col = 0;

		/*
		 * Display the line number.  The %6 format is specified
		 * by POSIX 1003.2, and is almost certainly large enough.
		 * Check, though, just in case.
		 */
		if (LF_ISSET(E_C_HASH)) {
			if (from <= 999999) {
				snprintf(buf, sizeof(buf), "%6ld  ",
					 (long) from);
				p = buf;
			} else
				p = "TOOBIG  ";
			if (ex_prchars(sp, p, &col, 8, 0, 0))
				return (1);
		}

		/*
		 * Display the line.  The format for E_C_PRINT isn't very good,
		 * especially in handling end-of-line tabs, but they're almost
		 * backward compatible.
		 */
		if (db_get(sp, from, DBG_FATAL, &p, &len))
			return (1);

		if (len == 0 && !LF_ISSET(E_C_LIST))
			(void)ex_puts(sp, "\n");
		else if (ex_ldisplay(sp, p, len, col, flags))
			return (1);

		if (INTERRUPTED(sp))
			break;
	}
	return (0);
}

/*
 * ex_ldisplay --
 *	Display a line without any preceding number.
 *
 * PUBLIC: int ex_ldisplay __P((SCR *, const char *, size_t, size_t, u_int));
 */
int
ex_ldisplay(sp, p, len, col, flags)
	SCR *sp;
	const char *p;
	size_t len, col;
	u_int flags;
{
	if (len > 0 && ex_prchars(sp, p, &col, len, LF_ISSET(E_C_LIST), 0))
		return (1);
	if (!INTERRUPTED(sp) && LF_ISSET(E_C_LIST)) {
		p = "$";
		if (ex_prchars(sp, p, &col, 1, LF_ISSET(E_C_LIST), 0))
			return (1);
	}
	if (!INTERRUPTED(sp))
		(void)ex_puts(sp, "\n");
	return (0);
}

/*
 * ex_scprint --
 *	Display a line for the substitute with confirmation routine.
 *
 * PUBLIC: int ex_scprint __P((SCR *, MARK *, MARK *));
 */
int
ex_scprint(sp, fp, tp)
	SCR *sp;
	MARK *fp, *tp;
{
	const char *p;
	size_t col, len;

	col = 0;
	if (O_ISSET(sp, O_NUMBER)) {
		p = "        ";
		if (ex_prchars(sp, p, &col, 8, 0, 0))
			return (1);
	}

	if (db_get(sp, fp->lno, DBG_FATAL, (char **)&p, &len))
		return (1);

	if (ex_prchars(sp, p, &col, fp->cno, 0, ' '))
		return (1);
	p += fp->cno;
	if (ex_prchars(sp,
	    p, &col, tp->cno == fp->cno ? 1 : tp->cno - fp->cno, 0, '^'))
		return (1);
	if (INTERRUPTED(sp))
		return (1);
	p = "[ynq]";		/* XXX: should be msg_cat. */
	if (ex_prchars(sp, p, &col, 5, 0, 0))
		return (1);
	(void)ex_fflush(sp);
	return (0);
}

/*
 * ex_prchars --
 *	Local routine to dump characters to the screen.
 */
static int
ex_prchars(sp, p, colp, len, flags, repeatc)
	SCR *sp;
	const char *p;
	size_t *colp, len;
	u_int flags;
	int repeatc;
{
	CHAR_T ch, *kp;
	GS *gp;
	size_t col, tlen, ts;

	if (O_ISSET(sp, O_LIST))
		LF_SET(E_C_LIST);
	gp = sp->gp;
	ts = O_VAL(sp, O_TABSTOP);
	for (col = *colp; len--;)
		if ((ch = *p++) == '\t' && !LF_ISSET(E_C_LIST))
			for (tlen = ts - col % ts;
			    col < sp->cols && tlen--; ++col) {
				(void)ex_printf(sp,
				    "%c", repeatc ? repeatc : ' ');
				if (INTERRUPTED(sp))
					goto intr;
			}
		else {
			kp = KEY_NAME(sp, ch);
			tlen = KEY_LEN(sp, ch);
			if (!repeatc  && col + tlen < sp->cols) {
				(void)ex_puts(sp, kp);
				col += tlen;
			} else
				for (; tlen--; ++kp, ++col) {
					if (col == sp->cols) {
						col = 0;
						(void)ex_puts(sp, "\n");
					}
					(void)ex_printf(sp,
					    "%c", repeatc ? repeatc : *kp);
					if (INTERRUPTED(sp))
						goto intr;
				}
		}
intr:	*colp = col;
	return (0);
}

/*
 * ex_printf --
 *	Ex's version of printf.
 *
 * PUBLIC: int ex_printf __P((SCR *, const char *, ...));
 */
int
#ifdef __STDC__
ex_printf(SCR *sp, const char *fmt, ...)
#else
ex_printf(sp, fmt, va_alist)
	SCR *sp;
	const char *fmt;
	va_dcl
#endif
{
	EX_PRIVATE *exp;
	va_list ap;
	size_t n;

	exp = EXP(sp);

#ifdef __STDC__
	va_start(ap, fmt);
#else
	va_start(ap);
#endif
	exp->obp_len += n = vsnprintf(exp->obp + exp->obp_len,
	    sizeof(exp->obp) - exp->obp_len, fmt, ap);
	va_end(ap);

	/* Flush when reach a <newline> or half the buffer. */
	if (exp->obp[exp->obp_len - 1] == '\n' ||
	    exp->obp_len > sizeof(exp->obp) / 2)
		(void)ex_fflush(sp);
	return (n);
}

/*
 * ex_puts --
 *	Ex's version of puts.
 *
 * PUBLIC: int ex_puts __P((SCR *, const char *));
 */
int
ex_puts(sp, str)
	SCR *sp;
	const char *str;
{
	EX_PRIVATE *exp;
	int doflush, n;

	exp = EXP(sp);

	/* Flush when reach a <newline> or the end of the buffer. */
	for (doflush = n = 0; *str != '\0'; ++n) {
		if (exp->obp_len > sizeof(exp->obp))
			(void)ex_fflush(sp);
		if ((exp->obp[exp->obp_len++] = *str++) == '\n')
			doflush = 1;
	}
	if (doflush)
		(void)ex_fflush(sp);
	return (n);
}

/*
 * ex_fflush --
 *	Ex's version of fflush.
 *
 * PUBLIC: int ex_fflush __P((SCR *sp));
 */
int
ex_fflush(sp)
	SCR *sp;
{
	EX_PRIVATE *exp;

	exp = EXP(sp);

	if (exp->obp_len != 0) {
		sp->gp->scr_msg(sp, M_NONE, exp->obp, exp->obp_len);
		exp->obp_len = 0;
	}
	return (0);
}
@


1.11
log
@Fix the RCSID's to be $NetBSD$ instead of $NetBSD
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.10 2002/04/09 01:47:33 thorpej Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD$");
@


1.10
log
@Use __RCSID() and __COPYRIGHT().
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.9 2001/03/31 11:37:50 aymeric Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD");
@


1.10.6.1
log
@Pull up revision 1.11 (requested by aymeric in ticket #1195):
Fix the RCSID's to be $NetBSD$ instead of $NetBSD
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.10 2002/04/09 01:47:33 thorpej Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD$");
@


1.10.4.1
log
@Fix the RCSID's to be $NetBSD$ instead of $NetBSD
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.10 2002/04/09 01:47:33 thorpej Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD$");
@


1.10.4.2
log
@Backout previous. Sorry.
@
text
@d19 1
a19 1
__RCSID("$NetBSD");
@


1.9
log
@merge changes after import of nvi 1.79
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.8 2000/10/11 14:46:21 is Exp $	*/
d14 1
d16 1
d18 3
@


1.8
log
@More format string cleanup by sommerfeld.
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.7 1998/01/09 08:07:57 perry Exp $	*/
d127 2
a128 2
				snprintf(buf, sizeof(buf), "%6ld  ", 
					 (long)from);
@


1.7
log
@RCS Id Police.
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d127 2
a128 1
				snprintf(buf, sizeof(buf), "%6ld  ", from);
@


1.7.2.1
log
@Pull up revision 1.8 (requested by he):
  Format string cleanup.
@
text
@d127 1
a127 2
				snprintf(buf, sizeof(buf), "%6ld  ", 
					 (long)from);
@


1.7.10.1
log
@Pullup usr.bin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
@
text
@d1 1
a1 1
/*	$NetBSD: ex_print.c,v 1.8 2000/10/11 14:46:21 is Exp $	*/
d127 1
a127 2
				snprintf(buf, sizeof(buf), "%6ld  ", 
					 (long)from);
@


1.6
log
@merge in nvi 1.66
@
text
@d1 2
@


1.5
log
@clean up import.
@
text
@d4 2
d7 1
a7 27
 * 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.
d10 2
d13 1
a13 1
static char sccsid[] = "@@(#)ex_print.c	8.16 (Berkeley) 8/17/94";
a17 1
#include <sys/time.h>
a21 1
#include <signal.h>
a23 1
#include <termios.h>
d25 7
a31 3
#include "compat.h"
#include <db.h>
#include <regex.h>
d33 1
a33 2
#include "vi.h"
#include "excmd.h"
d39 2
d43 1
a43 1
ex_list(sp, ep, cmdp)
d45 1
a45 2
	EXF *ep;
	EXCMDARG *cmdp;
d47 2
a48 2
	if (ex_print(sp, ep,
	    &cmdp->addr1, &cmdp->addr2, cmdp->flags | E_F_LIST))
d59 2
d63 1
a63 1
ex_number(sp, ep, cmdp)
d65 1
a65 2
	EXF *ep;
	EXCMDARG *cmdp;
d67 2
a68 2
	if (ex_print(sp, ep,
	    &cmdp->addr1, &cmdp->addr2, cmdp->flags | E_F_HASH))
d79 2
d83 1
a83 1
ex_pr(sp, ep, cmdp)
d85 1
a85 2
	EXF *ep;
	EXCMDARG *cmdp;
d87 1
a87 1
	if (ex_print(sp, ep, &cmdp->addr1, &cmdp->addr2, cmdp->flags))
d97 2
d101 1
a101 1
ex_print(sp, ep, fp, tp, flags)
d103 1
a103 1
	EXF *ep;
d105 1
a105 1
	register int flags;
d107 1
d110 3
a112 1
	char *p;
d114 1
a114 1
	F_SET(sp, S_INTERRUPTIBLE);
d116 2
d123 9
a131 7
		if (LF_ISSET(E_F_HASH))
			if (from <= 999999)
				col = ex_printf(EXCOOKIE, "%6ld  ", from);
			else
				col = ex_printf(EXCOOKIE, "TOOBIG  ");
		else
			col = 0;
d134 1
a134 1
		 * Display the line.  The format for E_F_PRINT isn't very good,
d138 1
a138 2
		if ((p = file_gline(sp, ep, from, &len)) == NULL) {
			GETLINE_ERR(sp, from);
a139 1
		}
d141 2
a142 2
		if (len == 0 && !LF_ISSET(E_F_LIST))
			(void)ex_printf(EXCOOKIE, "\n");
a148 1

d154 3
a156 1
 *	Display a line.
d159 1
a159 1
ex_ldisplay(sp, lp, len, col, flags)
d161 1
a161 1
	CHAR_T *lp;
d165 63
d229 2
a230 2
	u_long ts;
	size_t tlen;
d232 3
d236 2
a237 8
	for (;; --len) {
		if (len > 0)
			ch = *lp++;
		else if (LF_ISSET(E_F_LIST))
			ch = '$';
		else
			break;
		if (ch == '\t' && !LF_ISSET(E_F_LIST))
d239 6
a244 2
			    col < sp->cols && tlen--; ++col)
				(void)ex_printf(EXCOOKIE, " ");
d248 2
a249 2
			if (col + tlen < sp->cols) {
				(void)ex_printf(EXCOOKIE, "%s", kp);
d255 1
a255 1
						(void)ex_printf(EXCOOKIE, "\n");
d257 4
a260 1
					(void)ex_printf(EXCOOKIE, "%c", *kp);
d263 87
a349 2
		if (len == 0)
			break;
a350 1
	(void)ex_printf(EXCOOKIE, "\n");
@


1.5.2.1
log
@file ex_print.c was added on branch netbsd-1-0 on 1994-08-17 20:12:46 +0000
@
text
@d1 212
@


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

#ifndef lint
static char sccsid[] = "@@(#)ex_print.c	8.16 (Berkeley) 8/17/94";
#endif /* not lint */

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

#include <bitstring.h>
#include <ctype.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>

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

#include "vi.h"
#include "excmd.h"

/*
 * ex_list -- :[line [,line]] l[ist] [count] [flags]
 *
 *	Display the addressed lines such that the output is unambiguous.
 */
int
ex_list(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	if (ex_print(sp, ep,
	    &cmdp->addr1, &cmdp->addr2, cmdp->flags | E_F_LIST))
		return (1);
	sp->lno = cmdp->addr2.lno;
	sp->cno = cmdp->addr2.cno;
	return (0);
}

/*
 * ex_number -- :[line [,line]] nu[mber] [count] [flags]
 *
 *	Display the addressed lines with a leading line number.
 */
int
ex_number(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	if (ex_print(sp, ep,
	    &cmdp->addr1, &cmdp->addr2, cmdp->flags | E_F_HASH))
		return (1);
	sp->lno = cmdp->addr2.lno;
	sp->cno = cmdp->addr2.cno;
	return (0);
}

/*
 * ex_pr -- :[line [,line]] p[rint] [count] [flags]
 *
 *	Display the addressed lines.
 */
int
ex_pr(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	if (ex_print(sp, ep, &cmdp->addr1, &cmdp->addr2, cmdp->flags))
		return (1);
	sp->lno = cmdp->addr2.lno;
	sp->cno = cmdp->addr2.cno;
	return (0);
}

/*
 * ex_print --
 *	Print the selected lines.
 */
int
ex_print(sp, ep, fp, tp, flags)
	SCR *sp;
	EXF *ep;
	MARK *fp, *tp;
	register int flags;
{
	recno_t from, to;
	size_t col, len;
	char *p;

	F_SET(sp, S_INTERRUPTIBLE);
	for (from = fp->lno, to = tp->lno; from <= to; ++from) {
		/*
		 * Display the line number.  The %6 format is specified
		 * by POSIX 1003.2, and is almost certainly large enough.
		 * Check, though, just in case.
		 */
		if (LF_ISSET(E_F_HASH))
			if (from <= 999999)
				col = ex_printf(EXCOOKIE, "%6ld  ", from);
			else
				col = ex_printf(EXCOOKIE, "TOOBIG  ");
		else
			col = 0;

		/*
		 * Display the line.  The format for E_F_PRINT isn't very good,
		 * especially in handling end-of-line tabs, but they're almost
		 * backward compatible.
		 */
		if ((p = file_gline(sp, ep, from, &len)) == NULL) {
			GETLINE_ERR(sp, from);
			return (1);
		}

		if (len == 0 && !LF_ISSET(E_F_LIST))
			(void)ex_printf(EXCOOKIE, "\n");
		else if (ex_ldisplay(sp, p, len, col, flags))
			return (1);

		if (INTERRUPTED(sp))
			break;
	}

	return (0);
}

/*
 * ex_ldisplay --
 *	Display a line.
 */
int
ex_ldisplay(sp, lp, len, col, flags)
	SCR *sp;
	CHAR_T *lp;
	size_t len, col;
	u_int flags;
{
	CHAR_T ch, *kp;
	u_long ts;
	size_t tlen;

	ts = O_VAL(sp, O_TABSTOP);
	for (;; --len) {
		if (len > 0)
			ch = *lp++;
		else if (LF_ISSET(E_F_LIST))
			ch = '$';
		else
			break;
		if (ch == '\t' && !LF_ISSET(E_F_LIST))
			for (tlen = ts - col % ts;
			    col < sp->cols && tlen--; ++col)
				(void)ex_printf(EXCOOKIE, " ");
		else {
			kp = KEY_NAME(sp, ch);
			tlen = KEY_LEN(sp, ch);
			if (col + tlen < sp->cols) {
				(void)ex_printf(EXCOOKIE, "%s", kp);
				col += tlen;
			} else
				for (; tlen--; ++kp, ++col) {
					if (col == sp->cols) {
						col = 0;
						(void)ex_printf(EXCOOKIE, "\n");
					}
					(void)ex_printf(EXCOOKIE, "%c", *kp);
				}
		}
		if (len == 0)
			break;
	}
	(void)ex_printf(EXCOOKIE, "\n");
	return (0);
}
@


1.4
log
@clean up import.  still have to hack some things.
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_print.c	8.15 (Berkeley) 8/17/94";
@


1.3
log
@nvi 1.11(beta) from bostic.  reconcile conflicts/kill rcsids.
@
text
@d35 1
a35 1
static char sccsid[] = "@@(#)ex_print.c	8.8 (Berkeley) 3/14/94";
a123 1
	register int ch, col, rlen;
d125 2
a126 3
	size_t len;
	int cnt;
	char *p, buf[10];
d130 5
a134 1
		/* Display the line number. */
d136 4
a139 1
			col = ex_printf(EXCOOKIE, "%7ld ", from);
d153 10
a162 7
#define	WCHECK(ch) {							\
	if (col == sp->cols) {						\
		(void)ex_printf(EXCOOKIE, "\n");			\
		col = 0;						\
	}								\
	(void)ex_printf(EXCOOKIE, "%c", ch);				\
	++col;								\
d164 36
a199 21
		for (rlen = len; rlen--;) {
			ch = *p++;
			if (LF_ISSET(E_F_LIST))
				if (ch != '\t' && isprint(ch)) {
					WCHECK(ch);
				} else if (ch & 0x80) {
					(void)snprintf(buf,
					    sizeof(buf), "\\%03o", ch);
					len = strlen(buf);
					for (cnt = 0; cnt < len; ++cnt)
						WCHECK(buf[cnt]);
				} else {
					WCHECK('^');
					WCHECK(ch + 0x40);
				}
			else {
				ch &= 0x7f;
				if (ch == '\t') {
					while (col < sp->cols &&
					    ++col % O_VAL(sp, O_TABSTOP))
						(void)ex_printf(EXCOOKIE, " ");
d204 1
a204 8
				} else if (isprint(ch)) {
					WCHECK(ch);
				} else if (ch == '\n') {
					col = 0;
					(void)ex_printf(EXCOOKIE, "\n");
				} else {
					WCHECK('^');
					WCHECK(ch + 0x40);
a205 1
			}
d207 1
a207 12
		if (LF_ISSET(E_F_LIST)) {
			WCHECK('$');
		} else if (len == 0) {
			/*
			 * If the line is empty, output a space
			 * to overwrite the colon prompt.
			 */
			WCHECK(' ');
		}
		(void)ex_printf(EXCOOKIE, "\n");

		if (F_ISSET(sp, S_INTERRUPTED))
d210 1
@


1.2
log
@more Ids than you'll ever want.
@
text
@d2 1
a2 1
 * Copyright (c) 1992, 1993
d35 1
a35 2
/* from: static char sccsid[] = "@@(#)ex_print.c	8.6 (Berkeley) 11/2/93"; */
static char *rcsid = "$Id$";
d39 2
d42 1
d44 3
d48 5
d137 1
a137 1
	
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)ex_print.c	8.6 (Berkeley) 11/2/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) 1992, 1993, 1994
d35 1
a35 1
static char sccsid[] = "@@(#)ex_print.c	8.8 (Berkeley) 3/14/94";
a38 2
#include <sys/queue.h>
#include <sys/time.h>
a39 1
#include <bitstring.h>
a40 3
#include <limits.h>
#include <signal.h>
#include <stdio.h>
a41 5
#include <termios.h>

#include "compat.h"
#include <db.h>
#include <regex.h>
d126 1
a126 1

@


1.1.1.3
log
@new public version of nvi
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_print.c	8.15 (Berkeley) 8/17/94";
d124 1
d126 3
a128 2
	size_t col, len;
	char *p;
d132 1
a132 5
		/*
		 * Display the line number.  The %6 format is specified
		 * by POSIX 1003.2, and is almost certainly large enough.
		 * Check, though, just in case.
		 */
d134 1
a134 4
			if (from <= 999999)
				col = ex_printf(EXCOOKIE, "%6ld  ", from);
			else
				col = ex_printf(EXCOOKIE, "TOOBIG  ");
d148 7
a154 10
		if (len == 0 && !LF_ISSET(E_F_LIST))
			(void)ex_printf(EXCOOKIE, "\n");
		else if (ex_ldisplay(sp, p, len, col, flags))
			return (1);

		if (INTERRUPTED(sp))
			break;
	}

	return (0);
d156 21
a176 36

/*
 * ex_ldisplay --
 *	Display a line.
 */
int
ex_ldisplay(sp, lp, len, col, flags)
	SCR *sp;
	CHAR_T *lp;
	size_t len, col;
	u_int flags;
{
	CHAR_T ch, *kp;
	u_long ts;
	size_t tlen;

	ts = O_VAL(sp, O_TABSTOP);
	for (;; --len) {
		if (len > 0)
			ch = *lp++;
		else if (LF_ISSET(E_F_LIST))
			ch = '$';
		else
			break;
		if (ch == '\t' && !LF_ISSET(E_F_LIST))
			for (tlen = ts - col % ts;
			    col < sp->cols && tlen--; ++col)
				(void)ex_printf(EXCOOKIE, " ");
		else {
			kp = KEY_NAME(sp, ch);
			tlen = KEY_LEN(sp, ch);
			if (col + tlen < sp->cols) {
				(void)ex_printf(EXCOOKIE, "%s", kp);
				col += tlen;
			} else
				for (; tlen--; ++kp, ++col) {
d181 8
a188 1
					(void)ex_printf(EXCOOKIE, "%c", *kp);
d190 1
d192 12
a203 1
		if (len == 0)
a205 1
	(void)ex_printf(EXCOOKIE, "\n");
@


1.1.1.4
log
@new public version of nvi
@
text
@d35 1
a35 1
static char sccsid[] = "@@(#)ex_print.c	8.16 (Berkeley) 8/17/94";
@


1.1.1.5
log
@import of nvi 1.66
@
text
@a3 2
 * Copyright (c) 1992, 1993, 1994, 1995, 1996
 *	Keith Bostic.  All rights reserved.
d5 27
a31 1
 * See the LICENSE file for redistribution information.
a33 2
#include "config.h"

d35 1
a35 1
static const char sccsid[] = "@@(#)ex_print.c	10.18 (Berkeley) 5/12/96";
d40 1
d45 1
d48 1
d50 3
a52 7
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif

#include "../common/common.h"
d54 2
a55 1
static int ex_prchars __P((SCR *, const char *, size_t *, size_t, u_int, int));
a60 2
 *
 * PUBLIC: int ex_list __P((SCR *, EXCMD *));
d63 1
a63 1
ex_list(sp, cmdp)
d65 2
a66 1
	EXCMD *cmdp;
d68 2
a69 2
	if (ex_print(sp, cmdp,
	    &cmdp->addr1, &cmdp->addr2, cmdp->iflags | E_C_LIST))
a79 2
 *
 * PUBLIC: int ex_number __P((SCR *, EXCMD *));
d82 1
a82 1
ex_number(sp, cmdp)
d84 2
a85 1
	EXCMD *cmdp;
d87 2
a88 2
	if (ex_print(sp, cmdp,
	    &cmdp->addr1, &cmdp->addr2, cmdp->iflags | E_C_HASH))
a98 2
 *
 * PUBLIC: int ex_pr __P((SCR *, EXCMD *));
d101 1
a101 1
ex_pr(sp, cmdp)
d103 2
a104 1
	EXCMD *cmdp;
d106 1
a106 1
	if (ex_print(sp, cmdp, &cmdp->addr1, &cmdp->addr2, cmdp->iflags))
a115 2
 *
 * PUBLIC: int ex_print __P((SCR *, EXCMD *, MARK *, MARK *, u_int32_t));
d118 1
a118 1
ex_print(sp, cmdp, fp, tp, flags)
d120 1
a120 1
	EXCMD *cmdp;
d122 1
a122 1
	u_int32_t flags;
a123 1
	GS *gp;
d126 1
a126 3
	char *p, buf[10];

	NEEDFILE(sp, cmdp);
d128 1
a128 1
	gp = sp->gp;
a129 2
		col = 0;

d135 7
a141 9
		if (LF_ISSET(E_C_HASH)) {
			if (from <= 999999) {
				snprintf(buf, sizeof(buf), "%6ld  ", from);
				p = buf;
			} else
				p = "TOOBIG  ";
			if (ex_prchars(sp, p, &col, 8, 0, 0))
				return (1);
		}
d144 1
a144 1
		 * Display the line.  The format for E_C_PRINT isn't very good,
d148 2
a149 1
		if (db_get(sp, from, DBG_FATAL, &p, &len))
d151 1
d153 2
a154 2
		if (len == 0 && !LF_ISSET(E_C_LIST))
			(void)ex_puts(sp, "\n");
d161 1
d167 1
a167 3
 *	Display a line without any preceding number.
 *
 * PUBLIC: int ex_ldisplay __P((SCR *, const char *, size_t, size_t, u_int));
d170 1
a170 1
ex_ldisplay(sp, p, len, col, flags)
d172 1
a172 1
	const char *p;
a175 63
	if (len > 0 && ex_prchars(sp, p, &col, len, LF_ISSET(E_C_LIST), 0))
		return (1);
	if (!INTERRUPTED(sp) && LF_ISSET(E_C_LIST)) {
		p = "$";
		if (ex_prchars(sp, p, &col, 1, LF_ISSET(E_C_LIST), 0))
			return (1);
	}
	if (!INTERRUPTED(sp))
		(void)ex_puts(sp, "\n");
	return (0);
}

/*
 * ex_scprint --
 *	Display a line for the substitute with confirmation routine.
 *
 * PUBLIC: int ex_scprint __P((SCR *, MARK *, MARK *));
 */
int
ex_scprint(sp, fp, tp)
	SCR *sp;
	MARK *fp, *tp;
{
	const char *p;
	size_t col, len;

	col = 0;
	if (O_ISSET(sp, O_NUMBER)) {
		p = "        ";
		if (ex_prchars(sp, p, &col, 8, 0, 0))
			return (1);
	}

	if (db_get(sp, fp->lno, DBG_FATAL, (char **)&p, &len))
		return (1);

	if (ex_prchars(sp, p, &col, fp->cno, 0, ' '))
		return (1);
	p += fp->cno;
	if (ex_prchars(sp,
	    p, &col, tp->cno == fp->cno ? 1 : tp->cno - fp->cno, 0, '^'))
		return (1);
	if (INTERRUPTED(sp))
		return (1);
	p = "[ynq]";		/* XXX: should be msg_cat. */
	if (ex_prchars(sp, p, &col, 5, 0, 0))
		return (1);
	(void)ex_fflush(sp);
	return (0);
}

/*
 * ex_prchars --
 *	Local routine to dump characters to the screen.
 */
static int
ex_prchars(sp, p, colp, len, flags, repeatc)
	SCR *sp;
	const char *p;
	size_t *colp, len;
	u_int flags;
	int repeatc;
{
d177 2
a178 2
	GS *gp;
	size_t col, tlen, ts;
a179 3
	if (O_ISSET(sp, O_LIST))
		LF_SET(E_C_LIST);
	gp = sp->gp;
d181 8
a188 2
	for (col = *colp; len--;)
		if ((ch = *p++) == '\t' && !LF_ISSET(E_C_LIST))
d190 2
a191 6
			    col < sp->cols && tlen--; ++col) {
				(void)ex_printf(sp,
				    "%c", repeatc ? repeatc : ' ');
				if (INTERRUPTED(sp))
					goto intr;
			}
d195 2
a196 2
			if (!repeatc  && col + tlen < sp->cols) {
				(void)ex_puts(sp, kp);
d202 1
a202 1
						(void)ex_puts(sp, "\n");
d204 1
a204 4
					(void)ex_printf(sp,
					    "%c", repeatc ? repeatc : *kp);
					if (INTERRUPTED(sp))
						goto intr;
d207 2
a208 87
intr:	*colp = col;
	return (0);
}

/*
 * ex_printf --
 *	Ex's version of printf.
 *
 * PUBLIC: int ex_printf __P((SCR *, const char *, ...));
 */
int
#ifdef __STDC__
ex_printf(SCR *sp, const char *fmt, ...)
#else
ex_printf(sp, fmt, va_alist)
	SCR *sp;
	const char *fmt;
	va_dcl
#endif
{
	EX_PRIVATE *exp;
	va_list ap;
	size_t n;

	exp = EXP(sp);

#ifdef __STDC__
	va_start(ap, fmt);
#else
	va_start(ap);
#endif
	exp->obp_len += n = vsnprintf(exp->obp + exp->obp_len,
	    sizeof(exp->obp) - exp->obp_len, fmt, ap);
	va_end(ap);

	/* Flush when reach a <newline> or half the buffer. */
	if (exp->obp[exp->obp_len - 1] == '\n' ||
	    exp->obp_len > sizeof(exp->obp) / 2)
		(void)ex_fflush(sp);
	return (n);
}

/*
 * ex_puts --
 *	Ex's version of puts.
 *
 * PUBLIC: int ex_puts __P((SCR *, const char *));
 */
int
ex_puts(sp, str)
	SCR *sp;
	const char *str;
{
	EX_PRIVATE *exp;
	int doflush, n;

	exp = EXP(sp);

	/* Flush when reach a <newline> or the end of the buffer. */
	for (doflush = n = 0; *str != '\0'; ++n) {
		if (exp->obp_len > sizeof(exp->obp))
			(void)ex_fflush(sp);
		if ((exp->obp[exp->obp_len++] = *str++) == '\n')
			doflush = 1;
	}
	if (doflush)
		(void)ex_fflush(sp);
	return (n);
}

/*
 * ex_fflush --
 *	Ex's version of fflush.
 *
 * PUBLIC: int ex_fflush __P((SCR *sp));
 */
int
ex_fflush(sp)
	SCR *sp;
{
	EX_PRIVATE *exp;

	exp = EXP(sp);

	if (exp->obp_len != 0) {
		sp->gp->scr_msg(sp, M_NONE, exp->obp, exp->obp_len);
		exp->obp_len = 0;
d210 1
@
