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 /***************************************************************************
31 * Author : Juergen Pfeifer *
33 ***************************************************************************/
35 #include "form.priv.h"
37 MODULE_ID("$Id: fty_alpha.c,v 1.26 2010/01/23 21:14:36 tom Exp $")
39 #define thisARG alphaARG
47 /*---------------------------------------------------------------------------
49 | Function : static void *Generic_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 Generic_This_Type(void *arg
)
58 thisARG
*argp
= (thisARG
*) 0;
62 argp
= typeMalloc(thisARG
, 1);
66 T((T_CREATE("thisARG %p"), (void *)argp
));
67 argp
->width
= *((int *)arg
);
70 return ((void *)argp
);
73 /*---------------------------------------------------------------------------
75 | Function : static void *Make_This_Type(va_list *ap)
77 | Description : Allocate structure for alpha type argument.
79 | Return Values : Pointer to argument structure or NULL on error
80 +--------------------------------------------------------------------------*/
82 Make_This_Type(va_list *ap
)
84 int w
= va_arg(*ap
, int);
86 return Generic_This_Type((void *)&w
);
89 /*---------------------------------------------------------------------------
91 | Function : static void *Copy_This_Type(const void * argp)
93 | Description : Copy structure for alpha type argument.
95 | Return Values : Pointer to argument structure or NULL on error.
96 +--------------------------------------------------------------------------*/
98 Copy_This_Type(const void *argp
)
100 const thisARG
*ap
= (const thisARG
*)argp
;
101 thisARG
*result
= typeMalloc(thisARG
, 1);
105 T((T_CREATE("thisARG %p"), (void *)result
));
109 return ((void *)result
);
112 /*---------------------------------------------------------------------------
113 | Facility : libnform
114 | Function : static void Free_This_Type(void *argp)
116 | Description : Free structure for alpha type argument.
119 +--------------------------------------------------------------------------*/
121 Free_This_Type(void *argp
)
127 /*---------------------------------------------------------------------------
128 | Facility : libnform
129 | Function : static bool Check_This_Character(
133 | Description : Check a character for the alpha type.
135 | Return Values : TRUE - character is valid
136 | FALSE - character is invalid
137 +--------------------------------------------------------------------------*/
139 Check_This_Character(int c
, const void *argp GCC_UNUSED
)
141 #if USE_WIDEC_SUPPORT
142 if (iswalpha((wint_t) c
))
145 return (isalpha(UChar(c
)) ? TRUE
: FALSE
);
148 /*---------------------------------------------------------------------------
149 | Facility : libnform
150 | Function : static bool Check_This_Field(
154 | Description : Validate buffer content to be a valid alpha value
156 | Return Values : TRUE - field is valid
157 | FALSE - field is invalid
158 +--------------------------------------------------------------------------*/
160 Check_This_Field(FIELD
*field
, const void *argp
)
162 int width
= ((const thisARG
*)argp
)->width
;
163 unsigned char *bp
= (unsigned char *)field_buffer(field
, 0);
164 bool result
= (width
< 0);
166 Check_CTYPE_Field(result
, bp
, width
, Check_This_Character
);
170 static FIELDTYPE typeTHIS
=
172 _HAS_ARGS
| _RESIDENT
,
173 1, /* this is mutable, so we can't be const */
179 INIT_FT_FUNC(Check_This_Field
),
180 INIT_FT_FUNC(Check_This_Character
),
183 #if NCURSES_INTEROP_FUNCS
188 NCURSES_EXPORT_VAR(FIELDTYPE
*) TYPE_ALPHA
= &typeTHIS
;
190 #if NCURSES_INTEROP_FUNCS
191 /* The next routines are to simplify the use of ncurses from
192 programming languages with restictions on interop with C level
193 constructs (e.g. variable access or va_list + ellipsis constructs)
195 NCURSES_EXPORT(FIELDTYPE
*)
202 /* fty_alpha.c ends here */