head	1.11;
access;
symbols
	perseant-exfatfs-base-20250801:1.11
	perseant-exfatfs-base-20240630:1.11
	perseant-exfatfs:1.11.0.36
	perseant-exfatfs-base:1.11
	cjep_sun2x:1.11.0.34
	cjep_sun2x-base:1.11
	cjep_staticlib_x-base1:1.11
	cjep_staticlib_x:1.11.0.32
	cjep_staticlib_x-base:1.11
	phil-wifi-20200421:1.11
	phil-wifi-20200411:1.11
	phil-wifi-20200406:1.11
	pgoyette-compat-merge-20190127:1.11
	pgoyette-compat-20190127:1.11
	pgoyette-compat-20190118:1.11
	pgoyette-compat-1226:1.11
	pgoyette-compat-1126:1.11
	pgoyette-compat-1020:1.11
	pgoyette-compat-0930:1.11
	pgoyette-compat-0906:1.11
	pgoyette-compat-0728:1.11
	pgoyette-compat-0625:1.11
	pgoyette-compat-0521:1.11
	pgoyette-compat-0502:1.11
	pgoyette-compat-0422:1.11
	pgoyette-compat-0415:1.11
	pgoyette-compat-0407:1.11
	pgoyette-compat-0330:1.11
	pgoyette-compat-0322:1.11
	pgoyette-compat-0315:1.11
	pgoyette-compat:1.11.0.30
	pgoyette-compat-base:1.11
	perseant-stdc-iso10646:1.11.0.28
	perseant-stdc-iso10646-base:1.11
	prg-localcount2-base3:1.11
	prg-localcount2-base2:1.11
	prg-localcount2-base1:1.11
	prg-localcount2:1.11.0.26
	prg-localcount2-base:1.11
	pgoyette-localcount-20170426:1.11
	bouyer-socketcan-base1:1.11
	pgoyette-localcount-20170320:1.11
	bouyer-socketcan:1.11.0.24
	bouyer-socketcan-base:1.11
	pgoyette-localcount-20170107:1.11
	pgoyette-localcount-20161104:1.11
	localcount-20160914:1.11
	pgoyette-localcount-20160806:1.11
	pgoyette-localcount-20160726:1.11
	pgoyette-localcount:1.11.0.22
	pgoyette-localcount-base:1.11
	netbsd-5-2-3-RELEASE:1.11
	netbsd-5-1-5-RELEASE:1.11
	yamt-pagecache-base9:1.11
	yamt-pagecache-tag8:1.11
	tls-earlyentropy:1.11.0.18
	tls-earlyentropy-base:1.11
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.11
	riastradh-drm2-base3:1.11
	netbsd-5-2-2-RELEASE:1.11
	netbsd-5-1-4-RELEASE:1.11
	netbsd-5-2-1-RELEASE:1.11
	netbsd-5-1-3-RELEASE:1.11
	agc-symver:1.11.0.20
	agc-symver-base:1.11
	tls-maxphys-base:1.11
	yamt-pagecache-base8:1.11
	netbsd-5-2:1.11.0.16
	yamt-pagecache-base7:1.11
	netbsd-5-2-RELEASE:1.11
	netbsd-5-2-RC1:1.11
	yamt-pagecache-base6:1.11
	yamt-pagecache-base5:1.11
	yamt-pagecache-base4:1.11
	netbsd-5-1-2-RELEASE:1.11
	netbsd-5-1-1-RELEASE:1.11
	yamt-pagecache-base3:1.11
	yamt-pagecache-base2:1.11
	yamt-pagecache:1.11.0.14
	yamt-pagecache-base:1.11
	bouyer-quota2-nbase:1.11
	bouyer-quota2:1.11.0.12
	bouyer-quota2-base:1.11
	matt-nb5-pq3:1.11.0.10
	matt-nb5-pq3-base:1.11
	netbsd-5-1:1.11.0.8
	netbsd-5-1-RELEASE:1.11
	netbsd-5-1-RC4:1.11
	netbsd-5-1-RC3:1.11
	netbsd-5-1-RC2:1.11
	netbsd-5-1-RC1:1.11
	netbsd-5-0-2-RELEASE:1.11
	netbsd-5-0-1-RELEASE:1.11
	jym-xensuspend-nbase:1.11
	netbsd-5-0:1.11.0.6
	netbsd-5-0-RELEASE:1.11
	netbsd-5-0-RC4:1.11
	netbsd-5-0-RC3:1.11
	netbsd-5-0-RC2:1.11
	jym-xensuspend:1.11.0.4
	jym-xensuspend-base:1.11
	netbsd-5-0-RC1:1.11
	netbsd-5:1.11.0.2
	netbsd-5-base:1.11
	matt-mips64-base2:1.10
	matt-mips64:1.10.0.32
	mjf-devfs2:1.10.0.30
	mjf-devfs2-base:1.10
	netbsd-4-0-1-RELEASE:1.10
	wrstuden-revivesa-base-3:1.10
	wrstuden-revivesa-base-2:1.10
	wrstuden-fixsa-newbase:1.10
	wrstuden-revivesa-base-1:1.10
	yamt-pf42-base4:1.10
	yamt-pf42-base3:1.10
	hpcarm-cleanup-nbase:1.10
	yamt-pf42-baseX:1.10
	yamt-pf42-base2:1.10
	wrstuden-revivesa:1.10.0.28
	wrstuden-revivesa-base:1.10
	yamt-pf42:1.10.0.26
	yamt-pf42-base:1.10
	keiichi-mipv6-nbase:1.10
	keiichi-mipv6:1.10.0.24
	keiichi-mipv6-base:1.10
	matt-armv6-nbase:1.10
	matt-armv6-prevmlocking:1.10
	wrstuden-fixsa-base-1:1.10
	netbsd-4-0:1.10.0.22
	netbsd-4-0-RELEASE:1.10
	cube-autoconf:1.10.0.20
	cube-autoconf-base:1.10
	netbsd-4-0-RC5:1.10
	netbsd-4-0-RC4:1.10
	netbsd-4-0-RC3:1.10
	netbsd-4-0-RC2:1.10
	netbsd-4-0-RC1:1.10
	matt-armv6:1.10.0.18
	matt-armv6-base:1.10
	matt-mips64-base:1.10
	hpcarm-cleanup:1.10.0.16
	hpcarm-cleanup-base:1.10
	netbsd-3-1-1-RELEASE:1.10
	netbsd-3-0-3-RELEASE:1.10
	wrstuden-fixsa:1.10.0.14
	wrstuden-fixsa-base:1.10
	abandoned-netbsd-4-base:1.10
	abandoned-netbsd-4:1.10.0.8
	netbsd-3-1:1.10.0.10
	netbsd-3-1-RELEASE:1.10
	netbsd-3-0-2-RELEASE:1.10
	netbsd-3-1-RC4:1.10
	netbsd-3-1-RC3:1.10
	netbsd-3-1-RC2:1.10
	netbsd-3-1-RC1:1.10
	netbsd-4:1.10.0.12
	netbsd-4-base:1.10
	chap-midi-nbase:1.10
	netbsd-3-0-1-RELEASE:1.10
	chap-midi:1.10.0.6
	chap-midi-base:1.10
	netbsd-3-0:1.10.0.4
	netbsd-3-0-RELEASE:1.10
	netbsd-3-0-RC6:1.10
	netbsd-3-0-RC5:1.10
	netbsd-3-0-RC4:1.10
	netbsd-3-0-RC3:1.10
	netbsd-3-0-RC2:1.10
	netbsd-3-0-RC1:1.10
	netbsd-2-0-3-RELEASE:1.9.4.2
	netbsd-2-1:1.9.6.1.0.2
	netbsd-2-1-RELEASE:1.9.6.1
	netbsd-2-1-RC6:1.9.6.1
	netbsd-2-1-RC5:1.9.6.1
	netbsd-2-1-RC4:1.9.6.1
	netbsd-2-1-RC3:1.9.6.1
	netbsd-2-1-RC2:1.9.6.1
	netbsd-2-1-RC1:1.9.6.1
	netbsd-2-0-2-RELEASE:1.9.4.2
	netbsd-3:1.10.0.2
	netbsd-3-base:1.10
	netbsd-2-0-1-RELEASE:1.9
	netbsd-2:1.9.0.6
	netbsd-2-base:1.9
	netbsd-2-0-RELEASE:1.9
	netbsd-2-0-RC5:1.9
	netbsd-2-0-RC4:1.9
	netbsd-2-0-RC3:1.9
	netbsd-2-0-RC2:1.9
	netbsd-2-0-RC1:1.9
	netbsd-2-0:1.9.0.4
	netbsd-2-0-base:1.9
	netbsd-1-6-PATCH002-RELEASE:1.9
	netbsd-1-6-PATCH002:1.9
	netbsd-1-6-PATCH002-RC4:1.9
	netbsd-1-6-PATCH002-RC3:1.9
	netbsd-1-6-PATCH002-RC2:1.9
	netbsd-1-6-PATCH002-RC1:1.9
	netbsd-1-6-PATCH001:1.9
	netbsd-1-6-PATCH001-RELEASE:1.9
	netbsd-1-6-PATCH001-RC3:1.9
	netbsd-1-6-PATCH001-RC2:1.9
	netbsd-1-6-PATCH001-RC1:1.9
	fvdl_fs64_base:1.9
	netbsd-1-6-RELEASE:1.9
	netbsd-1-6-RC3:1.9
	netbsd-1-6-RC2:1.9
	netbsd-1-6-RC1:1.9
	netbsd-1-6:1.9.0.2
	netbsd-1-6-base:1.9
	netbsd-1-5-PATCH003:1.7
	netbsd-1-5-PATCH002:1.7
	netbsd-1-5-PATCH001:1.7
	nvi_1_79:1.1.1.6
	netbsd-1-5-RELEASE:1.7
	netbsd-1-5-BETA2:1.7
	netbsd-1-5-BETA:1.7
	netbsd-1-4-PATCH003:1.7
	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.11
