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. |
---|
6 | * |
---|
7 | * See the LICENSE file for redistribution information. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "config.h" |
---|
11 | |
---|
12 | #ifndef lint |
---|
13 | static const char sccsid[] = "@(#)options_f.c 10.25 (Berkeley) 7/12/96"; |
---|
14 | #endif /* not lint */ |
---|
15 | |
---|
16 | #include <sys/types.h> |
---|
17 | #include <sys/queue.h> |
---|
18 | #include <sys/stat.h> |
---|
19 | |
---|
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> |
---|
28 | |
---|
29 | #include "common.h" |
---|
30 | |
---|
31 | /* |
---|
32 | * PUBLIC: int f_altwerase __P((SCR *, OPTION *, char *, u_long *)); |
---|
33 | */ |
---|
34 | int |
---|
35 | f_altwerase(sp, op, str, valp) |
---|
36 | SCR *sp; |
---|
37 | OPTION *op; |
---|
38 | char *str; |
---|
39 | u_long *valp; |
---|
40 | { |
---|
41 | if (!*valp) |
---|
42 | O_CLR(sp, O_TTYWERASE); |
---|
43 | return (0); |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * PUBLIC: int f_columns __P((SCR *, OPTION *, char *, u_long *)); |
---|
48 | */ |
---|
49 | int |
---|
50 | f_columns(sp, op, str, valp) |
---|
51 | SCR *sp; |
---|
52 | OPTION *op; |
---|
53 | char *str; |
---|
54 | u_long *valp; |
---|
55 | { |
---|
56 | /* Validate the number. */ |
---|
57 | if (*valp < MINIMUM_SCREEN_COLS) { |
---|
58 | msgq(sp, M_ERR, "040|Screen columns too small, less than %d", |
---|
59 | MINIMUM_SCREEN_COLS); |
---|
60 | return (1); |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * !!! |
---|
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 |
---|
69 | * core. |
---|
70 | */ |
---|
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", |
---|
74 | MAXIMUM_SCREEN_COLS); |
---|
75 | return (1); |
---|
76 | } |
---|
77 | return (0); |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | * PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *)); |
---|
82 | */ |
---|
83 | int |
---|
84 | f_lines(sp, op, str, valp) |
---|
85 | SCR *sp; |
---|
86 | OPTION *op; |
---|
87 | char *str; |
---|
88 | u_long *valp; |
---|
89 | { |
---|
90 | /* Validate the number. */ |
---|
91 | if (*valp < MINIMUM_SCREEN_ROWS) { |
---|
92 | msgq(sp, M_ERR, "042|Screen lines too small, less than %d", |
---|
93 | MINIMUM_SCREEN_ROWS); |
---|
94 | return (1); |
---|
95 | } |
---|
96 | |
---|
97 | /* |
---|
98 | * !!! |
---|
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 |
---|
103 | * core. |
---|
104 | */ |
---|
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); |
---|
109 | return (1); |
---|
110 | } |
---|
111 | |
---|
112 | /* |
---|
113 | * Set the value, and the related scroll value. If no window |
---|
114 | * value set, set a new default window. |
---|
115 | */ |
---|
116 | o_set(sp, O_LINES, 0, NULL, *valp); |
---|
117 | if (*valp == 1) { |
---|
118 | sp->defscroll = 1; |
---|
119 | |
---|
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); |
---|
124 | } |
---|
125 | } else { |
---|
126 | sp->defscroll = (*valp - 1) / 2; |
---|
127 | |
---|
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); |
---|
132 | } |
---|
133 | } |
---|
134 | return (0); |
---|
135 | } |
---|
136 | |
---|
137 | /* |
---|
138 | * PUBLIC: int f_lisp __P((SCR *, OPTION *, char *, u_long *)); |
---|
139 | */ |
---|
140 | int |
---|
141 | f_lisp(sp, op, str, valp) |
---|
142 | SCR *sp; |
---|
143 | OPTION *op; |
---|
144 | char *str; |
---|
145 | u_long *valp; |
---|
146 | { |
---|
147 | msgq(sp, M_ERR, "044|The lisp option is not implemented"); |
---|
148 | return (0); |
---|
149 | } |
---|
150 | |
---|
151 | /* |
---|
152 | * PUBLIC: int f_msgcat __P((SCR *, OPTION *, char *, u_long *)); |
---|
153 | */ |
---|
154 | int |
---|
155 | f_msgcat(sp, op, str, valp) |
---|
156 | SCR *sp; |
---|
157 | OPTION *op; |
---|
158 | char *str; |
---|
159 | u_long *valp; |
---|
160 | { |
---|
161 | (void)msg_open(sp, str); |
---|
162 | return (0); |
---|
163 | } |
---|
164 | |
---|
165 | /* |
---|
166 | * PUBLIC: int f_paragraph __P((SCR *, OPTION *, char *, u_long *)); |
---|
167 | */ |
---|
168 | int |
---|
169 | f_paragraph(sp, op, str, valp) |
---|
170 | SCR *sp; |
---|
171 | OPTION *op; |
---|
172 | char *str; |
---|
173 | u_long *valp; |
---|
174 | { |
---|
175 | if (strlen(str) & 1) { |
---|
176 | msgq(sp, M_ERR, |
---|
177 | "048|The paragraph option must be in two character groups"); |
---|
178 | return (1); |
---|
179 | } |
---|
180 | return (0); |
---|
181 | } |
---|
182 | |
---|
183 | /* |
---|
184 | * PUBLIC: int f_print __P((SCR *, OPTION *, char *, u_long *)); |
---|
185 | */ |
---|
186 | int |
---|
187 | f_print(sp, op, str, valp) |
---|
188 | SCR *sp; |
---|
189 | OPTION *op; |
---|
190 | char *str; |
---|
191 | u_long *valp; |
---|
192 | { |
---|
193 | /* Reinitialize the key fast lookup table. */ |
---|
194 | v_key_ilookup(sp); |
---|
195 | |
---|
196 | /* Reformat the screen. */ |
---|
197 | F_SET(sp, SC_SCR_REFORMAT); |
---|
198 | return (0); |
---|
199 | } |
---|
200 | |
---|
201 | /* |
---|
202 | * PUBLIC: int f_readonly __P((SCR *, OPTION *, char *, u_long *)); |
---|
203 | */ |
---|
204 | int |
---|
205 | f_readonly(sp, op, str, valp) |
---|
206 | SCR *sp; |
---|
207 | OPTION *op; |
---|
208 | char *str; |
---|
209 | u_long *valp; |
---|
210 | { |
---|
211 | /* |
---|
212 | * !!! |
---|
213 | * See the comment in exf.c. |
---|
214 | */ |
---|
215 | if (*valp) |
---|
216 | F_CLR(sp, SC_READONLY); |
---|
217 | else |
---|
218 | F_SET(sp, SC_READONLY); |
---|
219 | return (0); |
---|
220 | } |
---|
221 | |
---|
222 | /* |
---|
223 | * PUBLIC: int f_recompile __P((SCR *, OPTION *, char *, u_long *)); |
---|
224 | */ |
---|
225 | int |
---|
226 | f_recompile(sp, op, str, valp) |
---|
227 | SCR *sp; |
---|
228 | OPTION *op; |
---|
229 | char *str; |
---|
230 | u_long *valp; |
---|
231 | { |
---|
232 | if (F_ISSET(sp, SC_RE_SEARCH)) { |
---|
233 | regfree(&sp->re_c); |
---|
234 | F_CLR(sp, SC_RE_SEARCH); |
---|
235 | } |
---|
236 | if (F_ISSET(sp, SC_RE_SUBST)) { |
---|
237 | regfree(&sp->subre_c); |
---|
238 | F_CLR(sp, SC_RE_SUBST); |
---|
239 | } |
---|
240 | return (0); |
---|
241 | } |
---|
242 | |
---|
243 | /* |
---|
244 | * PUBLIC: int f_reformat __P((SCR *, OPTION *, char *, u_long *)); |
---|
245 | */ |
---|
246 | int |
---|
247 | f_reformat(sp, op, str, valp) |
---|
248 | SCR *sp; |
---|
249 | OPTION *op; |
---|
250 | char *str; |
---|
251 | u_long *valp; |
---|
252 | { |
---|
253 | F_SET(sp, SC_SCR_REFORMAT); |
---|
254 | return (0); |
---|
255 | } |
---|
256 | |
---|
257 | /* |
---|
258 | * PUBLIC: int f_section __P((SCR *, OPTION *, char *, u_long *)); |
---|
259 | */ |
---|
260 | int |
---|
261 | f_section(sp, op, str, valp) |
---|
262 | SCR *sp; |
---|
263 | OPTION *op; |
---|
264 | char *str; |
---|
265 | u_long *valp; |
---|
266 | { |
---|
267 | if (strlen(str) & 1) { |
---|
268 | msgq(sp, M_ERR, |
---|
269 | "049|The section option must be in two character groups"); |
---|
270 | return (1); |
---|
271 | } |
---|
272 | return (0); |
---|
273 | } |
---|
274 | |
---|
275 | /* |
---|
276 | * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, char *, u_long *)); |
---|
277 | */ |
---|
278 | int |
---|
279 | f_ttywerase(sp, op, str, valp) |
---|
280 | SCR *sp; |
---|
281 | OPTION *op; |
---|
282 | char *str; |
---|
283 | u_long *valp; |
---|
284 | { |
---|
285 | if (!*valp) |
---|
286 | O_CLR(sp, O_ALTWERASE); |
---|
287 | return (0); |
---|
288 | } |
---|
289 | |
---|
290 | /* |
---|
291 | * PUBLIC: int f_w300 __P((SCR *, OPTION *, char *, u_long *)); |
---|
292 | */ |
---|
293 | int |
---|
294 | f_w300(sp, op, str, valp) |
---|
295 | SCR *sp; |
---|
296 | OPTION *op; |
---|
297 | char *str; |
---|
298 | u_long *valp; |
---|
299 | { |
---|
300 | u_long v; |
---|
301 | |
---|
302 | /* Historical behavior for w300 was < 1200. */ |
---|
303 | if (sp->gp->scr_baud(sp, &v)) |
---|
304 | return (1); |
---|
305 | if (v >= 1200) |
---|
306 | return (0); |
---|
307 | |
---|
308 | return (f_window(sp, op, str, valp)); |
---|
309 | } |
---|
310 | |
---|
311 | /* |
---|
312 | * PUBLIC: int f_w1200 __P((SCR *, OPTION *, char *, u_long *)); |
---|
313 | */ |
---|
314 | int |
---|
315 | f_w1200(sp, op, str, valp) |
---|
316 | SCR *sp; |
---|
317 | OPTION *op; |
---|
318 | char *str; |
---|
319 | u_long *valp; |
---|
320 | { |
---|
321 | u_long v; |
---|
322 | |
---|
323 | /* Historical behavior for w1200 was == 1200. */ |
---|
324 | if (sp->gp->scr_baud(sp, &v)) |
---|
325 | return (1); |
---|
326 | if (v < 1200 || v > 4800) |
---|
327 | return (0); |
---|
328 | |
---|
329 | return (f_window(sp, op, str, valp)); |
---|
330 | } |
---|
331 | |
---|
332 | /* |
---|
333 | * PUBLIC: int f_w9600 __P((SCR *, OPTION *, char *, u_long *)); |
---|
334 | */ |
---|
335 | int |
---|
336 | f_w9600(sp, op, str, valp) |
---|
337 | SCR *sp; |
---|
338 | OPTION *op; |
---|
339 | char *str; |
---|
340 | u_long *valp; |
---|
341 | { |
---|
342 | u_long v; |
---|
343 | |
---|
344 | /* Historical behavior for w9600 was > 1200. */ |
---|
345 | if (sp->gp->scr_baud(sp, &v)) |
---|
346 | return (1); |
---|
347 | if (v <= 4800) |
---|
348 | return (0); |
---|
349 | |
---|
350 | return (f_window(sp, op, str, valp)); |
---|
351 | } |
---|
352 | |
---|
353 | /* |
---|
354 | * PUBLIC: int f_window __P((SCR *, OPTION *, char *, u_long *)); |
---|
355 | */ |
---|
356 | int |
---|
357 | f_window(sp, op, str, valp) |
---|
358 | SCR *sp; |
---|
359 | OPTION *op; |
---|
360 | char *str; |
---|
361 | u_long *valp; |
---|
362 | { |
---|
363 | if (*valp >= O_VAL(sp, O_LINES) - 1 && |
---|
364 | (*valp = O_VAL(sp, O_LINES) - 1) == 0) |
---|
365 | *valp = 1; |
---|
366 | return (0); |
---|
367 | } |
---|