2 * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
3 * You may freely copy it for use as a template for your own field types.
4 * If you develop a field type that might be of general use, please send
5 * it back to the ncurses maintainers for inclusion in the next version.
7 /***************************************************************************
9 * Author : Juergen Pfeifer *
11 ***************************************************************************/
13 #include "form.priv.h"
15 MODULE_ID("$Id: fty_alpha.c,v 1.20 2005/08/20 18:37:48 tom Exp $")
17 #define thisARG alphaARG
25 /*---------------------------------------------------------------------------
27 | Function : static void *Make_This_Type(va_list *ap)
29 | Description : Allocate structure for alpha type argument.
31 | Return Values : Pointer to argument structure or NULL on error
32 +--------------------------------------------------------------------------*/
34 Make_This_Type(va_list *ap)
36 thisARG *argp = (thisARG *) malloc(sizeof(thisARG));
39 argp->width = va_arg(*ap, int);
41 return ((void *)argp);
44 /*---------------------------------------------------------------------------
46 | Function : static void *Copy_This_Type(const void * argp)
48 | Description : Copy structure for alpha type argument.
50 | Return Values : Pointer to argument structure or NULL on error.
51 +--------------------------------------------------------------------------*/
53 Copy_This_Type(const void *argp)
55 const thisARG *ap = (const thisARG *)argp;
56 thisARG *result = (thisARG *) malloc(sizeof(thisARG));
61 return ((void *)result);
64 /*---------------------------------------------------------------------------
66 | Function : static void Free_This_Type(void *argp)
68 | Description : Free structure for alpha type argument.
71 +--------------------------------------------------------------------------*/
73 Free_This_Type(void *argp)
79 /*---------------------------------------------------------------------------
81 | Function : static bool Check_This_Character(
85 | Description : Check a character for the alpha type.
87 | Return Values : TRUE - character is valid
88 | FALSE - character is invalid
89 +--------------------------------------------------------------------------*/
91 Check_This_Character(int c, const void *argp GCC_UNUSED)
94 if (iswalpha((wint_t) c))
97 return (isalpha(UChar(c)) ? TRUE : FALSE);
100 /*---------------------------------------------------------------------------
101 | Facility : libnform
102 | Function : static bool Check_This_Field(
106 | Description : Validate buffer content to be a valid alpha value
108 | Return Values : TRUE - field is valid
109 | FALSE - field is invalid
110 +--------------------------------------------------------------------------*/
112 Check_This_Field(FIELD *field, const void *argp)
114 int width = ((const thisARG *)argp)->width;
115 unsigned char *bp = (unsigned char *)field_buffer(field, 0);
116 bool result = (width < 0);
118 Check_CTYPE_Field(result, bp, width, Check_This_Character);
122 static FIELDTYPE typeTHIS =
124 _HAS_ARGS | _RESIDENT,
125 1, /* this is mutable, so we can't be const */
132 Check_This_Character,
137 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALPHA = &typeTHIS;
139 /* fty_alpha.c ends here */