head	1.4;
access;
symbols
	perseant-exfatfs-base-20250801:1.4
	perseant-exfatfs-base-20240630:1.4
	perseant-exfatfs:1.4.0.46
	perseant-exfatfs-base:1.4
	cjep_sun2x:1.4.0.44
	cjep_sun2x-base:1.4
	cjep_staticlib_x-base1:1.4
	cjep_staticlib_x:1.4.0.42
	cjep_staticlib_x-base:1.4
	phil-wifi-20200421:1.4
	phil-wifi-20200411:1.4
	phil-wifi-20200406:1.4
	pgoyette-compat-merge-20190127:1.4
	pgoyette-compat-20190127:1.4
	pgoyette-compat-20190118:1.4
	pgoyette-compat-1226:1.4
	pgoyette-compat-1126:1.4
	pgoyette-compat-1020:1.4
	pgoyette-compat-0930:1.4
	pgoyette-compat-0906:1.4
	pgoyette-compat-0728:1.4
	pgoyette-compat-0625:1.4
	pgoyette-compat-0521:1.4
	pgoyette-compat-0502:1.4
	pgoyette-compat-0422:1.4
	pgoyette-compat-0415:1.4
	pgoyette-compat-0407:1.4
	pgoyette-compat-0330:1.4
	pgoyette-compat-0322:1.4
	pgoyette-compat-0315:1.4
	pgoyette-compat:1.4.0.40
	pgoyette-compat-base:1.4
	perseant-stdc-iso10646:1.4.0.38
	perseant-stdc-iso10646-base:1.4
	prg-localcount2-base3:1.4
	prg-localcount2-base2:1.4
	prg-localcount2-base1:1.4
	prg-localcount2:1.4.0.36
	prg-localcount2-base:1.4
	pgoyette-localcount-20170426:1.4
	bouyer-socketcan-base1:1.4
	pgoyette-localcount-20170320:1.4
	bouyer-socketcan:1.4.0.34
	bouyer-socketcan-base:1.4
	pgoyette-localcount-20170107:1.4
	pgoyette-localcount-20161104:1.4
	localcount-20160914:1.4
	pgoyette-localcount-20160806:1.4
	pgoyette-localcount-20160726:1.4
	pgoyette-localcount:1.4.0.32
	pgoyette-localcount-base:1.4
	netbsd-5-2-3-RELEASE:1.4
	netbsd-5-1-5-RELEASE:1.4
	yamt-pagecache-base9:1.4
	yamt-pagecache-tag8:1.4
	tls-earlyentropy:1.4.0.28
	tls-earlyentropy-base:1.4
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.4
	riastradh-drm2-base3:1.4
	netbsd-5-2-2-RELEASE:1.4
	netbsd-5-1-4-RELEASE:1.4
	netbsd-5-2-1-RELEASE:1.4
	netbsd-5-1-3-RELEASE:1.4
	agc-symver:1.4.0.30
	agc-symver-base:1.4
	tls-maxphys-base:1.4
	yamt-pagecache-base8:1.4
	netbsd-5-2:1.4.0.26
	yamt-pagecache-base7:1.4
	netbsd-5-2-RELEASE:1.4
	netbsd-5-2-RC1:1.4
	yamt-pagecache-base6:1.4
	yamt-pagecache-base5:1.4
	yamt-pagecache-base4:1.4
	netbsd-5-1-2-RELEASE:1.4
	netbsd-5-1-1-RELEASE:1.4
	yamt-pagecache-base3:1.4
	yamt-pagecache-base2:1.4
	yamt-pagecache:1.4.0.24
	yamt-pagecache-base:1.4
	bouyer-quota2-nbase:1.4
	bouyer-quota2:1.4.0.22
	bouyer-quota2-base:1.4
	matt-nb5-pq3:1.4.0.20
	matt-nb5-pq3-base:1.4
	netbsd-5-1:1.4.0.18
	netbsd-5-1-RELEASE:1.4
	netbsd-5-1-RC4:1.4
	netbsd-5-1-RC3:1.4
	netbsd-5-1-RC2:1.4
	netbsd-5-1-RC1:1.4
	netbsd-5-0-2-RELEASE:1.4
	netbsd-5-0-1-RELEASE:1.4
	jym-xensuspend-nbase:1.4
	netbsd-5-0:1.4.0.16
	netbsd-5-0-RELEASE:1.4
	netbsd-5-0-RC4:1.4
	netbsd-5-0-RC3:1.4
	netbsd-5-0-RC2:1.4
	jym-xensuspend:1.4.0.14
	jym-xensuspend-base:1.4
	netbsd-5-0-RC1:1.4
	netbsd-5:1.4.0.12
	netbsd-5-base:1.4
	mjf-devfs2:1.4.0.10
	mjf-devfs2-base:1.4
	yamt-pf42-base4:1.4
	yamt-pf42-base3:1.4
	hpcarm-cleanup-nbase:1.4
	yamt-pf42-base2:1.4
	yamt-pf42:1.4.0.8
	yamt-pf42-base:1.4
	keiichi-mipv6-nbase:1.4
	keiichi-mipv6:1.4.0.6
	keiichi-mipv6-base:1.4
	cube-autoconf:1.4.0.4
	cube-autoconf-base:1.4
	hpcarm-cleanup:1.4.0.2
	hpcarm-cleanup-base:1.4
	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.4