date	2008.10.29.16.49.37;	author christos;	state dead;
branches;
next	1.10;

1.10
date	2005.02.12.12.53.22;	author aymeric;	state Exp;
branches;
next	1.9;

1.9
date	2002.04.09.01.47.33;	author thorpej;	state Exp;
branches
	1.9.4.1
	1.9.6.1;
next	1.8;

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

1.7
date	98.01.09.08.07.42;	author perry;	state Exp;
branches;
next	1.6;

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

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

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

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

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

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

1.9.4.1
date	2005.02.12.12.24.13;	author aymeric;	state Exp;
branches;
next	1.9.4.2;

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

1.9.6.1
date	2005.05.06.14.42.03;	author riz;	state Exp;
branches;
next	;

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

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

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

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

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

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

1.1.1.5
date	96.05.20.01.54.10;	author mrg;	state Exp;
branches;
next	1.1.1.6;

1.1.1.6
date	2001.03.31.11.29.46;	author aymeric;	state Exp;
branches;
next	;


desc
@@


1.11
log
@bye old vi!
@
text
@/*	$NetBSD: ex_bang.c,v 1.10 2005/02/12 12:53:22 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_bang.c	10.33 (Berkeley) 9/23/96";
#else
__RCSID("$NetBSD: ex_bang.c,v 1.10 2005/02/12 12:53:22 aymeric Exp $");
#endif
#endif /* not lint */

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

