1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 ****************************************************************************/
33 #include "form.priv.h"
35 MODULE_ID("$Id: fld_newftyp.c,v 1.19 2010/01/23 21:14:36 tom Exp $")
37 static FIELDTYPE default_fieldtype
=
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 */
55 NCURSES_EXPORT_VAR(FIELDTYPE
*)
56 _nc_Default_FieldType
= &default_fieldtype
;
58 /*---------------------------------------------------------------------------
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)"), field_check
, char_check
));
80 if ((field_check
) || (char_check
))
82 nftyp
= typeMalloc(FIELDTYPE
, 1);
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
;
92 nftyp
->fcheck
= field_check
;
93 nftyp
->ccheck
= char_check
;
98 SET_ERROR(E_SYSTEM_ERROR
);
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 +--------------------------------------------------------------------------*/
119 free_fieldtype(FIELDTYPE
*typ
)
121 T((T_CALLED("free_fieldtype(%p)"), (void *)typ
));
124 RETURN(E_BAD_ARGUMENT
);
129 if (typ
->status
& _RESIDENT
)
132 if (typ
->status
& _LINKED_TYPE
)
143 /* fld_newftyp.c ends here */