1 /****************************************************************************
2 * Copyright (c) 1998-2005,2006 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.21 2006/04/22 21:33:05 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 = (thisARG *) malloc(sizeof(thisARG));
61 argp->width = va_arg(*ap, int);
63 return ((void *)argp);
66 /*---------------------------------------------------------------------------
68 | Function : static void *Copy_This_Type(const void * argp)
70 | Description : Copy structure for alpha type argument.
72 | Return Values : Pointer to argument structure or NULL on error.
73 +--------------------------------------------------------------------------*/
75 Copy_This_Type(const void *argp)
77 const thisARG *ap = (const thisARG *)argp;
78 thisARG *result = (thisARG *) malloc(sizeof(thisARG));
83 return ((void *)result);
86 /*---------------------------------------------------------------------------
88 | Function : static void Free_This_Type(void *argp)
90 | Description : Free structure for alpha type argument.
93 +--------------------------------------------------------------------------*/
95 Free_This_Type(void *argp)
101 /*---------------------------------------------------------------------------
102 | Facility : libnform
103 | Function : static bool Check_This_Character(
107 | Description : Check a character for the alpha type.
109 | Return Values : TRUE - character is valid
110 | FALSE - character is invalid
111 +--------------------------------------------------------------------------*/
113 Check_This_Character(int c, const void *argp GCC_UNUSED)
115 #if USE_WIDEC_SUPPORT
116 if (iswalpha((wint_t) c))
119 return (isalpha(UChar(c)) ? TRUE : FALSE);
122 /*---------------------------------------------------------------------------
123 | Facility : libnform
124 | Function : static bool Check_This_Field(
128 | Description : Validate buffer content to be a valid alpha value
130 | Return Values : TRUE - field is valid
131 | FALSE - field is invalid
132 +--------------------------------------------------------------------------*/
134 Check_This_Field(FIELD *field, const void *argp)
136 int width = ((const thisARG *)argp)->width;
137 unsigned char *bp = (unsigned char *)field_buffer(field, 0);
138 bool result = (width < 0);
140 Check_CTYPE_Field(result, bp, width, Check_This_Character);
144 static FIELDTYPE typeTHIS =
146 _HAS_ARGS | _RESIDENT,
147 1, /* this is mutable, so we can't be const */
154 Check_This_Character,
159 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALPHA = &typeTHIS;
161 /* fty_alpha.c ends here */