add db.1.85
[nvi.git] / ex / ex_map.c
blob626372e20c3879a854236130f5af14d53f437060
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 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 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <ctype.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include "../common/common.h"
29 * ex_map -- :map[!] [input] [replacement]
30 * Map a key/string or display mapped keys.
32 * Historical note:
33 * Historic vi maps were fairly bizarre, and likely to differ in
34 * very subtle and strange ways from this implementation. Two
35 * things worth noting are that vi would often hang or drop core
36 * if the map was strange enough (ex: map X "xy$@x^V), or, simply
37 * not work. One trick worth remembering is that if you put a
38 * mark at the start of the map, e.g. map X mx"xy ...), or if you
39 * put the map in a .exrc file, things would often work much better.
40 * No clue why.
42 * PUBLIC: int ex_map __P((SCR *, EXCMD *));
44 int
45 ex_map(SCR *sp, EXCMD *cmdp)
47 seq_t stype;
48 CHAR_T *input, *p;
50 stype = FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND;
52 switch (cmdp->argc) {
53 case 0:
54 if (seq_dump(sp, stype, 1) == 0)
55 msgq(sp, M_INFO, stype == SEQ_INPUT ?
56 "132|No input map entries" :
57 "133|No command map entries");
58 return (0);
59 case 2:
60 input = cmdp->argv[0]->bp;
61 break;
62 default:
63 abort();
67 * If the mapped string is #[0-9]* (and wasn't quoted) then store the
68 * function key mapping. If the screen specific routine has been set,
69 * call it as well. Note, the SEQ_FUNCMAP type is persistent across
70 * screen types, maybe the next screen type will get it right.
72 if (input[0] == '#' && isdigit(input[1])) {
73 for (p = input + 2; isdigit(*p); ++p);
74 if (p[0] != '\0')
75 goto nofunc;
77 if (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
78 cmdp->argv[1]->bp, cmdp->argv[1]->len, stype,
79 SEQ_FUNCMAP | SEQ_USERDEF))
80 return (1);
81 return (sp->gp->scr_fmap == NULL ? 0 :
82 sp->gp->scr_fmap(sp, stype, input, cmdp->argv[0]->len,
83 cmdp->argv[1]->bp, cmdp->argv[1]->len));
86 /* Some single keys may not be remapped in command mode. */
87 nofunc: if (stype == SEQ_COMMAND && input[1] == '\0')
88 switch (KEY_VAL(sp, input[0])) {
89 case K_COLON:
90 case K_ESCAPE:
91 case K_NL:
92 msgq(sp, M_ERR,
93 "134|The %s character may not be remapped",
94 KEY_NAME(sp, input[0]));
95 return (1);
97 return (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
98 cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_USERDEF));
102 * ex_unmap -- (:unmap[!] key)
103 * Unmap a key.
105 * PUBLIC: int ex_unmap __P((SCR *, EXCMD *));
108 ex_unmap(SCR *sp, EXCMD *cmdp)
110 if (seq_delete(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len,
111 FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) {
112 msgq_wstr(sp, M_INFO,
113 cmdp->argv[0]->bp, "135|\"%s\" isn't currently mapped");
114 return (1);
116 return (0);