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 *
12 ***************************************************************************/
14 #include "form.priv.h"
16 MODULE_ID("$Id: fty_alnum.c,v 1.12 2003/10/25 14:54:48 tom Exp $")
22 /*---------------------------------------------------------------------------
24 | Function : static void *Make_AlphaNumeric_Type(va_list *ap)
26 | Description : Allocate structure for alphanumeric type argument.
28 | Return Values : Pointer to argument structure or NULL on error
29 +--------------------------------------------------------------------------*/
30 static void *Make_AlphaNumeric_Type(va_list * ap
)
32 alnumARG
*argp
= (alnumARG
*)malloc(sizeof(alnumARG
));
35 argp
->width
= va_arg(*ap
,int);
37 return ((void *)argp
);
40 /*---------------------------------------------------------------------------
42 | Function : static void *Copy_AlphaNumericType(const void *argp)
44 | Description : Copy structure for alphanumeric type argument.
46 | Return Values : Pointer to argument structure or NULL on error.
47 +--------------------------------------------------------------------------*/
48 static void *Copy_AlphaNumeric_Type(const void *argp
)
50 const alnumARG
*ap
= (const alnumARG
*)argp
;
51 alnumARG
*result
= (alnumARG
*)malloc(sizeof(alnumARG
));
56 return ((void *)result
);
59 /*---------------------------------------------------------------------------
61 | Function : static void Free_AlphaNumeric_Type(void *argp)
63 | Description : Free structure for alphanumeric type argument.
66 +--------------------------------------------------------------------------*/
67 static void Free_AlphaNumeric_Type(void * argp
)
73 /*---------------------------------------------------------------------------
75 | Function : static bool Check_AlphaNumeric_Field(
79 | Description : Validate buffer content to be a valid alphanumeric value
81 | Return Values : TRUE - field is valid
82 | FALSE - field is invalid
83 +--------------------------------------------------------------------------*/
84 static bool Check_AlphaNumeric_Field(FIELD
* field
, const void * argp
)
86 int width
= ((const alnumARG
*)argp
)->width
;
87 unsigned char *bp
= (unsigned char *)field_buffer(field
,0);
91 while(*bp
&& *bp
==' ')
96 while(*bp
&& isalnum(*bp
))
99 while(*bp
&& *bp
==' ')
102 return ((*bp
|| (l
< width
)) ? FALSE
: TRUE
);
105 /*---------------------------------------------------------------------------
106 | Facility : libnform
107 | Function : static bool Check_AlphaNumeric_Character(
111 | Description : Check a character for the alphanumeric type.
113 | Return Values : TRUE - character is valid
114 | FALSE - character is invalid
115 +--------------------------------------------------------------------------*/
116 static bool Check_AlphaNumeric_Character(int c
, const void * argp GCC_UNUSED
)
118 return (isalnum(c
) ? TRUE
: FALSE
);
121 static FIELDTYPE typeALNUM
= {
122 _HAS_ARGS
| _RESIDENT
,
123 1, /* this is mutable, so we can't be const */
126 Make_AlphaNumeric_Type
,
127 Copy_AlphaNumeric_Type
,
128 Free_AlphaNumeric_Type
,
129 Check_AlphaNumeric_Field
,
130 Check_AlphaNumeric_Character
,
135 NCURSES_EXPORT_VAR(FIELDTYPE
*) TYPE_ALNUM
= &typeALNUM
;
137 /* fty_alnum.c ends here */