xref: /minix3/external/bsd/nvi/dist/common/seq.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: seq.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
784d9c625SLionel Sambuc  *
884d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc  */
1084d9c625SLionel Sambuc 
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc 
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc static const char sccsid[] = "Id: seq.c,v 10.15 2001/06/25 15:19:12 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:12 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: seq.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc 
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc 
2584d9c625SLionel Sambuc #include <bitstring.h>
2684d9c625SLionel Sambuc #include <ctype.h>
2784d9c625SLionel Sambuc #include <errno.h>
2884d9c625SLionel Sambuc #include <limits.h>
2984d9c625SLionel Sambuc #include <stdio.h>
3084d9c625SLionel Sambuc #include <stdlib.h>
3184d9c625SLionel Sambuc #include <string.h>
3284d9c625SLionel Sambuc 
3384d9c625SLionel Sambuc #include "common.h"
3484d9c625SLionel Sambuc 
3584d9c625SLionel Sambuc /*
3684d9c625SLionel Sambuc  * seq_set --
3784d9c625SLionel Sambuc  *	Internal version to enter a sequence.
3884d9c625SLionel Sambuc  *
3984d9c625SLionel Sambuc  * PUBLIC: int seq_set __P((SCR *, CHAR_T *,
4084d9c625SLionel Sambuc  * PUBLIC:    size_t, CHAR_T *, size_t, CHAR_T *, size_t, seq_t, int));
4184d9c625SLionel Sambuc  */
4284d9c625SLionel Sambuc int
seq_set(SCR * sp,CHAR_T * name,size_t nlen,CHAR_T * input,size_t ilen,CHAR_T * output,size_t olen,seq_t stype,int flags)4384d9c625SLionel Sambuc seq_set(SCR *sp, CHAR_T *name, size_t nlen, CHAR_T *input, size_t ilen, CHAR_T *output, size_t olen, seq_t stype, int flags)
4484d9c625SLionel Sambuc {
4584d9c625SLionel Sambuc 	CHAR_T *p;
4684d9c625SLionel Sambuc 	SEQ *lastqp, *qp;
4784d9c625SLionel Sambuc 	int sv_errno;
4884d9c625SLionel Sambuc 
4984d9c625SLionel Sambuc 	/*
5084d9c625SLionel Sambuc 	 * An input string must always be present.  The output string
5184d9c625SLionel Sambuc 	 * can be NULL, when set internally, that's how we throw away
5284d9c625SLionel Sambuc 	 * input.
5384d9c625SLionel Sambuc 	 *
5484d9c625SLionel Sambuc 	 * Just replace the output field if the string already set.
5584d9c625SLionel Sambuc 	 */
5684d9c625SLionel Sambuc 	if ((qp =
5784d9c625SLionel Sambuc 	    seq_find(sp, &lastqp, NULL, input, ilen, stype, NULL)) != NULL) {
5884d9c625SLionel Sambuc 		if (LF_ISSET(SEQ_NOOVERWRITE))
5984d9c625SLionel Sambuc 			return (0);
6084d9c625SLionel Sambuc 		if (output == NULL || olen == 0) {
6184d9c625SLionel Sambuc 			p = NULL;
6284d9c625SLionel Sambuc 			olen = 0;
6384d9c625SLionel Sambuc 		} else if ((p = v_wstrdup(sp, output, olen)) == NULL) {
6484d9c625SLionel Sambuc 			sv_errno = errno;
6584d9c625SLionel Sambuc 			goto mem1;
6684d9c625SLionel Sambuc 		}
6784d9c625SLionel Sambuc 		if (qp->output != NULL)
6884d9c625SLionel Sambuc 			free(qp->output);
6984d9c625SLionel Sambuc 		qp->olen = olen;
7084d9c625SLionel Sambuc 		qp->output = p;
7184d9c625SLionel Sambuc 		return (0);
7284d9c625SLionel Sambuc 	}
7384d9c625SLionel Sambuc 
7484d9c625SLionel Sambuc 	/* Allocate and initialize SEQ structure. */
7584d9c625SLionel Sambuc 	CALLOC(sp, qp, SEQ *, 1, sizeof(SEQ));
7684d9c625SLionel Sambuc 	if (qp == NULL) {
7784d9c625SLionel Sambuc 		sv_errno = errno;
7884d9c625SLionel Sambuc 		goto mem1;
7984d9c625SLionel Sambuc 	}
8084d9c625SLionel Sambuc 
8184d9c625SLionel Sambuc 	/* Name. */
8284d9c625SLionel Sambuc 	if (name == NULL || nlen == 0)
8384d9c625SLionel Sambuc 		qp->name = NULL;
8484d9c625SLionel Sambuc 	else if ((qp->name = v_wstrdup(sp, name, nlen)) == NULL) {
8584d9c625SLionel Sambuc 		sv_errno = errno;
8684d9c625SLionel Sambuc 		goto mem2;
8784d9c625SLionel Sambuc 	}
8884d9c625SLionel Sambuc 	qp->nlen = nlen;
8984d9c625SLionel Sambuc 
9084d9c625SLionel Sambuc 	/* Input. */
9184d9c625SLionel Sambuc 	if ((qp->input = v_wstrdup(sp, input, ilen)) == NULL) {
9284d9c625SLionel Sambuc 		sv_errno = errno;
9384d9c625SLionel Sambuc 		goto mem3;
9484d9c625SLionel Sambuc 	}
9584d9c625SLionel Sambuc 	qp->ilen = ilen;
9684d9c625SLionel Sambuc 
9784d9c625SLionel Sambuc 	/* Output. */
9884d9c625SLionel Sambuc 	if (output == NULL) {
9984d9c625SLionel Sambuc 		qp->output = NULL;
10084d9c625SLionel Sambuc 		olen = 0;
10184d9c625SLionel Sambuc 	} else if ((qp->output = v_wstrdup(sp, output, olen)) == NULL) {
10284d9c625SLionel Sambuc 		sv_errno = errno;
10384d9c625SLionel Sambuc 		free(qp->input);
10484d9c625SLionel Sambuc mem3:		if (qp->name != NULL)
10584d9c625SLionel Sambuc 			free(qp->name);
10684d9c625SLionel Sambuc mem2:		free(qp);
10784d9c625SLionel Sambuc mem1:		errno = sv_errno;
10884d9c625SLionel Sambuc 		msgq(sp, M_SYSERR, NULL);
10984d9c625SLionel Sambuc 		return (1);
11084d9c625SLionel Sambuc 	}
11184d9c625SLionel Sambuc 	qp->olen = olen;
11284d9c625SLionel Sambuc 
11384d9c625SLionel Sambuc 	/* Type, flags. */
11484d9c625SLionel Sambuc 	qp->stype = stype;
11584d9c625SLionel Sambuc 	qp->flags = flags;
11684d9c625SLionel Sambuc 
11784d9c625SLionel Sambuc 	/* Link into the chain. */
11884d9c625SLionel Sambuc 	if (lastqp == NULL) {
11984d9c625SLionel Sambuc 		LIST_INSERT_HEAD(&sp->gp->seqq, qp, q);
12084d9c625SLionel Sambuc 	} else {
12184d9c625SLionel Sambuc 		LIST_INSERT_AFTER(lastqp, qp, q);
12284d9c625SLionel Sambuc 	}
12384d9c625SLionel Sambuc 
12484d9c625SLionel Sambuc 	/* Set the fast lookup bit. */
12584d9c625SLionel Sambuc 	if ((qp->input[0] & ~MAX_BIT_SEQ) == 0)
12684d9c625SLionel Sambuc 		bit_set(sp->gp->seqb, qp->input[0]);
12784d9c625SLionel Sambuc 
12884d9c625SLionel Sambuc 	return (0);
12984d9c625SLionel Sambuc }
13084d9c625SLionel Sambuc 
13184d9c625SLionel Sambuc /*
13284d9c625SLionel Sambuc  * seq_delete --
13384d9c625SLionel Sambuc  *	Delete a sequence.
13484d9c625SLionel Sambuc  *
13584d9c625SLionel Sambuc  * PUBLIC: int seq_delete __P((SCR *, CHAR_T *, size_t, seq_t));
13684d9c625SLionel Sambuc  */
13784d9c625SLionel Sambuc int
seq_delete(SCR * sp,CHAR_T * input,size_t ilen,seq_t stype)13884d9c625SLionel Sambuc seq_delete(SCR *sp, CHAR_T *input, size_t ilen, seq_t stype)
13984d9c625SLionel Sambuc {
14084d9c625SLionel Sambuc 	SEQ *qp;
14184d9c625SLionel Sambuc 
14284d9c625SLionel Sambuc 	if ((qp = seq_find(sp, NULL, NULL, input, ilen, stype, NULL)) == NULL)
14384d9c625SLionel Sambuc 		return (1);
14484d9c625SLionel Sambuc 	return (seq_mdel(qp));
14584d9c625SLionel Sambuc }
14684d9c625SLionel Sambuc 
14784d9c625SLionel Sambuc /*
14884d9c625SLionel Sambuc  * seq_mdel --
14984d9c625SLionel Sambuc  *	Delete a map entry, without lookup.
15084d9c625SLionel Sambuc  *
15184d9c625SLionel Sambuc  * PUBLIC: int seq_mdel __P((SEQ *));
15284d9c625SLionel Sambuc  */
15384d9c625SLionel Sambuc int
seq_mdel(SEQ * qp)15484d9c625SLionel Sambuc seq_mdel(SEQ *qp)
15584d9c625SLionel Sambuc {
15684d9c625SLionel Sambuc 	LIST_REMOVE(qp, q);
15784d9c625SLionel Sambuc 	if (qp->name != NULL)
15884d9c625SLionel Sambuc 		free(qp->name);
15984d9c625SLionel Sambuc 	free(qp->input);
16084d9c625SLionel Sambuc 	if (qp->output != NULL)
16184d9c625SLionel Sambuc 		free(qp->output);
16284d9c625SLionel Sambuc 	free(qp);
16384d9c625SLionel Sambuc 	return (0);
16484d9c625SLionel Sambuc }
16584d9c625SLionel Sambuc 
16684d9c625SLionel Sambuc /*
16784d9c625SLionel Sambuc  * seq_find --
16884d9c625SLionel Sambuc  *	Search the sequence list for a match to a buffer, if ispartial
16984d9c625SLionel Sambuc  *	isn't NULL, partial matches count.
17084d9c625SLionel Sambuc  *
17184d9c625SLionel Sambuc  * PUBLIC: SEQ *seq_find
17284d9c625SLionel Sambuc  * PUBLIC:    __P((SCR *, SEQ **, EVENT *, CHAR_T *, size_t, seq_t, int *));
17384d9c625SLionel Sambuc  */
17484d9c625SLionel Sambuc SEQ *
seq_find(SCR * sp,SEQ ** lastqp,EVENT * e_input,CHAR_T * c_input,size_t ilen,seq_t stype,int * ispartialp)17584d9c625SLionel Sambuc seq_find(SCR *sp, SEQ **lastqp, EVENT *e_input, CHAR_T *c_input, size_t ilen, seq_t stype, int *ispartialp)
17684d9c625SLionel Sambuc {
17784d9c625SLionel Sambuc 	SEQ *lqp, *qp;
17884d9c625SLionel Sambuc 	int diff;
17984d9c625SLionel Sambuc 
18084d9c625SLionel Sambuc 	/*
18184d9c625SLionel Sambuc 	 * Ispartialp is a location where we return if there was a
18284d9c625SLionel Sambuc 	 * partial match, i.e. if the string were extended it might
18384d9c625SLionel Sambuc 	 * match something.
18484d9c625SLionel Sambuc 	 *
18584d9c625SLionel Sambuc 	 * XXX
18684d9c625SLionel Sambuc 	 * Overload the meaning of ispartialp; only the terminal key
18784d9c625SLionel Sambuc 	 * search doesn't want the search limited to complete matches,
18884d9c625SLionel Sambuc 	 * i.e. ilen may be longer than the match.
18984d9c625SLionel Sambuc 	 */
19084d9c625SLionel Sambuc 	if (ispartialp != NULL)
19184d9c625SLionel Sambuc 		*ispartialp = 0;
19284d9c625SLionel Sambuc 
19384d9c625SLionel Sambuc 	for (lqp = NULL, qp = LIST_FIRST(&sp->gp->seqq);
19484d9c625SLionel Sambuc 	    qp != NULL;
19584d9c625SLionel Sambuc 	    lqp = qp, qp = LIST_NEXT(qp, q)) {
19684d9c625SLionel Sambuc 		/*
19784d9c625SLionel Sambuc 		 * Fast checks on the first character and type, and then
19884d9c625SLionel Sambuc 		 * a real comparison.
19984d9c625SLionel Sambuc 		 */
20084d9c625SLionel Sambuc 		if (e_input == NULL) {
20184d9c625SLionel Sambuc 			if (qp->input[0] > c_input[0])
20284d9c625SLionel Sambuc 				break;
20384d9c625SLionel Sambuc 			if (qp->input[0] < c_input[0] ||
20484d9c625SLionel Sambuc 			    qp->stype != stype || F_ISSET(qp, SEQ_FUNCMAP))
20584d9c625SLionel Sambuc 				continue;
20684d9c625SLionel Sambuc 			diff = MEMCMP(qp->input, c_input, MIN(qp->ilen, ilen));
20784d9c625SLionel Sambuc 		} else {
20884d9c625SLionel Sambuc 			if (qp->input[0] > e_input->e_c)
20984d9c625SLionel Sambuc 				break;
21084d9c625SLionel Sambuc 			if (qp->input[0] < e_input->e_c ||
21184d9c625SLionel Sambuc 			    qp->stype != stype || F_ISSET(qp, SEQ_FUNCMAP))
21284d9c625SLionel Sambuc 				continue;
21384d9c625SLionel Sambuc 			diff =
21484d9c625SLionel Sambuc 			    e_memcmp(qp->input, e_input, MIN(qp->ilen, ilen));
21584d9c625SLionel Sambuc 		}
21684d9c625SLionel Sambuc 		if (diff > 0)
21784d9c625SLionel Sambuc 			break;
21884d9c625SLionel Sambuc 		if (diff < 0)
21984d9c625SLionel Sambuc 			continue;
22084d9c625SLionel Sambuc 		/*
22184d9c625SLionel Sambuc 		 * If the entry is the same length as the string, return a
22284d9c625SLionel Sambuc 		 * match.  If the entry is shorter than the string, return a
22384d9c625SLionel Sambuc 		 * match if called from the terminal key routine.  Otherwise,
22484d9c625SLionel Sambuc 		 * keep searching for a complete match.
22584d9c625SLionel Sambuc 		 */
22684d9c625SLionel Sambuc 		if (qp->ilen <= ilen) {
22784d9c625SLionel Sambuc 			if (qp->ilen == ilen || ispartialp != NULL) {
22884d9c625SLionel Sambuc 				if (lastqp != NULL)
22984d9c625SLionel Sambuc 					*lastqp = lqp;
23084d9c625SLionel Sambuc 				return (qp);
23184d9c625SLionel Sambuc 			}
23284d9c625SLionel Sambuc 			continue;
23384d9c625SLionel Sambuc 		}
23484d9c625SLionel Sambuc 		/*
23584d9c625SLionel Sambuc 		 * If the entry longer than the string, return partial match
23684d9c625SLionel Sambuc 		 * if called from the terminal key routine.  Otherwise, no
23784d9c625SLionel Sambuc 		 * match.
23884d9c625SLionel Sambuc 		 */
23984d9c625SLionel Sambuc 		if (ispartialp != NULL)
24084d9c625SLionel Sambuc 			*ispartialp = 1;
24184d9c625SLionel Sambuc 		break;
24284d9c625SLionel Sambuc 	}
24384d9c625SLionel Sambuc 	if (lastqp != NULL)
24484d9c625SLionel Sambuc 		*lastqp = lqp;
24584d9c625SLionel Sambuc 	return (NULL);
24684d9c625SLionel Sambuc }
24784d9c625SLionel Sambuc 
24884d9c625SLionel Sambuc /*
24984d9c625SLionel Sambuc  * seq_close --
25084d9c625SLionel Sambuc  *	Discard all sequences.
25184d9c625SLionel Sambuc  *
25284d9c625SLionel Sambuc  * PUBLIC: void seq_close __P((GS *));
25384d9c625SLionel Sambuc  */
25484d9c625SLionel Sambuc void
seq_close(GS * gp)25584d9c625SLionel Sambuc seq_close(GS *gp)
25684d9c625SLionel Sambuc {
25784d9c625SLionel Sambuc 	SEQ *qp;
25884d9c625SLionel Sambuc 
25984d9c625SLionel Sambuc 	while ((qp = LIST_FIRST(&gp->seqq)) != NULL) {
26084d9c625SLionel Sambuc 		if (qp->name != NULL)
26184d9c625SLionel Sambuc 			free(qp->name);
26284d9c625SLionel Sambuc 		if (qp->input != NULL)
26384d9c625SLionel Sambuc 			free(qp->input);
26484d9c625SLionel Sambuc 		if (qp->output != NULL)
26584d9c625SLionel Sambuc 			free(qp->output);
26684d9c625SLionel Sambuc 		LIST_REMOVE(qp, q);
26784d9c625SLionel Sambuc 		free(qp);
26884d9c625SLionel Sambuc 	}
26984d9c625SLionel Sambuc }
27084d9c625SLionel Sambuc 
27184d9c625SLionel Sambuc /*
27284d9c625SLionel Sambuc  * seq_dump --
27384d9c625SLionel Sambuc  *	Display the sequence entries of a specified type.
27484d9c625SLionel Sambuc  *
27584d9c625SLionel Sambuc  * PUBLIC: int seq_dump __P((SCR *, seq_t, int));
27684d9c625SLionel Sambuc  */
27784d9c625SLionel Sambuc int
seq_dump(SCR * sp,seq_t stype,int isname)27884d9c625SLionel Sambuc seq_dump(SCR *sp, seq_t stype, int isname)
27984d9c625SLionel Sambuc {
28084d9c625SLionel Sambuc 	CHAR_T *p;
28184d9c625SLionel Sambuc 	GS *gp;
28284d9c625SLionel Sambuc 	SEQ *qp;
28384d9c625SLionel Sambuc 	int cnt, len, olen;
28484d9c625SLionel Sambuc 
28584d9c625SLionel Sambuc 	cnt = 0;
28684d9c625SLionel Sambuc 	gp = sp->gp;
28784d9c625SLionel Sambuc 	LIST_FOREACH(qp, &gp->seqq, q) {
28884d9c625SLionel Sambuc 		if (stype != qp->stype || F_ISSET(qp, SEQ_FUNCMAP))
28984d9c625SLionel Sambuc 			continue;
29084d9c625SLionel Sambuc 		++cnt;
29184d9c625SLionel Sambuc 		for (p = qp->input,
29284d9c625SLionel Sambuc 		    olen = qp->ilen, len = 0; olen > 0; --olen, ++p)
29384d9c625SLionel Sambuc 			len += ex_puts(sp, (char *)KEY_NAME(sp, *p));
29484d9c625SLionel Sambuc 		for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
29584d9c625SLionel Sambuc 			len -= ex_puts(sp, " ");
29684d9c625SLionel Sambuc 
29784d9c625SLionel Sambuc 		if (qp->output != NULL)
29884d9c625SLionel Sambuc 			for (p = qp->output,
29984d9c625SLionel Sambuc 			    olen = qp->olen, len = 0; olen > 0; --olen, ++p)
30084d9c625SLionel Sambuc 				len += ex_puts(sp, (char *)KEY_NAME(sp, *p));
30184d9c625SLionel Sambuc 		else
30284d9c625SLionel Sambuc 			len = 0;
30384d9c625SLionel Sambuc 
30484d9c625SLionel Sambuc 		if (isname && qp->name != NULL) {
30584d9c625SLionel Sambuc 			for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
30684d9c625SLionel Sambuc 				len -= ex_puts(sp, " ");
30784d9c625SLionel Sambuc 			for (p = qp->name,
30884d9c625SLionel Sambuc 			    olen = qp->nlen; olen > 0; --olen, ++p)
30984d9c625SLionel Sambuc 				(void)ex_puts(sp, (char *)KEY_NAME(sp, *p));
31084d9c625SLionel Sambuc 		}
31184d9c625SLionel Sambuc 		(void)ex_puts(sp, "\n");
31284d9c625SLionel Sambuc 	}
31384d9c625SLionel Sambuc 	return (cnt);
31484d9c625SLionel Sambuc }
31584d9c625SLionel Sambuc 
31684d9c625SLionel Sambuc /*
31784d9c625SLionel Sambuc  * seq_save --
31884d9c625SLionel Sambuc  *	Save the sequence entries to a file.
31984d9c625SLionel Sambuc  *
32084d9c625SLionel Sambuc  * PUBLIC: int seq_save __P((SCR *, FILE *, const char *, seq_t));
32184d9c625SLionel Sambuc  */
32284d9c625SLionel Sambuc int
seq_save(SCR * sp,FILE * fp,const char * prefix,seq_t stype)32384d9c625SLionel Sambuc seq_save(SCR *sp, FILE *fp, const char *prefix, seq_t stype)
32484d9c625SLionel Sambuc {
32584d9c625SLionel Sambuc 	CHAR_T *p;
32684d9c625SLionel Sambuc 	SEQ *qp;
32784d9c625SLionel Sambuc 	size_t olen;
32884d9c625SLionel Sambuc 	ARG_CHAR_T ch;
32984d9c625SLionel Sambuc 
33084d9c625SLionel Sambuc 	/* Write a sequence command for all keys the user defined. */
33184d9c625SLionel Sambuc 	LIST_FOREACH(qp, &sp->gp->seqq, q) {
33284d9c625SLionel Sambuc 		if (stype != qp->stype || !F_ISSET(qp, SEQ_USERDEF))
33384d9c625SLionel Sambuc 			continue;
33484d9c625SLionel Sambuc 		if (prefix)
33584d9c625SLionel Sambuc 			(void)fprintf(fp, "%s", prefix);
33684d9c625SLionel Sambuc 		for (p = qp->input, olen = qp->ilen; olen > 0; --olen) {
33784d9c625SLionel Sambuc 			ch = (UCHAR_T)*p++;
33884d9c625SLionel Sambuc 			if (ch == CH_LITERAL || ch == '|' ||
33984d9c625SLionel Sambuc 			    ISBLANK(ch) || KEY_VAL(sp, ch) == K_NL)
34084d9c625SLionel Sambuc 				(void)putc(CH_LITERAL, fp);
34184d9c625SLionel Sambuc 			(void)fprintf(fp, WC, ch);
34284d9c625SLionel Sambuc 		}
34384d9c625SLionel Sambuc 		(void)putc(' ', fp);
34484d9c625SLionel Sambuc 		if (qp->output != NULL)
34584d9c625SLionel Sambuc 			for (p = qp->output,
34684d9c625SLionel Sambuc 			    olen = qp->olen; olen > 0; --olen) {
34784d9c625SLionel Sambuc 				ch = (UCHAR_T)*p++;
34884d9c625SLionel Sambuc 				if (ch == CH_LITERAL || ch == '|' ||
34984d9c625SLionel Sambuc 				    KEY_VAL(sp, ch) == K_NL)
35084d9c625SLionel Sambuc 					(void)putc(CH_LITERAL, fp);
35184d9c625SLionel Sambuc 				(void)fprintf(fp, WC, ch);
35284d9c625SLionel Sambuc 			}
35384d9c625SLionel Sambuc 		(void)putc('\n', fp);
35484d9c625SLionel Sambuc 	}
35584d9c625SLionel Sambuc 	return (0);
35684d9c625SLionel Sambuc }
35784d9c625SLionel Sambuc 
35884d9c625SLionel Sambuc /*
35984d9c625SLionel Sambuc  * e_memcmp --
36084d9c625SLionel Sambuc  *	Compare a string of EVENT's to a string of CHAR_T's.
36184d9c625SLionel Sambuc  *
36284d9c625SLionel Sambuc  * PUBLIC: int e_memcmp __P((CHAR_T *, EVENT *, size_t));
36384d9c625SLionel Sambuc  */
36484d9c625SLionel Sambuc int
e_memcmp(CHAR_T * p1,EVENT * ep,size_t n)36584d9c625SLionel Sambuc e_memcmp(CHAR_T *p1, EVENT *ep, size_t n)
36684d9c625SLionel Sambuc {
36784d9c625SLionel Sambuc 	if (n != 0) {
36884d9c625SLionel Sambuc                 do {
36984d9c625SLionel Sambuc                         if (*p1++ != ep->e_c)
37084d9c625SLionel Sambuc                                 return (*--p1 - ep->e_c);
37184d9c625SLionel Sambuc 			++ep;
37284d9c625SLionel Sambuc                 } while (--n != 0);
37384d9c625SLionel Sambuc         }
37484d9c625SLionel Sambuc         return (0);
37584d9c625SLionel Sambuc }
376