1 /****************************************************************************
2 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2004,2010 Free Software Foundation, Inc. *
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: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
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. *
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 *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 #include "form.priv.h"
36 MODULE_ID("$Id: fld_opts.c,v 1.16 2021/06/17 21:20:30 tom Exp $")
38 /*----------------------------------------------------------------------------
39 Field-Options manipulation routines
40 --------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------
44 | Function : int set_field_opts(FIELD *field, Field_Options opts)
46 | Description : Turns on the named options for this field and turns
47 | off all the remaining options.
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 +--------------------------------------------------------------------------*/
55 set_field_opts(FIELD *field, Field_Options opts)
57 int res = E_BAD_ARGUMENT;
59 T((T_CALLED("set_field_opts(%p,%d)"), (void *)field, opts));
61 opts &= ALL_FIELD_OPTS;
62 if (!(opts & ~ALL_FIELD_OPTS))
63 res = _nc_Synchronize_Options(Normalize_Field(field), opts);
67 /*---------------------------------------------------------------------------
69 | Function : Field_Options field_opts(const FIELD *field)
71 | Description : Retrieve the field's options.
73 | Return Values : The options.
74 +--------------------------------------------------------------------------*/
75 FORM_EXPORT(Field_Options)
76 field_opts(const FIELD *field)
78 T((T_CALLED("field_opts(%p)"), (const void *)field));
80 returnCode(ALL_FIELD_OPTS & Normalize_Field(field)->opts);
83 /*---------------------------------------------------------------------------
85 | Function : int field_opts_on(FIELD *field, Field_Options opts)
87 | Description : Turns on the named options for this field and all the
88 | remaining options are unchanged.
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 +--------------------------------------------------------------------------*/
96 field_opts_on(FIELD *field, Field_Options opts)
98 int res = E_BAD_ARGUMENT;
100 T((T_CALLED("field_opts_on(%p,%d)"), (void *)field, opts));
102 opts &= ALL_FIELD_OPTS;
103 if (!(opts & ~ALL_FIELD_OPTS))
105 Normalize_Field(field);
106 res = _nc_Synchronize_Options(field, field->opts | opts);
111 /*---------------------------------------------------------------------------
112 | Facility : libnform
113 | Function : int field_opts_off(FIELD *field, Field_Options opts)
115 | Description : Turns off the named options for this field and all the
116 | remaining options are unchanged.
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 +--------------------------------------------------------------------------*/
124 field_opts_off(FIELD *field, Field_Options opts)
126 int res = E_BAD_ARGUMENT;
128 T((T_CALLED("field_opts_off(%p,%d)"), (void *)field, opts));
130 opts &= ALL_FIELD_OPTS;
131 if (!(opts & ~ALL_FIELD_OPTS))
133 Normalize_Field(field);
134 res = _nc_Synchronize_Options(field, field->opts & ~opts);
139 /* fld_opts.c ends here */