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