Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CursesDialog / form / fty_alpha.c
blob79756db21b2d7c4ac87e25ce1469f3b32b9ec37c
2 /*
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.
7 */
8 /***************************************************************************
9 * *
10 * Author : Juergen Pfeifer, juergen.pfeifer@gmx.net *
11 * *
12 ***************************************************************************/
14 #include "form.priv.h"
16 MODULE_ID("$Id: fty_alpha.c,v 1.2 2002/06/19 12:57:14 king Exp $")
18 typedef struct {
19 int width;
20 } alphaARG;
22 /*---------------------------------------------------------------------------
23 | Facility : libnform
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));
33 if (argp)
35 argp->width = va_arg(*ap,int);
37 return ((void *)argp);
40 /*---------------------------------------------------------------------------
41 | Facility : libnform
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));
53 if (result)
55 *result = *ap;
57 return ((void *)result);
60 /*---------------------------------------------------------------------------
61 | Facility : libnform
62 | Function : static void Free_Alpha_Type( void * argp )
64 | Description : Free structure for alpha type argument.
66 | Return Values : -
67 +--------------------------------------------------------------------------*/
68 static void Free_Alpha_Type(void * argp)
70 if (argp)
71 free(argp);
74 /*---------------------------------------------------------------------------
75 | Facility : libnform
76 | Function : static bool Check_Alpha_Field(
77 | FIELD * field,
78 | const void * argp)
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);
89 int l = -1;
90 unsigned char *s;
92 while(*bp && *bp==' ')
93 bp++;
94 if (*bp)
96 s = bp;
97 while(*bp && isalpha(*bp))
98 bp++;
99 l = (int)(bp-s);
100 while(*bp && *bp==' ')
101 bp++;
103 return ((*bp || (l < width)) ? FALSE : TRUE);
106 /*---------------------------------------------------------------------------
107 | Facility : libnform
108 | Function : static bool Check_Alpha_Character(
109 | int c,
110 | const void * argp)
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)
119 argp=0; /* Silence unused parameter warning. */
120 return (isalpha(c) ? TRUE : FALSE);
123 static FIELDTYPE typeALPHA = {
124 _HAS_ARGS | _RESIDENT,
125 1, /* this is mutable, so we can't be const */
126 (FIELDTYPE *)0,
127 (FIELDTYPE *)0,
128 Make_Alpha_Type,
129 Copy_Alpha_Type,
130 Free_Alpha_Type,
131 Check_Alpha_Field,
132 Check_Alpha_Character,
133 NULL,
134 NULL
137 FIELDTYPE* TYPE_ALPHA = &typeALPHA;
139 /* fty_alpha.c ends here */