1 /**************************************************************************** 2 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * 3 * * 4 * Permission is hereby granted, free of charge, to any person obtaining a * 5 * copy of this software and associated documentation files (the * 6 * "Software"), to deal in the Software without restriction, including * 7 * without limitation the rights to use, copy, modify, merge, publish, * 8 * distribute, distribute with modifications, sublicense, and/or sell * 9 * copies of the Software, and to permit persons to whom the Software is * 10 * furnished to do so, subject to the following conditions: * 11 * * 12 * The above copyright notice and this permission notice shall be included * 13 * in all copies or substantial portions of the Software. * 14 * * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22 * * 23 * Except as contained in this notice, the name(s) of the above copyright * 24 * holders shall not be used in advertising or otherwise to promote the * 25 * sale, use or other dealings in this Software without prior written * 26 * authorization. * 27 ****************************************************************************/ 28 29 /*************************************************************************** 30 * * 31 * Author : Juergen Pfeifer * 32 * * 33 ***************************************************************************/ 34 35 #include "form.priv.h" 36 37 MODULE_ID("$Id: fty_alnum.c,v 1.19 2006/04/22 21:33:05 tom Exp $") 38 39 #define thisARG alnumARG 40 41 typedef struct 42 { 43 int width; 44 } 45 thisARG; 46 47 /*--------------------------------------------------------------------------- 48 | Facility : libnform 49 | Function : static void *Make_This_Type(va_list *ap) 50 | 51 | Description : Allocate structure for alphanumeric type argument. 52 | 53 | Return Values : Pointer to argument structure or NULL on error 54 +--------------------------------------------------------------------------*/ 55 static void * 56 Make_This_Type(va_list *ap) 57 { 58 thisARG *argp = (thisARG *) malloc(sizeof(thisARG)); 59 60 if (argp) 61 argp->width = va_arg(*ap, int); 62 63 return ((void *)argp); 64 } 65 66 /*--------------------------------------------------------------------------- 67 | Facility : libnform 68 | Function : static void *Copy_ThisType(const void *argp) 69 | 70 | Description : Copy structure for alphanumeric type argument. 71 | 72 | Return Values : Pointer to argument structure or NULL on error. 73 +--------------------------------------------------------------------------*/ 74 static void * 75 Copy_This_Type(const void *argp) 76 { 77 const thisARG *ap = (const thisARG *)argp; 78 thisARG *result = (thisARG *) malloc(sizeof(thisARG)); 79 80 if (result) 81 *result = *ap; 82 83 return ((void *)result); 84 } 85 86 /*--------------------------------------------------------------------------- 87 | Facility : libnform 88 | Function : static void Free_This_Type(void *argp) 89 | 90 | Description : Free structure for alphanumeric type argument. 91 | 92 | Return Values : - 93 +--------------------------------------------------------------------------*/ 94 static void 95 Free_This_Type(void *argp) 96 { 97 if (argp) 98 free(argp); 99 } 100 101 /*--------------------------------------------------------------------------- 102 | Facility : libnform 103 | Function : static bool Check_This_Character( 104 | int c, 105 | const void *argp) 106 | 107 | Description : Check a character for the alphanumeric type. 108 | 109 | Return Values : TRUE - character is valid 110 | FALSE - character is invalid 111 +--------------------------------------------------------------------------*/ 112 static bool 113 Check_This_Character(int c, const void *argp GCC_UNUSED) 114 { 115 #if USE_WIDEC_SUPPORT 116 if (iswalnum((wint_t) c)) 117 return TRUE; 118 #endif 119 return (isalnum(UChar(c)) ? TRUE : FALSE); 120 } 121 122 /*--------------------------------------------------------------------------- 123 | Facility : libnform 124 | Function : static bool Check_This_Field( 125 | FIELD *field, 126 | const void *argp) 127 | 128 | Description : Validate buffer content to be a valid alphanumeric value 129 | 130 | Return Values : TRUE - field is valid 131 | FALSE - field is invalid 132 +--------------------------------------------------------------------------*/ 133 static bool 134 Check_This_Field(FIELD *field, const void *argp) 135 { 136 int width = ((const thisARG *)argp)->width; 137 unsigned char *bp = (unsigned char *)field_buffer(field, 0); 138 bool result = (width < 0); 139 140 Check_CTYPE_Field(result, bp, width, Check_This_Character); 141 return (result); 142 } 143 144 static FIELDTYPE typeTHIS = 145 { 146 _HAS_ARGS | _RESIDENT, 147 1, /* this is mutable, so we can't be const */ 148 (FIELDTYPE *)0, 149 (FIELDTYPE *)0, 150 Make_This_Type, 151 Copy_This_Type, 152 Free_This_Type, 153 Check_This_Field, 154 Check_This_Character, 155 NULL, 156 NULL 157 }; 158 159 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeTHIS; 160 161 /* fty_alnum.c ends here */ 162