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