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.58;	author cgd;	state Exp;
branches;
next	1.2;

1.2
date	94.01.24.06.39.15;	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.52.20;	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[] = "@@(#)seq.c	8.26 (Berkeley) 3/14/94";
#endif /* not lint */

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

#include <bitstring.h>
#include <ctype.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 "seq.h"
#include "excmd.h"

/*
 * seq_set --
 *	Internal version to enter a sequence.
 */
int
seq_set(sp, name, nlen, input, ilen, output, olen, stype, flags)
	SCR *sp;
	char *name, *input, *output;
	size_t nlen, ilen, olen;
	enum seqtype stype;
	int flags;
{
	SEQ *lastqp, *qp;
	CHAR_T *p;
	int sv_errno;

	/*
	 * An input string must always be present.  The output string
	 * can be NULL, when set internally, that's how we throw away
	 * input.
	 *
	 * Just replace the output field if the string already set.
	 */
	if ((qp = seq_find(sp, &lastqp, input, ilen, stype, NULL)) != NULL) {
		if (output == NULL || olen == 0) {
			p = NULL;
			olen = 0;
		} else if ((p = v_strdup(sp, output, olen)) == NULL) {
			sv_errno = errno;
			goto mem1;
		}
		if (qp->output != NULL)
			free(qp->output);
		qp->olen = olen;
		qp->output = p;
		return (0);
	}

	/* Allocate and initialize SEQ structure. */
	CALLOC(sp, qp, SEQ *, 1, sizeof(SEQ));
	if (qp == NULL) {
		sv_errno = errno;
		goto mem1;
	}

	/* Name. */
	if (name == NULL || nlen == 0)
		qp->name = NULL;
	else if ((qp->name = v_strdup(sp, name, nlen)) == NULL) {
		sv_errno = errno;
		goto mem2;
	}
	qp->nlen = nlen;

	/* Input. */
	if ((qp->input = v_strdup(sp, input, ilen)) == NULL) {
		sv_errno = errno;
		goto mem3;
	}
	qp->ilen = ilen;

	/* Output. */
	if (output == NULL) {
		qp->output = NULL;
		olen = 0;
	} else if ((qp->output = v_strdup(sp, output, olen)) == NULL) {
		sv_errno = errno;
		free(qp->input);
mem3:		if (qp->name != NULL)
			free(qp->name);
mem2:		FREE(qp, sizeof(SEQ));
mem1:		errno = sv_errno;
		msgq(sp, M_SYSERR, NULL);
		return (1);
	}
	qp->olen = olen;

	/* Type, flags. */
	qp->stype = stype;
	qp->flags = flags;

	/* Link into the chain. */
	if (lastqp == NULL) {
		LIST_INSERT_HEAD(&sp->gp->seqq, qp, q);
	} else {
		LIST_INSERT_AFTER(lastqp, qp, q);
	}

	/* Set the fast lookup bit. */
	bit_set(sp->gp->seqb, qp->input[0]);

	return (0);
}

/*
 * seq_delete --
 *	Delete a sequence.
 */
int
seq_delete(sp, input, ilen, stype)
	SCR *sp;
	char *input;
	size_t ilen;
	enum seqtype stype;
{
	SEQ *qp;

	if ((qp = seq_find(sp, NULL, input, ilen, stype, NULL)) == NULL)
		return (1);

	LIST_REMOVE(qp, q);
	if (qp->name != NULL)
		free(qp->name);
	free(qp->input);
	if (qp->output != NULL)
		free(qp->output);
	FREE(qp, sizeof(SEQ));
	return (0);
}

/*
 * seq_find --
 *	Search the sequence list for a match to a buffer, if ispartial
 *	isn't NULL, partial matches count.
 */
SEQ *
seq_find(sp, lastqp, input, ilen, stype, ispartialp)
	SCR *sp;
	SEQ **lastqp;
	char *input;
	size_t ilen;
	enum seqtype stype;
	int *ispartialp;
{
	SEQ *lqp, *qp;
	int diff;

	/*
	 * Ispartialp is a location where we return if there was a
	 * partial match, i.e. if the string were extended it might
	 * match something.
	 *
	 * XXX
	 * Overload the meaning of ispartialp; only the terminal key
	 * search doesn't want the search limited to complete matches,
	 * i.e. ilen may be longer than the match.
	 */
	if (ispartialp != NULL)
		*ispartialp = 0;
	for (lqp = NULL, qp = sp->gp->seqq.lh_first;
	    qp != NULL; lqp = qp, qp = qp->q.le_next) {
		/* Fast checks on the first character and type. */
		if (qp->input[0] > input[0])
			break;
		if (qp->input[0] < input[0] || qp->stype != stype)
			continue;

		/* Check on the real comparison. */
		diff = memcmp(qp->input, input, MIN(qp->ilen, ilen));
		if (diff > 0)
			break;
		if (diff < 0)
			continue;
		/*
		 * If the entry is the same length as the string, return a
		 * match.  If the entry is shorter than the string, return a
		 * match if called from the terminal key routine.  Otherwise,
		 * keep searching for a complete match.
		 */
		if (qp->ilen <= ilen) {
			if (qp->ilen == ilen || ispartialp != NULL) {
				if (lastqp != NULL)
					*lastqp = lqp;
				return (qp);
			}
			continue;
		}
		/*
		 * If the entry longer than the string, return partial match
		 * if called from the terminal key routine.  Otherwise, no
		 * match.
		 */
		if (ispartialp != NULL)
			*ispartialp = 1;
		break;
	}
	if (lastqp != NULL)
		*lastqp = lqp;
	return (NULL);
}

