Home | History | Annotate | Line # | Download | only in common
options_f.c revision 1.4
      1  1.4       rin /*	$NetBSD: options_f.c,v 1.4 2018/08/07 08:05:47 rin Exp $ */
      2  1.1  christos /*-
      3  1.1  christos  * Copyright (c) 1993, 1994
      4  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      5  1.1  christos  * Copyright (c) 1993, 1994, 1995, 1996
      6  1.1  christos  *	Keith Bostic.  All rights reserved.
      7  1.1  christos  *
      8  1.1  christos  * See the LICENSE file for redistribution information.
      9  1.1  christos  */
     10  1.1  christos 
     11  1.1  christos #include "config.h"
     12  1.1  christos 
     13  1.3  christos #include <sys/cdefs.h>
     14  1.3  christos #if 0
     15  1.1  christos #ifndef lint
     16  1.1  christos 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  1.1  christos #endif /* not lint */
     18  1.3  christos #else
     19  1.4       rin __RCSID("$NetBSD: options_f.c,v 1.4 2018/08/07 08:05:47 rin Exp $");
     20  1.3  christos #endif
     21  1.1  christos 
     22  1.1  christos #include <sys/types.h>
     23  1.1  christos #include <sys/queue.h>
     24  1.1  christos #include <sys/stat.h>
     25  1.1  christos 
     26  1.1  christos #include <bitstring.h>
     27  1.1  christos #include <ctype.h>
     28  1.1  christos #include <errno.h>
     29  1.1  christos #include <limits.h>
     30  1.1  christos #include <stdio.h>
     31  1.1  christos #include <stdlib.h>
     32  1.1  christos #include <string.h>
     33  1.1  christos #include <unistd.h>
     34  1.1  christos 
     35  1.1  christos #include "common.h"
     36  1.1  christos 
     37  1.1  christos /*
     38  1.2  christos  * PUBLIC: int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
     39  1.1  christos  */
     40  1.1  christos int
     41  1.2  christos f_altwerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
     42  1.1  christos {
     43  1.1  christos 	if (*valp)
     44  1.1  christos 		O_CLR(sp, O_TTYWERASE);
     45  1.1  christos 	return (0);
     46  1.1  christos }
     47  1.1  christos 
     48  1.1  christos /*
     49  1.2  christos  * PUBLIC: int f_columns __P((SCR *, OPTION *, const char *, u_long *));
     50  1.1  christos  */
     51  1.1  christos int
     52  1.2  christos f_columns(SCR *sp, OPTION *op, const char *str, u_long *valp)
     53  1.1  christos {
     54  1.1  christos 	/* Validate the number. */
     55  1.1  christos 	if (*valp < MINIMUM_SCREEN_COLS) {
     56  1.1  christos 		msgq(sp, M_ERR, "040|Screen columns too small, less than %d",
     57  1.1  christos 		    MINIMUM_SCREEN_COLS);
     58  1.1  christos 		return (1);
     59  1.1  christos 	}
     60  1.1  christos 
     61  1.1  christos 	/*
     62  1.1  christos 	 * !!!
     63  1.1  christos 	 * It's not uncommon for allocation of huge chunks of memory to cause
     64  1.1  christos 	 * core dumps on various systems.  So, we prune out numbers that are
     65  1.1  christos 	 * "obviously" wrong.  Vi will not work correctly if it has the wrong
     66  1.1  christos 	 * number of lines/columns for the screen, but at least we don't drop
     67  1.1  christos 	 * core.
     68  1.1  christos 	 */
     69  1.2  christos #define	MAXIMUM_SCREEN_COLS	4000
     70  1.1  christos 	if (*valp > MAXIMUM_SCREEN_COLS) {
     71  1.1  christos 		msgq(sp, M_ERR, "041|Screen columns too large, greater than %d",
     72  1.1  christos 		    MAXIMUM_SCREEN_COLS);
     73  1.1  christos 		return (1);
     74  1.1  christos 	}
     75  1.1  christos 	return (0);
     76  1.1  christos }
     77  1.1  christos 
     78  1.1  christos /*
     79  1.2  christos  * PUBLIC: int f_lines __P((SCR *, OPTION *, const char *, u_long *));
     80  1.1  christos  */
     81  1.1  christos int
     82  1.2  christos f_lines(SCR *sp, OPTION *op, const char *str, u_long *valp)
     83  1.1  christos {
     84  1.1  christos 	/* Validate the number. */
     85  1.1  christos 	if (*valp < MINIMUM_SCREEN_ROWS) {
     86  1.1  christos 		msgq(sp, M_ERR, "042|Screen lines too small, less than %d",
     87  1.1  christos 		    MINIMUM_SCREEN_ROWS);
     88  1.1  christos 		return (1);
     89  1.1  christos 	}
     90  1.1  christos 
     91  1.1  christos 	/*
     92  1.1  christos 	 * !!!
     93  1.1  christos 	 * It's not uncommon for allocation of huge chunks of memory to cause
     94  1.1  christos 	 * core dumps on various systems.  So, we prune out numbers that are
     95  1.1  christos 	 * "obviously" wrong.  Vi will not work correctly if it has the wrong
     96  1.1  christos 	 * number of lines/columns for the screen, but at least we don't drop
     97  1.1  christos 	 * core.
     98  1.1  christos 	 */
     99  1.2  christos #define	MAXIMUM_SCREEN_ROWS	4000
    100  1.1  christos 	if (*valp > MAXIMUM_SCREEN_ROWS) {
    101  1.1  christos 		msgq(sp, M_ERR, "043|Screen lines too large, greater than %d",
    102  1.1  christos 		    MAXIMUM_SCREEN_ROWS);
    103  1.1  christos 		return (1);
    104  1.1  christos 	}
    105  1.1  christos 
    106  1.1  christos 	/*
    107  1.1  christos 	 * Set the value, and the related scroll value.  If no window
    108  1.1  christos 	 * value set, set a new default window.
    109  1.1  christos 	 */
    110  1.1  christos 	o_set(sp, O_LINES, 0, NULL, *valp);
    111  1.1  christos 	if (*valp == 1) {
    112  1.1  christos 		sp->defscroll = 1;
    113  1.1  christos 
    114  1.1  christos 		if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
    115  1.1  christos 		    O_VAL(sp, O_WINDOW) > *valp) {
    116  1.1  christos 			o_set(sp, O_WINDOW, 0, NULL, 1);
    117  1.1  christos 			o_set(sp, O_WINDOW, OS_DEF, NULL, 1);
    118  1.1  christos 		}
    119  1.1  christos 	} else {
    120  1.1  christos 		sp->defscroll = (*valp - 1) / 2;
    121  1.1  christos 
    122  1.1  christos 		if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
    123  1.1  christos 		    O_VAL(sp, O_WINDOW) > *valp) {
    124  1.1  christos 			o_set(sp, O_WINDOW, 0, NULL, *valp - 1);
    125  1.1  christos 			o_set(sp, O_WINDOW, OS_DEF, NULL, *valp - 1);
    126  1.1  christos 		}
    127  1.1  christos 	}
    128  1.1  christos 	return (0);
    129  1.1  christos }
    130  1.1  christos 
    131  1.1  christos /*
    132  1.2  christos  * PUBLIC: int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
    133  1.1  christos  */
    134  1.1  christos int
    135  1.2  christos f_lisp(SCR *sp, OPTION *op, const char *str, u_long *valp)
    136  1.1  christos {
    137  1.1  christos 	msgq(sp, M_ERR, "044|The lisp option is not implemented");
    138  1.1  christos 	return (0);
    139  1.1  christos }
    140  1.1  christos 
    141  1.1  christos /*
    142  1.2  christos  * PUBLIC: int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
    143  1.1  christos  */
    144  1.1  christos int
    145  1.2  christos f_msgcat(SCR *sp, OPTION *op, const char *str, u_long *valp)
    146  1.1  christos {
    147  1.1  christos 	(void)msg_open(sp, str);
    148  1.1  christos 	return (0);
    149  1.1  christos }
    150  1.1  christos 
    151  1.1  christos /*
    152  1.2  christos  * PUBLIC: int f_print __P((SCR *, OPTION *, const char *, u_long *));
    153  1.1  christos  */
    154  1.1  christos int
    155  1.2  christos f_print(SCR *sp, OPTION *op, const char *str, u_long *valp)
    156  1.1  christos {
    157  1.1  christos 	int offset = op - sp->opts;
    158  1.1  christos 
    159  1.1  christos 	/* Preset the value, needed for reinitialization of lookup table. */
    160  1.1  christos 	if (offset == O_OCTAL) {
    161  1.1  christos 		if (*valp)
    162  1.1  christos 			O_SET(sp, offset);
    163  1.1  christos 		else
    164  1.1  christos 			O_CLR(sp, offset);
    165  1.1  christos 	} else if (o_set(sp, offset, OS_STRDUP, str, 0))
    166  1.1  christos 		return(1);
    167  1.1  christos 
    168  1.1  christos 	/* Reinitialize the key fast lookup table. */
    169  1.1  christos 	v_key_ilookup(sp);
    170  1.1  christos 
    171  1.1  christos 	/* Reformat the screen. */
    172  1.1  christos 	F_SET(sp, SC_SCR_REFORMAT);
    173  1.1  christos 	return (0);
    174  1.1  christos }
    175  1.1  christos 
    176  1.1  christos /*
    177  1.2  christos  * PUBLIC: int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
    178  1.1  christos  */
    179  1.1  christos int
    180  1.2  christos f_readonly(SCR *sp, OPTION *op, const char *str, u_long *valp)
    181  1.1  christos {
    182  1.1  christos 	/*
    183  1.1  christos 	 * !!!
    184  1.1  christos 	 * See the comment in exf.c.
    185  1.1  christos 	 */
    186  1.1  christos 	if (*valp)
    187  1.1  christos 		F_SET(sp, SC_READONLY);
    188  1.1  christos 	else
    189  1.1  christos 		F_CLR(sp, SC_READONLY);
    190  1.1  christos 	return (0);
    191  1.1  christos }
    192  1.1  christos 
    193  1.1  christos /*
    194  1.2  christos  * PUBLIC: int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
    195  1.1  christos  */
    196  1.1  christos int
    197  1.2  christos f_recompile(SCR *sp, OPTION *op, const char *str, u_long *valp)
    198  1.1  christos {
    199  1.1  christos 	if (F_ISSET(sp, SC_RE_SEARCH)) {
    200  1.1  christos 		regfree(&sp->re_c);
    201  1.1  christos 		F_CLR(sp, SC_RE_SEARCH);
    202  1.1  christos 	}
    203  1.1  christos 	if (F_ISSET(sp, SC_RE_SUBST)) {
    204  1.1  christos 		regfree(&sp->subre_c);
    205  1.1  christos 		F_CLR(sp, SC_RE_SUBST);
    206  1.1  christos 	}
    207  1.1  christos 	return (0);
    208  1.1  christos }
    209  1.1  christos 
    210  1.1  christos /*
    211  1.2  christos  * PUBLIC: int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
    212  1.1  christos  */
    213  1.1  christos int
    214  1.2  christos f_reformat(SCR *sp, OPTION *op, const char *str, u_long *valp)
    215  1.1  christos {
    216  1.1  christos 	F_SET(sp, SC_SCR_REFORMAT);
    217  1.1  christos 	return (0);
    218  1.1  christos }
    219  1.1  christos 
    220  1.1  christos /*
    221  1.2  christos  * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
    222  1.1  christos  */
    223  1.1  christos int
    224  1.2  christos f_ttywerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
    225  1.1  christos {
    226  1.1  christos 	if (*valp)
    227  1.1  christos 		O_CLR(sp, O_ALTWERASE);
    228  1.1  christos 	return (0);
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos /*
    232  1.2  christos  * PUBLIC: int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
    233  1.1  christos  */
    234  1.1  christos int
    235  1.2  christos f_w300(SCR *sp, OPTION *op, const char *str, u_long *valp)
    236  1.1  christos {
    237  1.1  christos 	u_long v;
    238  1.1  christos 
    239  1.1  christos 	/* Historical behavior for w300 was < 1200. */
    240  1.1  christos 	if (sp->gp->scr_baud(sp, &v))
    241  1.1  christos 		return (1);
    242  1.1  christos 	if (v >= 1200)
    243  1.1  christos 		return (0);
    244  1.1  christos 
    245  1.1  christos 	return (f_window(sp, op, str, valp));
    246  1.1  christos }
    247  1.1  christos 
    248  1.1  christos /*
    249  1.2  christos  * PUBLIC: int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
    250  1.1  christos  */
    251  1.1  christos int
    252  1.2  christos f_w1200(SCR *sp, OPTION *op, const char *str, u_long *valp)
    253  1.1  christos {
    254  1.1  christos 	u_long v;
    255  1.1  christos 
    256  1.1  christos 	/* Historical behavior for w1200 was == 1200. */
    257  1.1  christos 	if (sp->gp->scr_baud(sp, &v))
    258  1.1  christos 		return (1);
    259  1.1  christos 	if (v < 1200 || v > 4800)
    260  1.1  christos 		return (0);
    261  1.1  christos 
    262  1.1  christos 	return (f_window(sp, op, str, valp));
    263  1.1  christos }
    264  1.1  christos 
    265  1.1  christos /*
    266  1.2  christos  * PUBLIC: int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
    267  1.1  christos  */
    268  1.1  christos int
    269  1.2  christos f_w9600(SCR *sp, OPTION *op, const char *str, u_long *valp)
    270  1.1  christos {
    271  1.1  christos 	u_long v;
    272  1.1  christos 
    273  1.1  christos 	/* Historical behavior for w9600 was > 1200. */
    274  1.1  christos 	if (sp->gp->scr_baud(sp, &v))
    275  1.1  christos 		return (1);
    276  1.1  christos 	if (v <= 4800)
    277  1.1  christos 		return (0);
    278  1.1  christos 
    279  1.1  christos 	return (f_window(sp, op, str, valp));
    280  1.1  christos }
    281  1.1  christos 
    282  1.1  christos /*
    283  1.2  christos  * PUBLIC: int f_window __P((SCR *, OPTION *, const char *, u_long *));
    284  1.1  christos  */
    285  1.1  christos int
    286  1.2  christos f_window(SCR *sp, OPTION *op, const char *str, u_long *valp)
    287  1.1  christos {
    288  1.1  christos 	if (*valp >= O_VAL(sp, O_LINES) - 1 &&
    289  1.1  christos 	    (*valp = O_VAL(sp, O_LINES) - 1) == 0)
    290  1.1  christos 		*valp = 1;
    291  1.1  christos 	return (0);
    292  1.1  christos }
    293  1.1  christos 
    294  1.1  christos /*
    295  1.2  christos  * PUBLIC: int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
    296  1.1  christos  */
    297  1.1  christos int
    298  1.2  christos f_encoding(SCR *sp, OPTION *op, const char *str, u_long *valp)
    299  1.1  christos {
    300  1.1  christos 	int offset = op - sp->opts;
    301  1.1  christos 
    302  1.1  christos 	return conv_enc(sp, offset, str);
    303  1.1  christos }
    304  1.4       rin 
    305  1.4       rin #ifdef IMCTRL
    306  1.4       rin /*
    307  1.4       rin  * PUBLIC: #ifdef IMCTRL
    308  1.4       rin  * PUBLIC: int f_imctrl __P((SCR *, OPTION *, const char *, u_long *));
    309  1.4       rin  * PUBLIC: #endif
    310  1.4       rin  */
    311  1.4       rin int
    312  1.4       rin f_imctrl(SCR *sp, OPTION *op, const char *str, u_long *valp)
    313  1.4       rin {
    314  1.4       rin 
    315  1.4       rin 	if (*valp)
    316  1.4       rin 		sp->gp->scr_imctrl(sp, IMCTRL_INIT);
    317  1.4       rin 	return (0);
    318  1.4       rin }
    319  1.4       rin #endif
    320