move a bit of code
[nvi.git] / ip / ip_term.c
blobf2c34343563626afe6044108ebc4003d851ae8af
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.6 2000/06/28 20:20:37 skimo Exp $ (Berkeley) $Date: 2000/06/28 20:20:37 $";
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 msgq(sp, M_ERR, "The screen type may not be changed");
111 return (1);
114 opt = optlist + offset;
115 switch (opt->type) {
116 case OPT_0BOOL:
117 case OPT_1BOOL:
118 case OPT_NUM:
119 ipb.val1 = *valp;
120 ipb.len2 = 0;
121 break;
122 case OPT_STR:
123 if (str == NULL) {
124 ipb.str2 = "";
125 ipb.len2 = 1;
126 } else {
127 ipb.str2 = str;
128 ipb.len2 = strlen(str) + 1;
130 break;
133 ipb.code = SI_EDITOPT;
134 ipb.str1 = opt->name;
135 ipb.len1 = strlen(opt->name);
137 (void)vi_send(ipp->o_fd, "ab1", &ipb);
138 return (0);