date	95.03.01.00.00.00;	author mycroft;	state dead;
branches;
next	1.3;

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

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

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

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

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


desc
@@


1.4
log
@Clean up deleted files.
@
text
@/*-
 * 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[] = "@@(#)mark.c	8.17 (Berkeley) 3/15/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"

static LMARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T));

/*
 * Marks are maintained in a key sorted doubly linked list.  We can't
 * use arrays because we have no idea how big an index key could be.
 * The underlying assumption is that users don't have more than, say,
 * 10 marks at any one time, so this will be is fast enough.
 *
 * Marks are fixed, and modifications to the line don't update the mark's
 * position in the line.  This can be hard.  If you add text to the line,
 * place a mark in that text, undo the addition and use ` to move to the
 * mark, the location will have disappeared.  It's tempting to try to adjust
 * the mark with the changes in the line, but this is hard to do, especially
 * if we've given the line to v_ntext.c:v_ntext() for editing.  Historic vi
 * would move to the first non-blank on the line when the mark location was
 * past the end of the line.  This can be complicated by deleting to a mark
 * that has disappeared using the ` command.  Historic vi vi treated this as
 * a line-mode motion and deleted the line.  This implementation complains to
 * the user.
 *
 * In historic vi, marks returned if the operation was undone, unless the
 * mark had been subsequently reset.  Tricky.  This is hard to start with,
 * but in the presence of repeated undo it gets nasty.  When a line is
 * deleted, we delete (and log) any marks on that line.  An undo will create
 * the mark.  Any mark creations are noted as to whether the user created
 * it or if it was created by an undo.  The former cannot be reset by another
 * undo, but the latter may.
 *
 * All of these routines translate ABSMARK2 to ABSMARK1.  Setting either of
 * the absolute mark locations sets both, so that "m'" and "m`" work like
 * they, ah, for lack of a better word, "should".
 */

/*
 * mark_init --
 *	Set up the marks.
 */
int
mark_init(sp, ep)
	SCR *sp;
	EXF *ep;
{
	LMARK *lmp;

	/*
	 * Make sure the marks have been set up.  If they
	 * haven't, do so, and create the absolute mark.
	 */
	MALLOC_RET(sp, lmp, LMARK *, sizeof(LMARK));
	lmp->lno = 1;
	lmp->cno = 0;
	lmp->name = ABSMARK1;
	lmp->flags = 0;
	LIST_INSERT_HEAD(&ep->marks, lmp, q);
	return (0);
}

/*
 * mark_end --
 *	Free up the marks.
 */
int
mark_end(sp, ep)
	SCR *sp;
	EXF *ep;
{
	LMARK *lmp;

	while ((lmp = ep->marks.lh_first) != NULL) {
		LIST_REMOVE(lmp, q);
		FREE(lmp, sizeof(LMARK));
	}
	return (0);
}

/*
 * mark_get --
 *	Get the location referenced by a mark.
 */
int
mark_get(sp, ep, key, mp)
	SCR *sp;
	EXF *ep;
	ARG_CHAR_T key;
	MARK *mp;
{
	LMARK *lmp;
	size_t len;

	if (key == ABSMARK2)
		key = ABSMARK1;

	lmp = mark_find(sp, ep, key);
	if (lmp == NULL || lmp->name != key) {
		msgq(sp, M_BERR, "Mark %s: not set.", charname(sp, key));
                return (1);
	}
	if (F_ISSET(lmp, MARK_DELETED)) {
		msgq(sp, M_BERR,
		    "Mark %s: the line was deleted.", charname(sp, key));
                return (1);
	}
	if (file_gline(sp, ep, lmp->lno, &len) == NULL ||
	    lmp->cno > len || lmp->cno == len && len != 0) {
		msgq(sp, M_BERR, "Mark %s: cursor position no longer exists.",
		    charname(sp, key));
		return (1);
	}
	mp->lno = lmp->lno;
	mp->cno = lmp->cno;
	return (0);
}

/*
 * mark_set --
 *	Set the location referenced by a mark.
 */
