xref: /freebsd/contrib/nvi/common/options.h (revision a0b9e2e854027e6ff61fb075a1309dbc71c42b54)
1 /*-
2  * Copyright (c) 1991, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1991, 1993, 1994, 1995, 1996
5  *	Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9 
10 /*
11  * Edit option information.  Historically, if you set a boolean or numeric
12  * edit option value to its "default" value, it didn't show up in the :set
13  * display, i.e. it wasn't considered "changed".  String edit options would
14  * show up as changed, regardless.  We maintain a parallel set of values
15  * which are the default values and never consider an edit option changed
16  * if it was reset to the default value.
17  *
18  * Macros to retrieve boolean, integral and string option values, and to
19  * set, clear and test boolean option values.  Some options (secure, lines,
20  * columns, terminal type) are global in scope, and are therefore stored
21  * in the global area.  The offset in the global options array is stored
22  * in the screen's value field.  This is set up when the options are first
23  * initialized.
24  */
25 #define	O_V(sp, o, fld)							\
26 	(F_ISSET(&(sp)->opts[(o)], OPT_GLOBAL) ?			\
27 	    (sp)->gp->opts[(sp)->opts[(o)].o_cur.val].fld :		\
28 	    (sp)->opts[(o)].fld)
29 
30 /* Global option macros. */
31 #define	OG_CLR(gp, o)		((gp)->opts[(o)].o_cur.val) = 0
32 #define	OG_SET(gp, o)		((gp)->opts[(o)].o_cur.val) = 1
33 #define	OG_STR(gp, o)		((gp)->opts[(o)].o_cur.str)
34 #define	OG_VAL(gp, o)		((gp)->opts[(o)].o_cur.val)
35 #define	OG_ISSET(gp, o)		OG_VAL(gp, o)
36 
37 #define	OG_D_STR(gp, o)		((gp)->opts[(o)].o_def.str)
38 #define	OG_D_VAL(gp, o)		((gp)->opts[(o)].o_def.val)
39 
40 /*
41  * Flags to o_set(); need explicit OS_STR as can be setting the value to
42  * NULL.
43  */
44 #define	OS_DEF		0x01		/* Set the default value. */
45 #define	OS_NOFREE	0x02		/* Don't free the old string. */
46 #define	OS_STR		0x04		/* Set to string argument. */
47 #define	OS_STRDUP	0x08		/* Copy then set to string argument. */
48 
49 struct _option {
50 	union {
51 		u_long	 val;		/* Value or boolean. */
52 		char	*str;		/* String. */
53 	} o_cur;
54 #define	O_CLR(sp, o)		o_set(sp, o, 0, NULL, 0)
55 #define	O_SET(sp, o)		o_set(sp, o, 0, NULL, 1)
56 #define	O_STR(sp, o)		O_V(sp, o, o_cur.str)
57 #define	O_VAL(sp, o)		O_V(sp, o, o_cur.val)
58 #define	O_ISSET(sp, o)		O_VAL(sp, o)
59 
60 	union {
61 		u_long	 val;		/* Value or boolean. */
62 		char	*str;		/* String. */
63 	} o_def;
64 #define	O_D_CLR(sp, o)		o_set(sp, o, OS_DEF, NULL, 0)
65 #define	O_D_SET(sp, o)		o_set(sp, o, OS_DEF, NULL, 1)
66 #define	O_D_STR(sp, o)		O_V(sp, o, o_def.str)
67 #define	O_D_VAL(sp, o)		O_V(sp, o, o_def.val)
68 #define	O_D_ISSET(sp, o)	O_D_VAL(sp, o)
69 
70 #define	OPT_GLOBAL	0x01		/* Option is global. */
71 #define	OPT_SELECTED	0x02		/* Selected for display. */
72 	u_int8_t flags;
73 };
74 
75 /* List of option names, associated update functions and information. */
76 struct _optlist {
77 	CHAR_T	*name;			/* Name. */
78 					/* Change function. */
79 	int	(*func)(SCR *, OPTION *, char *, u_long *);
80 					/* Type of object. */
81 	enum { OPT_0BOOL, OPT_1BOOL, OPT_NUM, OPT_STR } type;
82 
83 #define	OPT_ADISP	0x001		/* Always display the option. */
84 #define	OPT_ALWAYS	0x002		/* Always call the support function. */
85 #define	OPT_NDISP	0x004		/* Never display the option. */
86 #define	OPT_NOSAVE	0x008		/* Mkexrc command doesn't save. */
87 #define	OPT_NOSET	0x010		/* Option may not be set. */
88 #define	OPT_NOUNSET	0x020		/* Option may not be unset. */
89 #define	OPT_NOZERO	0x040		/* Option may not be set to 0. */
90 #define	OPT_PAIRS	0x080		/* String with even length. */
91 	u_int8_t flags;
92 };
93 
94 /* Option argument to opts_dump(). */
95 enum optdisp { NO_DISPLAY, ALL_DISPLAY, CHANGED_DISPLAY, SELECT_DISPLAY };
96 
97 /* Options array. */
98 extern OPTLIST const optlist[];
99 
100 #include "options_def.h"
101