fm/ipmitopo: fix 64-bit compilation
[unleashed.git] / contrib / ncurses / form / fld_newftyp.c
blob4e5912546b8b4dbadc28f59e210b9d980a2d26f6
1 /****************************************************************************
2 * Copyright (c) 1998-2010,2016 Free Software Foundation, Inc. *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 ****************************************************************************/
33 #include "form.priv.h"
35 MODULE_ID("$Id: fld_newftyp.c,v 1.20 2016/01/23 21:32:00 tom Exp $")
37 static FIELDTYPE default_fieldtype =
39 0, /* status */
40 0L, /* reference count */
41 (FIELDTYPE *)0, /* pointer to left operand */
42 (FIELDTYPE *)0, /* pointer to right operand */
43 NULL, /* makearg function */
44 NULL, /* copyarg function */
45 NULL, /* freearg function */
46 INIT_FT_FUNC(NULL), /* field validation function */
47 INIT_FT_FUNC(NULL), /* Character check function */
48 INIT_FT_FUNC(NULL), /* enumerate next function */
49 INIT_FT_FUNC(NULL), /* enumerate previous function */
50 #if NCURSES_INTEROP_FUNCS
51 NULL /* generic callback alternative to makearg */
52 #endif
55 NCURSES_EXPORT_VAR(FIELDTYPE *)
56 _nc_Default_FieldType = &default_fieldtype;
58 /*---------------------------------------------------------------------------
59 | Facility : libnform
60 | Function : FIELDTYPE *new_fieldtype(
61 | bool (* const field_check)(FIELD *,const void *),
62 | bool (* const char_check) (int, const void *) )
64 | Description : Create a new fieldtype. The application programmer must
65 | write a field_check and a char_check function and give
66 | them as input to this call.
67 | If an error occurs, errno is set to
68 | E_BAD_ARGUMENT - invalid arguments
69 | E_SYSTEM_ERROR - system error (no memory)
71 | Return Values : Fieldtype pointer or NULL if error occurred
72 +--------------------------------------------------------------------------*/
73 NCURSES_EXPORT(FIELDTYPE *)
74 new_fieldtype(bool (*const field_check) (FIELD *, const void *),
75 bool (*const char_check) (int, const void *))
77 FIELDTYPE *nftyp = (FIELDTYPE *)0;
79 T((T_CALLED("new_fieldtype(%p,%p)"), TR_FUNC(field_check), TR_FUNC(char_check)));
80 if ((field_check) || (char_check))
82 nftyp = typeMalloc(FIELDTYPE, 1);
84 if (nftyp)
86 T((T_CREATE("fieldtype %p"), (void *)nftyp));
87 *nftyp = default_fieldtype;
88 #if NCURSES_INTEROP_FUNCS
89 nftyp->fieldcheck.ofcheck = field_check;
90 nftyp->charcheck.occheck = char_check;
91 #else
92 nftyp->fcheck = field_check;
93 nftyp->ccheck = char_check;
94 #endif
96 else
98 SET_ERROR(E_SYSTEM_ERROR);
101 else
103 SET_ERROR(E_BAD_ARGUMENT);
105 returnFieldType(nftyp);
108 /*---------------------------------------------------------------------------
109 | Facility : libnform
110 | Function : int free_fieldtype(FIELDTYPE *typ)
112 | Description : Release the memory associated with this fieldtype.
114 | Return Values : E_OK - success
115 | E_CONNECTED - there are fields referencing the type
116 | E_BAD_ARGUMENT - invalid fieldtype pointer
117 +--------------------------------------------------------------------------*/
118 NCURSES_EXPORT(int)
119 free_fieldtype(FIELDTYPE *typ)
121 T((T_CALLED("free_fieldtype(%p)"), (void *)typ));
123 if (!typ)
124 RETURN(E_BAD_ARGUMENT);
126 if (typ->ref != 0)
127 RETURN(E_CONNECTED);
129 if (typ->status & _RESIDENT)
130 RETURN(E_CONNECTED);
132 if (typ->status & _LINKED_TYPE)
134 if (typ->left)
135 typ->left->ref--;
136 if (typ->right)
137 typ->right->ref--;
139 free(typ);
140 RETURN(E_OK);
143 /* fld_newftyp.c ends here */