#include <bitstring.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

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

/*
 * ex_bang -- :[line [,line]] ! command
 *
 * Pass the rest of the line after the ! character to the program named by
 * the O_SHELL option.
 *
 * Historical vi did NOT do shell expansion on the arguments before passing
 * them, only file name expansion.  This means that the O_SHELL program got
 * "$t" as an argument if that is what the user entered.  Also, there's a
 * special expansion done for the bang command.  Any exclamation points in
 * the user's argument are replaced by the last, expanded ! command.
 *
 * There's some fairly amazing slop in this routine to make the different
 * ways of getting here display the right things.  It took a long time to
 * get it right (wrong?), so be careful.
 *
 * PUBLIC: int ex_bang __P((SCR *, EXCMD *));
 */
int
ex_bang(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	enum filtertype ftype;
	ARGS *ap;
	EX_PRIVATE *exp;
	MARK rm;
	recno_t lno;
	int rval;
	const char *msg;

	ap = cmdp->argv[0];
	if (ap->len == 0) {
		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
		return (1);
	}

	/* Set the "last bang command" remembered value. */
	exp = EXP(sp);
	if (exp->lastbcomm != NULL)
		free(exp->lastbcomm);
	if ((exp->lastbcomm = strdup(ap->bp)) == NULL) {
		msgq(sp, M_SYSERR, NULL);
		return (1);
	}

	/*
	 * If the command was modified by the expansion, it was historically
	 * redisplayed.
	 */
	if (F_ISSET(cmdp, E_MODIFY) && !F_ISSET(sp, SC_EX_SILENT)) {
		/*
		 * Display the command if modified.  Historic ex/vi displayed
		 * the command if it was modified due to file name and/or bang
		 * expansion.  If piping lines in vi, it would be immediately
		 * overwritten by any error or line change reporting.
		 */
		if (F_ISSET(sp, SC_VI))
			vs_update(sp, "!", ap->bp);
		else {
			(void)ex_printf(sp, "!%s\n", ap->bp);
			(void)ex_fflush(sp);
		}
	}

	/*
	 * If no addresses were specified, run the command.  If there's an
	 * underlying file, it's been modified and autowrite is set, write
	 * the file back.  If the file has been modified, autowrite is not
	 * set and the warn option is set, tell the user about the file.
	 */
	if (cmdp->addrcnt == 0) {
		msg = NULL;
		if (sp->ep != NULL && F_ISSET(sp->ep, F_MODIFIED))
			if (O_ISSET(sp, O_AUTOWRITE)) {
				if (file_aw(sp, FS_ALL))
					return (0);
			} else if (O_ISSET(sp, O_WARN) &&
			    !F_ISSET(sp, SC_EX_SILENT))
				msg = msg_cat(sp,
				    "303|File modified since last write.",
				    NULL);

		/* If we're still in a vi screen, move out explicitly. */
		(void)ex_exec_proc(sp,
		    cmdp, ap->bp, msg, !F_ISSET(sp, SC_EX | SC_SCR_EXWROTE));
	}

	/*
	 * If addresses were specified, pipe lines from the file through the
	 * command.
	 *
	 * Historically, vi lines were replaced by both the stdout and stderr
	 * lines of the command, but ex lines by only the stdout lines.  This
	 * makes no sense to me, so nvi makes it consistent for both, and
	 * matches vi's historic behavior.
	 */
	else {
		NEEDFILE(sp, cmdp);

		/* Autoprint is set historically, even if the command fails. */
		F_SET(cmdp, E_AUTOPRINT);

		/*
		 * !!!
		 * Historical vi permitted "!!" in an empty file.  When this
		 * happens, we arrive here with two addresses of 1,1 and a
		 * bad attitude.  The simple solution is to turn it into a
		 * FILTER_READ operation, with the exception that stdin isn't
		 * opened for the utility, and the cursor position isn't the
		 * same.  The only historic glitch (I think) is that we don't
		 * put an empty line into the default cut buffer, as historic
		 * vi did.  Imagine, if you can, my disappointment.
		 */
		ftype = FILTER_BANG;
		if (cmdp->addr1.lno == 1 && cmdp->addr2.lno == 1) {
			if (db_last(sp, &lno))
				return (1);
			if (lno == 0) {
				cmdp->addr1.lno = cmdp->addr2.lno = 0;
				ftype = FILTER_RBANG;
			}
		}
		rval = ex_filter(sp, cmdp,
		    &cmdp->addr1, &cmdp->addr2, &rm, ap->bp, ftype);

		/*
		 * If in vi mode, move to the first nonblank.
		 *
		 * !!!
		 * Historic vi wasn't consistent in this area -- if you used
		 * a forward motion it moved to the first nonblank, but if you
		 * did a backward motion it didn't.  And, if you followed a
		 * backward motion with a forward motion, it wouldn't move to
		 * the nonblank for either.  Going to the nonblank generally
		 * seems more useful and consistent, so we do it.
		 */
		sp->lno = rm.lno;
		if (F_ISSET(sp, SC_VI)) {
			sp->cno = 0;
			(void)nonblank(sp, sp->lno, &sp->cno);
		} else
			sp->cno = rm.cno;
	}

	/* Ex terminates with a bang, even if the command fails. */
	if (!F_ISSET(sp, SC_VI) && !F_ISSET(sp, SC_EX_SILENT))
		(void)ex_puts(sp, "!\n");

	/*
	 * XXX
	 * The ! commands never return an error, so that autoprint always
	 * happens in the ex parser.
	 */
	return (0);
}
@


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


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


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


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


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


