1/*	$NetBSD$ */
2
3/*-
4 * Copyright (c) 1996
5 *	Keith Bostic.  All rights reserved.
6 *
7 * See the LICENSE file for redistribution information.
8 */
9
10#include "config.h"
11
12#ifndef lint
13static const char sccsid[] = "Id: ip_term.c,v 8.9 2001/06/25 15:19:24 skimo Exp (Berkeley) Date: 2001/06/25 15:19:24";
14#endif /* not lint */
15
16#include <sys/types.h>
17#include <sys/queue.h>
18
19#include <bitstring.h>
20#include <stdio.h>
21#include <string.h>
22
23#include "../common/common.h"
24#include "../ipc/ip.h"
25#include "extern.h"
26
27/*
28 * ip_term_init --
29 *	Initialize the terminal special keys.
30 *
31 * PUBLIC: int ip_term_init __P((SCR *));
32 */
33int
34ip_term_init(SCR *sp)
35{
36	SEQ *qp;
37
38	/*
39	 * Rework any function key mappings that were set before the
40	 * screen was initialized.
41	 */
42	for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next)
43		if (F_ISSET(qp, SEQ_FUNCMAP))
44			(void)ip_fmap(sp, qp->stype,
45			    qp->input, qp->ilen, qp->output, qp->olen);
46	return (0);
47}
48
49/*
50 * ip_term_end --
51 *	End the special keys defined by the termcap/terminfo entry.
52 *
53 * PUBLIC: int ip_term_end __P((GS *));
54 */
55int
56ip_term_end(GS *gp)
57{
58	SEQ *qp, *nqp;
59
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);
65	}
66	return (0);
67}
68
69/*
70 * ip_fmap --
71 *	Map a function key.
72 *
73 * PUBLIC: int ip_fmap __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t));
74 */
75int
76ip_fmap(SCR *sp, seq_t stype, CHAR_T *from, size_t flen, CHAR_T *to, size_t tlen)
77{
78	/* Bind a function key to a string sequence. */
79	return (1);
80}
81
82/*
83 * ip_optchange --
84 *	IP screen specific "option changed" routine.
85 *
86 * PUBLIC: int ip_optchange __P((SCR *, int, char *, u_long *));
87 */
88int
89ip_optchange(SCR *sp, int offset, char *str, u_long *valp)
90{
91	IP_BUF ipb;
92	OPTLIST const *opt;
93	IP_PRIVATE *ipp = IPP(sp);
94	char *np;
95	size_t nlen;
96
97	switch (offset) {
98	case O_COLUMNS:
99	case O_LINES:
100		F_SET(sp->gp, G_SRESTART);
101		F_CLR(sp, SC_SCR_EX | SC_SCR_VI);
102		break;
103	case O_TERM:
104		/* Called with "ip_curses"; previously wasn't shown
105		 * because switching to EX wasn't allowed
106		msgq(sp, M_ERR, "The screen type may not be changed");
107		*/
108		return (1);
109	}
110
111	opt = optlist + offset;
112	switch (opt->type) {
113	case OPT_0BOOL:
114	case OPT_1BOOL:
115	case OPT_NUM:
116		ipb.val1 = *valp;
117		ipb.len2 = 0;
118		break;
119	case OPT_STR:
120		if (str == NULL) {
121			ipb.str2 = "";
122			ipb.len2 = 1;
123		} else {
124			ipb.str2 = str;
125			ipb.len2 = strlen(str) + 1;
126		}
127		break;
128	}
129
130	ipb.code = SI_EDITOPT;
131	ipb.str1 = (char*)opt->name;
132	ipb.len1 = STRLEN(opt->name) * sizeof(CHAR_T);
133
134	(void)vi_send(ipp->o_fd, "ab1", &ipb);
135	return (0);
136}
137