Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / common / options_f.c
blob88aad97cd112e8db5542a2638fc3c113c8dd94e4
1 /* $NetBSD: options_f.c,v 1.2 2008/10/01 21:20:09 christos Exp $ */
3 /*-
4 * Copyright (c) 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 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";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/stat.h>
22 #include <bitstring.h>
23 #include <ctype.h>
24 #include <errno.h>
25 #include <limits.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
31 #include "common.h"
34 * PUBLIC: int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
36 int
37 f_altwerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
39 if (*valp)
40 O_CLR(sp, O_TTYWERASE);
41 return (0);
45 * PUBLIC: int f_columns __P((SCR *, OPTION *, const char *, u_long *));
47 int
48 f_columns(SCR *sp, OPTION *op, const char *str, u_long *valp)
50 /* Validate the number. */
51 if (*valp < MINIMUM_SCREEN_COLS) {
52 msgq(sp, M_ERR, "040|Screen columns too small, less than %d",
53 MINIMUM_SCREEN_COLS);
54 return (1);
58 * !!!
59 * It's not uncommon for allocation of huge chunks of memory to cause
60 * core dumps on various systems. So, we prune out numbers that are
61 * "obviously" wrong. Vi will not work correctly if it has the wrong
62 * number of lines/columns for the screen, but at least we don't drop
63 * core.
65 #define MAXIMUM_SCREEN_COLS 4000
66 if (*valp > MAXIMUM_SCREEN_COLS) {
67 msgq(sp, M_ERR, "041|Screen columns too large, greater than %d",
68 MAXIMUM_SCREEN_COLS);
69 return (1);
71 return (0);
75 * PUBLIC: int f_lines __P((SCR *, OPTION *, const char *, u_long *));
77 int
78 f_lines(SCR *sp, OPTION *op, const char *str, u_long *valp)
80 /* Validate the number. */
81 if (*valp < MINIMUM_SCREEN_ROWS) {
82 msgq(sp, M_ERR, "042|Screen lines too small, less than %d",
83 MINIMUM_SCREEN_ROWS);
84 return (1);
88 * !!!
89 * It's not uncommon for allocation of huge chunks of memory to cause
90 * core dumps on various systems. So, we prune out numbers that are
91 * "obviously" wrong. Vi will not work correctly if it has the wrong
92 * number of lines/columns for the screen, but at least we don't drop
93 * core.
95 #define MAXIMUM_SCREEN_ROWS 4000
96 if (*valp > MAXIMUM_SCREEN_ROWS) {
97 msgq(sp, M_ERR, "043|Screen lines too large, greater than %d",
98 MAXIMUM_SCREEN_ROWS);
99 return (1);
103 * Set the value, and the related scroll value. If no window
104 * value set, set a new default window.
106 o_set(sp, O_LINES, 0, NULL, *valp);
107 if (*valp == 1) {
108 sp->defscroll = 1;
110 if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
111 O_VAL(sp, O_WINDOW) > *valp) {
112 o_set(sp, O_WINDOW, 0, NULL, 1);
113 o_set(sp, O_WINDOW, OS_DEF, NULL, 1);
115 } else {
116 sp->defscroll = (*valp - 1) / 2;
118 if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
119 O_VAL(sp, O_WINDOW) > *valp) {
120 o_set(sp, O_WINDOW, 0, NULL, *valp - 1);
121 o_set(sp, O_WINDOW, OS_DEF, NULL, *valp - 1);
124 return (0);
128 * PUBLIC: int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
131 f_lisp(SCR *sp, OPTION *op, const char *str, u_long *valp)
133 msgq(sp, M_ERR, "044|The lisp option is not implemented");
134 return (0);
138 * PUBLIC: int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
141 f_msgcat(SCR *sp, OPTION *op, const char *str, u_long *valp)
143 (void)msg_open(sp, str);
144 return (0);
148 * PUBLIC: int f_print __P((SCR *, OPTION *, const char *, u_long *));
151 f_print(SCR *sp, OPTION *op, const char *str, u_long *valp)
153 int offset = op - sp->opts;
155 /* Preset the value, needed for reinitialization of lookup table. */
156 if (offset == O_OCTAL) {
157 if (*valp)
158 O_SET(sp, offset);
159 else
160 O_CLR(sp, offset);
161 } else if (o_set(sp, offset, OS_STRDUP, str, 0))
162 return(1);
164 /* Reinitialize the key fast lookup table. */
165 v_key_ilookup(sp);
167 /* Reformat the screen. */
168 F_SET(sp, SC_SCR_REFORMAT);
169 return (0);
173 * PUBLIC: int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
176 f_readonly(SCR *sp, OPTION *op, const char *str, u_long *valp)
179 * !!!
180 * See the comment in exf.c.
182 if (*valp)
183 F_SET(sp, SC_READONLY);
184 else
185 F_CLR(sp, SC_READONLY);
186 return (0);
190 * PUBLIC: int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
193 f_recompile(SCR *sp, OPTION *op, const char *str, u_long *valp)
195 if (F_ISSET(sp, SC_RE_SEARCH)) {
196 regfree(&sp->re_c);
197 F_CLR(sp, SC_RE_SEARCH);
199 if (F_ISSET(sp, SC_RE_SUBST)) {
200 regfree(&sp->subre_c);
201 F_CLR(sp, SC_RE_SUBST);
203 return (0);
207 * PUBLIC: int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
210 f_reformat(SCR *sp, OPTION *op, const char *str, u_long *valp)
212 F_SET(sp, SC_SCR_REFORMAT);
213 return (0);
217 * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
220 f_ttywerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
222 if (*valp)
223 O_CLR(sp, O_ALTWERASE);
224 return (0);
228 * PUBLIC: int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
231 f_w300(SCR *sp, OPTION *op, const char *str, u_long *valp)
233 u_long v;
235 /* Historical behavior for w300 was < 1200. */
236 if (sp->gp->scr_baud(sp, &v))
237 return (1);
238 if (v >= 1200)
239 return (0);
241 return (f_window(sp, op, str, valp));
245 * PUBLIC: int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
248 f_w1200(SCR *sp, OPTION *op, const char *str, u_long *valp)
250 u_long v;
252 /* Historical behavior for w1200 was == 1200. */
253 if (sp->gp->scr_baud(sp, &v))
254 return (1);
255 if (v < 1200 || v > 4800)
256 return (0);
258 return (f_window(sp, op, str, valp));
262 * PUBLIC: int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
265 f_w9600(SCR *sp, OPTION *op, const char *str, u_long *valp)
267 u_long v;
269 /* Historical behavior for w9600 was > 1200. */
270 if (sp->gp->scr_baud(sp, &v))
271 return (1);
272 if (v <= 4800)
273 return (0);
275 return (f_window(sp, op, str, valp));
279 * PUBLIC: int f_window __P((SCR *, OPTION *, const char *, u_long *));
282 f_window(SCR *sp, OPTION *op, const char *str, u_long *valp)
284 if (*valp >= O_VAL(sp, O_LINES) - 1 &&
285 (*valp = O_VAL(sp, O_LINES) - 1) == 0)
286 *valp = 1;
287 return (0);
291 * PUBLIC: int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
294 f_encoding(SCR *sp, OPTION *op, const char *str, u_long *valp)
296 int offset = op - sp->opts;
298 return conv_enc(sp, offset, str);