00001 /* 00002 * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT. 00003 * You may freely copy it for use as a template for your own field types. 00004 * If you develop a field type that might be of general use, please send 00005 * it back to the ncurses maintainers for inclusion in the next version. 00006 */ 00007 /*************************************************************************** 00008 * * 00009 * Author : Juergen Pfeifer * 00010 * * 00011 ***************************************************************************/ 00012 00013 #include "form.priv.h" 00014 00015 MODULE_ID("$Id: fty_alnum.c,v 1.18 2005/08/20 18:26:16 tom Exp $") 00016 00017 #define thisARG alnumARG 00018 00019 typedef struct 00020 { 00021 int width; 00022 } 00023 thisARG; 00024 00025 /*--------------------------------------------------------------------------- 00026 | Facility : libnform 00027 | Function : static void *Make_This_Type(va_list *ap) 00028 | 00029 | Description : Allocate structure for alphanumeric type argument. 00030 | 00031 | Return Values : Pointer to argument structure or NULL on error 00032 +--------------------------------------------------------------------------*/ 00033 static void * 00034 Make_This_Type(va_list *ap) 00035 { 00036 thisARG *argp = (thisARG *) malloc(sizeof(thisARG)); 00037 00038 if (argp) 00039 argp->width = va_arg(*ap, int); 00040 00041 return ((void *)argp); 00042 } 00043 00044 /*--------------------------------------------------------------------------- 00045 | Facility : libnform 00046 | Function : static void *Copy_ThisType(const void *argp) 00047 | 00048 | Description : Copy structure for alphanumeric type argument. 00049 | 00050 | Return Values : Pointer to argument structure or NULL on error. 00051 +--------------------------------------------------------------------------*/ 00052 static void * 00053 Copy_This_Type(const void *argp) 00054 { 00055 const thisARG *ap = (const thisARG *)argp; 00056 thisARG *result = (thisARG *) malloc(sizeof(thisARG)); 00057 00058 if (result) 00059 *result = *ap; 00060 00061 return ((void *)result); 00062 } 00063 00064 /*--------------------------------------------------------------------------- 00065 | Facility : libnform 00066 | Function : static void Free_This_Type(void *argp) 00067 | 00068 | Description : Free structure for alphanumeric type argument. 00069 | 00070 | Return Values : - 00071 +--------------------------------------------------------------------------*/ 00072 static void 00073 Free_This_Type(void *argp) 00074 { 00075 if (argp) 00076 free(argp); 00077 } 00078 00079 /*--------------------------------------------------------------------------- 00080 | Facility : libnform 00081 | Function : static bool Check_This_Character( 00082 | int c, 00083 | const void *argp) 00084 | 00085 | Description : Check a character for the alphanumeric type. 00086 | 00087 | Return Values : TRUE - character is valid 00088 | FALSE - character is invalid 00089 +--------------------------------------------------------------------------*/ 00090 static bool 00091 Check_This_Character(int c, const void *argp GCC_UNUSED) 00092 { 00093 #if USE_WIDEC_SUPPORT 00094 if (iswalnum((wint_t) c)) 00095 return TRUE; 00096 #endif 00097 return (isalnum(UChar(c)) ? TRUE : FALSE); 00098 } 00099 00100 /*--------------------------------------------------------------------------- 00101 | Facility : libnform 00102 | Function : static bool Check_This_Field( 00103 | FIELD *field, 00104 | const void *argp) 00105 | 00106 | Description : Validate buffer content to be a valid alphanumeric value 00107 | 00108 | Return Values : TRUE - field is valid 00109 | FALSE - field is invalid 00110 +--------------------------------------------------------------------------*/ 00111 static bool 00112 Check_This_Field(FIELD *field, const void *argp) 00113 { 00114 int width = ((const thisARG *)argp)->width; 00115 unsigned char *bp = (unsigned char *)field_buffer(field, 0); 00116 bool result = (width < 0); 00117 00118 Check_CTYPE_Field(result, bp, width, Check_This_Character); 00119 return (result); 00120 } 00121 00122 static FIELDTYPE typeTHIS = 00123 { 00124 _HAS_ARGS | _RESIDENT, 00125 1, /* this is mutable, so we can't be const */ 00126 (FIELDTYPE *)0, 00127 (FIELDTYPE *)0, 00128 Make_This_Type, 00129 Copy_This_Type, 00130 Free_This_Type, 00131 Check_This_Field, 00132 Check_This_Character, 00133 NULL, 00134 NULL 00135 }; 00136 00137 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeTHIS; 00138 00139 /* fty_alnum.c ends here */