1*c7ef0cfcSnicm /* $OpenBSD: fld_opts.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm * Copyright 2020,2021 Thomas E. Dickey *
4*c7ef0cfcSnicm * Copyright 1998-2004,2010 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 ****************************************************************************/
3481d8c4e1Snicm
358d0fca71Smillert #include "form.priv.h"
368d0fca71Smillert
37*c7ef0cfcSnicm MODULE_ID("$Id: fld_opts.c,v 1.8 2023/10/17 09:52:10 nicm Exp $")
388d0fca71Smillert
398d0fca71Smillert /*----------------------------------------------------------------------------
408d0fca71Smillert Field-Options manipulation routines
418d0fca71Smillert --------------------------------------------------------------------------*/
428d0fca71Smillert
438d0fca71Smillert /*---------------------------------------------------------------------------
448d0fca71Smillert | Facility : libnform
458d0fca71Smillert | Function : int set_field_opts(FIELD *field, Field_Options opts)
468d0fca71Smillert |
478d0fca71Smillert | Description : Turns on the named options for this field and turns
488d0fca71Smillert | off all the remaining options.
498d0fca71Smillert |
508d0fca71Smillert | Return Values : E_OK - success
518d0fca71Smillert | E_CURRENT - the field is the current field
528d0fca71Smillert | E_BAD_ARGUMENT - invalid options
538d0fca71Smillert | E_SYSTEM_ERROR - system error
548d0fca71Smillert +--------------------------------------------------------------------------*/
FORM_EXPORT(int)55*c7ef0cfcSnicm FORM_EXPORT(int)
5684af20ceSmillert set_field_opts(FIELD *field, Field_Options opts)
578d0fca71Smillert {
588d0fca71Smillert int res = E_BAD_ARGUMENT;
5981d8c4e1Snicm
60*c7ef0cfcSnicm T((T_CALLED("set_field_opts(%p,%d)"), (void *)field, opts));
6181d8c4e1Snicm
62cf92880fSmillert opts &= ALL_FIELD_OPTS;
638d0fca71Smillert if (!(opts & ~ALL_FIELD_OPTS))
648d0fca71Smillert res = _nc_Synchronize_Options(Normalize_Field(field), opts);
658d0fca71Smillert RETURN(res);
668d0fca71Smillert }
678d0fca71Smillert
688d0fca71Smillert /*---------------------------------------------------------------------------
698d0fca71Smillert | Facility : libnform
708d0fca71Smillert | Function : Field_Options field_opts(const FIELD *field)
718d0fca71Smillert |
72*c7ef0cfcSnicm | Description : Retrieve the field's options.
738d0fca71Smillert |
748d0fca71Smillert | Return Values : The options.
758d0fca71Smillert +--------------------------------------------------------------------------*/
76*c7ef0cfcSnicm FORM_EXPORT(Field_Options)
field_opts(const FIELD * field)7784af20ceSmillert field_opts(const FIELD *field)
788d0fca71Smillert {
79*c7ef0cfcSnicm T((T_CALLED("field_opts(%p)"), (const void *)field));
8081d8c4e1Snicm
8181d8c4e1Snicm returnCode(ALL_FIELD_OPTS & Normalize_Field(field)->opts);
828d0fca71Smillert }
838d0fca71Smillert
848d0fca71Smillert /*---------------------------------------------------------------------------
858d0fca71Smillert | Facility : libnform
868d0fca71Smillert | Function : int field_opts_on(FIELD *field, Field_Options opts)
878d0fca71Smillert |
888d0fca71Smillert | Description : Turns on the named options for this field and all the
898d0fca71Smillert | remaining options are unchanged.
908d0fca71Smillert |
918d0fca71Smillert | Return Values : E_OK - success
928d0fca71Smillert | E_CURRENT - the field is the current field
938d0fca71Smillert | E_BAD_ARGUMENT - invalid options
948d0fca71Smillert | E_SYSTEM_ERROR - system error
958d0fca71Smillert +--------------------------------------------------------------------------*/
96*c7ef0cfcSnicm FORM_EXPORT(int)
field_opts_on(FIELD * field,Field_Options opts)9784af20ceSmillert field_opts_on(FIELD *field, Field_Options opts)
988d0fca71Smillert {
998d0fca71Smillert int res = E_BAD_ARGUMENT;
1008d0fca71Smillert
101*c7ef0cfcSnicm T((T_CALLED("field_opts_on(%p,%d)"), (void *)field, opts));
10281d8c4e1Snicm
103cf92880fSmillert opts &= ALL_FIELD_OPTS;
1048d0fca71Smillert if (!(opts & ~ALL_FIELD_OPTS))
1058d0fca71Smillert {
1068d0fca71Smillert Normalize_Field(field);
1078d0fca71Smillert res = _nc_Synchronize_Options(field, field->opts | opts);
1088d0fca71Smillert }
1098d0fca71Smillert RETURN(res);
1108d0fca71Smillert }
1118d0fca71Smillert
1128d0fca71Smillert /*---------------------------------------------------------------------------
1138d0fca71Smillert | Facility : libnform
1148d0fca71Smillert | Function : int field_opts_off(FIELD *field, Field_Options opts)
1158d0fca71Smillert |
1168d0fca71Smillert | Description : Turns off the named options for this field and all the
1178d0fca71Smillert | remaining options are unchanged.
1188d0fca71Smillert |
1198d0fca71Smillert | Return Values : E_OK - success
1208d0fca71Smillert | E_CURRENT - the field is the current field
1218d0fca71Smillert | E_BAD_ARGUMENT - invalid options
1228d0fca71Smillert | E_SYSTEM_ERROR - system error
1238d0fca71Smillert +--------------------------------------------------------------------------*/
124*c7ef0cfcSnicm FORM_EXPORT(int)
field_opts_off(FIELD * field,Field_Options opts)12584af20ceSmillert field_opts_off(FIELD *field, Field_Options opts)
1268d0fca71Smillert {
1278d0fca71Smillert int res = E_BAD_ARGUMENT;
1288d0fca71Smillert
129*c7ef0cfcSnicm T((T_CALLED("field_opts_off(%p,%d)"), (void *)field, opts));
13081d8c4e1Snicm
131cf92880fSmillert opts &= ALL_FIELD_OPTS;
1328d0fca71Smillert if (!(opts & ~ALL_FIELD_OPTS))
1338d0fca71Smillert {
1348d0fca71Smillert Normalize_Field(field);
1358d0fca71Smillert res = _nc_Synchronize_Options(field, field->opts & ~opts);
1368d0fca71Smillert }
1378d0fca71Smillert RETURN(res);
1388d0fca71Smillert }
1398d0fca71Smillert
1408d0fca71Smillert /* fld_opts.c ends here */
141