* 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
* 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
static char sccsid
[] = "@(#)seq.c 8.26 (Berkeley) 3/14/94";
* Internal version to enter a sequence.
seq_set(sp
, name
, nlen
, input
, ilen
, output
, olen
, stype
, flags
)
char *name
, *input
, *output
;
* An input string must always be present. The output string
* can be NULL, when set internally, that's how we throw away
* 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) {
} else if ((p
= v_strdup(sp
, output
, olen
)) == NULL
) {
/* Allocate and initialize SEQ structure. */
CALLOC(sp
, qp
, SEQ
*, 1, sizeof(SEQ
));
if (name
== NULL
|| nlen
== 0)
else if ((qp
->name
= v_strdup(sp
, name
, nlen
)) == NULL
) {
if ((qp
->input
= v_strdup(sp
, input
, ilen
)) == NULL
) {
} else if ((qp
->output
= v_strdup(sp
, output
, olen
)) == NULL
) {
mem3
: if (qp
->name
!= NULL
)
mem2
: FREE(qp
, sizeof(SEQ
));
msgq(sp
, M_SYSERR
, NULL
);
/* Link into the chain. */
LIST_INSERT_HEAD(&sp
->gp
->seqq
, qp
, q
);
LIST_INSERT_AFTER(lastqp
, qp
, q
);
/* Set the fast lookup bit. */
bit_set(sp
->gp
->seqb
, qp
->input
[0]);
seq_delete(sp
, input
, ilen
, stype
)
if ((qp
= seq_find(sp
, NULL
, input
, ilen
, stype
, NULL
)) == NULL
)
* Search the sequence list for a match to a buffer, if ispartial
* isn't NULL, partial matches count.
seq_find(sp
, lastqp
, input
, ilen
, stype
, ispartialp
)
* Ispartialp is a location where we return if there was a
* partial match, i.e. if the string were extended it might
* 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.
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])
if (qp
->input
[0] < input
[0] || qp
->stype
!= stype
)
/* Check on the real comparison. */
diff
= memcmp(qp
->input
, input
, MIN(qp
->ilen
, ilen
));
* 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
|| ispartialp
!= NULL
) {
* If the entry longer than the string, return partial match
* if called from the terminal key routine. Otherwise, no
* Display the sequence entries of a specified type.
seq_dump(sp
, stype
, isname
)
for (qp
= sp
->gp
->seqq
.lh_first
; qp
!= NULL
; qp
= qp
->q
.le_next
) {
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
, " ");
olen
= qp
->olen
, len
= 0; olen
> 0; --olen
)
ex_printf(EXCOOKIE
, "%s", cname
[*p
++].name
);
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
,
(void)ex_printf(EXCOOKIE
, "\n");
* Save the sequence entries to a file.
seq_save(sp
, fp
, prefix
, stype
)
/* 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
)
(void)fprintf(fp
, "%s", prefix
);
for (p
= qp
->input
, olen
= qp
->ilen
; olen
> 0; --olen
) {
if (ch
== LITERAL_CH
|| ch
== '|' ||
isblank(ch
) || term_key_val(sp
, ch
) == K_NL
)
(void)putc(LITERAL_CH
, fp
);
olen
= qp
->olen
; olen
> 0; --olen
) {
if (ch
== LITERAL_CH
|| ch
== '|' ||
term_key_val(sp
, ch
) == K_NL
)
(void)putc(LITERAL_CH
, fp
);