10e3d5408SPeter Wemm /****************************************************************************
2e1865124SBaptiste Daroussin * Copyright 2018,2020 Thomas E. Dickey *
3e1865124SBaptiste Daroussin * Copyright 1998-2012,2016 Free Software Foundation, Inc. *
40e3d5408SPeter Wemm * *
50e3d5408SPeter Wemm * Permission is hereby granted, free of charge, to any person obtaining a *
60e3d5408SPeter Wemm * copy of this software and associated documentation files (the *
70e3d5408SPeter Wemm * "Software"), to deal in the Software without restriction, including *
80e3d5408SPeter Wemm * without limitation the rights to use, copy, modify, merge, publish, *
90e3d5408SPeter Wemm * distribute, distribute with modifications, sublicense, and/or sell *
100e3d5408SPeter Wemm * copies of the Software, and to permit persons to whom the Software is *
110e3d5408SPeter Wemm * furnished to do so, subject to the following conditions: *
120e3d5408SPeter Wemm * *
130e3d5408SPeter Wemm * The above copyright notice and this permission notice shall be included *
140e3d5408SPeter Wemm * in all copies or substantial portions of the Software. *
150e3d5408SPeter Wemm * *
160e3d5408SPeter Wemm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
170e3d5408SPeter Wemm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
180e3d5408SPeter Wemm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
190e3d5408SPeter Wemm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
200e3d5408SPeter Wemm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
210e3d5408SPeter Wemm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
220e3d5408SPeter Wemm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
230e3d5408SPeter Wemm * *
240e3d5408SPeter Wemm * Except as contained in this notice, the name(s) of the above copyright *
250e3d5408SPeter Wemm * holders shall not be used in advertising or otherwise to promote the *
260e3d5408SPeter Wemm * sale, use or other dealings in this Software without prior written *
270e3d5408SPeter Wemm * authorization. *
280e3d5408SPeter Wemm ****************************************************************************/
290e3d5408SPeter Wemm
300e3d5408SPeter Wemm /****************************************************************************
314a1a9510SRong-En Fan * Author: Juergen Pfeifer, 1995,1997 *
320e3d5408SPeter Wemm ****************************************************************************/
330e3d5408SPeter Wemm
340e3d5408SPeter Wemm #include "form.priv.h"
350e3d5408SPeter Wemm
36*7a656419SBaptiste Daroussin MODULE_ID("$Id: fld_arg.c,v 1.18 2020/12/11 22:05:24 tom Exp $")
370e3d5408SPeter Wemm
380e3d5408SPeter Wemm /*---------------------------------------------------------------------------
390e3d5408SPeter Wemm | Facility : libnform
400e3d5408SPeter Wemm | Function : int set_fieldtype_arg(
410e3d5408SPeter Wemm | FIELDTYPE *typ,
420e3d5408SPeter Wemm | void * (* const make_arg)(va_list *),
430e3d5408SPeter Wemm | void * (* const copy_arg)(const void *),
440e3d5408SPeter Wemm | void (* const free_arg)(void *) )
450e3d5408SPeter Wemm |
460e3d5408SPeter Wemm | Description : Connects to the type additional arguments necessary
470e3d5408SPeter Wemm | for a set_field_type call. The various function pointer
480e3d5408SPeter Wemm | arguments are:
490e3d5408SPeter Wemm | make_arg : allocates a structure for the field
500e3d5408SPeter Wemm | specific parameters.
510e3d5408SPeter Wemm | copy_arg : duplicate the structure created by
520e3d5408SPeter Wemm | make_arg
530e3d5408SPeter Wemm | free_arg : Release the memory allocated by make_arg
540e3d5408SPeter Wemm | or copy_arg
550e3d5408SPeter Wemm |
560e3d5408SPeter Wemm | At least make_arg must be non-NULL.
570e3d5408SPeter Wemm | You may pass NULL for copy_arg and free_arg if your
580e3d5408SPeter Wemm | make_arg function doesn't allocate memory and your
590e3d5408SPeter Wemm | arg fits into the storage for a (void*).
600e3d5408SPeter Wemm |
610e3d5408SPeter Wemm | Return Values : E_OK - success
620e3d5408SPeter Wemm | E_BAD_ARGUMENT - invalid argument
630e3d5408SPeter Wemm +--------------------------------------------------------------------------*/
FORM_EXPORT(int)64*7a656419SBaptiste Daroussin FORM_EXPORT(int)
654a1a9510SRong-En Fan set_fieldtype_arg(FIELDTYPE *typ,
660e3d5408SPeter Wemm void *(*const make_arg)(va_list *),
670e3d5408SPeter Wemm void *(*const copy_arg)(const void *),
680e3d5408SPeter Wemm void (*const free_arg) (void *))
690e3d5408SPeter Wemm {
70aae38d10SBaptiste Daroussin TR_FUNC_BFR(3);
71aae38d10SBaptiste Daroussin
72aae38d10SBaptiste Daroussin T((T_CALLED("set_fieldtype_arg(%p,%s,%s,%s)"),
73aae38d10SBaptiste Daroussin (void *)typ,
74aae38d10SBaptiste Daroussin TR_FUNC_ARG(0, make_arg),
75aae38d10SBaptiste Daroussin TR_FUNC_ARG(1, copy_arg),
76aae38d10SBaptiste Daroussin TR_FUNC_ARG(2, free_arg)));
770e3d5408SPeter Wemm
784a1a9510SRong-En Fan if (typ != 0 && make_arg != (void *)0)
794a1a9510SRong-En Fan {
8073f0a83dSXin LI SetStatus(typ, _HAS_ARGS);
810e3d5408SPeter Wemm typ->makearg = make_arg;
820e3d5408SPeter Wemm typ->copyarg = copy_arg;
830e3d5408SPeter Wemm typ->freearg = free_arg;
840e3d5408SPeter Wemm RETURN(E_OK);
850e3d5408SPeter Wemm }
864a1a9510SRong-En Fan RETURN(E_BAD_ARGUMENT);
874a1a9510SRong-En Fan }
880e3d5408SPeter Wemm
890e3d5408SPeter Wemm /*---------------------------------------------------------------------------
900e3d5408SPeter Wemm | Facility : libnform
910e3d5408SPeter Wemm | Function : void *field_arg(const FIELD *field)
920e3d5408SPeter Wemm |
93*7a656419SBaptiste Daroussin | Description : Retrieve pointer to the field's argument structure.
940e3d5408SPeter Wemm |
950e3d5408SPeter Wemm | Return Values : Pointer to structure or NULL if none is defined.
960e3d5408SPeter Wemm +--------------------------------------------------------------------------*/
97*7a656419SBaptiste Daroussin FORM_EXPORT(void *)
field_arg(const FIELD * field)987a69bbfbSPeter Wemm field_arg(const FIELD *field)
990e3d5408SPeter Wemm {
10006bfebdeSXin LI T((T_CALLED("field_arg(%p)"), (const void *)field));
1014a1a9510SRong-En Fan returnVoidPtr(Normalize_Field(field)->arg);
1020e3d5408SPeter Wemm }
1030e3d5408SPeter Wemm
1040e3d5408SPeter Wemm /* fld_arg.c ends here */
105