3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: options_f.c,v 8.23 1993/11/22 14:46:40 bostic Exp $ (Berkeley) $Date: 1993/11/22 14:46:40 $";
12 #include <sys/types.h>
24 static int opt_putenv
__P((char *));
41 O_CLR(sp
, O_ALTWERASE
);
43 O_SET(sp
, O_ALTWERASE
);
44 O_CLR(sp
, O_TTYWERASE
);
52 O_CLR(sp
, O_TTYWERASE
);
54 O_SET(sp
, O_TTYWERASE
);
55 O_CLR(sp
, O_ALTWERASE
);
64 /* Validate the number. */
65 if (val
< MINIMUM_SCREEN_COLS
) {
66 msgq(sp
, M_ERR
, "Screen columns too small, less than %d.",
70 if (val
< O_VAL(sp
, O_SHIFTWIDTH
)) {
72 "Screen columns too small, less than shiftwidth.");
75 if (val
< O_VAL(sp
, O_SIDESCROLL
)) {
77 "Screen columns too small, less than sidescroll.");
80 if (val
< O_VAL(sp
, O_TABSTOP
)) {
82 "Screen columns too small, less than tabstop.");
85 if (val
< O_VAL(sp
, O_WRAPMARGIN
)) {
87 "Screen columns too small, less than wrapmargin.");
92 * This has to be checked by reaching down into the screen code.
94 if (val
< O_NUMBER_LENGTH
) {
96 "Screen columns too small, less than number option.");
100 /* Set the columns value in the environment for curses. */
101 (void)snprintf(buf
, sizeof(buf
), "COLUMNS=%lu", val
);
105 /* This is expensive, don't do it unless it's necessary. */
106 if (O_VAL(sp
, O_COLUMNS
) == val
)
110 O_VAL(sp
, O_COLUMNS
) = val
;
118 O_VAL(sp
, O_KEYTIME
) = val
;
125 O_CLR(sp
, O_LEFTRIGHT
);
127 O_SET(sp
, O_LEFTRIGHT
);
128 F_SET(sp
, S_REFORMAT
| S_REDRAW
);
136 /* Validate the number. */
137 if (val
< MINIMUM_SCREEN_ROWS
) {
138 msgq(sp
, M_ERR
, "Screen lines too small, less than %d.",
139 MINIMUM_SCREEN_ROWS
);
143 /* Set the rows value in the environment for curses. */
144 (void)snprintf(buf
, sizeof(buf
), "ROWS=%lu", val
);
148 /* This is expensive, don't do it unless it's necessary. */
149 if (O_VAL(sp
, O_LINES
) == val
)
153 O_VAL(sp
, O_LINES
) = val
;
156 * If no window value set, set a new default window and,
157 * optionally, a new scroll value.
159 if (!F_ISSET(&sp
->opts
[O_WINDOW
], OPT_SET
)) {
160 O_VAL(sp
, O_WINDOW
) = val
- 1;
161 if (!F_ISSET(&sp
->opts
[O_SCROLL
], OPT_SET
))
162 O_VAL(sp
, O_SCROLL
) = val
/ 2;
171 msgq(sp
, M_ERR
, "The lisp option is not implemented.");
182 F_SET(sp
, S_REFORMAT
| S_REDRAW
);
188 O_VAL(sp
, O_MATCHTIME
) = val
;
198 if ((tty
= ttyname(STDERR_FILENO
)) == NULL
) {
199 msgq(sp
, M_ERR
, "ttyname: %s.", strerror(errno
));
203 /* Save the tty mode for later; only save it once. */
204 if (!F_ISSET(sp
->gp
, G_SETMODE
)) {
205 F_SET(sp
->gp
, G_SETMODE
);
206 if (stat(tty
, &sb
) < 0) {
207 msgq(sp
, M_ERR
, "%s: %s.", tty
, strerror(errno
));
210 sp
->gp
->origmode
= sb
.st_mode
;
214 if (chmod(tty
, sp
->gp
->origmode
& ~S_IWGRP
) < 0) {
215 msgq(sp
, M_ERR
, "messages not turned off: %s: %s.",
216 tty
, strerror(errno
));
221 if (chmod(tty
, sp
->gp
->origmode
| S_IWGRP
) < 0) {
222 msgq(sp
, M_ERR
, "messages not turned on: %s: %s.",
223 tty
, strerror(errno
));
233 * This has been documented in historical systems as both "modeline"
234 * and as "modelines". Regardless of the name, this option represents
235 * a security problem of mammoth proportions, not to mention a stunning
236 * example of what your intro CS professor referred to as the perils of
237 * mixing code and data. Don't add it, or I will kill you.
242 msgq(sp
, M_ERR
, "The modelines option may never be set.");
253 F_SET(sp
, S_REFORMAT
| S_REDRAW
);
259 msgq(sp
, M_ERR
, "The optimize option is not implemented.");
265 if (strlen(str
) & 1) {
267 "Paragraph options must be in sets of two characters.");
271 if (F_ISSET(&sp
->opts
[O_PARAGRAPHS
], OPT_ALLOCATED
))
272 free(O_STR(sp
, O_PARAGRAPHS
));
273 if ((O_STR(sp
, O_PARAGRAPHS
) = strdup(str
)) == NULL
) {
274 msgq(sp
, M_SYSERR
, NULL
);
277 F_SET(&sp
->opts
[O_PARAGRAPHS
], OPT_ALLOCATED
| OPT_SET
);
284 O_CLR(sp
, O_READONLY
);
286 F_CLR(sp
->frp
, FR_RDONLY
);
288 O_SET(sp
, O_READONLY
);
290 F_SET(sp
->frp
, FR_RDONLY
);
306 if (strlen(str
) & 1) {
308 "Section options must be in sets of two characters.");
312 if (F_ISSET(&sp
->opts
[O_SECTIONS
], OPT_ALLOCATED
))
313 free(O_STR(sp
, O_SECTIONS
));
314 if ((O_STR(sp
, O_SECTIONS
) = strdup(str
)) == NULL
) {
315 msgq(sp
, M_SYSERR
, NULL
);
318 F_SET(&sp
->opts
[O_SECTIONS
], OPT_ALLOCATED
| OPT_SET
);
325 msgq(sp
, M_ERR
, "The shiftwidth can't be set to 0.");
328 if (val
> O_VAL(sp
, O_COLUMNS
)) {
330 "Shiftwidth can't be larger than screen size.");
333 O_VAL(sp
, O_SHIFTWIDTH
) = val
;
339 if (val
> O_VAL(sp
, O_COLUMNS
)) {
341 "Sidescroll can't be larger than screen size.");
344 O_VAL(sp
, O_SIDESCROLL
) = val
;
351 msgq(sp
, M_ERR
, "Tab stops can't be set to 0.");
354 #define MAXTABSTOP 20
355 if (val
> MAXTABSTOP
) {
357 "Tab stops can't be larger than %d.", MAXTABSTOP
);
360 if (val
> O_VAL(sp
, O_COLUMNS
)) {
362 "Tab stops can't be larger than screen size.",
366 O_VAL(sp
, O_TABSTOP
) = val
;
368 F_SET(sp
, S_REFORMAT
| S_REDRAW
);
376 /* Copy for user display. */
377 p
= O_STR(sp
, O_TAGS
);
378 if ((O_STR(sp
, O_TAGS
) = strdup(str
)) == NULL
) {
379 O_STR(sp
, O_TAGS
) = p
;
380 msgq(sp
, M_SYSERR
, NULL
);
383 if (F_ISSET(&sp
->opts
[O_TAGS
], OPT_ALLOCATED
))
384 FREE(p
, strlen(p
) + 1);
385 F_SET(&sp
->opts
[O_TAGS
], OPT_ALLOCATED
| OPT_SET
);
393 if (F_ISSET(&sp
->opts
[O_TERM
], OPT_ALLOCATED
))
394 free(O_STR(sp
, O_TERM
));
395 if ((O_STR(sp
, O_TERM
) = strdup(str
)) == NULL
) {
396 msgq(sp
, M_SYSERR
, NULL
);
399 F_SET(&sp
->opts
[O_TERM
], OPT_ALLOCATED
| OPT_SET
);
401 /* Set the terminal value in the environment for curses. */
402 (void)snprintf(buf
, sizeof(buf
), "TERM=%s", str
);
406 if (set_window_size(sp
, 0, 0))
413 /* Historical behavior for w300 was < 1200. */
414 if (baud_from_bval(sp
) >= 1200)
420 if (val
> O_VAL(sp
, O_LINES
) - 1)
421 val
= O_VAL(sp
, O_LINES
) - 1;
422 O_VAL(sp
, O_W300
) = val
;
430 /* Historical behavior for w1200 was == 1200. */
431 v
= baud_from_bval(sp
);
432 if (v
< 1200 || v
> 4800)
438 if (val
> O_VAL(sp
, O_LINES
) - 1)
439 val
= O_VAL(sp
, O_LINES
) - 1;
440 O_VAL(sp
, O_W1200
) = val
;
448 /* Historical behavior for w9600 was > 1200. */
449 v
= baud_from_bval(sp
);
456 if (val
> O_VAL(sp
, O_LINES
) - 1)
457 val
= O_VAL(sp
, O_LINES
) - 1;
458 O_VAL(sp
, O_W9600
) = val
;
464 if (val
< MINIMUM_SCREEN_ROWS
) {
465 msgq(sp
, M_ERR
, "Window too small, less than %d.",
466 MINIMUM_SCREEN_ROWS
);
469 if (val
> O_VAL(sp
, O_LINES
) - 1)
470 val
= O_VAL(sp
, O_LINES
) - 1;
471 O_VAL(sp
, O_WINDOW
) = val
;
472 O_VAL(sp
, O_SCROLL
) = val
/ 2;
479 if (val
> O_VAL(sp
, O_COLUMNS
)) {
481 "Wrapmargin value can't be larger than screen size.");
484 O_VAL(sp
, O_WRAPMARGIN
) = val
;
490 * Put a value into the environment. We use putenv(3) because it's
491 * more portable. The following hack is because some moron decided
492 * to keep a reference to the memory passed to putenv(3), instead of
493 * having it allocate its own. Someone clearly needs to get promoted
503 if ((t
= strdup(s
)) == NULL
)