1 /****************************************************************************
2 * Copyright 2018,2020 Thomas E. Dickey *
3 * Copyright 1998-2010,2016 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 #include "form.priv.h"
36 MODULE_ID("$Id: fld_newftyp.c,v 1.23 2020/05/24 01:40:20 anonymous.maarten Exp $")
38 static FIELDTYPE default_fieldtype =
41 0L, /* reference count */
42 (FIELDTYPE *)0, /* pointer to left operand */
43 (FIELDTYPE *)0, /* pointer to right operand */
44 NULL, /* makearg function */
45 NULL, /* copyarg function */
46 NULL, /* freearg function */
47 INIT_FT_FUNC(NULL), /* field validation function */
48 INIT_FT_FUNC(NULL), /* Character check function */
49 INIT_FT_FUNC(NULL), /* enumerate next function */
50 INIT_FT_FUNC(NULL), /* enumerate previous function */
51 #if NCURSES_INTEROP_FUNCS
52 NULL /* generic callback alternative to makearg */
56 FORM_EXPORT_VAR(FIELDTYPE *)
57 _nc_Default_FieldType = &default_fieldtype;
59 /*---------------------------------------------------------------------------
61 | Function : FIELDTYPE *new_fieldtype(
62 | bool (* const field_check)(FIELD *,const void *),
63 | bool (* const char_check) (int, const void *) )
65 | Description : Create a new fieldtype. The application programmer must
66 | write a field_check and a char_check function and give
67 | them as input to this call.
68 | If an error occurs, errno is set to
69 | E_BAD_ARGUMENT - invalid arguments
70 | E_SYSTEM_ERROR - system error (no memory)
72 | Return Values : Fieldtype pointer or NULL if error occurred
73 +--------------------------------------------------------------------------*/
74 FORM_EXPORT(FIELDTYPE *)
75 new_fieldtype(bool (*const field_check) (FIELD *, const void *),
76 bool (*const char_check) (int, const void *))
78 FIELDTYPE *nftyp = (FIELDTYPE *)0;
82 T((T_CALLED("new_fieldtype(%s,%s)"),
83 TR_FUNC_ARG(0, field_check),
84 TR_FUNC_ARG(1, char_check)));
86 if ((field_check) || (char_check))
88 nftyp = typeMalloc(FIELDTYPE, 1);
92 T((T_CREATE("fieldtype %p"), (void *)nftyp));
93 *nftyp = default_fieldtype;
94 #if NCURSES_INTEROP_FUNCS
95 nftyp->fieldcheck.ofcheck = field_check;
96 nftyp->charcheck.occheck = char_check;
98 nftyp->fcheck = field_check;
99 nftyp->ccheck = char_check;
104 SET_ERROR(E_SYSTEM_ERROR);
109 SET_ERROR(E_BAD_ARGUMENT);
111 returnFieldType(nftyp);
114 /*---------------------------------------------------------------------------
115 | Facility : libnform
116 | Function : int free_fieldtype(FIELDTYPE *typ)
118 | Description : Release the memory associated with this fieldtype.
120 | Return Values : E_OK - success
121 | E_CONNECTED - there are fields referencing the type
122 | E_BAD_ARGUMENT - invalid fieldtype pointer
123 +--------------------------------------------------------------------------*/
125 free_fieldtype(FIELDTYPE *typ)
127 T((T_CALLED("free_fieldtype(%p)"), (void *)typ));
130 RETURN(E_BAD_ARGUMENT);
135 if (typ->status & _RESIDENT)
138 if (typ->status & _LINKED_TYPE)
149 /* fld_newftyp.c ends here */