Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / ex / ex_map.c
blob106b2a8859f65a9f029be347327bc5c94c717c12
1 /* $NetBSD: ex_map.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
2 /*-
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.
9 */
11 #include "config.h"
13 #include <sys/cdefs.h>
14 #if 0
15 #ifndef lint
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 ";
17 #endif /* not lint */
18 #else
19 __RCSID("$NetBSD: ex_map.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #endif
22 #include <sys/types.h>
23 #include <sys/queue.h>
25 #include <bitstring.h>
26 #include <ctype.h>
27 #include <limits.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include "../common/common.h"
35 * ex_map -- :map[!] [input] [replacement]
36 * Map a key/string or display mapped keys.
38 * Historical note:
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.
46 * No clue why.
48 * PUBLIC: int ex_map __P((SCR *, EXCMD *));
50 int
51 ex_map(SCR *sp, EXCMD *cmdp)
53 seq_t stype;
54 CHAR_T *input, *p;
56 stype = FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND;
58 switch (cmdp->argc) {
59 case 0:
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");
64 return (0);
65 case 2:
66 input = cmdp->argv[0]->bp;
67 break;
68 default:
69 abort();
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);
80 if (p[0] != '\0')
81 goto nofunc;
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))
86 return (1);
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])) {
95 case K_COLON:
96 case K_ESCAPE:
97 case K_NL:
98 msgq(sp, M_ERR,
99 "134|The %s character may not be remapped",
100 KEY_NAME(sp, input[0]));
101 return (1);
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)
109 * Unmap a 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");
120 return (1);
122 return (0);