Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CursesDialog / form / fty_alnum.c
blob58c25196031f8f78ffb7cb8dc8c5f55586220895
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_alnum.c,v 1.2 2002/06/18 21:19:38 king Exp $")
18 typedef struct {
19 int width;
20 } alnumARG;
22 /*---------------------------------------------------------------------------
23 | Facility : libnform
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));
34 if (argp)
35 argp->width = va_arg(*ap,int);
37 return ((void *)argp);
40 /*---------------------------------------------------------------------------
41 | Facility : libnform
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));
53 if (result)
54 *result = *ap;
56 return ((void *)result);
59 /*---------------------------------------------------------------------------
60 | Facility : libnform
61 | Function : static void Free_AlphaNumeric_Type(void *argp)
63 | Description : Free structure for alphanumeric type argument.
65 | Return Values : -
66 +--------------------------------------------------------------------------*/
67 static void Free_AlphaNumeric_Type(void * argp)
69 if (argp)
70 free(argp);
73 /*---------------------------------------------------------------------------
74 | Facility : libnform
75 | Function : static bool Check_AlphaNumeric_Field(
76 | FIELD *field,
77 | const void *argp)
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);
88 int l = -1;
89 unsigned char *s;
91 while(*bp && *bp==' ')
92 bp++;
93 if (*bp)
95 s = bp;
96 while(*bp && isalnum(*bp))
97 bp++;
98 l = (int)(bp-s);
99 while(*bp && *bp==' ')
100 bp++;
102 return ((*bp || (l < width)) ? FALSE : TRUE);
105 /*---------------------------------------------------------------------------
106 | Facility : libnform
107 | Function : static bool Check_AlphaNumeric_Character(
108 | int c,
109 | const void *argp )
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)
118 argp=0; /* Silence unused parameter warning. */
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 */
125 (FIELDTYPE *)0,
126 (FIELDTYPE *)0,
127 Make_AlphaNumeric_Type,
128 Copy_AlphaNumeric_Type,
129 Free_AlphaNumeric_Type,
130 Check_AlphaNumeric_Field,
131 Check_AlphaNumeric_Character,
132 NULL,
133 NULL
136 FIELDTYPE* TYPE_ALNUM = &typeALNUM;
138 /* fty_alnum.c ends here */