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