/*
 * seq_dump --
 *	Display the sequence entries of a specified type.
 */
int
seq_dump(sp, stype, isname)
	SCR *sp;
	enum seqtype stype;
	int isname;
{
	CHNAME const *cname;
	SEQ *qp;
	int cnt, len, olen;
	char *p;

	cnt = 0;
	cname = sp->gp->cname;
	for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) {
		if (stype != qp->stype)
			continue;
		++cnt;
		for (p = qp->input,
		    olen = qp->ilen, len = 0; olen > 0; --olen)
			len += ex_printf(EXCOOKIE, "%s", cname[*p++].name);
		for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
			len -= ex_printf(EXCOOKIE, " ");

		if (qp->output != NULL)
			for (p = qp->output,
			    olen = qp->olen, len = 0; olen > 0; --olen)
				len +=
				    ex_printf(EXCOOKIE, "%s", cname[*p++].name);
		else
			len = 0;

		if (isname && qp->name != NULL) {
			for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
				len -= ex_printf(EXCOOKIE, " ");
			for (p = qp->name, olen = qp->nlen; olen > 0; --olen)
				(void)ex_printf(EXCOOKIE,
				    "%s", cname[*p++].name);
		}
		(void)ex_printf(EXCOOKIE, "\n");
	}
	return (cnt);
}

/*
 * seq_save --
 *	Save the sequence entries to a file.
 */
int
seq_save(sp, fp, prefix, stype)
	SCR *sp;
	FILE *fp;
	char *prefix;
	enum seqtype stype;
{
	SEQ *qp;
	size_t olen;
	int ch;
	char *p;

	/* Write a sequence command for all keys the user defined. */
	for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next) {
		if (!F_ISSET(qp, S_USERDEF) || stype != qp->stype)
			continue;
		if (prefix)
			(void)fprintf(fp, "%s", prefix);
		for (p = qp->input, olen = qp->ilen; olen > 0; --olen) {
			ch = *p++;
			if (ch == LITERAL_CH || ch == '|' ||
			    isblank(ch) || term_key_val(sp, ch) == K_NL)
				(void)putc(LITERAL_CH, fp);
			(void)putc(ch, fp);
		}
		(void)putc(' ', fp);
		if (qp->output != NULL)
			for (p = qp->output,
			    olen = qp->olen; olen > 0; --olen) {
				ch = *p++;
				if (ch == LITERAL_CH || ch == '|' ||
				    term_key_val(sp, ch) == K_NL)
					(void)putc(LITERAL_CH, fp);
				(void)putc(ch, fp);
			}
		(void)putc('\n', fp);
	}
	return (0);
}
@


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[] = "@@(#)seq.c	8.21 (Berkeley) 12/9/93"; */
static char *rcsid = "$Id$";
d39 2
d42 1
d45 3
d50 5
d65 1
a65 1
seq_set(sp, name, nlen, input, ilen, output, olen, stype, userdef)
d70 1
a70 1
	int userdef;
d74 1
d76 7
a82 5
#if defined(DEBUG) && 0
	TRACE(sp, "seq_set: name {%s} input {%s} output {%s}\n",
	    name ? name : "", input, output);
#endif
	/* Just replace the output field in any previous occurrence. */
d84 5
a88 1
		if ((p = v_strdup(sp, output, olen)) == NULL)
d90 3
a92 1
		FREE(qp->output, qp->olen);
d98 1
a98 1
	/* Allocate and initialize space. */
d100 2
a101 1
	if (qp == NULL)
d103 4
a106 1
	if (name == NULL)
d108 2
a109 1
	else if ((qp->name = v_strdup(sp, name, nlen)) == NULL)
d111 6
a116 1
	if ((qp->input = v_strdup(sp, input, ilen)) == NULL)
d118 10
a127 2
	if ((qp->output = v_strdup(sp, output, olen)) == NULL) {
		FREE(qp->input, ilen);
d129 1
a129 1
			FREE(qp->name, nlen);
d131 2
a132 1
mem1:		msgq(sp, M_SYSERR, NULL);
d135 1
d137 1
d139 1
a139 4
	qp->nlen = nlen;
	qp->ilen = ilen;
	qp->olen = olen;
	qp->flags = userdef ? S_USERDEF : 0;
d172 4
a175 3
		FREE(qp->name, qp->nlen);
	FREE(qp->input, qp->ilen);
	FREE(qp->output, qp->olen);
d201 1
a201 1
	 * 
d263 1
a263 1
	int cnt, len, olen, tablen;
a267 1
	tablen = O_VAL(sp, O_TABSTOP);
d273 12
a284 7
		    olen = qp->ilen, len = 0; olen > 0; --olen, ++len)
			(void)ex_printf(EXCOOKIE, "%s", cname[*p++].name);
		for (len = tablen - len % tablen; len; --len)
			(void)ex_printf(EXCOOKIE, " ");

		for (p = qp->output, olen = qp->olen; olen > 0; --olen)
			(void)ex_printf(EXCOOKIE, "%s", cname[*p++].name);
