1 /* $NetBSD: options_f.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 static const char sccsid
[] = "Id: options_f.c,v 10.33 2001/06/25 15:19:11 skimo Exp (Berkeley) Date: 2001/06/25 15:19:11 ";
19 __RCSID("$NetBSD: options_f.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
38 * PUBLIC: int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
41 f_altwerase(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
44 O_CLR(sp
, O_TTYWERASE
);
49 * PUBLIC: int f_columns __P((SCR *, OPTION *, const char *, u_long *));
52 f_columns(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
54 /* Validate the number. */
55 if (*valp
< MINIMUM_SCREEN_COLS
) {
56 msgq(sp
, M_ERR
, "040|Screen columns too small, less than %d",
63 * It's not uncommon for allocation of huge chunks of memory to cause
64 * core dumps on various systems. So, we prune out numbers that are
65 * "obviously" wrong. Vi will not work correctly if it has the wrong
66 * number of lines/columns for the screen, but at least we don't drop
69 #define MAXIMUM_SCREEN_COLS 4000
70 if (*valp
> MAXIMUM_SCREEN_COLS
) {
71 msgq(sp
, M_ERR
, "041|Screen columns too large, greater than %d",
79 * PUBLIC: int f_lines __P((SCR *, OPTION *, const char *, u_long *));
82 f_lines(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
84 /* Validate the number. */
85 if (*valp
< MINIMUM_SCREEN_ROWS
) {
86 msgq(sp
, M_ERR
, "042|Screen lines too small, less than %d",
93 * It's not uncommon for allocation of huge chunks of memory to cause
94 * core dumps on various systems. So, we prune out numbers that are
95 * "obviously" wrong. Vi will not work correctly if it has the wrong
96 * number of lines/columns for the screen, but at least we don't drop
99 #define MAXIMUM_SCREEN_ROWS 4000
100 if (*valp
> MAXIMUM_SCREEN_ROWS
) {
101 msgq(sp
, M_ERR
, "043|Screen lines too large, greater than %d",
102 MAXIMUM_SCREEN_ROWS
);
107 * Set the value, and the related scroll value. If no window
108 * value set, set a new default window.
110 o_set(sp
, O_LINES
, 0, NULL
, *valp
);
114 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
115 O_VAL(sp
, O_WINDOW
) > *valp
) {
116 o_set(sp
, O_WINDOW
, 0, NULL
, 1);
117 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, 1);
120 sp
->defscroll
= (*valp
- 1) / 2;
122 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
123 O_VAL(sp
, O_WINDOW
) > *valp
) {
124 o_set(sp
, O_WINDOW
, 0, NULL
, *valp
- 1);
125 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, *valp
- 1);
132 * PUBLIC: int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
135 f_lisp(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
137 msgq(sp
, M_ERR
, "044|The lisp option is not implemented");
142 * PUBLIC: int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
145 f_msgcat(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
147 (void)msg_open(sp
, str
);
152 * PUBLIC: int f_print __P((SCR *, OPTION *, const char *, u_long *));
155 f_print(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
157 int offset
= op
- sp
->opts
;
159 /* Preset the value, needed for reinitialization of lookup table. */
160 if (offset
== O_OCTAL
) {
165 } else if (o_set(sp
, offset
, OS_STRDUP
, str
, 0))
168 /* Reinitialize the key fast lookup table. */
171 /* Reformat the screen. */
172 F_SET(sp
, SC_SCR_REFORMAT
);
177 * PUBLIC: int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
180 f_readonly(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
184 * See the comment in exf.c.
187 F_SET(sp
, SC_READONLY
);
189 F_CLR(sp
, SC_READONLY
);
194 * PUBLIC: int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
197 f_recompile(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
199 if (F_ISSET(sp
, SC_RE_SEARCH
)) {
201 F_CLR(sp
, SC_RE_SEARCH
);
203 if (F_ISSET(sp
, SC_RE_SUBST
)) {
204 regfree(&sp
->subre_c
);
205 F_CLR(sp
, SC_RE_SUBST
);
211 * PUBLIC: int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
214 f_reformat(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
216 F_SET(sp
, SC_SCR_REFORMAT
);
221 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
224 f_ttywerase(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
227 O_CLR(sp
, O_ALTWERASE
);
232 * PUBLIC: int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
235 f_w300(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
239 /* Historical behavior for w300 was < 1200. */
240 if (sp
->gp
->scr_baud(sp
, &v
))
245 return (f_window(sp
, op
, str
, valp
));
249 * PUBLIC: int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
252 f_w1200(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
256 /* Historical behavior for w1200 was == 1200. */
257 if (sp
->gp
->scr_baud(sp
, &v
))
259 if (v
< 1200 || v
> 4800)
262 return (f_window(sp
, op
, str
, valp
));
266 * PUBLIC: int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
269 f_w9600(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
273 /* Historical behavior for w9600 was > 1200. */
274 if (sp
->gp
->scr_baud(sp
, &v
))
279 return (f_window(sp
, op
, str
, valp
));
283 * PUBLIC: int f_window __P((SCR *, OPTION *, const char *, u_long *));
286 f_window(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
288 if (*valp
>= O_VAL(sp
, O_LINES
) - 1 &&
289 (*valp
= O_VAL(sp
, O_LINES
) - 1) == 0)
295 * PUBLIC: int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
298 f_encoding(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
300 int offset
= op
- sp
->opts
;
302 return conv_enc(sp
, offset
, str
);