1 /* $NetBSD: options_f.c,v 1.2 2008/10/01 21:20:09 christos Exp $ */
4 * Copyright (c) 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 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";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
34 * PUBLIC: int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
37 f_altwerase(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
40 O_CLR(sp
, O_TTYWERASE
);
45 * PUBLIC: int f_columns __P((SCR *, OPTION *, const char *, u_long *));
48 f_columns(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
50 /* Validate the number. */
51 if (*valp
< MINIMUM_SCREEN_COLS
) {
52 msgq(sp
, M_ERR
, "040|Screen columns too small, less than %d",
59 * It's not uncommon for allocation of huge chunks of memory to cause
60 * core dumps on various systems. So, we prune out numbers that are
61 * "obviously" wrong. Vi will not work correctly if it has the wrong
62 * number of lines/columns for the screen, but at least we don't drop
65 #define MAXIMUM_SCREEN_COLS 4000
66 if (*valp
> MAXIMUM_SCREEN_COLS
) {
67 msgq(sp
, M_ERR
, "041|Screen columns too large, greater than %d",
75 * PUBLIC: int f_lines __P((SCR *, OPTION *, const char *, u_long *));
78 f_lines(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
80 /* Validate the number. */
81 if (*valp
< MINIMUM_SCREEN_ROWS
) {
82 msgq(sp
, M_ERR
, "042|Screen lines too small, less than %d",
89 * It's not uncommon for allocation of huge chunks of memory to cause
90 * core dumps on various systems. So, we prune out numbers that are
91 * "obviously" wrong. Vi will not work correctly if it has the wrong
92 * number of lines/columns for the screen, but at least we don't drop
95 #define MAXIMUM_SCREEN_ROWS 4000
96 if (*valp
> MAXIMUM_SCREEN_ROWS
) {
97 msgq(sp
, M_ERR
, "043|Screen lines too large, greater than %d",
103 * Set the value, and the related scroll value. If no window
104 * value set, set a new default window.
106 o_set(sp
, O_LINES
, 0, NULL
, *valp
);
110 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
111 O_VAL(sp
, O_WINDOW
) > *valp
) {
112 o_set(sp
, O_WINDOW
, 0, NULL
, 1);
113 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, 1);
116 sp
->defscroll
= (*valp
- 1) / 2;
118 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
119 O_VAL(sp
, O_WINDOW
) > *valp
) {
120 o_set(sp
, O_WINDOW
, 0, NULL
, *valp
- 1);
121 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, *valp
- 1);
128 * PUBLIC: int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
131 f_lisp(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
133 msgq(sp
, M_ERR
, "044|The lisp option is not implemented");
138 * PUBLIC: int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
141 f_msgcat(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
143 (void)msg_open(sp
, str
);
148 * PUBLIC: int f_print __P((SCR *, OPTION *, const char *, u_long *));
151 f_print(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
153 int offset
= op
- sp
->opts
;
155 /* Preset the value, needed for reinitialization of lookup table. */
156 if (offset
== O_OCTAL
) {
161 } else if (o_set(sp
, offset
, OS_STRDUP
, str
, 0))
164 /* Reinitialize the key fast lookup table. */
167 /* Reformat the screen. */
168 F_SET(sp
, SC_SCR_REFORMAT
);
173 * PUBLIC: int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
176 f_readonly(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
180 * See the comment in exf.c.
183 F_SET(sp
, SC_READONLY
);
185 F_CLR(sp
, SC_READONLY
);
190 * PUBLIC: int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
193 f_recompile(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
195 if (F_ISSET(sp
, SC_RE_SEARCH
)) {
197 F_CLR(sp
, SC_RE_SEARCH
);
199 if (F_ISSET(sp
, SC_RE_SUBST
)) {
200 regfree(&sp
->subre_c
);
201 F_CLR(sp
, SC_RE_SUBST
);
207 * PUBLIC: int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
210 f_reformat(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
212 F_SET(sp
, SC_SCR_REFORMAT
);
217 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
220 f_ttywerase(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
223 O_CLR(sp
, O_ALTWERASE
);
228 * PUBLIC: int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
231 f_w300(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
235 /* Historical behavior for w300 was < 1200. */
236 if (sp
->gp
->scr_baud(sp
, &v
))
241 return (f_window(sp
, op
, str
, valp
));
245 * PUBLIC: int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
248 f_w1200(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
252 /* Historical behavior for w1200 was == 1200. */
253 if (sp
->gp
->scr_baud(sp
, &v
))
255 if (v
< 1200 || v
> 4800)
258 return (f_window(sp
, op
, str
, valp
));
262 * PUBLIC: int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
265 f_w9600(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
269 /* Historical behavior for w9600 was > 1200. */
270 if (sp
->gp
->scr_baud(sp
, &v
))
275 return (f_window(sp
, op
, str
, valp
));
279 * PUBLIC: int f_window __P((SCR *, OPTION *, const char *, u_long *));
282 f_window(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
284 if (*valp
>= O_VAL(sp
, O_LINES
) - 1 &&
285 (*valp
= O_VAL(sp
, O_LINES
) - 1) == 0)
291 * PUBLIC: int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
294 f_encoding(SCR
*sp
, OPTION
*op
, const char *str
, u_long
*valp
)
296 int offset
= op
- sp
->opts
;
298 return conv_enc(sp
, offset
, str
);