1 /* $OpenBSD: fld_opts.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
2 /****************************************************************************
3 * Copyright 2020,2021 Thomas E. Dickey *
4 * Copyright 1998-2004,2010 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: fld_opts.c,v 1.8 2023/10/17 09:52:10 nicm Exp $")
38
39 /*----------------------------------------------------------------------------
40 Field-Options manipulation routines
41 --------------------------------------------------------------------------*/
42
43 /*---------------------------------------------------------------------------
44 | Facility : libnform
45 | Function : int set_field_opts(FIELD *field, Field_Options opts)
46 |
47 | Description : Turns on the named options for this field and turns
48 | off all the remaining options.
49 |
50 | Return Values : E_OK - success
51 | E_CURRENT - the field is the current field
52 | E_BAD_ARGUMENT - invalid options
53 | E_SYSTEM_ERROR - system error
54 +--------------------------------------------------------------------------*/
FORM_EXPORT(int)55 FORM_EXPORT(int)
56 set_field_opts(FIELD *field, Field_Options opts)
57 {
58 int res = E_BAD_ARGUMENT;
59
60 T((T_CALLED("set_field_opts(%p,%d)"), (void *)field, opts));
61
62 opts &= ALL_FIELD_OPTS;
63 if (!(opts & ~ALL_FIELD_OPTS))
64 res = _nc_Synchronize_Options(Normalize_Field(field), opts);
65 RETURN(res);
66 }
67
68 /*---------------------------------------------------------------------------
69 | Facility : libnform
70 | Function : Field_Options field_opts(const FIELD *field)
71 |
72 | Description : Retrieve the field's options.
73 |
74 | Return Values : The options.
75 +--------------------------------------------------------------------------*/
76 FORM_EXPORT(Field_Options)
field_opts(const FIELD * field)77 field_opts(const FIELD *field)
78 {
79 T((T_CALLED("field_opts(%p)"), (const void *)field));
80
81 returnCode(ALL_FIELD_OPTS & Normalize_Field(field)->opts);
82 }
83
84 /*---------------------------------------------------------------------------
85 | Facility : libnform
86 | Function : int field_opts_on(FIELD *field, Field_Options opts)
87 |
88 | Description : Turns on the named options for this field and all the
89 | remaining options are unchanged.
90 |
91 | Return Values : E_OK - success
92 | E_CURRENT - the field is the current field
93 | E_BAD_ARGUMENT - invalid options
94 | E_SYSTEM_ERROR - system error
95 +--------------------------------------------------------------------------*/
96 FORM_EXPORT(int)
field_opts_on(FIELD * field,Field_Options opts)97 field_opts_on(FIELD *field, Field_Options opts)
98 {
99 int res = E_BAD_ARGUMENT;
100
101 T((T_CALLED("field_opts_on(%p,%d)"), (void *)field, opts));
102
103 opts &= ALL_FIELD_OPTS;
104 if (!(opts & ~ALL_FIELD_OPTS))
105 {
106 Normalize_Field(field);
107 res = _nc_Synchronize_Options(field, field->opts | opts);
108 }
109 RETURN(res);
110 }
111
112 /*---------------------------------------------------------------------------
113 | Facility : libnform
114 | Function : int field_opts_off(FIELD *field, Field_Options opts)
115 |
116 | Description : Turns off the named options for this field and all the
117 | remaining options are unchanged.
118 |
119 | Return Values : E_OK - success
120 | E_CURRENT - the field is the current field
121 | E_BAD_ARGUMENT - invalid options
122 | E_SYSTEM_ERROR - system error
123 +--------------------------------------------------------------------------*/
124 FORM_EXPORT(int)
field_opts_off(FIELD * field,Field_Options opts)125 field_opts_off(FIELD *field, Field_Options opts)
126 {
127 int res = E_BAD_ARGUMENT;
128
129 T((T_CALLED("field_opts_off(%p,%d)"), (void *)field, opts));
130
131 opts &= ALL_FIELD_OPTS;
132 if (!(opts & ~ALL_FIELD_OPTS))
133 {
134 Normalize_Field(field);
135 res = _nc_Synchronize_Options(field, field->opts & ~opts);
136 }
137 RETURN(res);
138 }
139
140 /* fld_opts.c ends here */
141