3 * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
4 * You may freely copy it for use as a template for your own field types.
5 * If you develop a field type that might be of general use, please send
6 * it back to the ncurses maintainers for inclusion in the next version.
8 /***************************************************************************
10 * Author : Juergen Pfeifer *
11 * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en *
13 ***************************************************************************/
15 #include "form.priv.h"
17 MODULE_ID("$Id: fty_alpha.c,v 1.11 2002/07/06 15:33:27 juergen Exp $")
23 /*---------------------------------------------------------------------------
25 | Function : static void *Make_Alpha_Type(va_list *ap)
27 | Description : Allocate structure for alpha type argument.
29 | Return Values : Pointer to argument structure or NULL on error
30 +--------------------------------------------------------------------------*/
31 static void *Make_Alpha_Type(va_list * ap)
33 alphaARG *argp = (alphaARG *)malloc(sizeof(alphaARG));
36 argp->width = va_arg(*ap,int);
38 return ((void *)argp);
41 /*---------------------------------------------------------------------------
43 | Function : static void *Copy_Alpha_Type(const void * argp)
45 | Description : Copy structure for alpha type argument.
47 | Return Values : Pointer to argument structure or NULL on error.
48 +--------------------------------------------------------------------------*/
49 static void *Copy_Alpha_Type(const void * argp)
51 const alphaARG *ap = (const alphaARG *)argp;
52 alphaARG *result = (alphaARG *)malloc(sizeof(alphaARG));
58 return ((void *)result);
61 /*---------------------------------------------------------------------------
63 | Function : static void Free_Alpha_Type( void * argp )
65 | Description : Free structure for alpha type argument.
68 +--------------------------------------------------------------------------*/
69 static void Free_Alpha_Type(void * argp)
75 /*---------------------------------------------------------------------------
77 | Function : static bool Check_Alpha_Field(
81 | Description : Validate buffer content to be a valid alpha value
83 | Return Values : TRUE - field is valid
84 | FALSE - field is invalid
85 +--------------------------------------------------------------------------*/
86 static bool Check_Alpha_Field(FIELD * field, const void * argp)
88 int width = ((const alphaARG *)argp)->width;
89 unsigned char *bp = (unsigned char *)field_buffer(field,0);
93 while(*bp && *bp==' ')
98 while(*bp && isalpha(*bp))
101 while(*bp && *bp==' ')
104 return ((*bp || (l < width)) ? FALSE : TRUE);
107 /*---------------------------------------------------------------------------
108 | Facility : libnform
109 | Function : static bool Check_Alpha_Character(
113 | Description : Check a character for the alpha type.
115 | Return Values : TRUE - character is valid
116 | FALSE - character is invalid
117 +--------------------------------------------------------------------------*/
118 static bool Check_Alpha_Character(int c, const void * argp GCC_UNUSED)
120 return (isalpha(c) ? TRUE : FALSE);
123 static FIELDTYPE typeALPHA = {
124 _HAS_ARGS | _RESIDENT,
125 1, /* this is mutable, so we can't be const */
132 Check_Alpha_Character,
137 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALPHA = &typeALPHA;
139 /* fty_alpha.c ends here */