1 /* $NetBSD: ex_map.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 static const char sccsid
[] = "Id: ex_map.c,v 10.11 2001/06/25 15:19:17 skimo Exp (Berkeley) Date: 2001/06/25 15:19:17 ";
19 __RCSID("$NetBSD: ex_map.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
25 #include <bitstring.h>
32 #include "../common/common.h"
35 * ex_map -- :map[!] [input] [replacement]
36 * Map a key/string or display mapped keys.
39 * Historic vi maps were fairly bizarre, and likely to differ in
40 * very subtle and strange ways from this implementation. Two
41 * things worth noting are that vi would often hang or drop core
42 * if the map was strange enough (ex: map X "xy$@x^V), or, simply
43 * not work. One trick worth remembering is that if you put a
44 * mark at the start of the map, e.g. map X mx"xy ...), or if you
45 * put the map in a .exrc file, things would often work much better.
48 * PUBLIC: int ex_map __P((SCR *, EXCMD *));
51 ex_map(SCR
*sp
, EXCMD
*cmdp
)
56 stype
= FL_ISSET(cmdp
->iflags
, E_C_FORCE
) ? SEQ_INPUT
: SEQ_COMMAND
;
60 if (seq_dump(sp
, stype
, 1) == 0)
61 msgq(sp
, M_INFO
, stype
== SEQ_INPUT
?
62 "132|No input map entries" :
63 "133|No command map entries");
66 input
= cmdp
->argv
[0]->bp
;
73 * If the mapped string is #[0-9]* (and wasn't quoted) then store the
74 * function key mapping. If the screen specific routine has been set,
75 * call it as well. Note, the SEQ_FUNCMAP type is persistent across
76 * screen types, maybe the next screen type will get it right.
78 if (input
[0] == '#' && ISDIGIT((UCHAR_T
)input
[1])) {
79 for (p
= input
+ 2; ISDIGIT((UCHAR_T
)*p
); ++p
);
83 if (seq_set(sp
, NULL
, 0, input
, cmdp
->argv
[0]->len
,
84 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
, stype
,
85 SEQ_FUNCMAP
| SEQ_USERDEF
))
87 return (sp
->gp
->scr_fmap
== NULL
? 0 :
88 sp
->gp
->scr_fmap(sp
, stype
, input
, cmdp
->argv
[0]->len
,
89 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
));
92 /* Some single keys may not be remapped in command mode. */
93 nofunc
: if (stype
== SEQ_COMMAND
&& input
[1] == '\0')
94 switch (KEY_VAL(sp
, input
[0])) {
99 "134|The %s character may not be remapped",
100 KEY_NAME(sp
, input
[0]));
103 return (seq_set(sp
, NULL
, 0, input
, cmdp
->argv
[0]->len
,
104 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
, stype
, SEQ_USERDEF
));
108 * ex_unmap -- (:unmap[!] key)
111 * PUBLIC: int ex_unmap __P((SCR *, EXCMD *));
114 ex_unmap(SCR
*sp
, EXCMD
*cmdp
)
116 if (seq_delete(sp
, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
,
117 FL_ISSET(cmdp
->iflags
, E_C_FORCE
) ? SEQ_INPUT
: SEQ_COMMAND
)) {
118 msgq_wstr(sp
, M_INFO
,
119 cmdp
->argv
[0]->bp
, "135|\"%s\" isn't currently mapped");