d287 2
a288 2
			for (len = tablen - len % tablen; len; --len)
				(void)ex_printf(EXCOOKIE, " ");
a308 1
	CHAR_T esc;
a314 1
	(void)term_key_ch(sp, K_VLNEXT, &esc);
d316 1
a316 3
		if (!F_ISSET(qp, S_USERDEF))
			continue;
		if (stype != qp->stype)
d322 1
a322 1
			if (ch == esc || ch == '|' ||
d324 1
a324 1
				(void)putc(esc, fp);
d328 9
a336 7
		for (p = qp->output, olen = qp->olen; olen > 0; --olen) {
			ch = *p++;
			if (ch == esc || ch == '|' ||
			    term_key_val(sp, ch) == K_NL)
				(void)putc(esc, fp);
			(void)putc(ch, fp);
		}
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)seq.c	8.21 (Berkeley) 12/9/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[] = "@@(#)seq.c	8.26 (Berkeley) 3/14/94";
a38 2
#include <sys/queue.h>
#include <sys/time.h>
a39 1
#include <bitstring.h>
a41 3
#include <limits.h>
#include <signal.h>
#include <stdio.h>
a43 5
#include <termios.h>

#include "compat.h"
#include <db.h>
#include <regex.h>
d54 1
a54 1
seq_set(sp, name, nlen, input, ilen, output, olen, stype, flags)
d59 1
a59 1
	int flags;
a62 1
	int sv_errno;
d64 5
a68 7
	/*
	 * An input string must always be present.  The output string
	 * can be NULL, when set internally, that's how we throw away
	 * input.
	 *
	 * Just replace the output field if the string already set.
	 */
d70 1
a70 5
		if (output == NULL || olen == 0) {
			p = NULL;
			olen = 0;
		} else if ((p = v_strdup(sp, output, olen)) == NULL) {
			sv_errno = errno;
d72 1
a72 3
		}
		if (qp->output != NULL)
			free(qp->output);
d78 1
a78 1
	/* Allocate and initialize SEQ structure. */
d80 1
a80 2
	if (qp == NULL) {
		sv_errno = errno;
d82 1
a82 4
	}

	/* Name. */
	if (name == NULL || nlen == 0)
d84 1
a84 2
	else if ((qp->name = v_strdup(sp, name, nlen)) == NULL) {
		sv_errno = errno;
d86 1
a86 6
	}
	qp->nlen = nlen;

	/* Input. */
	if ((qp->input = v_strdup(sp, input, ilen)) == NULL) {
		sv_errno = errno;
d88 2
a89 10
	}
	qp->ilen = ilen;

	/* Output. */
	if (output == NULL) {
		qp->output = NULL;
		olen = 0;
	} else if ((qp->output = v_strdup(sp, output, olen)) == NULL) {
		sv_errno = errno;
		free(qp->input);
d91 1
a91 1
			free(qp->name);
d93 1
a93 2
mem1:		errno = sv_errno;
		msgq(sp, M_SYSERR, NULL);
a95 1
	qp->olen = olen;
a96 1
	/* Type, flags. */
d98 4
a101 1
	qp->flags = flags;
d134 3
a136 4
		free(qp->name);
	free(qp->input);
	if (qp->output != NULL)
		free(qp->output);
d162 1
a162 1
	 *
d224 1
a224 1
	int cnt, len, olen;
d229 1
d235 7
a241 12
		    olen = qp->ilen, len = 0; olen > 0; --olen)
			len += ex_printf(EXCOOKIE, "%s", cname[*p++].name);
		for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
			len -= ex_printf(EXCOOKIE, " ");

		if (qp->output != NULL)
			for (p = qp->output,
			    olen = qp->olen, len = 0; olen > 0; --olen)
				len +=
				    ex_printf(EXCOOKIE, "%s", cname[*p++].name);
		else
			len = 0;
d244 2
a245 2
			for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
				len -= ex_printf(EXCOOKIE, " ");
d266 1
d273 1
d275 3
a277 1
		if (!F_ISSET(qp, S_USERDEF) || stype != qp->stype)
d283 1
a283 1
			if (ch == LITERAL_CH || ch == '|' ||
d285 1
a285 1
				(void)putc(LITERAL_CH, fp);
d289 7
a295 9
		if (qp->output != NULL)
			for (p = qp->output,
			    olen = qp->olen; olen > 0; --olen) {
				ch = *p++;
				if (ch == LITERAL_CH || ch == '|' ||
				    term_key_val(sp, ch) == K_NL)
					(void)putc(LITERAL_CH, fp);
				(void)putc(ch, fp);
			}
@
