xref: /openbsd-src/lib/libform/frm_opts.c (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /*	$OpenBSD: frm_opts.c,v 1.10 2023/10/17 09:52:10 nicm Exp $	*/
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm  * Copyright 2020,2021 Thomas E. Dickey                                     *
4*c7ef0cfcSnicm  * Copyright 1998-2012,2013 Free Software Foundation, Inc.                  *
502f2426aSmillert  *                                                                          *
602f2426aSmillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
702f2426aSmillert  * copy of this software and associated documentation files (the            *
802f2426aSmillert  * "Software"), to deal in the Software without restriction, including      *
902f2426aSmillert  * without limitation the rights to use, copy, modify, merge, publish,      *
1002f2426aSmillert  * distribute, distribute with modifications, sublicense, and/or sell       *
1102f2426aSmillert  * copies of the Software, and to permit persons to whom the Software is    *
1202f2426aSmillert  * furnished to do so, subject to the following conditions:                 *
1302f2426aSmillert  *                                                                          *
1402f2426aSmillert  * The above copyright notice and this permission notice shall be included  *
1502f2426aSmillert  * in all copies or substantial portions of the Software.                   *
1602f2426aSmillert  *                                                                          *
1702f2426aSmillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1802f2426aSmillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1902f2426aSmillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
2002f2426aSmillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
2102f2426aSmillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2202f2426aSmillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2302f2426aSmillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2402f2426aSmillert  *                                                                          *
2502f2426aSmillert  * Except as contained in this notice, the name(s) of the above copyright   *
2602f2426aSmillert  * holders shall not be used in advertising or otherwise to promote the     *
2702f2426aSmillert  * sale, use or other dealings in this Software without prior written       *
2802f2426aSmillert  * authorization.                                                           *
2902f2426aSmillert  ****************************************************************************/
3002f2426aSmillert 
3102f2426aSmillert /****************************************************************************
3281d8c4e1Snicm  *   Author:  Juergen Pfeifer, 1995,1997                                    *
3302f2426aSmillert  ****************************************************************************/
34ae611fdaStholo 
35ae611fdaStholo #include "form.priv.h"
36ae611fdaStholo 
37*c7ef0cfcSnicm MODULE_ID("$Id: frm_opts.c,v 1.10 2023/10/17 09:52:10 nicm Exp $")
386cd90de4Smillert 
39ae611fdaStholo /*---------------------------------------------------------------------------
40ae611fdaStholo |   Facility      :  libnform
41ae611fdaStholo |   Function      :  int set_form_opts(FORM *form, Form_Options opts)
42ae611fdaStholo |
43ae611fdaStholo |   Description   :  Turns on the named options and turns off all the
44ae611fdaStholo |                    remaining options for that form.
45ae611fdaStholo |
46ae611fdaStholo |   Return Values :  E_OK              - success
47ae611fdaStholo |                    E_BAD_ARGUMENT    - invalid options
48ae611fdaStholo +--------------------------------------------------------------------------*/
FORM_EXPORT(int)49*c7ef0cfcSnicm FORM_EXPORT(int)
5084af20ceSmillert set_form_opts(FORM *form, Form_Options opts)
51ae611fdaStholo {
52*c7ef0cfcSnicm   T((T_CALLED("set_form_opts(%p,%d)"), (void *)form, opts));
5381d8c4e1Snicm 
54*c7ef0cfcSnicm   opts &= (Form_Options)ALL_FORM_OPTS;
55*c7ef0cfcSnicm   if ((unsigned)opts & ~ALL_FORM_OPTS)
56ae611fdaStholo     RETURN(E_BAD_ARGUMENT);
57ae611fdaStholo   else
58ae611fdaStholo     {
59ae611fdaStholo       Normalize_Form(form)->opts = opts;
60ae611fdaStholo       RETURN(E_OK);
61ae611fdaStholo     }
62ae611fdaStholo }
63ae611fdaStholo 
64ae611fdaStholo /*---------------------------------------------------------------------------
65ae611fdaStholo |   Facility      :  libnform
66ae611fdaStholo |   Function      :  Form_Options form_opts(const FORM *)
67ae611fdaStholo |
68ae611fdaStholo |   Description   :  Retrieves the current form options.
69ae611fdaStholo |
70ae611fdaStholo |   Return Values :  The option flags.
71ae611fdaStholo +--------------------------------------------------------------------------*/
72*c7ef0cfcSnicm FORM_EXPORT(Form_Options)
form_opts(const FORM * form)7384af20ceSmillert form_opts(const FORM *form)
74ae611fdaStholo {
75*c7ef0cfcSnicm   T((T_CALLED("form_opts(%p)"), (const void *)form));
76*c7ef0cfcSnicm   returnCode((Form_Options)((unsigned)Normalize_Form(form)->opts & ALL_FORM_OPTS));
77ae611fdaStholo }
78ae611fdaStholo 
79ae611fdaStholo /*---------------------------------------------------------------------------
80ae611fdaStholo |   Facility      :  libnform
81ae611fdaStholo |   Function      :  int form_opts_on(FORM *form, Form_Options opts)
82ae611fdaStholo |
83ae611fdaStholo |   Description   :  Turns on the named options; no other options are
84ae611fdaStholo |                    changed.
85ae611fdaStholo |
86ae611fdaStholo |   Return Values :  E_OK            - success
87ae611fdaStholo |                    E_BAD_ARGUMENT  - invalid options
88ae611fdaStholo +--------------------------------------------------------------------------*/
89*c7ef0cfcSnicm FORM_EXPORT(int)
form_opts_on(FORM * form,Form_Options opts)9084af20ceSmillert form_opts_on(FORM *form, Form_Options opts)
91ae611fdaStholo {
92*c7ef0cfcSnicm   T((T_CALLED("form_opts_on(%p,%d)"), (void *)form, opts));
9381d8c4e1Snicm 
94*c7ef0cfcSnicm   opts &= (Form_Options)ALL_FORM_OPTS;
95*c7ef0cfcSnicm   if ((unsigned)opts & ~ALL_FORM_OPTS)
96ae611fdaStholo     RETURN(E_BAD_ARGUMENT);
97ae611fdaStholo   else
98ae611fdaStholo     {
99ae611fdaStholo       Normalize_Form(form)->opts |= opts;
100ae611fdaStholo       RETURN(E_OK);
101ae611fdaStholo     }
102ae611fdaStholo }
103ae611fdaStholo 
104ae611fdaStholo /*---------------------------------------------------------------------------
105ae611fdaStholo |   Facility      :  libnform
106ae611fdaStholo |   Function      :  int form_opts_off(FORM *form, Form_Options opts)
107ae611fdaStholo |
108ae611fdaStholo |   Description   :  Turns off the named options; no other options are
109ae611fdaStholo |                    changed.
110ae611fdaStholo |
111ae611fdaStholo |   Return Values :  E_OK            - success
112ae611fdaStholo |                    E_BAD_ARGUMENT  - invalid options
113ae611fdaStholo +--------------------------------------------------------------------------*/
114*c7ef0cfcSnicm FORM_EXPORT(int)
form_opts_off(FORM * form,Form_Options opts)11584af20ceSmillert form_opts_off(FORM *form, Form_Options opts)
116ae611fdaStholo {
117*c7ef0cfcSnicm   T((T_CALLED("form_opts_off(%p,%d)"), (void *)form, opts));
11881d8c4e1Snicm 
119*c7ef0cfcSnicm   opts &= (Form_Options)ALL_FORM_OPTS;
120*c7ef0cfcSnicm   if ((unsigned)opts & ~ALL_FORM_OPTS)
121ae611fdaStholo     RETURN(E_BAD_ARGUMENT);
122ae611fdaStholo   else
123ae611fdaStholo     {
124ae611fdaStholo       Normalize_Form(form)->opts &= ~opts;
125ae611fdaStholo       RETURN(E_OK);
126ae611fdaStholo     }
127ae611fdaStholo }
128ae611fdaStholo 
129ae611fdaStholo /* frm_opts.c ends here */
130