blob: ab4d55943a0771bbb98122c64628a36ad4751759 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2004,2010 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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
micky3879b9f5e72025-07-08 18:04:53 -040036MODULE_ID("$Id: fld_opts.c,v 1.16 2021/06/17 21:20:30 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053037
38/*----------------------------------------------------------------------------
39 Field-Options manipulation routines
40 --------------------------------------------------------------------------*/
41
42/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040043| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053044| Function : int set_field_opts(FIELD *field, Field_Options opts)
micky3879b9f5e72025-07-08 18:04:53 -040045|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053046| 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+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040054FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053055set_field_opts(FIELD *field, Field_Options opts)
56{
57 int res = E_BAD_ARGUMENT;
58
Steve Kondikae271bc2015-11-15 02:50:53 +010059 T((T_CALLED("set_field_opts(%p,%d)"), (void *)field, opts));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053060
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/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040068| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053069| Function : Field_Options field_opts(const FIELD *field)
micky3879b9f5e72025-07-08 18:04:53 -040070|
71| Description : Retrieve the field's options.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053072|
73| Return Values : The options.
74+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040075FORM_EXPORT(Field_Options)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053076field_opts(const FIELD *field)
77{
Steve Kondikae271bc2015-11-15 02:50:53 +010078 T((T_CALLED("field_opts(%p)"), (const void *)field));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053079
80 returnCode(ALL_FIELD_OPTS & Normalize_Field(field)->opts);
81}
82
83/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040084| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053085| Function : int field_opts_on(FIELD *field, Field_Options opts)
micky3879b9f5e72025-07-08 18:04:53 -040086|
87| Description : Turns on the named options for this field and all the
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053088| 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+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040095FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053096field_opts_on(FIELD *field, Field_Options opts)
97{
98 int res = E_BAD_ARGUMENT;
99
Steve Kondikae271bc2015-11-15 02:50:53 +0100100 T((T_CALLED("field_opts_on(%p,%d)"), (void *)field, opts));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530101
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/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400112| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530113| Function : int field_opts_off(FIELD *field, Field_Options opts)
micky3879b9f5e72025-07-08 18:04:53 -0400114|
115| Description : Turns off the named options for this field and all the
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530116| 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+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -0400123FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530124field_opts_off(FIELD *field, Field_Options opts)
125{
126 int res = E_BAD_ARGUMENT;
127
Steve Kondikae271bc2015-11-15 02:50:53 +0100128 T((T_CALLED("field_opts_off(%p,%d)"), (void *)field, opts));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530129
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 */