xref: /openbsd-src/lib/libform/frm_hook.c (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1 /*	$OpenBSD: frm_hook.c,v 1.9 2023/10/17 09:52:10 nicm Exp $	*/
2 /****************************************************************************
3  * Copyright 2018,2020 Thomas E. Dickey                                     *
4  * Copyright 1998-2012,2016 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, 1995,1997                                    *
33  ****************************************************************************/
34 
35 #include "form.priv.h"
36 
37 MODULE_ID("$Id: frm_hook.c,v 1.9 2023/10/17 09:52:10 nicm Exp $")
38 
39 /* "Template" macro to generate function to set application specific hook */
40 #define GEN_HOOK_SET_FUNCTION( typ, name ) \
41 FORM_IMPEXP int NCURSES_API set_ ## typ ## _ ## name (FORM *form, Form_Hook func)\
42 {\
43    TR_FUNC_BFR(1); \
44    T((T_CALLED("set_" #typ"_"#name"(%p,%s)"), (void *) form, TR_FUNC_ARG(0, func)));\
45    (Normalize_Form( form ) -> typ ## name) = func ;\
46    RETURN(E_OK);\
47 }
48 
49 /* "Template" macro to generate function to get application specific hook */
50 #define GEN_HOOK_GET_FUNCTION( typ, name ) \
51 FORM_IMPEXP Form_Hook NCURSES_API typ ## _ ## name ( const FORM *form )\
52 {\
53    T((T_CALLED(#typ "_" #name "(%p)"), (const void *) form));\
54    returnFormHook( Normalize_Form( form ) -> typ ## name );\
55 }
56 
57 /*---------------------------------------------------------------------------
58 |   Facility      :  libnform
59 |   Function      :  int set_field_init(FORM *form, Form_Hook f)
60 |
61 |   Description   :  Assigns an application defined initialization function
62 |                    to be called when the form is posted and just after
63 |                    the current field changes.
64 |
65 |   Return Values :  E_OK      - success
66 +--------------------------------------------------------------------------*/
67 GEN_HOOK_SET_FUNCTION(field, init)
68 
69 /*---------------------------------------------------------------------------
70 |   Facility      :  libnform
71 |   Function      :  Form_Hook field_init(const FORM *form)
72 |
73 |   Description   :  Retrieve field initialization routine address.
74 |
75 |   Return Values :  The address or NULL if no hook defined.
76 +--------------------------------------------------------------------------*/
77 GEN_HOOK_GET_FUNCTION(field, init)
78 
79 /*---------------------------------------------------------------------------
80 |   Facility      :  libnform
81 |   Function      :  int set_field_term(FORM *form, Form_Hook f)
82 |
83 |   Description   :  Assigns an application defined finalization function
84 |                    to be called when the form is unposted and just before
85 |                    the current field changes.
86 |
87 |   Return Values :  E_OK      - success
88 +--------------------------------------------------------------------------*/
89 GEN_HOOK_SET_FUNCTION(field, term)
90 
91 /*---------------------------------------------------------------------------
92 |   Facility      :  libnform
93 |   Function      :  Form_Hook field_term(const FORM *form)
94 |
95 |   Description   :  Retrieve field finalization routine address.
96 |
97 |   Return Values :  The address or NULL if no hook defined.
98 +--------------------------------------------------------------------------*/
99 GEN_HOOK_GET_FUNCTION(field, term)
100 
101 /*---------------------------------------------------------------------------
102 |   Facility      :  libnform
103 |   Function      :  int set_form_init(FORM *form, Form_Hook f)
104 |
105 |   Description   :  Assigns an application defined initialization function
106 |                    to be called when the form is posted and just after
107 |                    a page change.
108 |
109 |   Return Values :  E_OK       - success
110 +--------------------------------------------------------------------------*/
111 GEN_HOOK_SET_FUNCTION(form, init)
112 
113 /*---------------------------------------------------------------------------
114 |   Facility      :  libnform
115 |   Function      :  Form_Hook form_init(const FORM *form)
116 |
117 |   Description   :  Retrieve form initialization routine address.
118 |
119 |   Return Values :  The address or NULL if no hook defined.
120 +--------------------------------------------------------------------------*/
121 GEN_HOOK_GET_FUNCTION(form, init)
122 
123 /*---------------------------------------------------------------------------
124 |   Facility      :  libnform
125 |   Function      :  int set_form_term(FORM *form, Form_Hook f)
126 |
127 |   Description   :  Assigns an application defined finalization function
128 |                    to be called when the form is unposted and just before
129 |                    a page change.
130 |
131 |   Return Values :  E_OK       - success
132 +--------------------------------------------------------------------------*/
133 GEN_HOOK_SET_FUNCTION(form, term)
134 
135 /*---------------------------------------------------------------------------
136 |   Facility      :  libnform
137 |   Function      :  Form_Hook form_term(const FORM *form)
138 |
139 |   Description   :  Retrieve form finalization routine address.
140 |
141 |   Return Values :  The address or NULL if no hook defined.
142 +--------------------------------------------------------------------------*/
143 GEN_HOOK_GET_FUNCTION(form, term)
144 
145 /* frm_hook.c ends here */
146