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} alnumARG;2021/*---------------------------------------------------------------------------22| Facility : libnform23| Function : static void *Make_AlphaNumeric_Type(va_list *ap)24|25| Description : Allocate structure for alphanumeric type argument.26|27| Return Values : Pointer to argument structure or NULL on error28+--------------------------------------------------------------------------*/29static void *Make_AlphaNumeric_Type(va_list * ap)30{31alnumARG *argp = (alnumARG *)malloc(sizeof(alnumARG));3233if (argp)34argp->width = va_arg(*ap,int);3536return ((void *)argp);37}3839/*---------------------------------------------------------------------------40| Facility : libnform41| Function : static void *Copy_AlphaNumericType(const void *argp)42|43| Description : Copy structure for alphanumeric type argument.44|45| Return Values : Pointer to argument structure or NULL on error.46+--------------------------------------------------------------------------*/47static void *Copy_AlphaNumeric_Type(const void *argp)48{49const alnumARG *ap = (const alnumARG *)argp;50alnumARG *result = (alnumARG *)malloc(sizeof(alnumARG));5152if (result)53*result = *ap;5455return ((void *)result);56}5758/*---------------------------------------------------------------------------59| Facility : libnform60| Function : static void Free_AlphaNumeric_Type(void *argp)61|62| Description : Free structure for alphanumeric type argument.63|64| Return Values : -65+--------------------------------------------------------------------------*/66static void Free_AlphaNumeric_Type(void * argp)67{68if (argp)69free(argp);70}7172/*---------------------------------------------------------------------------73| Facility : libnform74| Function : static bool Check_AlphaNumeric_Field(75| FIELD *field,76| const void *argp)77|78| Description : Validate buffer content to be a valid alphanumeric value79|80| Return Values : TRUE - field is valid81| FALSE - field is invalid82+--------------------------------------------------------------------------*/83static bool Check_AlphaNumeric_Field(FIELD * field, const void * argp)84{85int width = ((const alnumARG *)argp)->width;86unsigned char *bp = (unsigned char *)field_buffer(field,0);87int l = -1;88unsigned char *s;8990while(*bp && *bp==' ')91bp++;92if (*bp)93{94s = bp;95while(*bp && isalnum(*bp))96bp++;97l = (int)(bp-s);98while(*bp && *bp==' ')99bp++;100}101return ((*bp || (l < width)) ? FALSE : TRUE);102}103104/*---------------------------------------------------------------------------105| Facility : libnform106| Function : static bool Check_AlphaNumeric_Character(107| int c,108| const void *argp )109|110| Description : Check a character for the alphanumeric type.111|112| Return Values : TRUE - character is valid113| FALSE - character is invalid114+--------------------------------------------------------------------------*/115static bool Check_AlphaNumeric_Character(int c, const void * argp)116{117argp=0; /* Silence unused parameter warning. */118return (isalnum(c) ? TRUE : FALSE);119}120121static FIELDTYPE typeALNUM = {122_HAS_ARGS | _RESIDENT,1231, /* this is mutable, so we can't be const */124(FIELDTYPE *)0,125(FIELDTYPE *)0,126Make_AlphaNumeric_Type,127Copy_AlphaNumeric_Type,128Free_AlphaNumeric_Type,129Check_AlphaNumeric_Field,130Check_AlphaNumeric_Character,131NULL,132NULL133};134135FIELDTYPE* TYPE_ALNUM = &typeALNUM;136137/* fty_alnum.c ends here */138139140