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.34 04/07/11 16:06:29 zy Exp $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
32 * PUBLIC: int f_altwerase(SCR *, OPTION *, char *, u_long *);
42 O_CLR(sp, O_TTYWERASE);
47 * PUBLIC: int f_columns(SCR *, OPTION *, char *, u_long *);
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(SCR *, OPTION *, char *, u_long *);
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(SCR *, OPTION *, char *, u_long *);
147 msgq(sp, M_ERR, "044|The lisp option is not implemented");
152 * PUBLIC: int f_msgcat(SCR *, OPTION *, char *, u_long *);
161 (void)msg_open(sp, str);
166 * PUBLIC: int f_print(SCR *, OPTION *, char *, u_long *);
175 int offset = op - sp->opts;
177 /* Preset the value, needed for reinitialization of lookup table. */
178 if (offset == O_OCTAL) {
183 } else if (o_set(sp, offset, OS_STRDUP, str, 0))
186 /* Reinitialize the key fast lookup table. */
189 /* Reformat the screen. */
190 F_SET(sp, SC_SCR_REFORMAT);
195 * PUBLIC: int f_readonly(SCR *, OPTION *, char *, u_long *);
206 * See the comment in exf.c.
209 F_SET(sp, SC_READONLY);
211 F_CLR(sp, SC_READONLY);
216 * PUBLIC: int f_recompile(SCR *, OPTION *, char *, u_long *);
225 if (F_ISSET(sp, SC_RE_SEARCH)) {
227 F_CLR(sp, SC_RE_SEARCH);
229 if (F_ISSET(sp, SC_RE_SUBST)) {
230 regfree(&sp->subre_c);
231 F_CLR(sp, SC_RE_SUBST);
237 * PUBLIC: int f_reformat(SCR *, OPTION *, char *, u_long *);
246 F_SET(sp, SC_SCR_REFORMAT);
251 * PUBLIC: int f_ttywerase(SCR *, OPTION *, char *, u_long *);
261 O_CLR(sp, O_ALTWERASE);
266 * PUBLIC: int f_w300(SCR *, OPTION *, char *, u_long *);
277 /* Historical behavior for w300 was < 1200. */
278 if (sp->gp->scr_baud(sp, &v))
283 return (f_window(sp, op, str, valp));
287 * PUBLIC: int f_w1200(SCR *, OPTION *, char *, u_long *);
298 /* Historical behavior for w1200 was == 1200. */
299 if (sp->gp->scr_baud(sp, &v))
301 if (v < 1200 || v > 4800)
304 return (f_window(sp, op, str, valp));
308 * PUBLIC: int f_w9600(SCR *, OPTION *, char *, u_long *);
319 /* Historical behavior for w9600 was > 1200. */
320 if (sp->gp->scr_baud(sp, &v))
325 return (f_window(sp, op, str, valp));
329 * PUBLIC: int f_window(SCR *, OPTION *, char *, u_long *);
338 if (*valp >= O_VAL(sp, O_LINES) - 1 &&
339 (*valp = O_VAL(sp, O_LINES) - 1) == 0)
345 * PUBLIC: int f_encoding(SCR *, OPTION *, char *, u_long *);
354 int offset = op - sp->opts;
356 return conv_enc(sp, offset, str);