| 1 | /*
|
|---|
| 2 | * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
|
|---|
| 3 | * You may freely copy it for use as a template for your own field types.
|
|---|
| 4 | * If you develop a field type that might be of general use, please send
|
|---|
| 5 | * it back to the ncurses maintainers for inclusion in the next version.
|
|---|
| 6 | */
|
|---|
| 7 | /***************************************************************************
|
|---|
| 8 | * *
|
|---|
| 9 | * Author : Juergen Pfeifer *
|
|---|
| 10 | * *
|
|---|
| 11 | ***************************************************************************/
|
|---|
| 12 |
|
|---|
| 13 | #include "form.priv.h"
|
|---|
| 14 |
|
|---|
| 15 | MODULE_ID("$Id: fty_alnum.c,v 1.18 2005/08/20 18:26:16 tom Exp $")
|
|---|
| 16 |
|
|---|
| 17 | #define thisARG alnumARG
|
|---|
| 18 |
|
|---|
| 19 | typedef struct
|
|---|
| 20 | {
|
|---|
| 21 | int width;
|
|---|
| 22 | }
|
|---|
| 23 | thisARG;
|
|---|
| 24 |
|
|---|
| 25 | /*---------------------------------------------------------------------------
|
|---|
| 26 | | Facility : libnform
|
|---|
| 27 | | Function : static void *Make_This_Type(va_list *ap)
|
|---|
| 28 | |
|
|---|
| 29 | | Description : Allocate structure for alphanumeric type argument.
|
|---|
| 30 | |
|
|---|
| 31 | | Return Values : Pointer to argument structure or NULL on error
|
|---|
| 32 | +--------------------------------------------------------------------------*/
|
|---|
| 33 | static void *
|
|---|
| 34 | Make_This_Type(va_list *ap)
|
|---|
| 35 | {
|
|---|
| 36 | thisARG *argp = (thisARG *) malloc(sizeof(thisARG));
|
|---|
| 37 |
|
|---|
| 38 | if (argp)
|
|---|
| 39 | argp->width = va_arg(*ap, int);
|
|---|
| 40 |
|
|---|
| 41 | return ((void *)argp);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | /*---------------------------------------------------------------------------
|
|---|
| 45 | | Facility : libnform
|
|---|
| 46 | | Function : static void *Copy_ThisType(const void *argp)
|
|---|
| 47 | |
|
|---|
| 48 | | Description : Copy structure for alphanumeric type argument.
|
|---|
| 49 | |
|
|---|
| 50 | | Return Values : Pointer to argument structure or NULL on error.
|
|---|
| 51 | +--------------------------------------------------------------------------*/
|
|---|
| 52 | static void *
|
|---|
| 53 | Copy_This_Type(const void *argp)
|
|---|
| 54 | {
|
|---|
| 55 | const thisARG *ap = (const thisARG *)argp;
|
|---|
| 56 | thisARG *result = (thisARG *) malloc(sizeof(thisARG));
|
|---|
| 57 |
|
|---|
| 58 | if (result)
|
|---|
| 59 | *result = *ap;
|
|---|
| 60 |
|
|---|
| 61 | return ((void *)result);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /*---------------------------------------------------------------------------
|
|---|
| 65 | | Facility : libnform
|
|---|
| 66 | | Function : static void Free_This_Type(void *argp)
|
|---|
| 67 | |
|
|---|
| 68 | | Description : Free structure for alphanumeric type argument.
|
|---|
| 69 | |
|
|---|
| 70 | | Return Values : -
|
|---|
| 71 | +--------------------------------------------------------------------------*/
|
|---|
| 72 | static void
|
|---|
| 73 | Free_This_Type(void *argp)
|
|---|
| 74 | {
|
|---|
| 75 | if (argp)
|
|---|
| 76 | free(argp);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /*---------------------------------------------------------------------------
|
|---|
| 80 | | Facility : libnform
|
|---|
| 81 | | Function : static bool Check_This_Character(
|
|---|
| 82 | | int c,
|
|---|
| 83 | | const void *argp)
|
|---|
| 84 | |
|
|---|
| 85 | | Description : Check a character for the alphanumeric type.
|
|---|
| 86 | |
|
|---|
| 87 | | Return Values : TRUE - character is valid
|
|---|
| 88 | | FALSE - character is invalid
|
|---|
| 89 | +--------------------------------------------------------------------------*/
|
|---|
| 90 | static bool
|
|---|
| 91 | Check_This_Character(int c, const void *argp GCC_UNUSED)
|
|---|
| 92 | {
|
|---|
| 93 | #if USE_WIDEC_SUPPORT
|
|---|
| 94 | if (iswalnum((wint_t) c))
|
|---|
| 95 | return TRUE;
|
|---|
| 96 | #endif
|
|---|
| 97 | return (isalnum(UChar(c)) ? TRUE : FALSE);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /*---------------------------------------------------------------------------
|
|---|
| 101 | | Facility : libnform
|
|---|
| 102 | | Function : static bool Check_This_Field(
|
|---|
| 103 | | FIELD *field,
|
|---|
| 104 | | const void *argp)
|
|---|
| 105 | |
|
|---|
| 106 | | Description : Validate buffer content to be a valid alphanumeric value
|
|---|
| 107 | |
|
|---|
| 108 | | Return Values : TRUE - field is valid
|
|---|
| 109 | | FALSE - field is invalid
|
|---|
| 110 | +--------------------------------------------------------------------------*/
|
|---|
| 111 | static bool
|
|---|
| 112 | Check_This_Field(FIELD *field, const void *argp)
|
|---|
| 113 | {
|
|---|
| 114 | int width = ((const thisARG *)argp)->width;
|
|---|
| 115 | unsigned char *bp = (unsigned char *)field_buffer(field, 0);
|
|---|
| 116 | bool result = (width < 0);
|
|---|
| 117 |
|
|---|
| 118 | Check_CTYPE_Field(result, bp, width, Check_This_Character);
|
|---|
| 119 | return (result);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | static FIELDTYPE typeTHIS =
|
|---|
| 123 | {
|
|---|
| 124 | _HAS_ARGS | _RESIDENT,
|
|---|
| 125 | 1, /* this is mutable, so we can't be const */
|
|---|
| 126 | (FIELDTYPE *)0,
|
|---|
| 127 | (FIELDTYPE *)0,
|
|---|
| 128 | Make_This_Type,
|
|---|
| 129 | Copy_This_Type,
|
|---|
| 130 | Free_This_Type,
|
|---|
| 131 | Check_This_Field,
|
|---|
| 132 | Check_This_Character,
|
|---|
| 133 | NULL,
|
|---|
| 134 | NULL
|
|---|
| 135 | };
|
|---|
| 136 |
|
|---|
| 137 | NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeTHIS;
|
|---|
| 138 |
|
|---|
| 139 | /* fty_alnum.c ends here */
|
|---|