int
mark_set(sp, ep, key, value, userset)
	SCR *sp;
	EXF *ep;
	ARG_CHAR_T key;
	MARK *value;
	int userset;
{
	LMARK *lmp, *lmt;

	if (key == ABSMARK2)
		key = ABSMARK1;

	/*
	 * The rules are simple.  If the user is setting a mark (if it's a
	 * new mark this is always true), it always happens.  If not, it's
	 * an undo, and we set it if it's not already set or if it was set
	 * by a previous undo.
	 */
	lmp = mark_find(sp, ep, key);
	if (lmp == NULL || lmp->name != key) {
		MALLOC_RET(sp, lmt, LMARK *, sizeof(LMARK));
		if (lmp == NULL) {
			LIST_INSERT_HEAD(&ep->marks, lmt, q);
		} else
			LIST_INSERT_AFTER(lmp, lmt, q);
		lmp = lmt;
	} else if (!userset &&
	    !F_ISSET(lmp, MARK_DELETED) && F_ISSET(lmp, MARK_USERSET))
		return (0);

	lmp->lno = value->lno;
	lmp->cno = value->cno;
	lmp->name = key;
	lmp->flags = userset ? MARK_USERSET : 0;
	return (0);
}

/*
 * mark_find --
 *	Find the requested mark, or, the slot immediately before
 *	where it would go.
 */
static LMARK *
mark_find(sp, ep, key)
	SCR *sp;
	EXF *ep;
	ARG_CHAR_T key;
{
	LMARK *lmp, *lastlmp;

	/*
	 * Return the requested mark or the slot immediately before
	 * where it should go.
	 */
	for (lastlmp = NULL, lmp = ep->marks.lh_first;
	    lmp != NULL; lastlmp = lmp, lmp = lmp->q.le_next)
		if (lmp->name >= key)
			return (lmp->name == key ? lmp : lastlmp);
	return (lastlmp);
}

/*
 * mark_insdel --
 *	Update the marks based on an insertion or deletion.
 */
void
mark_insdel(sp, ep, op, lno)
	SCR *sp;
	EXF *ep;
	enum operation op;
	recno_t lno;
{
	LMARK *lmp;

	switch (op) {
	case LINE_APPEND:
		return;
	case LINE_DELETE:
		for (lmp = ep->marks.lh_first;
		    lmp != NULL; lmp = lmp->q.le_next)
			if (lmp->lno >= lno)
				if (lmp->lno == lno) {
					F_SET(lmp, MARK_DELETED);
					(void)log_mark(sp, ep, lmp);
				} else
					--lmp->lno;
		return;
	case LINE_INSERT:
		for (lmp = ep->marks.lh_first;
		    lmp != NULL; lmp = lmp->q.le_next)
			if (lmp->lno >= lno)
				++lmp->lno;
		return;
	case LINE_RESET:
		return;
	}
	/* NOTREACHED */
}
@


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


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[] = "@@(#)mark.c	8.12 (Berkeley) 12/27/93"; */
static char *rcsid = "$Id$";
d39 2
d42 1
d44 3
d49 5
d57 1
a57 1
static MARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T));
d83 1
a83 1
 * undo, but the latter may. 
d99 1
a99 1
	MARK *mp;
d105 6
a110 6
	MALLOC_RET(sp, mp, MARK *, sizeof(MARK));
	mp->lno = 1;
	mp->cno = 0;
	mp->name = ABSMARK1;
	mp->flags = 0;
	LIST_INSERT_HEAD(&ep->marks, mp, q);
d123 1
a123 1
	MARK *mp;
