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