1.8
log
@merge changes after import of nvi 1.79
@
text
@d1 1
a1 1
/*	$NetBSD: ex_bang.c,v 1.7 1998/01/09 08:07:42 perry Exp $	*/
d14 1
d16 1
d18 3
@


1.7
log
@RCS Id Police.
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d15 1
a15 1
static const char sccsid[] = "@@(#)ex_bang.c	10.32 (Berkeley) 5/18/96";
d99 4
a102 4
	 * If no addresses were specified, run the command.  If the file has
	 * been modified and autowrite is set, write the file back.  If the
	 * file has been modified, autowrite is not set and the warn option is
	 * set, tell the user about the file.
d106 1
a106 1
		if (F_ISSET(sp->ep, F_MODIFIED))
@


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_bang.c	8.35 (Berkeley) 8/17/94";
a22 1
#include <signal.h>
a25 1
#include <termios.h>
d28 2
a29 7
#include "compat.h"
#include <db.h>
#include <regex.h>

#include "vi.h"
#include "excmd.h"
#include "../sex/sex_screen.h"
d46 2
d50 1
a50 1
ex_bang(sp, ep, cmdp)
d52 1
a52 2
	EXF *ep;
	EXCMDARG *cmdp;
a58 1
	size_t blen;
d60 1
a60 1
	char *bp, *msg;
d64 1
a64 1
		msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
d68 1
a68 1
	/* Set the last bang command. */
d78 2
a79 4
	 * If the command was modified by the expansion, we redisplay it.
	 * Redisplaying it in vi mode is tricky, and handled separately
	 * in each case below.  If we're in ex mode, it's easy, so we just
	 * do it here.
