2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 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 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
32 * PUBLIC: int f_altwerase __P((SCR *, OPTION *, char *, u_long *));
35 f_altwerase(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
38 O_CLR(sp
, O_TTYWERASE
);
43 * PUBLIC: int f_columns __P((SCR *, OPTION *, char *, u_long *));
46 f_columns(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
48 /* Validate the number. */
49 if (*valp
< MINIMUM_SCREEN_COLS
) {
50 msgq(sp
, M_ERR
, "040|Screen columns too small, less than %d",
57 * It's not uncommon for allocation of huge chunks of memory to cause
58 * core dumps on various systems. So, we prune out numbers that are
59 * "obviously" wrong. Vi will not work correctly if it has the wrong
60 * number of lines/columns for the screen, but at least we don't drop
63 #define MAXIMUM_SCREEN_COLS 500
64 if (*valp
> MAXIMUM_SCREEN_COLS
) {
65 msgq(sp
, M_ERR
, "041|Screen columns too large, greater than %d",
73 * PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *));
76 f_lines(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
78 /* Validate the number. */
79 if (*valp
< MINIMUM_SCREEN_ROWS
) {
80 msgq(sp
, M_ERR
, "042|Screen lines too small, less than %d",
87 * It's not uncommon for allocation of huge chunks of memory to cause
88 * core dumps on various systems. So, we prune out numbers that are
89 * "obviously" wrong. Vi will not work correctly if it has the wrong
90 * number of lines/columns for the screen, but at least we don't drop
93 #define MAXIMUM_SCREEN_ROWS 500
94 if (*valp
> MAXIMUM_SCREEN_ROWS
) {
95 msgq(sp
, M_ERR
, "043|Screen lines too large, greater than %d",
101 * Set the value, and the related scroll value. If no window
102 * value set, set a new default window.
104 o_set(sp
, O_LINES
, 0, NULL
, *valp
);
108 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
109 O_VAL(sp
, O_WINDOW
) > *valp
) {
110 o_set(sp
, O_WINDOW
, 0, NULL
, 1);
111 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, 1);
114 sp
->defscroll
= (*valp
- 1) / 2;
116 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
117 O_VAL(sp
, O_WINDOW
) > *valp
) {
118 o_set(sp
, O_WINDOW
, 0, NULL
, *valp
- 1);
119 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, *valp
- 1);
126 * PUBLIC: int f_lisp __P((SCR *, OPTION *, char *, u_long *));
129 f_lisp(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
131 msgq(sp
, M_ERR
, "044|The lisp option is not implemented");
136 * PUBLIC: int f_msgcat __P((SCR *, OPTION *, char *, u_long *));
139 f_msgcat(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
141 (void)msg_open(sp
, str
);
146 * PUBLIC: int f_paragraph __P((SCR *, OPTION *, char *, u_long *));
149 f_paragraph(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
151 if (strlen(str
) & 1) {
153 "048|The paragraph option must be in two character groups");
160 * PUBLIC: int f_print __P((SCR *, OPTION *, char *, u_long *));
163 f_print(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
165 int offset
= op
- sp
->opts
;
167 /* Preset the value, needed for reinitialization of lookup table. */
168 if (offset
== O_OCTAL
) {
173 } else if (o_set(sp
, offset
, OS_STRDUP
, str
, 0))
176 /* Reinitialize the key fast lookup table. */
179 /* Reformat the screen. */
180 F_SET(sp
, SC_SCR_REFORMAT
);
185 * PUBLIC: int f_readonly __P((SCR *, OPTION *, char *, u_long *));
188 f_readonly(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
192 * See the comment in exf.c.
195 F_SET(sp
, SC_READONLY
);
197 F_CLR(sp
, SC_READONLY
);
202 * PUBLIC: int f_recompile __P((SCR *, OPTION *, char *, u_long *));
205 f_recompile(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
207 if (F_ISSET(sp
, SC_RE_SEARCH
)) {
209 F_CLR(sp
, SC_RE_SEARCH
);
211 if (F_ISSET(sp
, SC_RE_SUBST
)) {
212 regfree(&sp
->subre_c
);
213 F_CLR(sp
, SC_RE_SUBST
);
219 * PUBLIC: int f_reformat __P((SCR *, OPTION *, char *, u_long *));
222 f_reformat(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
224 F_SET(sp
, SC_SCR_REFORMAT
);
229 * PUBLIC: int f_section __P((SCR *, OPTION *, char *, u_long *));
232 f_section(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
234 if (strlen(str
) & 1) {
236 "049|The section option must be in two character groups");
243 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, char *, u_long *));
246 f_ttywerase(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
249 O_CLR(sp
, O_ALTWERASE
);
254 * PUBLIC: int f_w300 __P((SCR *, OPTION *, char *, u_long *));
257 f_w300(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
261 /* Historical behavior for w300 was < 1200. */
262 if (sp
->gp
->scr_baud(sp
, &v
))
267 return (f_window(sp
, op
, str
, valp
));
271 * PUBLIC: int f_w1200 __P((SCR *, OPTION *, char *, u_long *));
274 f_w1200(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
278 /* Historical behavior for w1200 was == 1200. */
279 if (sp
->gp
->scr_baud(sp
, &v
))
281 if (v
< 1200 || v
> 4800)
284 return (f_window(sp
, op
, str
, valp
));
288 * PUBLIC: int f_w9600 __P((SCR *, OPTION *, char *, u_long *));
291 f_w9600(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
295 /* Historical behavior for w9600 was > 1200. */
296 if (sp
->gp
->scr_baud(sp
, &v
))
301 return (f_window(sp
, op
, str
, valp
));
305 * PUBLIC: int f_window __P((SCR *, OPTION *, char *, u_long *));
308 f_window(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
310 if (*valp
>= O_VAL(sp
, O_LINES
) - 1 &&
311 (*valp
= O_VAL(sp
, O_LINES
) - 1) == 0)
317 * PUBLIC: int f_encoding __P((SCR *, OPTION *, char *, u_long *));
320 f_encoding(SCR
*sp
, OPTION
*op
, char *str
, u_long
*valp
)
322 int offset
= op
- sp
->opts
;
324 return conv_enc(sp
, offset
, str
);