1/*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 send5* it back to the ncurses maintainers for inclusion in the next version.6*/7/***************************************************************************8* *9* Author : Juergen Pfeifer, [email protected] *10* *11***************************************************************************/1213#include "form.priv.h"1415MODULE_ID("$Id$")1617typedef struct {18int width;19} alphaARG;2021/*---------------------------------------------------------------------------22| Facility : libnform23| Function : static void *Make_Alpha_Type(va_list *ap)24|25| Description : Allocate structure for alpha type argument.26|27| Return Values : Pointer to argument structure or NULL on error28+--------------------------------------------------------------------------*/29static void *Make_Alpha_Type(va_list * ap)30{31alphaARG *argp = (alphaARG *)malloc(sizeof(alphaARG));32if (argp)33{34argp->width = va_arg(*ap,int);35}36return ((void *)argp);37}3839/*---------------------------------------------------------------------------40| Facility : libnform41| Function : static void *Copy_Alpha_Type(const void * argp)42|43| Description : Copy structure for alpha type argument.44|45| Return Values : Pointer to argument structure or NULL on error.46+--------------------------------------------------------------------------*/47static void *Copy_Alpha_Type(const void * argp)48{49const alphaARG *ap = (const alphaARG *)argp;50alphaARG *result = (alphaARG *)malloc(sizeof(alphaARG));5152if (result)53{54*result = *ap;55}56return ((void *)result);57}5859/*---------------------------------------------------------------------------60| Facility : libnform61| Function : static void Free_Alpha_Type( void * argp )62|63| Description : Free structure for alpha type argument.64|65| Return Values : -66+--------------------------------------------------------------------------*/67static void Free_Alpha_Type(void * argp)68{69if (argp)70free(argp);71}7273/*---------------------------------------------------------------------------74| Facility : libnform75| Function : static bool Check_Alpha_Field(76| FIELD * field,77| const void * argp)78|79| Description : Validate buffer content to be a valid alpha value80|81| Return Values : TRUE - field is valid82| FALSE - field is invalid83+--------------------------------------------------------------------------*/84static bool Check_Alpha_Field(FIELD * field, const void * argp)85{86int width = ((const alphaARG *)argp)->width;87unsigned char *bp = (unsigned char *)field_buffer(field,0);88int l = -1;89unsigned char *s;9091while(*bp && *bp==' ')92bp++;93if (*bp)94{95s = bp;96while(*bp && isalpha(*bp))97bp++;98l = (int)(bp-s);99while(*bp && *bp==' ')100bp++;101}102return ((*bp || (l < width)) ? FALSE : TRUE);103}104105/*---------------------------------------------------------------------------106| Facility : libnform107| Function : static bool Check_Alpha_Character(108| int c,109| const void * argp)110|111| Description : Check a character for the alpha type.112|113| Return Values : TRUE - character is valid114| FALSE - character is invalid115+--------------------------------------------------------------------------*/116static bool Check_Alpha_Character(int c, const void * argp)117{118argp=0; /* Silence unused parameter warning. */119return (isalpha(c) ? TRUE : FALSE);120}121122static FIELDTYPE typeALPHA = {123_HAS_ARGS | _RESIDENT,1241, /* this is mutable, so we can't be const */125(FIELDTYPE *)0,126(FIELDTYPE *)0,127Make_Alpha_Type,128Copy_Alpha_Type,129Free_Alpha_Type,130Check_Alpha_Field,131Check_Alpha_Character,132NULL,133NULL134};135136FIELDTYPE* TYPE_ALPHA = &typeALPHA;137138/* fty_alpha.c ends here */139140141