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.36;	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.32;	author thorpej;	state Exp;
branches
	1.9.4.1
	1.9.6.1;
next	1.8;

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

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

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

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

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

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

1.2
date	94.01.24.06.40.06;	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.09;	author cgd;	state dead;
branches;
next	1.5.2.2;

1.5.2.2
date	94.08.17.20.12.10;	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.04;	author cgd;	state Exp;
branches;
next	1.1.1.3;

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

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

1.1.1.5
date	96.05.20.01.53.55;	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_args.c,v 1.10 2005/02/12 12:53:22 aymeric Exp $	*/

/*-
 * Copyright (c) 1991, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 * Copyright (c) 1991, 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_args.c	10.16 (Berkeley) 7/13/96";
#else
__RCSID("$NetBSD: ex_args.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 "../common/common.h"
#include "../vi/vi.h"

static int ex_N_next __P((SCR *, EXCMD *));

/*
 * ex_next -- :next [+cmd] [files]
 *	Edit the next file, optionally setting the list of files.
 *
 * !!!
 * The :next command behaved differently from the :rewind command in
 * historic vi.  See nvi/docs/autowrite for details, but the basic
 * idea was that it ignored the force flag if the autowrite flag was
 * set.  This implementation handles them all identically.
 *
 * PUBLIC: int ex_next __P((SCR *, EXCMD *));
 */
