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.31 2000/10/31 12:41:14 skimo Exp $ (Berkeley) $Date: 2000/10/31 12:41:14 $";
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(sp
, op
, str
, valp
)
42 O_CLR(sp
, O_TTYWERASE
);
47 * PUBLIC: int f_columns __P((SCR *, OPTION *, char *, u_long *));
50 f_columns(sp
, op
, str
, valp
)
56 /* Validate the number. */
57 if (*valp
< MINIMUM_SCREEN_COLS
) {
58 msgq(sp
, M_ERR
, "040|Screen columns too small, less than %d",
65 * It's not uncommon for allocation of huge chunks of memory to cause
66 * core dumps on various systems. So, we prune out numbers that are
67 * "obviously" wrong. Vi will not work correctly if it has the wrong
68 * number of lines/columns for the screen, but at least we don't drop
71 #define MAXIMUM_SCREEN_COLS 500
72 if (*valp
> MAXIMUM_SCREEN_COLS
) {
73 msgq(sp
, M_ERR
, "041|Screen columns too large, greater than %d",
81 * PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *));
84 f_lines(sp
, op
, str
, valp
)
90 /* Validate the number. */
91 if (*valp
< MINIMUM_SCREEN_ROWS
) {
92 msgq(sp
, M_ERR
, "042|Screen lines too small, less than %d",
99 * It's not uncommon for allocation of huge chunks of memory to cause
100 * core dumps on various systems. So, we prune out numbers that are
101 * "obviously" wrong. Vi will not work correctly if it has the wrong
102 * number of lines/columns for the screen, but at least we don't drop
105 #define MAXIMUM_SCREEN_ROWS 500
106 if (*valp
> MAXIMUM_SCREEN_ROWS
) {
107 msgq(sp
, M_ERR
, "043|Screen lines too large, greater than %d",
108 MAXIMUM_SCREEN_ROWS
);
113 * Set the value, and the related scroll value. If no window
114 * value set, set a new default window.
116 o_set(sp
, O_LINES
, 0, NULL
, *valp
);
120 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
121 O_VAL(sp
, O_WINDOW
) > *valp
) {
122 o_set(sp
, O_WINDOW
, 0, NULL
, 1);
123 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, 1);
126 sp
->defscroll
= (*valp
- 1) / 2;
128 if (O_VAL(sp
, O_WINDOW
) == O_D_VAL(sp
, O_WINDOW
) ||
129 O_VAL(sp
, O_WINDOW
) > *valp
) {
130 o_set(sp
, O_WINDOW
, 0, NULL
, *valp
- 1);
131 o_set(sp
, O_WINDOW
, OS_DEF
, NULL
, *valp
- 1);
138 * PUBLIC: int f_lisp __P((SCR *, OPTION *, char *, u_long *));
141 f_lisp(sp
, op
, str
, valp
)
147 msgq(sp
, M_ERR
, "044|The lisp option is not implemented");
152 * PUBLIC: int f_msgcat __P((SCR *, OPTION *, char *, u_long *));
155 f_msgcat(sp
, op
, str
, valp
)
161 (void)msg_open(sp
, str
);
166 * PUBLIC: int f_paragraph __P((SCR *, OPTION *, char *, u_long *));
169 f_paragraph(sp
, op
, str
, valp
)
175 if (strlen(str
) & 1) {
177 "048|The paragraph option must be in two character groups");
184 * PUBLIC: int f_print __P((SCR *, OPTION *, char *, u_long *));
187 f_print(sp
, op
, str
, valp
)
193 int offset
= op
- sp
->opts
;
195 /* Preset the value, needed for reinitialization of lookup table. */
196 if (offset
== O_OCTAL
) {
201 } else if (o_set(sp
, offset
, OS_STRDUP
, str
, 0))
204 /* Reinitialize the key fast lookup table. */
207 /* Reformat the screen. */
208 F_SET(sp
, SC_SCR_REFORMAT
);
213 * PUBLIC: int f_readonly __P((SCR *, OPTION *, char *, u_long *));
216 f_readonly(sp
, op
, str
, valp
)
224 * See the comment in exf.c.
227 F_SET(sp
, SC_READONLY
);
229 F_CLR(sp
, SC_READONLY
);
234 * PUBLIC: int f_recompile __P((SCR *, OPTION *, char *, u_long *));
237 f_recompile(sp
, op
, str
, valp
)
243 if (F_ISSET(sp
, SC_RE_SEARCH
)) {
245 F_CLR(sp
, SC_RE_SEARCH
);
247 if (F_ISSET(sp
, SC_RE_SUBST
)) {
248 regfree(&sp
->subre_c
);
249 F_CLR(sp
, SC_RE_SUBST
);
255 * PUBLIC: int f_reformat __P((SCR *, OPTION *, char *, u_long *));
258 f_reformat(sp
, op
, str
, valp
)
264 F_SET(sp
, SC_SCR_REFORMAT
);
269 * PUBLIC: int f_section __P((SCR *, OPTION *, char *, u_long *));
272 f_section(sp
, op
, str
, valp
)
278 if (strlen(str
) & 1) {
280 "049|The section option must be in two character groups");
287 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, char *, u_long *));
290 f_ttywerase(sp
, op
, str
, valp
)
297 O_CLR(sp
, O_ALTWERASE
);
302 * PUBLIC: int f_w300 __P((SCR *, OPTION *, char *, u_long *));
305 f_w300(sp
, op
, str
, valp
)
313 /* Historical behavior for w300 was < 1200. */
314 if (sp
->gp
->scr_baud(sp
, &v
))
319 return (f_window(sp
, op
, str
, valp
));
323 * PUBLIC: int f_w1200 __P((SCR *, OPTION *, char *, u_long *));
326 f_w1200(sp
, op
, str
, valp
)
334 /* Historical behavior for w1200 was == 1200. */
335 if (sp
->gp
->scr_baud(sp
, &v
))
337 if (v
< 1200 || v
> 4800)
340 return (f_window(sp
, op
, str
, valp
));
344 * PUBLIC: int f_w9600 __P((SCR *, OPTION *, char *, u_long *));
347 f_w9600(sp
, op
, str
, valp
)
355 /* Historical behavior for w9600 was > 1200. */
356 if (sp
->gp
->scr_baud(sp
, &v
))
361 return (f_window(sp
, op
, str
, valp
));
365 * PUBLIC: int f_window __P((SCR *, OPTION *, char *, u_long *));
368 f_window(sp
, op
, str
, valp
)
374 if (*valp
>= O_VAL(sp
, O_LINES
) - 1 &&
375 (*valp
= O_VAL(sp
, O_LINES
) - 1) == 0)
381 * PUBLIC: int f_fileencoding __P((SCR *, OPTION *, char *, u_long *));
384 f_fileencoding(sp
, op
, str
, valp
)
390 return conv_enc(sp
, str
);