xref: /netbsd/external/bsd/nvi/dist/common/options.h (revision 08d478e3)
1*08d478e3Schristos /*	$NetBSD: options.h,v 1.2 2013/11/22 15:52:05 christos Exp $ */
23a571abcSchristos /*-
33a571abcSchristos  * Copyright (c) 1991, 1993, 1994
43a571abcSchristos  *	The Regents of the University of California.  All rights reserved.
53a571abcSchristos  * Copyright (c) 1991, 1993, 1994, 1995, 1996
63a571abcSchristos  *	Keith Bostic.  All rights reserved.
73a571abcSchristos  *
83a571abcSchristos  * See the LICENSE file for redistribution information.
93a571abcSchristos  *
103a571abcSchristos  *	Id: options.h,v 10.20 2001/06/09 18:26:28 skimo Exp  (Berkeley) Date: 2001/06/09 18:26:28
113a571abcSchristos  */
123a571abcSchristos 
133a571abcSchristos /*
143a571abcSchristos  * Edit option information.  Historically, if you set a boolean or numeric
153a571abcSchristos  * edit option value to its "default" value, it didn't show up in the :set
163a571abcSchristos  * display, i.e. it wasn't considered "changed".  String edit options would
173a571abcSchristos  * show up as changed, regardless.  We maintain a parallel set of values
183a571abcSchristos  * which are the default values and never consider an edit option changed
193a571abcSchristos  * if it was reset to the default value.
203a571abcSchristos  *
213a571abcSchristos  * Macros to retrieve boolean, integral and string option values, and to
223a571abcSchristos  * set, clear and test boolean option values.  Some options (secure, lines,
233a571abcSchristos  * columns, terminal type) are global in scope, and are therefore stored
243a571abcSchristos  * in the global area.  The offset in the global options array is stored
253a571abcSchristos  * in the screen's value field.  This is set up when the options are first
263a571abcSchristos  * initialized.
273a571abcSchristos  */
283a571abcSchristos #define	O_V(sp, o, fld)							\
293a571abcSchristos 	(F_ISSET(&(sp)->opts[(o)], OPT_GLOBAL) ?			\
303a571abcSchristos 	    (sp)->gp->opts[(sp)->opts[(o)].o_cur.val].fld :		\
313a571abcSchristos 	    (sp)->opts[(o)].fld)
323a571abcSchristos 
333a571abcSchristos /* Global option macros. */
343a571abcSchristos #define	OG_CLR(gp, o)		((gp)->opts[(o)].o_cur.val) = 0
353a571abcSchristos #define	OG_SET(gp, o)		((gp)->opts[(o)].o_cur.val) = 1
363a571abcSchristos #define	OG_STR(gp, o)		((gp)->opts[(o)].o_cur.str)
373a571abcSchristos #define	OG_VAL(gp, o)		((gp)->opts[(o)].o_cur.val)
383a571abcSchristos #define	OG_ISSET(gp, o)		OG_VAL(gp, o)
393a571abcSchristos 
403a571abcSchristos #define	OG_D_STR(gp, o)		((gp)->opts[(o)].o_def.str)
413a571abcSchristos #define	OG_D_VAL(gp, o)		((gp)->opts[(o)].o_def.val)
423a571abcSchristos 
433a571abcSchristos /*
443a571abcSchristos  * Flags to o_set(); need explicit OS_STR as can be setting the value to
453a571abcSchristos  * NULL.
463a571abcSchristos  */
473a571abcSchristos #define	OS_DEF		0x01		/* Set the default value. */
483a571abcSchristos #define	OS_NOFREE	0x02		/* Don't free the old string. */
493a571abcSchristos #define	OS_STR		0x04		/* Set to string argument. */
503a571abcSchristos #define	OS_STRDUP	0x08		/* Copy then set to string argument. */
513a571abcSchristos 
523a571abcSchristos struct _option {
533a571abcSchristos 	union {
543a571abcSchristos 		u_long	 val;		/* Value or boolean. */
55*08d478e3Schristos 		const char *str;	/* String. */
563a571abcSchristos 	} o_cur;
573a571abcSchristos #define	O_CLR(sp, o)		o_set(sp, o, 0, NULL, 0)
583a571abcSchristos #define	O_SET(sp, o)		o_set(sp, o, 0, NULL, 1)
593a571abcSchristos #define	O_STR(sp, o)		O_V(sp, o, o_cur.str)
603a571abcSchristos #define	O_VAL(sp, o)		O_V(sp, o, o_cur.val)
613a571abcSchristos #define	O_ISSET(sp, o)		O_VAL(sp, o)
623a571abcSchristos 
633a571abcSchristos 	union {
643a571abcSchristos 		u_long	 val;		/* Value or boolean. */
65*08d478e3Schristos 		const char *str;	/* String. */
663a571abcSchristos 	} o_def;
673a571abcSchristos #define	O_D_CLR(sp, o)		o_set(sp, o, OS_DEF, NULL, 0)
683a571abcSchristos #define	O_D_SET(sp, o)		o_set(sp, o, OS_DEF, NULL, 1)
693a571abcSchristos #define	O_D_STR(sp, o)		O_V(sp, o, o_def.str)
703a571abcSchristos #define	O_D_VAL(sp, o)		O_V(sp, o, o_def.val)
713a571abcSchristos #define	O_D_ISSET(sp, o)	O_D_VAL(sp, o)
723a571abcSchristos 
733a571abcSchristos #define	OPT_GLOBAL	0x01		/* Option is global. */
743a571abcSchristos #define	OPT_SELECTED	0x02		/* Selected for display. */
753a571abcSchristos 	u_int8_t flags;
763a571abcSchristos };
773a571abcSchristos 
783a571abcSchristos /* List of option names, associated update functions and information. */
793a571abcSchristos struct _optlist {
80*08d478e3Schristos 	const CHAR_T *name;		/* Name. */
813a571abcSchristos 					/* Change function. */
82*08d478e3Schristos 	int	(*func) __P((SCR *, OPTION *, const char *, u_long *));
833a571abcSchristos 					/* Type of object. */
843a571abcSchristos 	enum { OPT_0BOOL, OPT_1BOOL, OPT_NUM, OPT_STR } type;
853a571abcSchristos 
863a571abcSchristos #define	OPT_ADISP	0x001		/* Always display the option. */
873a571abcSchristos #define	OPT_ALWAYS	0x002		/* Always call the support function. */
883a571abcSchristos #define	OPT_NDISP	0x004		/* Never display the option. */
893a571abcSchristos #define	OPT_NOSAVE	0x008		/* Mkexrc command doesn't save. */
903a571abcSchristos #define	OPT_NOSET	0x010		/* Option may not be set. */
913a571abcSchristos #define	OPT_NOUNSET	0x020		/* Option may not be unset. */
923a571abcSchristos #define	OPT_NOZERO	0x040		/* Option may not be set to 0. */
93*08d478e3Schristos #define	OPT_PAIRS	0x080		/* String with even length */
943a571abcSchristos 	u_int8_t flags;
953a571abcSchristos };
963a571abcSchristos 
973a571abcSchristos /* Option argument to opts_dump(). */
983a571abcSchristos enum optdisp { NO_DISPLAY, ALL_DISPLAY, CHANGED_DISPLAY, SELECT_DISPLAY };
993a571abcSchristos 
1003a571abcSchristos /* Options array. */
1013a571abcSchristos extern OPTLIST const optlist[];
1023a571abcSchristos 
1033a571abcSchristos #include "options_def.h"
104