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_alnum.c,v 1.11 2002/07/06 15:33:27 juergen Exp $")
23 /*---------------------------------------------------------------------------
25 | Function : static void *Make_AlphaNumeric_Type(va_list *ap)
27 | Description : Allocate structure for alphanumeric type argument.
29 | Return Values : Pointer to argument structure or NULL on error
30 +--------------------------------------------------------------------------*/
31 static void *Make_AlphaNumeric_Type(va_list * ap)
33 alnumARG *argp = (alnumARG *)malloc(sizeof(alnumARG));
36 argp->width = va_arg(*ap,int);
38 return ((void *)argp);
41 /*---------------------------------------------------------------------------
43 | Function : static void *Copy_AlphaNumericType(const void *argp)
45 | Description : Copy structure for alphanumeric type argument.
47 | Return Values : Pointer to argument structure or NULL on error.
48 +--------------------------------------------------------------------------*/
49 static void *Copy_AlphaNumeric_Type(const void *argp)
51 const alnumARG *ap = (const alnumARG *)argp;
52 alnumARG *result = (alnumARG *)malloc(sizeof(alnumARG));
57 return ((void *)result);
60 /*---------------------------------------------------------------------------
62 | Function : static void Free_AlphaNumeric_Type(void *argp)
64 | Description : Free structure for alphanumeric type argument.
67 +--------------------------------------------------------------------------*/
68 static void Free_AlphaNumeric_Type(void * argp)
74 /*---------------------------------------------------------------------------
76 | Function : static bool Check_AlphaNumeric_Field(
80 | Description : Validate buffer content to be a valid alphanumeric value
82 | Return Values : TRUE - field is valid
83 | FALSE - field is invalid
84 +--------------------------------------------------------------------------*/
85 static bool Check_AlphaNumeric_Field(FIELD * field, const void * argp)
87 int width = ((const alnumARG *)argp)->width;
88 unsigned char *bp = (unsigned char *)field_buffer(field,0);
92 while(*bp && *bp==' ')
97 while(*bp && isalnum(*bp))
100 while(*bp && *bp==' ')
103 return ((*bp || (l < width)) ? FALSE : TRUE);
106 /*---------------------------------------------------------------------------
107 | Facility : libnform
108 | Function : static bool Check_AlphaNumeric_Character(
112 | Description : Check a character for the alphanumeric type.
114 | Return Values : TRUE - character is valid
115 | FALSE - character is invalid
116 +--------------------------------------------------------------------------*/
117 static bool Check_AlphaNumeric_Character(int c, const void * argp GCC_UNUSED)
119 return (isalnum(c) ? TRUE : FALSE);
122 static FIELDTYPE typeALNUM = {
123 _HAS_ARGS | _RESIDENT,
124 1, /* this is mutable, so we can't be const */
127 Make_AlphaNumeric_Type,
128 Copy_AlphaNumeric_Type,
129 Free_AlphaNumeric_Type,
130 Check_AlphaNumeric_Field,
131 Check_AlphaNumeric_Character,
136 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeALNUM;
138 /* fty_alnum.c ends here */