handle input encoding
[nvi.git] / ip / ip_term.c
blob6173f36654f4b09e2ac85981eb6647399b5988ff
1 /*-
2 * Copyright (c) 1996
3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "$Id: ip_term.c,v 8.7 2000/07/11 15:11:00 skimo Exp $ (Berkeley) $Date: 2000/07/11 15:11:00 $";
12 #endif /* not lint */
14 #include <sys/types.h>
15 #include <sys/queue.h>
17 #include <bitstring.h>
18 #include <stdio.h>
19 #include <string.h>
21 #include "../common/common.h"
22 #include "../ipc/ip.h"
23 #include "extern.h"
26 * ip_term_init --
27 * Initialize the terminal special keys.
29 * PUBLIC: int ip_term_init __P((SCR *));
31 int
32 ip_term_init(sp)
33 SCR *sp;
35 SEQ *qp;
38 * Rework any function key mappings that were set before the
39 * screen was initialized.
41 for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next)
42 if (F_ISSET(qp, SEQ_FUNCMAP))
43 (void)ip_fmap(sp, qp->stype,
44 qp->input, qp->ilen, qp->output, qp->olen);
45 return (0);
49 * ip_term_end --
50 * End the special keys defined by the termcap/terminfo entry.
52 * PUBLIC: int ip_term_end __P((GS *));
54 int
55 ip_term_end(gp)
56 GS *gp;
58 SEQ *qp, *nqp;
60 /* Delete screen specific mappings. */
61 for (qp = gp->seqq.lh_first; qp != NULL; qp = nqp) {
62 nqp = qp->q.le_next;
63 if (F_ISSET(qp, SEQ_SCREEN))
64 (void)seq_mdel(qp);
66 return (0);
70 * ip_fmap --
71 * Map a function key.
73 * PUBLIC: int ip_fmap __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t));
75 int
76 ip_fmap(sp, stype, from, flen, to, tlen)
77 SCR *sp;
78 seq_t stype;
79 CHAR_T *from, *to;
80 size_t flen, tlen;
82 /* Bind a function key to a string sequence. */
83 return (1);
87 * ip_optchange --
88 * IP screen specific "option changed" routine.
90 * PUBLIC: int ip_optchange __P((SCR *, int, char *, u_long *));
92 int
93 ip_optchange(sp, offset, str, valp)
94 SCR *sp;
95 int offset;
96 char *str;
97 u_long *valp;
99 IP_BUF ipb;
100 OPTLIST const *opt;
101 IP_PRIVATE *ipp = IPP(sp);
103 switch (offset) {
104 case O_COLUMNS:
105 case O_LINES:
106 F_SET(sp->gp, G_SRESTART);
107 F_CLR(sp, SC_SCR_EX | SC_SCR_VI);
108 break;
109 case O_TERM:
110 /* Called with "ip_curses"; previously wasn't shown
111 * because switching to EX wasn't allowed
112 msgq(sp, M_ERR, "The screen type may not be changed");
114 return (1);
117 opt = optlist + offset;
118 switch (opt->type) {
119 case OPT_0BOOL:
120 case OPT_1BOOL:
121 case OPT_NUM:
122 ipb.val1 = *valp;
123 ipb.len2 = 0;
124 break;
125 case OPT_STR:
126 if (str == NULL) {
127 ipb.str2 = "";
128 ipb.len2 = 1;
129 } else {
130 ipb.str2 = str;
131 ipb.len2 = strlen(str) + 1;
133 break;
136 ipb.code = SI_EDITOPT;
137 ipb.str1 = opt->name;
138 ipb.len1 = strlen(opt->name);
140 (void)vi_send(ipp->o_fd, "ab1", &ipb);
141 return (0);