Add /etc/bluetooth/ with common files.
[dragonfly.git] / contrib / ncurses-5.4 / form / fty_alnum.c
blob7eb5a788ecd367443b9d41fd52f7ef5814252788
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 *
11 * *
12 ***************************************************************************/
14 #include "form.priv.h"
16 MODULE_ID("$Id: fty_alnum.c,v 1.12 2003/10/25 14:54:48 tom 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 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 */
124 (FIELDTYPE *)0,
125 (FIELDTYPE *)0,
126 Make_AlphaNumeric_Type,
127 Copy_AlphaNumeric_Type,
128 Free_AlphaNumeric_Type,
129 Check_AlphaNumeric_Field,
130 Check_AlphaNumeric_Character,
131 NULL,
132 NULL
135 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeALNUM;
137 /* fty_alnum.c ends here */