1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 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 /***************************************************************************
31 * Author : Juergen Pfeifer *
33 ***************************************************************************/
35 #include "form.priv.h"
37 MODULE_ID("$Id: fty_alpha.c,v 1.23 2007/10/13 19:32:09 tom Exp $")
39 #define thisARG alphaARG
47 /*---------------------------------------------------------------------------
49 | Function : static void *Make_This_Type(va_list *ap)
51 | Description : Allocate structure for alpha type argument.
53 | Return Values : Pointer to argument structure or NULL on error
54 +--------------------------------------------------------------------------*/
56 Make_This_Type(va_list *ap
)
58 thisARG
*argp
= typeMalloc(thisARG
, 1);
62 T((T_CREATE("thisARG %p"), argp
));
63 argp
->width
= va_arg(*ap
, int);
66 return ((void *)argp
);
69 /*---------------------------------------------------------------------------
71 | Function : static void *Copy_This_Type(const void * argp)
73 | Description : Copy structure for alpha type argument.
75 | Return Values : Pointer to argument structure or NULL on error.
76 +--------------------------------------------------------------------------*/
78 Copy_This_Type(const void *argp
)
80 const thisARG
*ap
= (const thisARG
*)argp
;
81 thisARG
*result
= typeMalloc(thisARG
, 1);
85 T((T_CREATE("thisARG %p"), result
));
89 return ((void *)result
);
92 /*---------------------------------------------------------------------------
94 | Function : static void Free_This_Type(void *argp)
96 | Description : Free structure for alpha type argument.
99 +--------------------------------------------------------------------------*/
101 Free_This_Type(void *argp
)
107 /*---------------------------------------------------------------------------
108 | Facility : libnform
109 | Function : static bool Check_This_Character(
113 | Description : Check a character for the alpha type.
115 | Return Values : TRUE - character is valid
116 | FALSE - character is invalid
117 +--------------------------------------------------------------------------*/
119 Check_This_Character(int c
, const void *argp GCC_UNUSED
)
121 #if USE_WIDEC_SUPPORT
122 if (iswalpha((wint_t) c
))
125 return (isalpha(UChar(c
)) ? TRUE
: FALSE
);
128 /*---------------------------------------------------------------------------
129 | Facility : libnform
130 | Function : static bool Check_This_Field(
134 | Description : Validate buffer content to be a valid alpha value
136 | Return Values : TRUE - field is valid
137 | FALSE - field is invalid
138 +--------------------------------------------------------------------------*/
140 Check_This_Field(FIELD
*field
, const void *argp
)
142 int width
= ((const thisARG
*)argp
)->width
;
143 unsigned char *bp
= (unsigned char *)field_buffer(field
, 0);
144 bool result
= (width
< 0);
146 Check_CTYPE_Field(result
, bp
, width
, Check_This_Character
);
150 static FIELDTYPE typeTHIS
=
152 _HAS_ARGS
| _RESIDENT
,
153 1, /* this is mutable, so we can't be const */
160 Check_This_Character
,
165 NCURSES_EXPORT_VAR(FIELDTYPE
*) TYPE_ALPHA
= &typeTHIS
;
167 /* fty_alpha.c ends here */