2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1991, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "$Id: key.c,v 10.34 1996/11/27 11:59:36 bostic Exp $ (Berkeley) $Date: 1996/11/27 11:59:36 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
33 static int v_event_append
__P((SCR
*, EVENT
*));
34 static int v_event_grow
__P((SCR
*, int));
35 static int v_key_cmp
__P((const void *, const void *));
36 static void v_keyval
__P((SCR
*, int, scr_keyval_t
));
37 static void v_sync
__P((SCR
*, int));
41 * Historic vi always used:
43 * ^D: autoindent deletion
44 * ^H: last character deletion
45 * ^W: last word deletion
46 * ^Q: quote the next character (if not used in flow control).
47 * ^V: quote the next character
49 * regardless of the user's choices for these characters. The user's erase
50 * and kill characters worked in addition to these characters. Nvi wires
51 * down the above characters, but in addition permits the VEOF, VERASE, VKILL
52 * and VWERASE characters described by the user's termios structure.
54 * Ex was not consistent with this scheme, as it historically ran in tty
55 * cooked mode. This meant that the scroll command and autoindent erase
56 * characters were mapped to the user's EOF character, and the character
57 * and word deletion characters were the user's tty character and word
58 * deletion characters. This implementation makes it all consistent, as
59 * described above for vi.
62 * This means that all screens share a special key set.
65 {K_BACKSLASH
, '\\'}, /* \ */
66 {K_CARAT
, '^'}, /* ^ */
67 {K_CNTRLD
, '\004'}, /* ^D */
68 {K_CNTRLR
, '\022'}, /* ^R */
69 {K_CNTRLT
, '\024'}, /* ^T */
70 {K_CNTRLZ
, '\032'}, /* ^Z */
71 {K_COLON
, ':'}, /* : */
72 {K_CR
, '\r'}, /* \r */
73 {K_ESCAPE
, '\033'}, /* ^[ */
74 {K_FORMFEED
, '\f'}, /* \f */
75 {K_HEXCHAR
, '\030'}, /* ^X */
76 {K_NL
, '\n'}, /* \n */
77 {K_RIGHTBRACE
, '}'}, /* } */
78 {K_RIGHTPAREN
, ')'}, /* ) */
79 {K_TAB
, '\t'}, /* \t */
80 {K_VERASE
, '\b'}, /* \b */
81 {K_VKILL
, '\025'}, /* ^U */
82 {K_VLNEXT
, '\021'}, /* ^Q */
83 {K_VLNEXT
, '\026'}, /* ^V */
84 {K_VWERASE
, '\027'}, /* ^W */
85 {K_ZERO
, '0'}, /* 0 */
87 #define ADDITIONAL_CHARACTERS 4
88 {K_NOTUSED
, 0}, /* VEOF, VERASE, VKILL, VWERASE */
94 (sizeof(keylist
) / sizeof(keylist
[0])) - ADDITIONAL_CHARACTERS
;
98 * Initialize the special key lookup table.
100 * PUBLIC: int v_key_init __P((SCR *));
115 * 8-bit only, for now. Recompilation should get you any 8-bit
116 * character set, as long as nul isn't a character.
118 (void)setlocale(LC_ALL
, "");
121 * In libc 4.5.26, setlocale(LC_ALL, ""), doesn't setup the table
122 * for ctype(3c) correctly. This bug is fixed in libc 4.6.x.
124 * This code works around this problem for libc 4.5.x users.
125 * Note that this code is harmless if you're using libc 4.6.x.
127 (void)setlocale(LC_CTYPE
, "");
131 v_keyval(sp
, K_CNTRLD
, KEY_VEOF
);
132 v_keyval(sp
, K_VERASE
, KEY_VERASE
);
133 v_keyval(sp
, K_VKILL
, KEY_VKILL
);
134 v_keyval(sp
, K_VWERASE
, KEY_VWERASE
);
136 /* Sort the special key list. */
137 qsort(keylist
, nkeylist
, sizeof(keylist
[0]), v_key_cmp
);
139 /* Initialize the fast lookup table. */
140 for (gp
->max_special
= 0, kp
= keylist
, cnt
= nkeylist
; cnt
--; ++kp
) {
141 if (gp
->max_special
< kp
->value
)
142 gp
->max_special
= kp
->value
;
143 if (kp
->ch
<= MAX_FAST_KEY
)
144 gp
->special_key
[kp
->ch
] = kp
->value
;
147 /* Find a non-printable character to use as a message separator. */
148 for (ch
= 1; ch
<= MAX_CHAR_T
; ++ch
)
153 if (ch
!= gp
->noprint
) {
154 msgq(sp
, M_ERR
, "079|No non-printable character found");
164 * We've left some open slots in the keylist table, and if these values exist,
165 * we put them into place. Note, they may reset (or duplicate) values already
166 * in the table, so we check for that first.
169 v_keyval(sp
, val
, name
)
178 /* Get the key's value from the screen. */
179 if (sp
->gp
->scr_keyval(sp
, name
, &ch
, &dne
))
184 /* Check for duplication. */
185 for (kp
= keylist
; kp
->value
!= K_NOTUSED
; ++kp
)
191 /* Add a new entry. */
192 if (kp
->value
== K_NOTUSED
) {
193 keylist
[nkeylist
].ch
= ch
;
194 keylist
[nkeylist
].value
= val
;
201 * Build the fast-lookup key display array.
203 * PUBLIC: void v_key_ilookup __P((SCR *));
213 for (gp
= sp
->gp
, ch
= 0;; ++ch
) {
214 for (p
= gp
->cname
[ch
].name
, t
= v_key_name(sp
, ch
),
215 len
= gp
->cname
[ch
].len
= sp
->clen
; len
--;)
217 if (ch
== MAX_FAST_KEY
)
224 * Return the length of the string that will display the key.
225 * This routine is the backup for the KEY_LEN() macro.
227 * PUBLIC: size_t v_key_len __P((SCR *, ARG_CHAR_T));
234 (void)v_key_name(sp
, ch
);
240 * Return the string that will display the key. This routine
241 * is the backup for the KEY_NAME() macro.
243 * PUBLIC: CHAR_T *v_key_name __P((SCR *, ARG_CHAR_T));
250 static const CHAR_T hexdigit
[] = "0123456789abcdef";
251 static const CHAR_T octdigit
[] = "01234567";
252 CHAR_T ch
, *chp
, mask
;
258 /* See if the character was explicitly declared printable or not. */
259 if ((chp
= O_STR(sp
, O_PRINT
)) != NULL
)
260 for (; *chp
!= '\0'; ++chp
)
263 if ((chp
= O_STR(sp
, O_NOPRINT
)) != NULL
)
264 for (; *chp
!= '\0'; ++chp
)
269 * Historical (ARPA standard) mappings. Printable characters are left
270 * alone. Control characters less than 0x20 are represented as '^'
271 * followed by the character offset from the '@' character in the ASCII
272 * character set. Del (0x7f) is represented as '^' followed by '?'.
275 * The following code depends on the current locale being identical to
276 * the ASCII map from 0x40 to 0x5f (since 0x1f + 0x40 == 0x5f). I'm
277 * told that this is a reasonable assumption...
280 * This code will only work with CHAR_T's that are multiples of 8-bit
284 * NB: There's an assumption here that all printable characters take
285 * up a single column on the screen. This is not always correct.
288 pr
: sp
->cname
[0] = ch
;
292 nopr
: if (iscntrl(ch
) && (ch
< 0x20 || ch
== 0x7f)) {
294 sp
->cname
[1] = ch
== 0x7f ? '?' : '@' + ch
;
296 } else if (O_ISSET(sp
, O_OCTAL
)) {
297 #define BITS (sizeof(CHAR_T) * 8)
298 #define SHIFT (BITS - BITS % 3)
299 #define TOPMASK (BITS % 3 == 2 ? 3 : 1) << (BITS - BITS % 3)
301 sp
->cname
[1] = octdigit
[(ch
& TOPMASK
) >> SHIFT
];
303 for (len
= 2, mask
= 7 << (SHIFT
- 3),
304 cnt
= BITS
/ 3; cnt
-- > 0; mask
>>= 3, shift
-= 3)
305 sp
->cname
[len
++] = octdigit
[(ch
& mask
) >> shift
];
309 for (len
= 2, chp
= (u_int8_t
*)&ch
,
310 cnt
= sizeof(CHAR_T
); cnt
-- > 0; ++chp
) {
311 sp
->cname
[len
++] = hexdigit
[(*chp
& 0xf0) >> 4];
312 sp
->cname
[len
++] = hexdigit
[*chp
& 0x0f];
315 done
: sp
->cname
[sp
->clen
= len
] = '\0';
321 * Fill in the value for a key. This routine is the backup
322 * for the KEY_VAL() macro.
324 * PUBLIC: int v_key_val __P((SCR *, ARG_CHAR_T));
334 kp
= bsearch(&k
, keylist
, nkeylist
, sizeof(keylist
[0]), v_key_cmp
);
335 return (kp
== NULL
? K_NOTUSED
: kp
->value
);
340 * Push events/keys onto the front of the buffer.
342 * There is a single input buffer in ex/vi. Characters are put onto the
343 * end of the buffer by the terminal input routines, and pushed onto the
344 * front of the buffer by various other functions in ex/vi. Each key has
345 * an associated flag value, which indicates if it has already been quoted,
346 * and if it is the result of a mapping or an abbreviation.
348 * PUBLIC: int v_event_push __P((SCR *, EVENT *, CHAR_T *, size_t, u_int));
351 v_event_push(sp
, p_evp
, p_s
, nitems
, flags
)
353 EVENT
*p_evp
; /* Push event. */
354 CHAR_T
*p_s
; /* Push characters. */
355 size_t nitems
; /* Number of items to push. */
356 u_int flags
; /* CH_* flags. */
362 /* If we have room, stuff the items into the buffer. */
364 if (nitems
<= gp
->i_next
||
365 (gp
->i_event
!= NULL
&& gp
->i_cnt
== 0 && nitems
<= gp
->i_nelem
)) {
367 gp
->i_next
-= nitems
;
372 * If there are currently items in the queue, shift them up,
373 * leaving some extra room. Get enough space plus a little
376 #define TERM_PUSH_SHIFT 30
377 total
= gp
->i_cnt
+ gp
->i_next
+ nitems
+ TERM_PUSH_SHIFT
;
378 if (total
>= gp
->i_nelem
&& v_event_grow(sp
, MAX(total
, 64)))
381 MEMMOVE(gp
->i_event
+ TERM_PUSH_SHIFT
+ nitems
,
382 gp
->i_event
+ gp
->i_next
, gp
->i_cnt
);
383 gp
->i_next
= TERM_PUSH_SHIFT
;
385 /* Put the new items into the queue. */
386 copy
: gp
->i_cnt
+= nitems
;
387 for (evp
= gp
->i_event
+ gp
->i_next
; nitems
--; ++evp
) {
391 evp
->e_event
= E_CHARACTER
;
393 evp
->e_value
= KEY_VAL(sp
, evp
->e_c
);
394 F_INIT(&evp
->e_ch
, flags
);
402 * Append events onto the tail of the buffer.
405 v_event_append(sp
, argp
)
409 CHAR_T
*s
; /* Characters. */
412 size_t nevents
; /* Number of events. */
414 /* Grow the buffer as necessary. */
415 nevents
= argp
->e_event
== E_STRING
? argp
->e_len
: 1;
417 if (gp
->i_event
== NULL
||
418 nevents
> gp
->i_nelem
- (gp
->i_next
+ gp
->i_cnt
))
419 v_event_grow(sp
, MAX(nevents
, 64));
420 evp
= gp
->i_event
+ gp
->i_next
+ gp
->i_cnt
;
421 gp
->i_cnt
+= nevents
;
423 /* Transform strings of characters into single events. */
424 if (argp
->e_event
== E_STRING
)
425 for (s
= argp
->e_csp
; nevents
--; ++evp
) {
426 evp
->e_event
= E_CHARACTER
;
428 evp
->e_value
= KEY_VAL(sp
, evp
->e_c
);
436 /* Remove events from the queue. */
437 #define QREM(len) { \
438 if ((gp->i_cnt -= len) == 0) \
446 * Return the next event.
449 * The flag EC_NODIGIT probably needs some explanation. First, the idea of
450 * mapping keys is that one or more keystrokes act like a function key.
451 * What's going on is that vi is reading a number, and the character following
452 * the number may or may not be mapped (EC_MAPCOMMAND). For example, if the
453 * user is entering the z command, a valid command is "z40+", and we don't want
454 * to map the '+', i.e. if '+' is mapped to "xxx", we don't want to change it
455 * into "z40xxx". However, if the user enters "35x", we want to put all of the
456 * characters through the mapping code.
458 * Historical practice is a bit muddled here. (Surprise!) It always permitted
459 * mapping digits as long as they weren't the first character of the map, e.g.
460 * ":map ^A1 xxx" was okay. It also permitted the mapping of the digits 1-9
461 * (the digit 0 was a special case as it doesn't indicate the start of a count)
462 * as the first character of the map, but then ignored those mappings. While
463 * it's probably stupid to map digits, vi isn't your mother.
465 * The way this works is that the EC_MAPNODIGIT causes term_key to return the
466 * end-of-digit without "looking" at the next character, i.e. leaving it as the
467 * user entered it. Presumably, the next term_key call will tell us how the
468 * user wants it handled.
470 * There is one more complication. Users might map keys to digits, and, as
471 * it's described above, the commands:
476 * would return the keys "d2<end-of-digits>1G", when the user probably wanted
477 * "d21<end-of-digits>G". So, if a map starts off with a digit we continue as
478 * before, otherwise, we pretend we haven't mapped the character, and return
481 * Now that that's out of the way, let's talk about Energizer Bunny macros.
482 * It's easy to create macros that expand to a loop, e.g. map x 3x. It's
483 * fairly easy to detect this example, because it's all internal to term_key.
484 * If we're expanding a macro and it gets big enough, at some point we can
485 * assume it's looping and kill it. The examples that are tough are the ones
486 * where the parser is involved, e.g. map x "ayyx"byy. We do an expansion
487 * on 'x', and get "ayyx"byy. We then return the first 4 characters, and then
488 * find the looping macro again. There is no way that we can detect this
489 * without doing a full parse of the command, because the character that might
490 * cause the loop (in this case 'x') may be a literal character, e.g. the map
491 * map x "ayy"xyy"byy is perfectly legal and won't cause a loop.
493 * Historic vi tried to detect looping macros by disallowing obvious cases in
494 * the map command, maps that that ended with the same letter as they started
495 * (which wrongly disallowed "map x 'x"), and detecting macros that expanded
496 * too many times before keys were returned to the command parser. It didn't
497 * get many (most?) of the tricky cases right, however, and it was certainly
498 * possible to create macros that ran forever. And, even if it did figure out
499 * what was going on, the user was usually tossed into ex mode. Finally, any
500 * changes made before vi realized that the macro was recursing were left in
501 * place. We recover gracefully, but the only recourse the user has in an
502 * infinite macro loop is to interrupt.
505 * It is historic practice that mapping characters to themselves as the first
506 * part of the mapped string was legal, and did not cause infinite loops, i.e.
507 * ":map! { {^M^T" and ":map n nz." were known to work. The initial, matching
508 * characters were returned instead of being remapped.
511 * It is also historic practice that the macro "map ] ]]^" caused a single ]
512 * keypress to behave as the command ]] (the ^ got the map past the vi check
513 * for "tail recursion"). Conversely, the mapping "map n nn^" went recursive.
514 * What happened was that, in the historic vi, maps were expanded as the keys
515 * were retrieved, but not all at once and not centrally. So, the keypress ]
516 * pushed ]]^ on the stack, and then the first ] from the stack was passed to
517 * the ]] command code. The ]] command then retrieved a key without entering
518 * the mapping code. This could bite us anytime a user has a map that depends
519 * on secondary keys NOT being mapped. I can't see any possible way to make
520 * this work in here without the complete abandonment of Rationality Itself.
523 * The final issue is recovery. It would be possible to undo all of the work
524 * that was done by the macro if we entered a record into the log so that we
525 * knew when the macro started, and, in fact, this might be worth doing at some
526 * point. Given that this might make the log grow unacceptably (consider that
527 * cursor keys are done with maps), for now we leave any changes made in place.
529 * PUBLIC: int v_event_get __P((SCR *, EVENT *, int, u_int32_t));
532 v_event_get(sp
, argp
, timeout
, flags
)
541 int init_nomap
, ispartial
, istimeout
, remap_cnt
;
545 /* If simply checking for interrupts, argp may be NULL. */
549 retry
: istimeout
= remap_cnt
= 0;
552 * If the queue isn't empty and we're timing out for characters,
553 * return immediately.
555 if (gp
->i_cnt
!= 0 && LF_ISSET(EC_TIMEOUT
))
559 * If the queue is empty, we're checking for interrupts, or we're
560 * timing out for characters, get more events.
562 if (gp
->i_cnt
== 0 || LF_ISSET(EC_INTERRUPT
| EC_TIMEOUT
)) {
564 * If we're reading new characters, check any scripting
567 if (F_ISSET(gp
, G_SCRWIN
) && sscr_input(sp
))
569 loop
: if (gp
->scr_event(sp
, argp
,
570 LF_ISSET(EC_INTERRUPT
| EC_QUOTED
| EC_RAW
), timeout
))
572 switch (argp
->e_event
) {
577 * Fatal conditions cause the file to be synced to
580 v_sync(sp
, RCV_ENDSESSION
| RCV_PRESERVE
|
581 (argp
->e_event
== E_SIGTERM
? 0: RCV_EMAIL
));
587 /* Set the global interrupt flag. */
588 F_SET(sp
->gp
, G_INTERRUPTED
);
591 * If the caller was interested in interrupts, return
594 if (LF_ISSET(EC_INTERRUPT
))
598 append
: if (v_event_append(sp
, argp
))
605 * If the caller was only interested in interrupts or timeouts, return
606 * immediately. (We may have gotten characters, and that's okay, they
607 * were queued up for later use.)
609 if (LF_ISSET(EC_INTERRUPT
| EC_TIMEOUT
))
612 newmap
: evp
= &gp
->i_event
[gp
->i_next
];
615 * If the next event in the queue isn't a character event, return
618 if (evp
->e_event
!= E_CHARACTER
) {
625 * If the key isn't mappable because:
627 * + ... the timeout has expired
628 * + ... it's not a mappable key
629 * + ... neither the command or input map flags are set
630 * + ... there are no maps that can apply to it
632 * return it forthwith.
634 if (istimeout
|| F_ISSET(&evp
->e_ch
, CH_NOMAP
) ||
635 !LF_ISSET(EC_MAPCOMMAND
| EC_MAPINPUT
) ||
636 evp
->e_c
< MAX_BIT_SEQ
&& !bit_test(gp
->seqb
, evp
->e_c
))
639 /* Search the map. */
640 qp
= seq_find(sp
, NULL
, evp
, NULL
, gp
->i_cnt
,
641 LF_ISSET(EC_MAPCOMMAND
) ? SEQ_COMMAND
: SEQ_INPUT
, &ispartial
);
644 * If get a partial match, get more characters and retry the map.
645 * If time out without further characters, return the characters
649 * <escape> characters are a problem. Cursor keys start with <escape>
650 * characters, so there's almost always a map in place that begins with
651 * an <escape> character. If we timeout <escape> keys in the same way
652 * that we timeout other keys, the user will get a noticeable pause as
653 * they enter <escape> to terminate input mode. If key timeout is set
654 * for a slow link, users will get an even longer pause. Nvi used to
655 * simply timeout <escape> characters at 1/10th of a second, but this
656 * loses over PPP links where the latency is greater than 100Ms.
659 if (O_ISSET(sp
, O_TIMEOUT
))
660 timeout
= (evp
->e_value
== K_ESCAPE
?
661 O_VAL(sp
, O_ESCAPETIME
) :
662 O_VAL(sp
, O_KEYTIME
)) * 100;
668 /* If no map, return the character. */
670 nomap
: if (!isdigit(evp
->e_c
) && LF_ISSET(EC_MAPNODIGIT
))
678 * If looking for the end of a digit string, and the first character
679 * of the map is it, pretend we haven't seen the character.
681 if (LF_ISSET(EC_MAPNODIGIT
) &&
682 qp
->output
!= NULL
&& !isdigit(qp
->output
[0])) {
683 not_digit
: argp
->e_c
= CH_NOT_DIGIT
;
684 argp
->e_value
= K_NOTUSED
;
685 argp
->e_event
= E_CHARACTER
;
686 F_INIT(&argp
->e_ch
, 0);
690 /* Find out if the initial segments are identical. */
691 init_nomap
= !e_memcmp(qp
->output
, &gp
->i_event
[gp
->i_next
], qp
->ilen
);
693 /* Delete the mapped characters from the queue. */
696 /* If keys mapped to nothing, go get more. */
697 if (qp
->output
== NULL
)
700 /* If remapping characters... */
701 if (O_ISSET(sp
, O_REMAP
)) {
703 * Periodically check for interrupts. Always check the first
704 * time through, because it's possible to set up a map that
705 * will return a character every time, but will expand to more,
706 * e.g. "map! a aaaa" will always return a 'a', but we'll never
707 * get anywhere useful.
709 if ((++remap_cnt
== 1 || remap_cnt
% 10 == 0) &&
710 (gp
->scr_event(sp
, &ev
,
711 EC_INTERRUPT
, 0) || ev
.e_event
== E_INTERRUPT
)) {
712 F_SET(sp
->gp
, G_INTERRUPTED
);
713 argp
->e_event
= E_INTERRUPT
;
718 * If an initial part of the characters mapped, they are not
719 * further remapped -- return the first one. Push the rest
720 * of the characters, or all of the characters if no initial
721 * part mapped, back on the queue.
724 if (v_event_push(sp
, NULL
, qp
->output
+ qp
->ilen
,
725 qp
->olen
- qp
->ilen
, CH_MAPPED
))
727 if (v_event_push(sp
, NULL
,
728 qp
->output
, qp
->ilen
, CH_NOMAP
| CH_MAPPED
))
730 evp
= &gp
->i_event
[gp
->i_next
];
733 if (v_event_push(sp
, NULL
, qp
->output
, qp
->olen
, CH_MAPPED
))
738 /* Else, push the characters on the queue and return one. */
739 if (v_event_push(sp
, NULL
, qp
->output
, qp
->olen
, CH_MAPPED
| CH_NOMAP
))
747 * Walk the screen lists, sync'ing files to their backup copies.
757 for (sp
= gp
->dq
.cqh_first
; sp
!= (void *)&gp
->dq
; sp
= sp
->q
.cqe_next
)
759 for (sp
= gp
->hq
.cqh_first
; sp
!= (void *)&gp
->hq
; sp
= sp
->q
.cqe_next
)
767 * PUBLIC: void v_event_err __P((SCR *, EVENT *));
774 switch (evp
->e_event
) {
776 msgq(sp
, M_ERR
, "276|Unexpected character event");
779 msgq(sp
, M_ERR
, "277|Unexpected end-of-file event");
782 msgq(sp
, M_ERR
, "279|Unexpected interrupt event");
785 msgq(sp
, M_ERR
, "280|Unexpected quit event");
788 msgq(sp
, M_ERR
, "281|Unexpected repaint event");
791 msgq(sp
, M_ERR
, "285|Unexpected string event");
794 msgq(sp
, M_ERR
, "286|Unexpected timeout event");
797 msgq(sp
, M_ERR
, "316|Unexpected resize event");
800 msgq(sp
, M_ERR
, "287|Unexpected write event");
804 * Theoretically, none of these can occur, as they're handled at the
814 /* Free any allocated memory. */
815 if (evp
->e_asp
!= NULL
)
821 * Flush any flagged keys, returning if any keys were flushed.
823 * PUBLIC: int v_event_flush __P((SCR *, u_int));
826 v_event_flush(sp
, flags
)
833 for (rval
= 0, gp
= sp
->gp
; gp
->i_cnt
!= 0 &&
834 F_ISSET(&gp
->i_event
[gp
->i_next
].e_ch
, flags
); rval
= 1)
841 * Grow the terminal queue.
844 v_event_grow(sp
, add
)
849 size_t new_nelem
, olen
;
852 new_nelem
= gp
->i_nelem
+ add
;
853 olen
= gp
->i_nelem
* sizeof(gp
->i_event
[0]);
854 BINC_RET(sp
, gp
->i_event
, olen
, new_nelem
* sizeof(gp
->i_event
[0]));
855 gp
->i_nelem
= olen
/ sizeof(gp
->i_event
[0]);
861 * Compare two keys for sorting.
867 return (((KEYLIST
*)ap
)->ch
- ((KEYLIST
*)bp
)->ch
);