remove generated compile, depcomp, missing and mkinstalldirs
[nvi.git] / common / options_f.c
blob7dcff64080e43db2ced53bd411a6d7bc159786bc
1 /*-
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.
8 */
10 #include "config.h"
12 #ifndef lint
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 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/stat.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <errno.h>
23 #include <limits.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
29 #include "common.h"
32 * PUBLIC: int f_altwerase __P((SCR *, OPTION *, char *, u_long *));
34 int
35 f_altwerase(SCR *sp, OPTION *op, char *str, u_long *valp)
37 if (*valp)
38 O_CLR(sp, O_TTYWERASE);
39 return (0);
43 * PUBLIC: int f_columns __P((SCR *, OPTION *, char *, u_long *));
45 int
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",
51 MINIMUM_SCREEN_COLS);
52 return (1);
56 * !!!
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
61 * core.
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",
66 MAXIMUM_SCREEN_COLS);
67 return (1);
69 return (0);
73 * PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *));
75 int
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",
81 MINIMUM_SCREEN_ROWS);
82 return (1);
86 * !!!
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
91 * core.
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",
96 MAXIMUM_SCREEN_ROWS);
97 return (1);
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);
105 if (*valp == 1) {
106 sp->defscroll = 1;
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);
113 } else {
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);
122 return (0);
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");
132 return (0);
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);
142 return (0);
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) {
152 msgq(sp, M_ERR,
153 "048|The paragraph option must be in two character groups");
154 return (1);
156 return (0);
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) {
169 if (*valp)
170 O_SET(sp, offset);
171 else
172 O_CLR(sp, offset);
173 } else if (o_set(sp, offset, OS_STRDUP, str, 0))
174 return(1);
176 /* Reinitialize the key fast lookup table. */
177 v_key_ilookup(sp);
179 /* Reformat the screen. */
180 F_SET(sp, SC_SCR_REFORMAT);
181 return (0);
185 * PUBLIC: int f_readonly __P((SCR *, OPTION *, char *, u_long *));
188 f_readonly(SCR *sp, OPTION *op, char *str, u_long *valp)
191 * !!!
192 * See the comment in exf.c.
194 if (*valp)
195 F_SET(sp, SC_READONLY);
196 else
197 F_CLR(sp, SC_READONLY);
198 return (0);
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)) {
208 regfree(&sp->re_c);
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);
215 return (0);
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);
225 return (0);
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) {
235 msgq(sp, M_ERR,
236 "049|The section option must be in two character groups");
237 return (1);
239 return (0);
243 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, char *, u_long *));
246 f_ttywerase(SCR *sp, OPTION *op, char *str, u_long *valp)
248 if (*valp)
249 O_CLR(sp, O_ALTWERASE);
250 return (0);
254 * PUBLIC: int f_w300 __P((SCR *, OPTION *, char *, u_long *));
257 f_w300(SCR *sp, OPTION *op, char *str, u_long *valp)
259 u_long v;
261 /* Historical behavior for w300 was < 1200. */
262 if (sp->gp->scr_baud(sp, &v))
263 return (1);
264 if (v >= 1200)
265 return (0);
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)
276 u_long v;
278 /* Historical behavior for w1200 was == 1200. */
279 if (sp->gp->scr_baud(sp, &v))
280 return (1);
281 if (v < 1200 || v > 4800)
282 return (0);
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)
293 u_long v;
295 /* Historical behavior for w9600 was > 1200. */
296 if (sp->gp->scr_baud(sp, &v))
297 return (1);
298 if (v <= 4800)
299 return (0);
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)
312 *valp = 1;
313 return (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);