d81 1
a81 6
	bp = NULL;
	if (F_ISSET(cmdp, E_MODIFY) && !F_ISSET(sp, S_EXSILENT)) {
		if (IN_EX_MODE(sp)) {
			(void)ex_printf(EXCOOKIE, "!%s\n", ap->bp);
			(void)ex_fflush(EXCOOKIE);
		}
d83 1
a83 1
		 * Vi: Display the command if modified.  Historic vi displayed
d85 2
a86 6
		 * expansion.  If piping lines, it was immediately overwritten
		 * by any error or line change reporting.  We don't the user to
		 * have to page through the responses, so we only post it until
		 * it's erased by something else.  Otherwise, pass it on to the
		 * ex_exec_proc routine to display after the screen has been
		 * cleaned up.
d88 5
a92 6
		if (IN_VI_MODE(sp)) {
			GET_SPACE_RET(sp, bp, blen, ap->len + 3);
			bp[0] = '!';
			memmove(bp + 1, ap->bp, ap->len);
			bp[ap->len + 1] = '\n';
			bp[ap->len + 2] = '\0';
d97 23
d124 3
a126 3
	 * lines of the command, but ex by only the stdout lines.  This makes
	 * no sense to me, so nvi makes it consistent for both, and matches
	 * vi's historic behavior.
d128 3
a130 1
	if (cmdp->addrcnt != 0) {
d132 1
a132 5
		F_SET(exp, EX_AUTOPRINT);

		/* Vi gets a busy message. */
		if (bp != NULL)
			(void)sp->s_busy(sp, bp);
d136 2
a137 2
		 * Historical vi permitted "!!" in an empty file.  When it
		 * happens, we get called with two addresses of 1,1 and a
d139 5
a143 3
		 * FILTER_READ operation, but that means that we don't put
		 * an empty line into the default cut buffer as did historic
		 * vi.  Tough.
d145 1
a145 1
		ftype = FILTER;
d147 1
a147 1
			if (file_lline(sp, ep, &lno))
d151 1
a151 1
				ftype = FILTER_READ;
d154 1
a154 1
		rval = filtercmd(sp, ep,
d166 1
a166 1
		 * seems more useful, so we do it.
d168 6
a173 44
		if (rval == 0) {
			sp->lno = rm.lno;
			if (IN_VI_MODE(sp)) {
				sp->cno = 0;
				(void)nonblank(sp, ep, sp->lno, &sp->cno);
			}
		}
		goto ret2;
	}

	/*
	 * If no addresses were specified, run the command.  If the file
	 * has been modified and autowrite is set, write the file back.
	 * If the file has been modified, autowrite is not set and the
	 * warn option is set, tell the user about the file.
	 */
	msg = NULL;
	if (F_ISSET(ep, F_MODIFIED))
		if (O_ISSET(sp, O_AUTOWRITE)) {
			if (file_write(sp, ep, NULL, NULL, NULL, FS_ALL)) {
				rval = 1;
				goto ret1;
			}
		} else if (O_ISSET(sp, O_WARN) && !F_ISSET(sp, S_EXSILENT))
			msg = "File modified since last write.\n";

	/* Run the command. */
	rval = ex_exec_proc(sp, ap->bp, bp, msg);

	/* Vi requires user permission to continue. */
	if (IN_VI_MODE(sp))
		F_SET(sp, S_CONTINUE);

ret2:	if (IN_EX_MODE(sp)) {
		/*
		 * Put ex error messages out so they aren't confused with
		 * the autoprint output.
		 */
		if (rval)
			(void)sex_refresh(sp, sp->ep);

		/* Ex terminates with a bang, even if the command fails. */
		if (!F_ISSET(sp, S_EXSILENT))
			(void)write(STDOUT_FILENO, "!\n", 2);
d176 3
a178 3
	/* Free the extra space. */
ret1:	if (bp != NULL)
		FREE_SPACE(sp, bp, blen);
@


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


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

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

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

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

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

#include "vi.h"
#include "excmd.h"
#include "../sex/sex_screen.h"

/*
 * ex_bang -- :[line [,line]] ! command
 *
 * Pass the rest of the line after the ! character to the program named by
 * the O_SHELL option.
 *
 * Historical vi did NOT do shell expansion on the arguments before passing
 * them, only file name expansion.  This means that the O_SHELL program got
 * "$t" as an argument if that is what the user entered.  Also, there's a
 * special expansion done for the bang command.  Any exclamation points in
 * the user's argument are replaced by the last, expanded ! command.
 *
 * There's some fairly amazing slop in this routine to make the different
 * ways of getting here display the right things.  It took a long time to
 * get it right (wrong?), so be careful.
 */
int
ex_bang(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	enum filtertype ftype;
	ARGS *ap;
	EX_PRIVATE *exp;
	MARK rm;
	recno_t lno;
	size_t blen;
	int rval;
	char *bp, *msg;

	ap = cmdp->argv[0];
	if (ap->len == 0) {
		msgq(sp, M_ERR, "Usage: %s", cmdp->cmd->usage);
		return (1);
	}

	/* Set the last bang command. */
	exp = EXP(sp);
	if (exp->lastbcomm != NULL)
		free(exp->lastbcomm);
	if ((exp->lastbcomm = strdup(ap->bp)) == NULL) {
		msgq(sp, M_SYSERR, NULL);
		return (1);
	}

	/*
	 * If the command was modified by the expansion, we redisplay it.
	 * Redisplaying it in vi mode is tricky, and handled separately
	 * in each case below.  If we're in ex mode, it's easy, so we just
	 * do it here.
	 */
	bp = NULL;
	if (F_ISSET(cmdp, E_MODIFY) && !F_ISSET(sp, S_EXSILENT)) {
		if (IN_EX_MODE(sp)) {
			(void)ex_printf(EXCOOKIE, "!%s\n", ap->bp);
			(void)ex_fflush(EXCOOKIE);
		}
		/*
		 * Vi: Display the command if modified.  Historic vi displayed
		 * the command if it was modified due to file name and/or bang
		 * expansion.  If piping lines, it was immediately overwritten
		 * by any error or line change reporting.  We don't the user to
		 * have to page through the responses, so we only post it until
		 * it's erased by something else.  Otherwise, pass it on to the
		 * ex_exec_proc routine to display after the screen has been
		 * cleaned up.
		 */
		if (IN_VI_MODE(sp)) {
			GET_SPACE_RET(sp, bp, blen, ap->len + 3);
			bp[0] = '!';
			memmove(bp + 1, ap->bp, ap->len);
			bp[ap->len + 1] = '\n';
			bp[ap->len + 2] = '\0';
		}
	}

	/*
	 * If addresses were specified, pipe lines from the file through the
	 * command.
	 *
	 * Historically, vi lines were replaced by both the stdout and stderr
	 * lines of the command, but ex by only the stdout lines.  This makes
	 * no sense to me, so nvi makes it consistent for both, and matches
	 * vi's historic behavior.
	 */
	if (cmdp->addrcnt != 0) {
		/* Autoprint is set historically, even if the command fails. */
		F_SET(exp, EX_AUTOPRINT);

		/* Vi gets a busy message. */
		if (bp != NULL)
			(void)sp->s_busy(sp, bp);

		/*
		 * !!!
		 * Historical vi permitted "!!" in an empty file.  When it
		 * happens, we get called with two addresses of 1,1 and a
		 * bad attitude.  The simple solution is to turn it into a
		 * FILTER_READ operation, but that means that we don't put
		 * an empty line into the default cut buffer as did historic
		 * vi.  Tough.
		 */
		ftype = FILTER;
		if (cmdp->addr1.lno == 1 && cmdp->addr2.lno == 1) {
			if (file_lline(sp, ep, &lno))
				return (1);
			if (lno == 0) {
				cmdp->addr1.lno = cmdp->addr2.lno = 0;
				ftype = FILTER_READ;
			}
		}
		rval = filtercmd(sp, ep,
		    &cmdp->addr1, &cmdp->addr2, &rm, ap->bp, ftype);

		/*
		 * If in vi mode, move to the first nonblank.
		 *
		 * !!!
		 * Historic vi wasn't consistent in this area -- if you used
		 * a forward motion it moved to the first nonblank, but if you
		 * did a backward motion it didn't.  And, if you followed a
		 * backward motion with a forward motion, it wouldn't move to
		 * the nonblank for either.  Going to the nonblank generally
		 * seems more useful, so we do it.
		 */
		if (rval == 0) {
			sp->lno = rm.lno;
			if (IN_VI_MODE(sp)) {
				sp->cno = 0;
				(void)nonblank(sp, ep, sp->lno, &sp->cno);
			}
		}
		goto ret2;
	}

	/*
	 * If no addresses were specified, run the command.  If the file
	 * has been modified and autowrite is set, write the file back.
	 * If the file has been modified, autowrite is not set and the
	 * warn option is set, tell the user about the file.
	 */
	msg = NULL;
	if (F_ISSET(ep, F_MODIFIED))
		if (O_ISSET(sp, O_AUTOWRITE)) {
			if (file_write(sp, ep, NULL, NULL, NULL, FS_ALL)) {
				rval = 1;
				goto ret1;
			}
		} else if (O_ISSET(sp, O_WARN) && !F_ISSET(sp, S_EXSILENT))
			msg = "File modified since last write.\n";

	/* Run the command. */
	rval = ex_exec_proc(sp, ap->bp, bp, msg);

	/* Vi requires user permission to continue. */
	if (IN_VI_MODE(sp))
		F_SET(sp, S_CONTINUE);

ret2:	if (IN_EX_MODE(sp)) {
		/*
		 * Put ex error messages out so they aren't confused with
		 * the autoprint output.
		 */
		if (rval)
			(void)sex_refresh(sp, sp->ep);

		/* Ex terminates with a bang, even if the command fails. */
		if (!F_ISSET(sp, S_EXSILENT))
			(void)write(STDOUT_FILENO, "!\n", 2);
	}

	/* Free the extra space. */
ret1:	if (bp != NULL)
		FREE_SPACE(sp, bp, blen);

	/*
	 * XXX
	 * The ! commands never return an error, so that autoprint always
	 * happens in the ex parser.
	 */
	return (0);
}
@


1.4
log
@clean up import.  still have to hack some things.
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_bang.c	8.34 (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_bang.c	8.24 (Berkeley) 3/14/94";
d58 1
a58 1
#include "sex/sex_screen.h"
d74 1
a74 1
 * get get right (wrong?), so be careful.
d97 1
a97 1
	/* Swap commands. */
d100 1
a100 1
		FREE(exp->lastbcomm, strlen(exp->lastbcomm) + 1);
d113 1
a113 1
	if (F_ISSET(cmdp, E_MODIFY)) {
d129 1
a129 1
			GET_SPACE_RET(sp, bp, blen, ap->len + 2);
d131 3
a133 1
			memmove(bp + 1, ap->bp, ap->len + 1);
d138 7
a144 2
	 * If addresses were specified, pipe lines from the file through
	 * the command.
d147 5
a151 1
		if (bp != NULL) {
d153 1
a153 2
			FREE_SPACE(sp, bp, blen);
		}
d158 4
a161 1
		 * bad attitude.
d172 22
a193 6
		if (filtercmd(sp, ep,
		    &cmdp->addr1, &cmdp->addr2, &rm, ap->bp, ftype))
			return (1);
		sp->lno = rm.lno;
		F_SET(exp, EX_AUTOPRINT);
		return (0);
d202 1
a202 1
	msg = "\n";
d207 1
a207 1
				goto ret;
d209 2
a210 5
		} else if (O_ISSET(sp, O_WARN))
			if (IN_VI_MODE(sp) && F_ISSET(cmdp, E_MODIFY))
				msg = "\nFile modified since last write.\n";
			else
				msg = "File modified since last write.\n";
a214 4
	/* Ex terminates with a bang. */
	if (IN_EX_MODE(sp))
		(void)write(STDOUT_FILENO, "!\n", 2);

d219 13
d233 1
a233 1
ret:	if (bp != NULL)
d236 6
a241 1
	return (rval);
@


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_bang.c	8.22 (Berkeley) 12/29/93"; */
static char *rcsid = "$Id$";
d39 2
d42 1
d44 3
d49 1
d52 4
a90 1
	
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)ex_bang.c	8.22 (Berkeley) 12/29/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_bang.c	8.24 (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>
a42 1
#include <termios.h>
a44 4
#include "compat.h"
#include <db.h>
#include <regex.h>

d80 1
@


1.1.1.3
log
@new public version of nvi
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_bang.c	8.34 (Berkeley) 8/17/94";
d58 1
a58 1
#include "../sex/sex_screen.h"
d74 1
a74 1
 * get it right (wrong?), so be careful.
d97 1
a97 1
	/* Set the last bang command. */
d100 1
a100 1
		free(exp->lastbcomm);
d113 1
a113 1
	if (F_ISSET(cmdp, E_MODIFY) && !F_ISSET(sp, S_EXSILENT)) {
d129 1
a129 1
			GET_SPACE_RET(sp, bp, blen, ap->len + 3);
d131 1
a131 3
			memmove(bp + 1, ap->bp, ap->len);
			bp[ap->len + 1] = '\n';
			bp[ap->len + 2] = '\0';
d136 2
a137 7
	 * If addresses were specified, pipe lines from the file through the
	 * command.
	 *
	 * Historically, vi lines were replaced by both the stdout and stderr
	 * lines of the command, but ex by only the stdout lines.  This makes
	 * no sense to me, so nvi makes it consistent for both, and matches
	 * vi's historic behavior.
d140 1
a140 5
		/* Autoprint is set historically, even if the command fails. */
		F_SET(exp, EX_AUTOPRINT);

		/* Vi gets a busy message. */
		if (bp != NULL)
d142 2
a143 1

d148 1
a148 4
		 * bad attitude.  The simple solution is to turn it into a
		 * FILTER_READ operation, but that means that we don't put
		 * an empty line into the default cut buffer as did historic
		 * vi.  Tough.
d159 6
a164 22
		rval = filtercmd(sp, ep,
		    &cmdp->addr1, &cmdp->addr2, &rm, ap->bp, ftype);

		/*
		 * If in vi mode, move to the first nonblank.
		 *
		 * !!!
		 * Historic vi wasn't consistent in this area -- if you used
		 * a forward motion it moved to the first nonblank, but if you
		 * did a backward motion it didn't.  And, if you followed a
		 * backward motion with a forward motion, it wouldn't move to
		 * the nonblank for either.  Going to the nonblank generally
		 * seems more useful, so we do it.
		 */
		if (rval == 0) {
			sp->lno = rm.lno;
			if (IN_VI_MODE(sp)) {
				sp->cno = 0;
				(void)nonblank(sp, ep, sp->lno, &sp->cno);
			}
		}
		goto ret2;
d173 1
a173 1
	msg = NULL;
d178 1
a178 1
				goto ret1;
d180 5
a184 2
		} else if (O_ISSET(sp, O_WARN) && !F_ISSET(sp, S_EXSILENT))
			msg = "File modified since last write.\n";
d189 4
a196 13
ret2:	if (IN_EX_MODE(sp)) {
		/*
		 * Put ex error messages out so they aren't confused with
		 * the autoprint output.
		 */
		if (rval)
			(void)sex_refresh(sp, sp->ep);

		/* Ex terminates with a bang, even if the command fails. */
		if (!F_ISSET(sp, S_EXSILENT))
			(void)write(STDOUT_FILENO, "!\n", 2);
	}

d198 1
a198 1
ret1:	if (bp != NULL)
d201 1
a201 6
	/*
	 * XXX
	 * The ! commands never return an error, so that autoprint always
	 * happens in the ex parser.
	 */
	return (0);
@


1.1.1.4
log
@new public version of nvi
@
text
@d35 1
a35 1
static char sccsid[] = "@@(#)ex_bang.c	8.35 (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_bang.c	10.32 (Berkeley) 5/18/96";
d45 1
d49 1
d52 7
a58 2
#include "../common/common.h"
#include "../vi/vi.h"
a74 2
 *
 * PUBLIC: int ex_bang __P((SCR *, EXCMD *));
d77 1
a77 1
ex_bang(sp, cmdp)
d79 2
a80 1
	EXCMD *cmdp;
d87 1
d89 1
a89 1
	const char *msg;
d93 1
a93 1
		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
d97 1
a97 1
	/* Set the "last bang command" remembered value. */
d107 4
a110 2
	 * If the command was modified by the expansion, it was historically
	 * redisplayed.
d112 6
a117 1
	if (F_ISSET(cmdp, E_MODIFY) && !F_ISSET(sp, SC_EX_SILENT)) {
d119 1
a119 1
		 * Display the command if modified.  Historic ex/vi displayed
d121 6
a126 2
		 * expansion.  If piping lines in vi, it would be immediately
		 * overwritten by any error or line change reporting.
d128 6
a133 5
		if (F_ISSET(sp, SC_VI))
			vs_update(sp, "!", ap->bp);
		else {
			(void)ex_printf(sp, "!%s\n", ap->bp);
			(void)ex_fflush(sp);
a137 23
	 * If no addresses were specified, run the command.  If the file has
	 * been modified and autowrite is set, write the file back.  If the
	 * file has been modified, autowrite is not set and the warn option is
	 * set, tell the user about the file.
	 */
	if (cmdp->addrcnt == 0) {
		msg = NULL;
		if (F_ISSET(sp->ep, F_MODIFIED))
			if (O_ISSET(sp, O_AUTOWRITE)) {
				if (file_aw(sp, FS_ALL))
					return (0);
			} else if (O_ISSET(sp, O_WARN) &&
			    !F_ISSET(sp, SC_EX_SILENT))
				msg = msg_cat(sp,
				    "303|File modified since last write.",
				    NULL);

		/* If we're still in a vi screen, move out explicitly. */
		(void)ex_exec_proc(sp,
		    cmdp, ap->bp, msg, !F_ISSET(sp, SC_EX | SC_SCR_EXWROTE));
	}

	/*
d142 3
a144 3
	 * lines of the command, but ex lines by only the stdout lines.  This
	 * makes no sense to me, so nvi makes it consistent for both, and
	 * matches vi's historic behavior.
d146 3
a148 2
	else {
		NEEDFILE(sp, cmdp);
d150 3
a152 2
		/* Autoprint is set historically, even if the command fails. */
		F_SET(cmdp, E_AUTOPRINT);
d156 2
a157 2
		 * Historical vi permitted "!!" in an empty file.  When this
		 * happens, we arrive here with two addresses of 1,1 and a
d159 3
a161 5
		 * FILTER_READ operation, with the exception that stdin isn't
		 * opened for the utility, and the cursor position isn't the
		 * same.  The only historic glitch (I think) is that we don't
		 * put an empty line into the default cut buffer, as historic
		 * vi did.  Imagine, if you can, my disappointment.
d163 1
a163 1
		ftype = FILTER_BANG;
d165 1
a165 1
			if (db_last(sp, &lno))
d169 1
a169 1
				ftype = FILTER_RBANG;
d172 1
a172 1
		rval = ex_filter(sp, cmdp,
d184 1
a184 1
		 * seems more useful and consistent, so we do it.
d186 44
a229 6
		sp->lno = rm.lno;
		if (F_ISSET(sp, SC_VI)) {
			sp->cno = 0;
			(void)nonblank(sp, sp->lno, &sp->cno);
		} else
			sp->cno = rm.cno;
d232 3
a234 3
	/* Ex terminates with a bang, even if the command fails. */
	if (!F_ISSET(sp, SC_VI) && !F_ISSET(sp, SC_EX_SILENT))
		(void)ex_puts(sp, "!\n");
@


1.1.1.6
log
@import of nvi 1.79
@
text
@d13 1
a13 1
static const char sccsid[] = "@@(#)ex_bang.c	10.33 (Berkeley) 9/23/96";
d97 4
a100 4
	 * If no addresses were specified, run the command.  If there's an
	 * underlying file, it's been modified and autowrite is set, write
	 * the file back.  If the file has been modified, autowrite is not
	 * set and the warn option is set, tell the user about the file.
d104 1
a104 1
		if (sp->ep != NULL && F_ISSET(sp->ep, F_MODIFIED))
@

