1166124Srafan/**************************************************************************** 2174993Srafan * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * 3166124Srafan * * 4166124Srafan * Permission is hereby granted, free of charge, to any person obtaining a * 5166124Srafan * copy of this software and associated documentation files (the * 6166124Srafan * "Software"), to deal in the Software without restriction, including * 7166124Srafan * without limitation the rights to use, copy, modify, merge, publish, * 8166124Srafan * distribute, distribute with modifications, sublicense, and/or sell * 9166124Srafan * copies of the Software, and to permit persons to whom the Software is * 10166124Srafan * furnished to do so, subject to the following conditions: * 11166124Srafan * * 12166124Srafan * The above copyright notice and this permission notice shall be included * 13166124Srafan * in all copies or substantial portions of the Software. * 14166124Srafan * * 15166124Srafan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16166124Srafan * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17166124Srafan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18166124Srafan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19166124Srafan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20166124Srafan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21166124Srafan * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22166124Srafan * * 23166124Srafan * Except as contained in this notice, the name(s) of the above copyright * 24166124Srafan * holders shall not be used in advertising or otherwise to promote the * 25166124Srafan * sale, use or other dealings in this Software without prior written * 26166124Srafan * authorization. * 27166124Srafan ****************************************************************************/ 2850276Speter 2950276Speter/*************************************************************************** 3050276Speter* * 31166124Srafan* Author : Juergen Pfeifer * 3250276Speter* * 3350276Speter***************************************************************************/ 3450276Speter 3550276Speter#include "form.priv.h" 3650276Speter 37174993SrafanMODULE_ID("$Id: fty_alnum.c,v 1.21 2007/10/13 19:31:52 tom Exp $") 3850276Speter 39166124Srafan#define thisARG alnumARG 4050276Speter 41166124Srafantypedef struct 42166124Srafan { 43166124Srafan int width; 44166124Srafan } 45166124SrafanthisARG; 46166124Srafan 4750276Speter/*--------------------------------------------------------------------------- 48166124Srafan| Facility : libnform 49166124Srafan| Function : static void *Make_This_Type(va_list *ap) 50166124Srafan| 5150276Speter| Description : Allocate structure for alphanumeric type argument. 5250276Speter| 5350276Speter| Return Values : Pointer to argument structure or NULL on error 5450276Speter+--------------------------------------------------------------------------*/ 55166124Srafanstatic void * 56166124SrafanMake_This_Type(va_list *ap) 5750276Speter{ 58174993Srafan thisARG *argp = typeMalloc(thisARG, 1); 5950276Speter 6050276Speter if (argp) 61174993Srafan { 62174993Srafan T((T_CREATE("thisARG %p"), argp)); 63174993Srafan argp->width = va_arg(*ap, int); 64174993Srafan } 6550276Speter 6650276Speter return ((void *)argp); 6750276Speter} 6850276Speter 6950276Speter/*--------------------------------------------------------------------------- 70166124Srafan| Facility : libnform 71166124Srafan| Function : static void *Copy_ThisType(const void *argp) 7250276Speter| 73166124Srafan| Description : Copy structure for alphanumeric type argument. 74166124Srafan| 7550276Speter| Return Values : Pointer to argument structure or NULL on error. 7650276Speter+--------------------------------------------------------------------------*/ 77166124Srafanstatic void * 78166124SrafanCopy_This_Type(const void *argp) 7950276Speter{ 80166124Srafan const thisARG *ap = (const thisARG *)argp; 81174993Srafan thisARG *result = typeMalloc(thisARG, 1); 8250276Speter 8350276Speter if (result) 84174993Srafan { 85174993Srafan T((T_CREATE("thisARG %p"), result)); 86174993Srafan *result = *ap; 87174993Srafan } 8850276Speter 8950276Speter return ((void *)result); 9050276Speter} 9150276Speter 9250276Speter/*--------------------------------------------------------------------------- 93166124Srafan| Facility : libnform 94166124Srafan| Function : static void Free_This_Type(void *argp) 95166124Srafan| 9650276Speter| Description : Free structure for alphanumeric type argument. 9750276Speter| 9850276Speter| Return Values : - 9950276Speter+--------------------------------------------------------------------------*/ 100166124Srafanstatic void 101166124SrafanFree_This_Type(void *argp) 10250276Speter{ 103166124Srafan if (argp) 10450276Speter free(argp); 10550276Speter} 10650276Speter 10750276Speter/*--------------------------------------------------------------------------- 108166124Srafan| Facility : libnform 109166124Srafan| Function : static bool Check_This_Character( 110166124Srafan| int c, 111166124Srafan| const void *argp) 112166124Srafan| 113166124Srafan| Description : Check a character for the alphanumeric type. 114166124Srafan| 115166124Srafan| Return Values : TRUE - character is valid 116166124Srafan| FALSE - character is invalid 117166124Srafan+--------------------------------------------------------------------------*/ 118166124Srafanstatic bool 119166124SrafanCheck_This_Character(int c, const void *argp GCC_UNUSED) 120166124Srafan{ 121166124Srafan#if USE_WIDEC_SUPPORT 122166124Srafan if (iswalnum((wint_t) c)) 123166124Srafan return TRUE; 124166124Srafan#endif 125166124Srafan return (isalnum(UChar(c)) ? TRUE : FALSE); 126166124Srafan} 127166124Srafan 128166124Srafan/*--------------------------------------------------------------------------- 129166124Srafan| Facility : libnform 130166124Srafan| Function : static bool Check_This_Field( 13150276Speter| FIELD *field, 13250276Speter| const void *argp) 133166124Srafan| 13450276Speter| Description : Validate buffer content to be a valid alphanumeric value 13550276Speter| 13650276Speter| Return Values : TRUE - field is valid 13750276Speter| FALSE - field is invalid 13850276Speter+--------------------------------------------------------------------------*/ 139166124Srafanstatic bool 140166124SrafanCheck_This_Field(FIELD *field, const void *argp) 14150276Speter{ 142166124Srafan int width = ((const thisARG *)argp)->width; 143166124Srafan unsigned char *bp = (unsigned char *)field_buffer(field, 0); 144166124Srafan bool result = (width < 0); 14550276Speter 146166124Srafan Check_CTYPE_Field(result, bp, width, Check_This_Character); 147166124Srafan return (result); 14850276Speter} 14950276Speter 150166124Srafanstatic FIELDTYPE typeTHIS = 15150276Speter{ 15250276Speter _HAS_ARGS | _RESIDENT, 153166124Srafan 1, /* this is mutable, so we can't be const */ 15450276Speter (FIELDTYPE *)0, 15550276Speter (FIELDTYPE *)0, 156166124Srafan Make_This_Type, 157166124Srafan Copy_This_Type, 158166124Srafan Free_This_Type, 159166124Srafan Check_This_Field, 160166124Srafan Check_This_Character, 16150276Speter NULL, 16250276Speter NULL 16350276Speter}; 16450276Speter 165166124SrafanNCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeTHIS; 16650276Speter 16750276Speter/* fty_alnum.c ends here */ 168