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, Juergen.Pfeifer@T-Online.de *
12 ***************************************************************************/
14 #include "form.priv.h"
16 MODULE_ID("$Id: fty_alpha.c,v 1.7 1997/10/18 19:33:38 tom Exp $")
22 /*---------------------------------------------------------------------------
24 | Function : static void *Make_Alpha_Type(va_list *ap)
26 | Description : Allocate structure for alpha type argument.
28 | Return Values : Pointer to argument structure or NULL on error
29 +--------------------------------------------------------------------------*/
30 static void *Make_Alpha_Type(va_list * ap)
32 alphaARG *argp = (alphaARG *)malloc(sizeof(alphaARG));
35 argp->width = va_arg(*ap,int);
37 return ((void *)argp);
40 /*---------------------------------------------------------------------------
42 | Function : static void *Copy_Alpha_Type(const void * argp)
44 | Description : Copy structure for alpha type argument.
46 | Return Values : Pointer to argument structure or NULL on error.
47 +--------------------------------------------------------------------------*/
48 static void *Copy_Alpha_Type(const void * argp)
50 const alphaARG *ap = (const alphaARG *)argp;
51 alphaARG *result = (alphaARG *)malloc(sizeof(alphaARG));
57 return ((void *)result);
60 /*---------------------------------------------------------------------------
62 | Function : static void Free_Alpha_Type( void * argp )
64 | Description : Free structure for alpha type argument.
67 +--------------------------------------------------------------------------*/
68 static void Free_Alpha_Type(void * argp)
74 /*---------------------------------------------------------------------------
76 | Function : static bool Check_Alpha_Field(
80 | Description : Validate buffer content to be a valid alpha value
82 | Return Values : TRUE - field is valid
83 | FALSE - field is invalid
84 +--------------------------------------------------------------------------*/
85 static bool Check_Alpha_Field(FIELD * field, const void * argp)
87 int width = ((const alphaARG *)argp)->width;
88 unsigned char *bp = (unsigned char *)field_buffer(field,0);
92 while(*bp && *bp==' ')
97 while(*bp && isalpha(*bp))
100 while(*bp && *bp==' ')
103 return ((*bp || (l < width)) ? FALSE : TRUE);
106 /*---------------------------------------------------------------------------
107 | Facility : libnform
108 | Function : static bool Check_Alpha_Character(
112 | Description : Check a character for the alpha type.
114 | Return Values : TRUE - character is valid
115 | FALSE - character is invalid
116 +--------------------------------------------------------------------------*/
117 static bool Check_Alpha_Character(int c, const void * argp GCC_UNUSED)
119 return (isalpha(c) ? TRUE : FALSE);
122 static FIELDTYPE typeALPHA = {
123 _HAS_ARGS | _RESIDENT,
124 1, /* this is mutable, so we can't be const */
131 Check_Alpha_Character,
136 FIELDTYPE* TYPE_ALPHA = &typeALPHA;
138 /* fty_alpha.c ends here */