Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / common / options_f.c
blobcc9cf5066c37d6926c719af0d49c9466402e3441
1 /* $NetBSD: options_f.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
2 /*-
3 * Copyright (c) 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
9 */
11 #include "config.h"
13 #include <sys/cdefs.h>
14 #if 0
15 #ifndef lint
16 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 ";
17 #endif /* not lint */
18 #else
19 __RCSID("$NetBSD: options_f.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #endif
22 #include <sys/types.h>
23 #include <sys/queue.h>
24 #include <sys/stat.h>
26 #include <bitstring.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <limits.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
35 #include "common.h"
38 * PUBLIC: int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
40 int
41 f_altwerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
43 if (*valp)
44 O_CLR(sp, O_TTYWERASE);
45 return (0);
49 * PUBLIC: int f_columns __P((SCR *, OPTION *, const char *, u_long *));
51 int
52 f_columns(SCR *sp, OPTION *op, const char *str, u_long *valp)
54 /* Validate the number. */
55 if (*valp < MINIMUM_SCREEN_COLS) {
56 msgq(sp, M_ERR, "040|Screen columns too small, less than %d",
57 MINIMUM_SCREEN_COLS);
58 return (1);
62 * !!!
63 * It's not uncommon for allocation of huge chunks of memory to cause
64 * core dumps on various systems. So, we prune out numbers that are
65 * "obviously" wrong. Vi will not work correctly if it has the wrong
66 * number of lines/columns for the screen, but at least we don't drop
67 * core.
69 #define MAXIMUM_SCREEN_COLS 4000
70 if (*valp > MAXIMUM_SCREEN_COLS) {
71 msgq(sp, M_ERR, "041|Screen columns too large, greater than %d",
72 MAXIMUM_SCREEN_COLS);
73 return (1);
75 return (0);
79 * PUBLIC: int f_lines __P((SCR *, OPTION *, const char *, u_long *));
81 int
82 f_lines(SCR *sp, OPTION *op, const char *str, u_long *valp)
84 /* Validate the number. */
85 if (*valp < MINIMUM_SCREEN_ROWS) {
86 msgq(sp, M_ERR, "042|Screen lines too small, less than %d",
87 MINIMUM_SCREEN_ROWS);
88 return (1);
92 * !!!
93 * It's not uncommon for allocation of huge chunks of memory to cause
94 * core dumps on various systems. So, we prune out numbers that are
95 * "obviously" wrong. Vi will not work correctly if it has the wrong
96 * number of lines/columns for the screen, but at least we don't drop
97 * core.
99 #define MAXIMUM_SCREEN_ROWS 4000
100 if (*valp > MAXIMUM_SCREEN_ROWS) {
101 msgq(sp, M_ERR, "043|Screen lines too large, greater than %d",
102 MAXIMUM_SCREEN_ROWS);
103 return (1);
107 * Set the value, and the related scroll value. If no window
108 * value set, set a new default window.
110 o_set(sp, O_LINES, 0, NULL, *valp);
111 if (*valp == 1) {
112 sp->defscroll = 1;
114 if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
115 O_VAL(sp, O_WINDOW) > *valp) {
116 o_set(sp, O_WINDOW, 0, NULL, 1);
117 o_set(sp, O_WINDOW, OS_DEF, NULL, 1);
119 } else {
120 sp->defscroll = (*valp - 1) / 2;
122 if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
123 O_VAL(sp, O_WINDOW) > *valp) {
124 o_set(sp, O_WINDOW, 0, NULL, *valp - 1);
125 o_set(sp, O_WINDOW, OS_DEF, NULL, *valp - 1);
128 return (0);
132 * PUBLIC: int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
135 f_lisp(SCR *sp, OPTION *op, const char *str, u_long *valp)
137 msgq(sp, M_ERR, "044|The lisp option is not implemented");
138 return (0);
142 * PUBLIC: int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
145 f_msgcat(SCR *sp, OPTION *op, const char *str, u_long *valp)
147 (void)msg_open(sp, str);
148 return (0);
152 * PUBLIC: int f_print __P((SCR *, OPTION *, const char *, u_long *));
155 f_print(SCR *sp, OPTION *op, const char *str, u_long *valp)
157 int offset = op - sp->opts;
159 /* Preset the value, needed for reinitialization of lookup table. */
160 if (offset == O_OCTAL) {
161 if (*valp)
162 O_SET(sp, offset);
163 else
164 O_CLR(sp, offset);
165 } else if (o_set(sp, offset, OS_STRDUP, str, 0))
166 return(1);
168 /* Reinitialize the key fast lookup table. */
169 v_key_ilookup(sp);
171 /* Reformat the screen. */
172 F_SET(sp, SC_SCR_REFORMAT);
173 return (0);
177 * PUBLIC: int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
180 f_readonly(SCR *sp, OPTION *op, const char *str, u_long *valp)
183 * !!!
184 * See the comment in exf.c.
186 if (*valp)
187 F_SET(sp, SC_READONLY);
188 else
189 F_CLR(sp, SC_READONLY);
190 return (0);
194 * PUBLIC: int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
197 f_recompile(SCR *sp, OPTION *op, const char *str, u_long *valp)
199 if (F_ISSET(sp, SC_RE_SEARCH)) {
200 regfree(&sp->re_c);
201 F_CLR(sp, SC_RE_SEARCH);
203 if (F_ISSET(sp, SC_RE_SUBST)) {
204 regfree(&sp->subre_c);
205 F_CLR(sp, SC_RE_SUBST);
207 return (0);
211 * PUBLIC: int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
214 f_reformat(SCR *sp, OPTION *op, const char *str, u_long *valp)
216 F_SET(sp, SC_SCR_REFORMAT);
217 return (0);
221 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
224 f_ttywerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
226 if (*valp)
227 O_CLR(sp, O_ALTWERASE);
228 return (0);
232 * PUBLIC: int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
235 f_w300(SCR *sp, OPTION *op, const char *str, u_long *valp)
237 u_long v;
239 /* Historical behavior for w300 was < 1200. */
240 if (sp->gp->scr_baud(sp, &v))
241 return (1);
242 if (v >= 1200)
243 return (0);
245 return (f_window(sp, op, str, valp));
249 * PUBLIC: int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
252 f_w1200(SCR *sp, OPTION *op, const char *str, u_long *valp)
254 u_long v;
256 /* Historical behavior for w1200 was == 1200. */
257 if (sp->gp->scr_baud(sp, &v))
258 return (1);
259 if (v < 1200 || v > 4800)
260 return (0);
262 return (f_window(sp, op, str, valp));
266 * PUBLIC: int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
269 f_w9600(SCR *sp, OPTION *op, const char *str, u_long *valp)
271 u_long v;
273 /* Historical behavior for w9600 was > 1200. */
274 if (sp->gp->scr_baud(sp, &v))
275 return (1);
276 if (v <= 4800)
277 return (0);
279 return (f_window(sp, op, str, valp));
283 * PUBLIC: int f_window __P((SCR *, OPTION *, const char *, u_long *));
286 f_window(SCR *sp, OPTION *op, const char *str, u_long *valp)
288 if (*valp >= O_VAL(sp, O_LINES) - 1 &&
289 (*valp = O_VAL(sp, O_LINES) - 1) == 0)
290 *valp = 1;
291 return (0);
295 * PUBLIC: int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
298 f_encoding(SCR *sp, OPTION *op, const char *str, u_long *valp)
300 int offset = op - sp->opts;
302 return conv_enc(sp, offset, str);