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