1*c7ef0cfcSnicm /* $OpenBSD: fld_arg.c,v 1.7 2023/10/17 09:52:10 nicm Exp $ */
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm * Copyright 2018,2020 Thomas E. Dickey *
4*c7ef0cfcSnicm * Copyright 1998-2012,2016 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 ****************************************************************************/
348d0fca71Smillert
358d0fca71Smillert #include "form.priv.h"
368d0fca71Smillert
37*c7ef0cfcSnicm MODULE_ID("$Id: fld_arg.c,v 1.7 2023/10/17 09:52:10 nicm Exp $")
388d0fca71Smillert
398d0fca71Smillert /*---------------------------------------------------------------------------
408d0fca71Smillert | Facility : libnform
418d0fca71Smillert | Function : int set_fieldtype_arg(
428d0fca71Smillert | FIELDTYPE *typ,
438d0fca71Smillert | void * (* const make_arg)(va_list *),
448d0fca71Smillert | void * (* const copy_arg)(const void *),
458d0fca71Smillert | void (* const free_arg)(void *) )
468d0fca71Smillert |
478d0fca71Smillert | Description : Connects to the type additional arguments necessary
488d0fca71Smillert | for a set_field_type call. The various function pointer
498d0fca71Smillert | arguments are:
508d0fca71Smillert | make_arg : allocates a structure for the field
518d0fca71Smillert | specific parameters.
528d0fca71Smillert | copy_arg : duplicate the structure created by
538d0fca71Smillert | make_arg
548d0fca71Smillert | free_arg : Release the memory allocated by make_arg
558d0fca71Smillert | or copy_arg
568d0fca71Smillert |
578d0fca71Smillert | At least make_arg must be non-NULL.
588d0fca71Smillert | You may pass NULL for copy_arg and free_arg if your
598d0fca71Smillert | make_arg function doesn't allocate memory and your
608d0fca71Smillert | arg fits into the storage for a (void*).
618d0fca71Smillert |
628d0fca71Smillert | Return Values : E_OK - success
638d0fca71Smillert | E_BAD_ARGUMENT - invalid argument
648d0fca71Smillert +--------------------------------------------------------------------------*/
FORM_EXPORT(int)65*c7ef0cfcSnicm FORM_EXPORT(int)
6681d8c4e1Snicm set_fieldtype_arg(FIELDTYPE *typ,
678d0fca71Smillert void *(*const make_arg)(va_list *),
688d0fca71Smillert void *(*const copy_arg)(const void *),
698d0fca71Smillert void (*const free_arg) (void *))
708d0fca71Smillert {
71*c7ef0cfcSnicm TR_FUNC_BFR(3);
72*c7ef0cfcSnicm
73*c7ef0cfcSnicm T((T_CALLED("set_fieldtype_arg(%p,%s,%s,%s)"),
74*c7ef0cfcSnicm (void *)typ,
75*c7ef0cfcSnicm TR_FUNC_ARG(0, make_arg),
76*c7ef0cfcSnicm TR_FUNC_ARG(1, copy_arg),
77*c7ef0cfcSnicm TR_FUNC_ARG(2, free_arg)));
788d0fca71Smillert
7981d8c4e1Snicm if (typ != 0 && make_arg != (void *)0)
8081d8c4e1Snicm {
81*c7ef0cfcSnicm SetStatus(typ, _HAS_ARGS);
828d0fca71Smillert typ->makearg = make_arg;
838d0fca71Smillert typ->copyarg = copy_arg;
848d0fca71Smillert typ->freearg = free_arg;
858d0fca71Smillert RETURN(E_OK);
868d0fca71Smillert }
8781d8c4e1Snicm RETURN(E_BAD_ARGUMENT);
8881d8c4e1Snicm }
898d0fca71Smillert
908d0fca71Smillert /*---------------------------------------------------------------------------
918d0fca71Smillert | Facility : libnform
928d0fca71Smillert | Function : void *field_arg(const FIELD *field)
938d0fca71Smillert |
94*c7ef0cfcSnicm | Description : Retrieve pointer to the field's argument structure.
958d0fca71Smillert |
968d0fca71Smillert | Return Values : Pointer to structure or NULL if none is defined.
978d0fca71Smillert +--------------------------------------------------------------------------*/
98*c7ef0cfcSnicm FORM_EXPORT(void *)
field_arg(const FIELD * field)9984af20ceSmillert field_arg(const FIELD *field)
1008d0fca71Smillert {
101*c7ef0cfcSnicm T((T_CALLED("field_arg(%p)"), (const void *)field));
10281d8c4e1Snicm returnVoidPtr(Normalize_Field(field)->arg);
1038d0fca71Smillert }
1048d0fca71Smillert
1058d0fca71Smillert /* fld_arg.c ends here */
106