d125 3
a127 3
	while ((mp = ep->marks.lh_first) != NULL) {
		LIST_REMOVE(mp, q);
		FREE(mp, sizeof(MARK));
d136 2
a137 2
MARK *
mark_get(sp, ep, key)
d141 1
d143 1
a143 1
	MARK *mp;
a144 1
	char *p;
d149 2
a150 2
	mp = mark_find(sp, ep, key);
	if (mp == NULL || mp->name != key) {
d152 1
a152 1
                return (NULL);
d154 1
a154 1
	if (F_ISSET(mp, MARK_DELETED)) {
d157 1
a157 1
                return (NULL);
d159 2
a160 2
	if ((p = file_gline(sp, ep, mp->lno, &len)) == NULL ||
	    mp->cno > len || mp->cno == len && len != 0) {
d163 1
a163 1
		return (NULL);
d165 3
a167 1
	return (mp);
d182 1
a182 1
	MARK *mp, *mt;
d193 5
a197 5
	mp = mark_find(sp, ep, key);
	if (mp == NULL || mp->name != key) {
		MALLOC_RET(sp, mt, MARK *, sizeof(MARK));
		if (mp == NULL) {
			LIST_INSERT_HEAD(&ep->marks, mt, q);
d199 2
a200 2
			LIST_INSERT_AFTER(mp, mt, q);
		mp = mt;
d202 1
a202 1
	    !F_ISSET(mp, MARK_DELETED) && F_ISSET(mp, MARK_USERSET))
d205 4
a208 4
	mp->lno = value->lno;
	mp->cno = value->cno;
	mp->name = key;
	mp->flags = userset ? MARK_USERSET : 0;
d217 1
a217 1
static MARK *
d223 1
a223 1
	MARK *mp, *lastmp;
d229 5
a233 5
	for (lastmp = NULL, mp = ep->marks.lh_first;
	    mp != NULL; lastmp = mp, mp = mp->q.le_next)
		if (mp->name >= key)
			return (mp->name == key ? mp : lastmp);
	return (lastmp);
d247 1
a247 1
	MARK *mp;
d253 6
a258 5
		for (mp = ep->marks.lh_first; mp != NULL; mp = mp->q.le_next)
			if (mp->lno >= lno)
				if (mp->lno == lno) {
					F_SET(mp, MARK_DELETED);
					(void)log_mark(sp, ep, mp);
d260 1
a260 1
					--mp->lno;
d263 4
a266 3
		for (mp = ep->marks.lh_first; mp != NULL; mp = mp->q.le_next)
			if (mp->lno >= lno)
				++mp->lno;
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)mark.c	8.12 (Berkeley) 12/27/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[] = "@@(#)mark.c	8.17 (Berkeley) 3/15/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>
d46 1
a46 1
static LMARK *mark_find __P((SCR *, EXF *, ARG_CHAR_T));
d72 1
a72 1
 * undo, but the latter may.
d88 1
a88 1
	LMARK *lmp;
d94 6
a99 6
	MALLOC_RET(sp, lmp, LMARK *, sizeof(LMARK));
	lmp->lno = 1;
	lmp->cno = 0;
	lmp->name = ABSMARK1;
	lmp->flags = 0;
	LIST_INSERT_HEAD(&ep->marks, lmp, q);
d112 1
a112 1
	LMARK *lmp;
d114 3
a116 3
	while ((lmp = ep->marks.lh_first) != NULL) {
		LIST_REMOVE(lmp, q);
		FREE(lmp, sizeof(LMARK));
d125 2
a126 2
int
mark_get(sp, ep, key, mp)
d130 1
a131 2
{
	LMARK *lmp;
d133 1
d138 2
a139 2
	lmp = mark_find(sp, ep, key);
	if (lmp == NULL || lmp->name != key) {
d141 1
a141 1
                return (1);
d143 1
a143 1
	if (F_ISSET(lmp, MARK_DELETED)) {
d146 1
a146 1
                return (1);
d148 2
a149 2
	if (file_gline(sp, ep, lmp->lno, &len) == NULL ||
	    lmp->cno > len || lmp->cno == len && len != 0) {
d152 1
a152 1
		return (1);
d154 1
a154 3
	mp->lno = lmp->lno;
	mp->cno = lmp->cno;
	return (0);
d169 1
a169 1
	LMARK *lmp, *lmt;
d180 5
a184 5
	lmp = mark_find(sp, ep, key);
	if (lmp == NULL || lmp->name != key) {
		MALLOC_RET(sp, lmt, LMARK *, sizeof(LMARK));
		if (lmp == NULL) {
			LIST_INSERT_HEAD(&ep->marks, lmt, q);
d186 2
a187 2
			LIST_INSERT_AFTER(lmp, lmt, q);
		lmp = lmt;
d189 1
a189 1
	    !F_ISSET(lmp, MARK_DELETED) && F_ISSET(lmp, MARK_USERSET))
d192 4
a195 4
	lmp->lno = value->lno;
	lmp->cno = value->cno;
	lmp->name = key;
	lmp->flags = userset ? MARK_USERSET : 0;
d204 1
a204 1
static LMARK *
d210 1
a210 1
	LMARK *lmp, *lastlmp;
d216 5
a220 5
	for (lastlmp = NULL, lmp = ep->marks.lh_first;
	    lmp != NULL; lastlmp = lmp, lmp = lmp->q.le_next)
		if (lmp->name >= key)
			return (lmp->name == key ? lmp : lastlmp);
	return (lastlmp);
d234 1
a234 1
	LMARK *lmp;
d240 5
a244 6
		for (lmp = ep->marks.lh_first;
		    lmp != NULL; lmp = lmp->q.le_next)
			if (lmp->lno >= lno)
				if (lmp->lno == lno) {
					F_SET(lmp, MARK_DELETED);
					(void)log_mark(sp, ep, lmp);
d246 1
a246 1
					--lmp->lno;
d249 3
a251 4
		for (lmp = ep->marks.lh_first;
		    lmp != NULL; lmp = lmp->q.le_next)
			if (lmp->lno >= lno)
				++lmp->lno;
@
