xref: /openbsd-src/lib/libform/fld_arg.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: fld_arg.c,v 1.4 2001/01/22 18:02:11 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997            *
33  ****************************************************************************/
34 
35 #include "form.priv.h"
36 
37 MODULE_ID("$From: fld_arg.c,v 1.5 2000/12/10 02:09:37 tom Exp $")
38 
39 /*---------------------------------------------------------------------------
40 |   Facility      :  libnform
41 |   Function      :  int set_fieldtype_arg(
42 |                            FIELDTYPE *typ,
43 |                            void * (* const make_arg)(va_list *),
44 |                            void * (* const copy_arg)(const void *),
45 |                            void   (* const free_arg)(void *) )
46 |
47 |   Description   :  Connects to the type additional arguments necessary
48 |                    for a set_field_type call. The various function pointer
49 |                    arguments are:
50 |                       make_arg : allocates a structure for the field
51 |                                  specific parameters.
52 |                       copy_arg : duplicate the structure created by
53 |                                  make_arg
54 |                       free_arg : Release the memory allocated by make_arg
55 |                                  or copy_arg
56 |
57 |                    At least make_arg must be non-NULL.
58 |                    You may pass NULL for copy_arg and free_arg if your
59 |                    make_arg function doesn't allocate memory and your
60 |                    arg fits into the storage for a (void*).
61 |
62 |   Return Values :  E_OK           - success
63 |                    E_BAD_ARGUMENT - invalid argument
64 +--------------------------------------------------------------------------*/
65 NCURSES_EXPORT(int)
66 set_fieldtype_arg
67     (FIELDTYPE * typ,
68      void * (* const make_arg)(va_list *),
69      void * (* const copy_arg)(const void *),
70      void   (* const free_arg)(void *))
71 {
72   if ( !typ || !make_arg )
73     RETURN(E_BAD_ARGUMENT);
74 
75   typ->status |= _HAS_ARGS;
76   typ->makearg = make_arg;
77   typ->copyarg = copy_arg;
78   typ->freearg = free_arg;
79   RETURN(E_OK);
80 }
81 
82 /*---------------------------------------------------------------------------
83 |   Facility      :  libnform
84 |   Function      :  void *field_arg(const FIELD *field)
85 |
86 |   Description   :  Retrieve pointer to the fields argument structure.
87 |
88 |   Return Values :  Pointer to structure or NULL if none is defined.
89 +--------------------------------------------------------------------------*/
90 NCURSES_EXPORT(void *)
91 field_arg (const FIELD * field)
92 {
93   return Normalize_Field(field)->arg;
94 }
95 
96 /* fld_arg.c ends here */
97