int
ex_next(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	ARGS **argv;
	FREF *frp;
	int noargs;
	char **ap;

	/* Check for file to move to. */
	if (cmdp->argc == 0 && (sp->cargv == NULL || sp->cargv[1] == NULL)) {
		msgq(sp, M_ERR, "111|No more files to edit");
		return (1);
	}

	if (F_ISSET(cmdp, E_NEWSCREEN)) {
		/* By default, edit the next file in the old argument list. */
		if (cmdp->argc == 0) {
			if (argv_exp0(sp,
			    cmdp, sp->cargv[1], strlen(sp->cargv[1])))
				return (1);
			return (ex_edit(sp, cmdp));
		}
		return (ex_N_next(sp, cmdp));
	}

	/* Check modification. */
	if (file_m1(sp,
	    FL_ISSET(cmdp->iflags, E_C_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);

	/* Any arguments are a replacement file list. */
	if (cmdp->argc) {
		/* Free the current list. */
		if (!F_ISSET(sp, SC_ARGNOFREE) && sp->argv != NULL) {
			for (ap = sp->argv; *ap != NULL; ++ap)
				free(*ap);
			free(sp->argv);
		}
		F_CLR(sp, SC_ARGNOFREE | SC_ARGRECOVER);
		sp->cargv = NULL;

		/* Create a new list. */
		CALLOC_RET(sp,
		    sp->argv, char **, cmdp->argc + 1, sizeof(char *));
		for (ap = sp->argv,
		    argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv)
			if ((*ap =
			    v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
				return (1);
		*ap = NULL;

		/* Switch to the first file. */
		sp->cargv = sp->argv;
		if ((frp = file_add(sp, *sp->cargv)) == NULL)
			return (1);
		noargs = 0;

		/* Display a file count with the welcome message. */
		F_SET(sp, SC_STATUS_CNT);
	} else {
		if ((frp = file_add(sp, sp->cargv[1])) == NULL)
			return (1);
		if (F_ISSET(sp, SC_ARGRECOVER))
			F_SET(frp, FR_RECOVER);
		noargs = 1;
	}

	if (file_init(sp, frp, NULL, FS_SETALT |
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
		return (1);
	if (noargs)
		++sp->cargv;

	F_SET(sp, SC_FSWITCH);
	return (0);
}

/*
 * ex_N_next --
 *	New screen version of ex_next.
 */
static int
ex_N_next(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	SCR *new;
	FREF *frp;

	/* Get a new screen. */
	if (screen_init(sp->gp, sp, &new))
		return (1);
	if (vs_split(sp, new, 0)) {
		(void)screen_end(new);
		return (1);
	}

	/* Get a backing file. */
	if ((frp = file_add(new, cmdp->argv[0]->bp)) == NULL ||
	    file_init(new, frp, NULL,
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0))) {
		(void)vs_discard(new, NULL);
		(void)screen_end(new);
		return (1);
	}

	/* The arguments are a replacement file list. */
	new->cargv = new->argv = ex_buildargv(sp, cmdp, NULL);

	/* Display a file count with the welcome message. */
	F_SET(new, SC_STATUS_CNT);

	/* Set up the switch. */
	sp->nextdisp = new;
	F_SET(sp, SC_SSWITCH);

	return (0);
}

/*
 * ex_prev -- :prev
 *	Edit the previous file.
 *
 * PUBLIC: int ex_prev __P((SCR *, EXCMD *));
 */
int
ex_prev(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	FREF *frp;

	if (sp->cargv == sp->argv) {
		msgq(sp, M_ERR, "112|No previous files to edit");
		return (1);
	}

	if (F_ISSET(cmdp, E_NEWSCREEN)) {
		if (argv_exp0(sp, cmdp, sp->cargv[-1], strlen(sp->cargv[-1])))
			return (1);
		return (ex_edit(sp, cmdp));
	}

	if (file_m1(sp,
	    FL_ISSET(cmdp->iflags, E_C_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);

	if ((frp = file_add(sp, sp->cargv[-1])) == NULL)
		return (1);

	if (file_init(sp, frp, NULL, FS_SETALT |
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
		return (1);
	--sp->cargv;

	F_SET(sp, SC_FSWITCH);
	return (0);
}

/*
 * ex_rew -- :rew
 *	Re-edit the list of files.
 *
 * !!!
 * Historic practice was that all files would start editing at the beginning
 * of the file.  We don't get this right because we may have multiple screens
 * and we can't clear the FR_CURSORSET bit for a single screen.  I don't see
 * anyone noticing, but if they do, we'll have to put information into the SCR
 * structure so we can keep track of it.
 *
 * PUBLIC: int ex_rew __P((SCR *, EXCMD *));
 */
int
ex_rew(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	FREF *frp;

	/*
	 * !!!
	 * Historic practice -- you can rewind to the current file.
	 */
	if (sp->argv == NULL) {
		msgq(sp, M_ERR, "113|No previous files to rewind");
		return (1);
	}

	if (file_m1(sp,
	    FL_ISSET(cmdp->iflags, E_C_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);

	/* Switch to the first one. */
	sp->cargv = sp->argv;
	if ((frp = file_add(sp, *sp->cargv)) == NULL)
		return (1);
	if (file_init(sp, frp, NULL, FS_SETALT |
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
		return (1);

	/* Switch and display a file count with the welcome message. */
	F_SET(sp, SC_FSWITCH | SC_STATUS_CNT);

	return (0);
}

/*
 * ex_args -- :args
 *	Display the list of files.
 *
 * PUBLIC: int ex_args __P((SCR *, EXCMD *));
 */
int
ex_args(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	GS *gp;
	int cnt, col, len, sep;
	char **ap;

	if (sp->argv == NULL) {
		(void)msgq(sp, M_ERR, "114|No file list to display");
		return (0);
	}

	gp = sp->gp;
	col = len = sep = 0;
	for (cnt = 1, ap = sp->argv; *ap != NULL; ++ap) {
		col += len = strlen(*ap) + sep + (ap == sp->cargv ? 2 : 0);
		if (col >= sp->cols - 1) {
			col = len;
			sep = 0;
			(void)ex_puts(sp, "\n");
		} else if (cnt != 1) {
			sep = 1;
			(void)ex_puts(sp, " ");
		}
		++cnt;

		(void)ex_printf(sp, "%s%s%s", ap == sp->cargv ? "[" : "",
		    *ap, ap == sp->cargv ? "]" : "");
		if (INTERRUPTED(sp))
			break;
	}
	(void)ex_puts(sp, "\n");
	return (0);
}

/*
 * ex_buildargv --
 *	Build a new file argument list.
 *
 * PUBLIC: char **ex_buildargv __P((SCR *, EXCMD *, char *));
 */
char **
ex_buildargv(sp, cmdp, name)
	SCR *sp;
	EXCMD *cmdp;
	char *name;
{
	ARGS **argv;
	int argc;
	char **ap, **s_argv;

	argc = cmdp == NULL ? 1 : cmdp->argc;
	CALLOC(sp, s_argv, char **, argc + 1, sizeof(char *));
	if ((ap = s_argv) == NULL)
		return (NULL);

	if (cmdp == NULL) {
		if ((*ap = v_strdup(sp, name, strlen(name))) == NULL)
			return (NULL);
		++ap;
	} else
		for (argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv)
			if ((*ap =
			    v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
				return (NULL);
	*ap = NULL;
	return (s_argv);
}
@


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


1.9
log
@Use __RCSID() and __COPYRIGHT().
@
text
@d1 1
a1 1
/*	$NetBSD: ex_args.c,v 1.8 2001/03/31 11:37:49 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_args.c,v 1.9 2002/04/09 01:47:32 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_args.c,v 1.9 2002/04/09 01:47:32 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_args.c,v 1.7 1998/01/09 08:07:40 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_args.c	10.14 (Berkeley) 4/27/96";
d104 3
d157 3
d248 3
a250 1
	F_SET(sp, SC_FSWITCH);
@


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_args.c	8.29 (Berkeley) 8/17/94";
a22 1
#include <signal.h>
a25 1
#include <termios.h>
d27 2
a28 3
#include "compat.h"
#include <db.h>
#include <regex.h>
d30 1
a30 2
#include "vi.h"
#include "excmd.h"
d41 2
d45 1
a45 1
ex_next(sp, ep, cmdp)
d47 1
a47 2
	EXF *ep;
	EXCMDARG *cmdp;
d49 1
a49 1
	ARGS **argv, **pc;
d54 3
a56 1
	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
d58 12
d71 4
a74 10
	/*
	 * If the first argument is a plus sign, '+', it's an initial
	 * ex command.
	 */
	argv = cmdp->argv;
	if (cmdp->argc && argv[0]->bp[0] == '+') {
		--cmdp->argc;
		pc = argv++;
	} else
		pc = NULL;
d76 1
a76 1
	/* Any other arguments are a replacement file list. */
d79 1
a79 1
		if (!F_ISSET(sp, S_ARGNOFREE) && sp->argv != NULL) {
d84 1
a84 1
		F_CLR(sp, S_ARGNOFREE | S_ARGRECOVER);
d97 1
a97 1
		/* Switch to the first one. */
a102 4
		if (sp->cargv == NULL || sp->cargv[1] == NULL) {
			msgq(sp, M_ERR, "No more files to edit");
			return (1);
		}
d105 1
a105 1
		if (F_ISSET(sp, S_ARGRECOVER))
d110 2
a111 1
	if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
d116 39
a154 11
	/* Push the initial command onto the stack. */
	if (pc != NULL)
		if (IN_EX_MODE(sp))
			(void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
		else if (IN_VI_MODE(sp)) {
			(void)term_push(sp, "\n", 1, 0);
			(void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
			(void)term_push(sp, ":", 1, 0);
			(void)file_lline(sp, sp->ep, &sp->frp->lno);
			F_SET(sp->frp, FR_CURSORSET);
		}
a155 1
	F_SET(sp, S_FSWITCH);
d162 2
d166 1
a166 1
ex_prev(sp, ep, cmdp)
d168 1
a168 2
	EXF *ep;
	EXCMDARG *cmdp;
d172 2
a173 1
	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
d175 1
d177 8
a184 2
	if (sp->cargv == sp->argv) {
		msgq(sp, M_ERR, "No previous files to edit");
d186 1
a186 1
	}
d190 2
a191 1
	if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
d193 1
d195 1
a195 2
	--sp->cargv;
	F_SET(sp, S_FSWITCH);
d202 9
d213 1
a213 1
ex_rew(sp, ep, cmdp)
d215 1
a215 2
	EXF *ep;
	EXCMDARG *cmdp;
d224 1
a224 1
		msgq(sp, M_ERR, "No previous files to rewind");
d228 2
a229 1
	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
a231 8
	/*
	 * !!!
	 * Historic practice, start at the beginning of the file.
	 */
	for (frp = sp->frefq.cqh_first;
	    frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next)
		F_CLR(frp, FR_CURSORSET | FR_FNONBLANK);
	
d236 2
a237 1
	if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
d240 1
a240 1
	F_SET(sp, S_FSWITCH);
d247 2
d251 1
a251 1
ex_args(sp, ep, cmdp)
d253 1
a253 2
	EXF *ep;
	EXCMDARG *cmdp;
d255 1
d260 1
a260 1
		(void)ex_printf(EXCOOKIE, "No file list to display.\n");
d263 2
a264 1
		
d271 1
a271 1
			(void)ex_printf(EXCOOKIE, "\n");
d274 1
a274 1
			(void)ex_printf(EXCOOKIE, " ");
d278 4
a281 4
		if (ap == sp->cargv)
			(void)ex_printf(EXCOOKIE, "[%s]", *ap);
		else
			(void)ex_printf(EXCOOKIE, "%s", *ap);
d283 1
a283 1
	(void)ex_printf(EXCOOKIE, "\n");
d285 34
@


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


1.5.2.2
log
@clean up import.
@
text
@a0 263
/*-
 * 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[] = "@@(#)ex_args.c	8.29 (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 "compat.h"
#include <db.h>
#include <regex.h>

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

/*
 * ex_next -- :next [+cmd] [files]
 *	Edit the next file, optionally setting the list of files.
 *
 * !!!
 * The :next command behaved differently from the :rewind command in
 * historic vi.  See nvi/docs/autowrite for details, but the basic
 * idea was that it ignored the force flag if the autowrite flag was
 * set.  This implementation handles them all identically.
 */
int
ex_next(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	ARGS **argv, **pc;
	FREF *frp;
	int noargs;
	char **ap;

	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);

	/*
	 * If the first argument is a plus sign, '+', it's an initial
	 * ex command.
	 */
	argv = cmdp->argv;
	if (cmdp->argc && argv[0]->bp[0] == '+') {
		--cmdp->argc;
		pc = argv++;
	} else
		pc = NULL;

	/* Any other arguments are a replacement file list. */
	if (cmdp->argc) {
		/* Free the current list. */
		if (!F_ISSET(sp, S_ARGNOFREE) && sp->argv != NULL) {
			for (ap = sp->argv; *ap != NULL; ++ap)
				free(*ap);
			free(sp->argv);
		}
		F_CLR(sp, S_ARGNOFREE | S_ARGRECOVER);
		sp->cargv = NULL;

		/* Create a new list. */
		CALLOC_RET(sp,
		    sp->argv, char **, cmdp->argc + 1, sizeof(char *));
		for (ap = sp->argv,
		    argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv)
			if ((*ap =
			    v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
				return (1);
		*ap = NULL;

		/* Switch to the first one. */
		sp->cargv = sp->argv;
		if ((frp = file_add(sp, *sp->cargv)) == NULL)
			return (1);
		noargs = 0;
	} else {
		if (sp->cargv == NULL || sp->cargv[1] == NULL) {
			msgq(sp, M_ERR, "No more files to edit");
			return (1);
		}
		if ((frp = file_add(sp, sp->cargv[1])) == NULL)
			return (1);
		if (F_ISSET(sp, S_ARGRECOVER))
			F_SET(frp, FR_RECOVER);
		noargs = 1;
	}

	if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
		return (1);
	if (noargs)
		++sp->cargv;

	/* Push the initial command onto the stack. */
	if (pc != NULL)
		if (IN_EX_MODE(sp))
			(void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
		else if (IN_VI_MODE(sp)) {
			(void)term_push(sp, "\n", 1, 0);
			(void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
			(void)term_push(sp, ":", 1, 0);
			(void)file_lline(sp, sp->ep, &sp->frp->lno);
			F_SET(sp->frp, FR_CURSORSET);
		}

	F_SET(sp, S_FSWITCH);
	return (0);
}

/*
 * ex_prev -- :prev
 *	Edit the previous file.
 */
int
ex_prev(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	FREF *frp;

	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);

	if (sp->cargv == sp->argv) {
		msgq(sp, M_ERR, "No previous files to edit");
		return (1);
	}
	if ((frp = file_add(sp, sp->cargv[-1])) == NULL)
		return (1);

	if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
		return (1);

	--sp->cargv;
	F_SET(sp, S_FSWITCH);
	return (0);
}

/*
 * ex_rew -- :rew
 *	Re-edit the list of files.
 */
int
ex_rew(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	FREF *frp;

	/*
	 * !!!
	 * Historic practice -- you can rewind to the current file.
	 */
	if (sp->argv == NULL) {
		msgq(sp, M_ERR, "No previous files to rewind");
		return (1);
	}

	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);

	/*
	 * !!!
	 * Historic practice, start at the beginning of the file.
	 */
	for (frp = sp->frefq.cqh_first;
	    frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next)
		F_CLR(frp, FR_CURSORSET | FR_FNONBLANK);
	
	/* Switch to the first one. */
	sp->cargv = sp->argv;
	if ((frp = file_add(sp, *sp->cargv)) == NULL)
		return (1);
	if (file_init(sp, frp, NULL, F_ISSET(cmdp, E_FORCE)))
		return (1);

	F_SET(sp, S_FSWITCH);
	return (0);
}

/*
 * ex_args -- :args
 *	Display the list of files.
 */
int
ex_args(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	int cnt, col, len, sep;
	char **ap;

	if (sp->argv == NULL) {
		(void)ex_printf(EXCOOKIE, "No file list to display.\n");
		return (0);
	}
		
	col = len = sep = 0;
	for (cnt = 1, ap = sp->argv; *ap != NULL; ++ap) {
		col += len = strlen(*ap) + sep + (ap == sp->cargv ? 2 : 0);
		if (col >= sp->cols - 1) {
			col = len;
			sep = 0;
			(void)ex_printf(EXCOOKIE, "\n");
		} else if (cnt != 1) {
			sep = 1;
			(void)ex_printf(EXCOOKIE, " ");
		}
		++cnt;

		if (ap == sp->cargv)
			(void)ex_printf(EXCOOKIE, "[%s]", *ap);
		else
			(void)ex_printf(EXCOOKIE, "%s", *ap);
	}
	(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_args.c	8.28 (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_args.c	8.16 (Berkeley) 3/14/94";
d59 1
a59 1
 * ex_next -- :next [files]
d74 1
a74 1
	ARGS **argv;
d76 2
a77 1
	char *name;
d79 2
a80 1
	MODIFY_RET(sp, ep, F_ISSET(cmdp, E_FORCE));
d82 12
d95 16
a110 8
		/* Mark all the current files as ignored. */
		for (frp = sp->frefq.cqh_first;
		    frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next)
			F_SET(frp, FR_IGNORE);

		/* Add the new files into the file list. */
		for (argv = cmdp->argv; argv[0]->len != 0; ++argv)
			if (file_add(sp, NULL, argv[0]->bp, 0) == NULL)
d112 1
d114 11
a124 1
		if ((frp = file_first(sp)) == NULL)
d126 3
a128 3
	} else if ((frp = file_next(sp, sp->a_frp)) == NULL) {
		msgq(sp, M_ERR, "No more files to edit.");
		return (1);
a130 14
	/*
	 * There's a tricky sequence, where the user edits two files, e.g.
	 * "x" and "y".  While in "x", they do ":e y|:f foo", which changes
	 * the name of that FRP entry.  Then, the :n command finds the file
	 * "y" with a name change.  If the file name has been changed, get
	 * a new FREF for the original file name, and make it be the one that
	 * is displayed in the argument list, not the one with the name change.
	 */
	if (frp->cname != NULL) {
		F_SET(frp, FR_IGNORE);
		name = frp->name == NULL ? frp->tname : frp->name;
		if ((frp = file_add(sp, sp->a_frp, name, 0)) == NULL)
			return (1);
	}
d133 15
a147 1
	sp->a_frp = frp;
a162 1
	char *name;
d164 2
a165 1
	MODIFY_RET(sp, ep, F_ISSET(cmdp, E_FORCE));
d167 2
a168 2
	if ((frp = file_prev(sp, sp->a_frp)) == NULL) {
		msgq(sp, M_ERR, "No previous files to edit.");
d171 2
a173 7
	/* See comment in ex_next(). */
	if (frp->cname != NULL) {
		F_SET(frp, FR_IGNORE);
		name = frp->name == NULL ? frp->tname : frp->name;
		if ((frp = file_add(sp, frp, name, 0)) == NULL)
			return (1);
	}
d176 2
a177 1
	sp->a_frp = frp;
d192 1
a192 1
	FREF *frp, *tfrp;
d198 2
a199 2
	if ((frp = file_first(sp)) == NULL) {
		msgq(sp, M_ERR, "No previous files to rewind.");
d203 2
a204 1
	MODIFY_RET(sp, ep, F_ISSET(cmdp, E_FORCE));
d208 1
a208 3
	 * Historic practice, turn off the edited bit.  The :next and :prev
	 * code will discard any name changes, so ignore them here.  Start
	 * at the beginning of the file, too.
d210 8
a217 4
	for (tfrp = sp->frefq.cqh_first;
	    tfrp != (FREF *)&sp->frefq; tfrp = tfrp->q.cqe_next)
		F_CLR(tfrp, FR_CHANGEWRITE | FR_CURSORSET | FR_EDITED);

d220 1
a220 1
	sp->a_frp = frp;
d235 2
a236 3
	FREF *frp;
	int cnt, col, iscur, len, nlen, sep;
	char *name;
d238 5
a242 22
	/*
	 * !!!
	 * Ignore files that aren't in the "argument" list unless they are the
	 * one we're currently editing.  I'm not sure this is right, but the
	 * historic vi behavior of not showing the current file if it was the
	 * result of a ":e" command, or if the file name was changed was wrong.
	 * This is actually pretty tricky, don't modify it without thinking it
	 * through.  There have been a lot of problems in here.
	 *
	 * Also, historic practice was to display the original name of the file
	 * even if the user had used a file command to change the file name.
	 * Confusing, at best.  We show both names: the original as that's what
	 * the user will get in a next, prev or rewind, and the new one since
	 * that's what the user is actually editing now.
	 *
	 * When we find the "argument" FREF, i.e. the current location in the
	 * user's argument list, if it's not the same as the current FREF, we
	 * display the current FREF as following the argument in the list.
	 * This means that if the user edits three files, "x", "y" and "z", and
	 * then does a :e command in the file "x" to edit "z", "z" will appear
	 * in the list twice.
	 */
d244 2
a245 25
	for (cnt = 1, frp = sp->frefq.cqh_first;
	    frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next) {
		iscur = 0;
		/*
		 * If the last argument FREF structure, and we're editing
		 * it, set the current bit.  Otherwise, we'll display it,
		 * then the file we're editing, and the latter will have
		 * the current bit set.
		 */
		if (frp == sp->a_frp) {
			if (frp == sp->frp && frp->cname == NULL)
				iscur = 1;
		} else if (F_ISSET(frp, FR_IGNORE))
			continue;
		name = frp->name == NULL ? frp->tname : frp->name;
		/*
		 * Mistake.  The user edited a temporary file (vi /tmp), then
		 * switched to another file (:e file).  The argument FREF is
		 * pointing to the temporary file, but it doesn't have a name.
		 * Gracefully recover through the creative use of goto's.
		 */
		if (name == NULL)
			goto testcur;
extra:		nlen = strlen(name);
		col += len = nlen + sep + (iscur ? 2 : 0);
d256 4
a259 13
		if (iscur)
			(void)ex_printf(EXCOOKIE, "[%s]", name);
		else {
			(void)ex_printf(EXCOOKIE, "%s", name);
testcur:		if (frp == sp->a_frp) {
				if (frp != sp->frp)
					name = FILENAME(sp->frp);
				else
					name = frp->cname;
				iscur = 1;
				goto extra;
			}
		}
d261 1
a261 5
	/* This should never happen; left in because it's been known to. */
	if (cnt == 1)
		(void)ex_printf(EXCOOKIE, "No files.\n");
	else
		(void)ex_printf(EXCOOKIE, "\n");
@


1.2
log
@more Ids than you'll ever want.
@
text
@d2 1
a2 1
 * Copyright (c) 1991, 1993
d35 1
a35 2
/* from: static char sccsid[] = "@@(#)ex_args.c	8.13 (Berkeley) 12/20/93"; */
static char *rcsid = "$Id$";
d39 2
d42 1
d44 3
d49 5
d78 1
a78 1
	MODIFY_CHECK(sp, ep, F_ISSET(cmdp, E_FORCE));
d90 1
a90 1
		
d132 1
a132 1
	MODIFY_CHECK(sp, ep, F_ISSET(cmdp, E_FORCE));
d174 1
a174 1
	MODIFY_CHECK(sp, ep, F_ISSET(cmdp, E_FORCE));
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)ex_args.c	8.13 (Berkeley) 12/20/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[] = "@@(#)ex_args.c	8.16 (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 5
#include <termios.h>

#include "compat.h"
#include <db.h>
#include <regex.h>
d67 1
a67 1
	MODIFY_RET(sp, ep, F_ISSET(cmdp, E_FORCE));
d79 1
a79 1

d121 1
a121 1
	MODIFY_RET(sp, ep, F_ISSET(cmdp, E_FORCE));
d163 1
a163 1
	MODIFY_RET(sp, ep, F_ISSET(cmdp, E_FORCE));
@


1.1.1.3
log
@new public version of nvi
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_args.c	8.28 (Berkeley) 8/17/94";
d59 1
a59 1
 * ex_next -- :next [+cmd] [files]
d74 1
a74 1
	ARGS **argv, **pc;
d76 1
a76 2
	int noargs;
	char **ap;
d78 1
a78 2
	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);
a79 12
	/*
	 * If the first argument is a plus sign, '+', it's an initial
	 * ex command.
	 */
	argv = cmdp->argv;
	if (cmdp->argc && argv[0]->bp[0] == '+') {
		--cmdp->argc;
		pc = argv++;
	} else
		pc = NULL;

	/* Any other arguments are a replacement file list. */
d81 8
a88 16
		/* Free the current list. */
		if (!F_ISSET(sp, S_ARGNOFREE) && sp->argv != NULL) {
			for (ap = sp->argv; *ap != NULL; ++ap)
				free(*ap);
			free(sp->argv);
		}
		F_CLR(sp, S_ARGNOFREE | S_ARGRECOVER);
		sp->cargv = NULL;

		/* Create a new list. */
		CALLOC_RET(sp,
		    sp->argv, char **, cmdp->argc + 1, sizeof(char *));
		for (ap = sp->argv,
		    argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv)
			if ((*ap =
			    v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
a89 1
		*ap = NULL;
d91 1
a91 3
		/* Switch to the first one. */
		sp->cargv = sp->argv;
		if ((frp = file_add(sp, *sp->cargv)) == NULL)
d93 17
a109 7
		noargs = 0;
	} else {
		if (sp->cargv == NULL || sp->cargv[1] == NULL) {
			msgq(sp, M_ERR, "No more files to edit");
			return (1);
		}
		if ((frp = file_add(sp, sp->cargv[1])) == NULL)
a110 3
		if (F_ISSET(sp, S_ARGRECOVER))
			F_SET(frp, FR_RECOVER);
		noargs = 1;
a111 1

d114 1
a114 15
	if (noargs)
		++sp->cargv;

	/* Push the initial command onto the stack. */
	if (pc != NULL)
		if (IN_EX_MODE(sp))
			(void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
		else if (IN_VI_MODE(sp)) {
			(void)term_push(sp, "\n", 1, 0);
			(void)term_push(sp, pc[0]->bp, pc[0]->len, 0);
			(void)term_push(sp, ":", 1, 0);
			(void)file_lline(sp, sp->ep, &sp->frp->lno);
			F_SET(sp->frp, FR_CURSORSET);
		}

d130 1
d132 1
a132 2
	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);
d134 2
a135 2
	if (sp->cargv == sp->argv) {
		msgq(sp, M_ERR, "No previous files to edit");
a137 2
	if ((frp = file_add(sp, sp->cargv[-1])) == NULL)
		return (1);
d139 7
d148 1
a148 2

	--sp->cargv;
d163 1
a163 1
	FREF *frp;
d169 2
a170 2
	if (sp->argv == NULL) {
		msgq(sp, M_ERR, "No previous files to rewind");
d174 1
a174 2
	if (file_m1(sp, ep, F_ISSET(cmdp, E_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);
d178 3
a180 1
	 * Historic practice, start at the beginning of the file.
d182 4
a185 8
	for (frp = sp->frefq.cqh_first;
	    frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next)
		F_CLR(frp, FR_CURSORSET | FR_FNONBLANK);
	
	/* Switch to the first one. */
	sp->cargv = sp->argv;
	if ((frp = file_add(sp, *sp->cargv)) == NULL)
		return (1);
d188 1
a188 1

d203 3
a205 2
	int cnt, col, len, sep;
	char **ap;
d207 22
a228 5
	if (sp->argv == NULL) {
		(void)ex_printf(EXCOOKIE, "No file list to display.\n");
		return (0);
	}
		
d230 25
a254 2
	for (cnt = 1, ap = sp->argv; *ap != NULL; ++ap) {
		col += len = strlen(*ap) + sep + (ap == sp->cargv ? 2 : 0);
d265 13
a277 4
		if (ap == sp->cargv)
			(void)ex_printf(EXCOOKIE, "[%s]", *ap);
		else
			(void)ex_printf(EXCOOKIE, "%s", *ap);
d279 5
a283 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_args.c	8.29 (Berkeley) 8/17/94";
@


1.1.1.5
log
@import of nvi 1.66
@
text
@a3 2
 * Copyright (c) 1991, 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_args.c	10.14 (Berkeley) 4/27/96";
d45 1
d49 1
d51 3
a53 2
#include "../common/common.h"
#include "../vi/vi.h"
d55 2
a56 1
static int ex_N_next __P((SCR *, EXCMD *));
a66 2
 *
 * PUBLIC: int ex_next __P((SCR *, EXCMD *));
d69 1
a69 1
ex_next(sp, cmdp)
d71 2
a72 1
	EXCMD *cmdp;
d74 1
a74 1
	ARGS **argv;
d79 1
a79 3
	/* Check for file to move to. */
	if (cmdp->argc == 0 && (sp->cargv == NULL || sp->cargv[1] == NULL)) {
		msgq(sp, M_ERR, "111|No more files to edit");
a80 1
	}
d82 10
a91 15
	if (F_ISSET(cmdp, E_NEWSCREEN)) {
		/* By default, edit the next file in the old argument list. */
		if (cmdp->argc == 0) {
			if (argv_exp0(sp,
			    cmdp, sp->cargv[1], strlen(sp->cargv[1])))
				return (1);
			return (ex_edit(sp, cmdp));
		}
		return (ex_N_next(sp, cmdp));
	}

	/* Check modification. */
	if (file_m1(sp,
	    FL_ISSET(cmdp->iflags, E_C_FORCE), FS_ALL | FS_POSSIBLE))
		return (1);
d93 1
a93 1
	/* Any arguments are a replacement file list. */
d96 1
a96 1
		if (!F_ISSET(sp, SC_ARGNOFREE) && sp->argv != NULL) {
d101 1
a101 1
		F_CLR(sp, SC_ARGNOFREE | SC_ARGRECOVER);
d114 1
a114 1
		/* Switch to the first file. */
d120 4
d126 1
a126 1
		if (F_ISSET(sp, SC_ARGRECOVER))
d131 1
a131 2
	if (file_init(sp, frp, NULL, FS_SETALT |
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
d136 11
a146 39
	F_SET(sp, SC_FSWITCH);
	return (0);
}

/*
 * ex_N_next --
 *	New screen version of ex_next.
 */
static int
ex_N_next(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	SCR *new;
	FREF *frp;

	/* Get a new screen. */
	if (screen_init(sp->gp, sp, &new))
		return (1);
	if (vs_split(sp, new, 0)) {
		(void)screen_end(new);
		return (1);
	}

	/* Get a backing file. */
	if ((frp = file_add(new, cmdp->argv[0]->bp)) == NULL ||
	    file_init(new, frp, NULL,
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0))) {
		(void)vs_discard(new, NULL);
		(void)screen_end(new);
		return (1);
	}

	/* The arguments are a replacement file list. */
	new->cargv = new->argv = ex_buildargv(sp, cmdp, NULL);

	/* Set up the switch. */
	sp->nextdisp = new;
	F_SET(sp, SC_SSWITCH);
d148 1
a154 2
 *
 * PUBLIC: int ex_prev __P((SCR *, EXCMD *));
d157 1
a157 1
ex_prev(sp, cmdp)
d159 2
a160 1
	EXCMD *cmdp;
d164 3
d168 1
a168 1
		msgq(sp, M_ERR, "112|No previous files to edit");
d171 1
a171 9

	if (F_ISSET(cmdp, E_NEWSCREEN)) {
		if (argv_exp0(sp, cmdp, sp->cargv[-1], strlen(sp->cargv[-1])))
			return (1);
		return (ex_edit(sp, cmdp));
	}

	if (file_m1(sp,
	    FL_ISSET(cmdp->iflags, E_C_FORCE), FS_ALL | FS_POSSIBLE))
d174 1
a174 1
	if ((frp = file_add(sp, sp->cargv[-1])) == NULL)
a176 3
	if (file_init(sp, frp, NULL, FS_SETALT |
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
		return (1);
d178 1
a178 2

	F_SET(sp, SC_FSWITCH);
a184 9
 *
 * !!!
 * Historic practice was that all files would start editing at the beginning
 * of the file.  We don't get this right because we may have multiple screens
 * and we can't clear the FR_CURSORSET bit for a single screen.  I don't see
 * anyone noticing, but if they do, we'll have to put information into the SCR
 * structure so we can keep track of it.
 *
 * PUBLIC: int ex_rew __P((SCR *, EXCMD *));
d187 1
a187 1
ex_rew(sp, cmdp)
d189 2
a190 1
	EXCMD *cmdp;
d199 1
a199 1
		msgq(sp, M_ERR, "113|No previous files to rewind");
d203 1
a203 2
	if (file_m1(sp,
	    FL_ISSET(cmdp->iflags, E_C_FORCE), FS_ALL | FS_POSSIBLE))
d206 8
d218 1
a218 2
	if (file_init(sp, frp, NULL, FS_SETALT |
	    (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
d221 1
a221 1
	F_SET(sp, SC_FSWITCH);
a227 2
 *
 * PUBLIC: int ex_args __P((SCR *, EXCMD *));
d230 1
a230 1
ex_args(sp, cmdp)
d232 2
a233 1
	EXCMD *cmdp;
a234 1
	GS *gp;
d239 1
a239 1
		(void)msgq(sp, M_ERR, "114|No file list to display");
d242 1
a242 2

	gp = sp->gp;
d249 1
a249 1
			(void)ex_puts(sp, "\n");
d252 1
a252 1
			(void)ex_puts(sp, " ");
d256 4
a259 4
		(void)ex_printf(sp, "%s%s%s", ap == sp->cargv ? "[" : "",
		    *ap, ap == sp->cargv ? "]" : "");
		if (INTERRUPTED(sp))
			break;
d261 1
a261 1
	(void)ex_puts(sp, "\n");
a262 34
}

/*
 * ex_buildargv --
 *	Build a new file argument list.
 *
 * PUBLIC: char **ex_buildargv __P((SCR *, EXCMD *, char *));
 */
char **
ex_buildargv(sp, cmdp, name)
	SCR *sp;
	EXCMD *cmdp;
	char *name;
{
	ARGS **argv;
	int argc;
	char **ap, **s_argv;

	argc = cmdp == NULL ? 1 : cmdp->argc;
	CALLOC(sp, s_argv, char **, argc + 1, sizeof(char *));
	if ((ap = s_argv) == NULL)
		return (NULL);

	if (cmdp == NULL) {
		if ((*ap = v_strdup(sp, name, strlen(name))) == NULL)
			return (NULL);
		++ap;
	} else
		for (argv = cmdp->argv; argv[0]->len != 0; ++ap, ++argv)
			if ((*ap =
			    v_strdup(sp, argv[0]->bp, argv[0]->len)) == NULL)
				return (NULL);
	*ap = NULL;
	return (s_argv);
@


1.1.1.6
log
@import of nvi 1.79
@
text
@d13 1
a13 1
static const char sccsid[] = "@@(#)ex_args.c	10.16 (Berkeley) 7/13/96";
a101 3

		/* Display a file count with the welcome message. */
		F_SET(sp, SC_STATUS_CNT);
a151 3
	/* Display a file count with the welcome message. */
	F_SET(new, SC_STATUS_CNT);

d240 1
a240 3
	/* Switch and display a file count with the welcome message. */
	F_SET(sp, SC_FSWITCH | SC_STATUS_CNT);

@

