1 /* $OpenBSD: frm_opts.c,v 1.10 2023/10/17 09:52:10 nicm Exp $ */ 2 /**************************************************************************** 3 * Copyright 2020,2021 Thomas E. Dickey * 4 * Copyright 1998-2012,2013 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Juergen Pfeifer, 1995,1997 * 33 ****************************************************************************/ 34 35 #include "form.priv.h" 36 37 MODULE_ID("$Id: frm_opts.c,v 1.10 2023/10/17 09:52:10 nicm Exp $") 38 39 /*--------------------------------------------------------------------------- 40 | Facility : libnform 41 | Function : int set_form_opts(FORM *form, Form_Options opts) 42 | 43 | Description : Turns on the named options and turns off all the 44 | remaining options for that form. 45 | 46 | Return Values : E_OK - success 47 | E_BAD_ARGUMENT - invalid options 48 +--------------------------------------------------------------------------*/ 49 FORM_EXPORT(int) 50 set_form_opts(FORM *form, Form_Options opts) 51 { 52 T((T_CALLED("set_form_opts(%p,%d)"), (void *)form, opts)); 53 54 opts &= (Form_Options)ALL_FORM_OPTS; 55 if ((unsigned)opts & ~ALL_FORM_OPTS) 56 RETURN(E_BAD_ARGUMENT); 57 else 58 { 59 Normalize_Form(form)->opts = opts; 60 RETURN(E_OK); 61 } 62 } 63 64 /*--------------------------------------------------------------------------- 65 | Facility : libnform 66 | Function : Form_Options form_opts(const FORM *) 67 | 68 | Description : Retrieves the current form options. 69 | 70 | Return Values : The option flags. 71 +--------------------------------------------------------------------------*/ 72 FORM_EXPORT(Form_Options) 73 form_opts(const FORM *form) 74 { 75 T((T_CALLED("form_opts(%p)"), (const void *)form)); 76 returnCode((Form_Options)((unsigned)Normalize_Form(form)->opts & ALL_FORM_OPTS)); 77 } 78 79 /*--------------------------------------------------------------------------- 80 | Facility : libnform 81 | Function : int form_opts_on(FORM *form, Form_Options opts) 82 | 83 | Description : Turns on the named options; no other options are 84 | changed. 85 | 86 | Return Values : E_OK - success 87 | E_BAD_ARGUMENT - invalid options 88 +--------------------------------------------------------------------------*/ 89 FORM_EXPORT(int) 90 form_opts_on(FORM *form, Form_Options opts) 91 { 92 T((T_CALLED("form_opts_on(%p,%d)"), (void *)form, opts)); 93 94 opts &= (Form_Options)ALL_FORM_OPTS; 95 if ((unsigned)opts & ~ALL_FORM_OPTS) 96 RETURN(E_BAD_ARGUMENT); 97 else 98 { 99 Normalize_Form(form)->opts |= opts; 100 RETURN(E_OK); 101 } 102 } 103 104 /*--------------------------------------------------------------------------- 105 | Facility : libnform 106 | Function : int form_opts_off(FORM *form, Form_Options opts) 107 | 108 | Description : Turns off the named options; no other options are 109 | changed. 110 | 111 | Return Values : E_OK - success 112 | E_BAD_ARGUMENT - invalid options 113 +--------------------------------------------------------------------------*/ 114 FORM_EXPORT(int) 115 form_opts_off(FORM *form, Form_Options opts) 116 { 117 T((T_CALLED("form_opts_off(%p,%d)"), (void *)form, opts)); 118 119 opts &= (Form_Options)ALL_FORM_OPTS; 120 if ((unsigned)opts & ~ALL_FORM_OPTS) 121 RETURN(E_BAD_ARGUMENT); 122 else 123 { 124 Normalize_Form(form)->opts &= ~opts; 125 RETURN(E_OK); 126 } 127 } 128 129 /* frm_opts.c ends here */ 130