ncursesw-morphos/form/fty_alnum.c

140 lines
4.2 KiB
C
Raw Normal View History

1997-05-15 12:00:00 +08:00
/*
* THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
* You may freely copy it for use as a template for your own field types.
* If you develop a field type that might be of general use, please send
* it back to the ncurses maintainers for inclusion in the next version.
*/
/***************************************************************************
* *
2002-10-13 11:35:53 +08:00
* Author : Juergen Pfeifer *
1997-05-15 12:00:00 +08:00
* *
***************************************************************************/
#include "form.priv.h"
2005-10-10 02:41:57 +08:00
MODULE_ID("$Id: fty_alnum.c,v 1.18 2005/08/20 18:26:16 tom Exp $")
#define thisARG alnumARG
1997-05-15 12:00:00 +08:00
2005-10-10 02:41:57 +08:00
typedef struct
{
int width;
}
thisARG;
1997-05-15 12:00:00 +08:00
/*---------------------------------------------------------------------------
2005-10-10 02:41:57 +08:00
| Facility : libnform
| Function : static void *Make_This_Type(va_list *ap)
|
1997-05-15 12:00:00 +08:00
| Description : Allocate structure for alphanumeric type argument.
|
| Return Values : Pointer to argument structure or NULL on error
+--------------------------------------------------------------------------*/
2005-10-10 02:41:57 +08:00
static void *
Make_This_Type(va_list *ap)
1997-05-15 12:00:00 +08:00
{
2005-10-10 02:41:57 +08:00
thisARG *argp = (thisARG *) malloc(sizeof(thisARG));
1997-05-15 12:00:00 +08:00
if (argp)
2005-10-10 02:41:57 +08:00
argp->width = va_arg(*ap, int);
1997-05-15 12:00:00 +08:00
return ((void *)argp);
}
/*---------------------------------------------------------------------------
2005-10-10 02:41:57 +08:00
| Facility : libnform
| Function : static void *Copy_ThisType(const void *argp)
|
| Description : Copy structure for alphanumeric type argument.
1997-05-15 12:00:00 +08:00
|
| Return Values : Pointer to argument structure or NULL on error.
+--------------------------------------------------------------------------*/
2005-10-10 02:41:57 +08:00
static void *
Copy_This_Type(const void *argp)
1997-05-15 12:00:00 +08:00
{
2005-10-10 02:41:57 +08:00
const thisARG *ap = (const thisARG *)argp;
thisARG *result = (thisARG *) malloc(sizeof(thisARG));
1997-05-15 12:00:00 +08:00
1998-03-01 12:21:12 +08:00
if (result)
*result = *ap;
1997-05-15 12:00:00 +08:00
1998-03-01 12:21:12 +08:00
return ((void *)result);
1997-05-15 12:00:00 +08:00
}
/*---------------------------------------------------------------------------
2005-10-10 02:41:57 +08:00
| Facility : libnform
| Function : static void Free_This_Type(void *argp)
|
1997-05-15 12:00:00 +08:00
| Description : Free structure for alphanumeric type argument.
|
| Return Values : -
+--------------------------------------------------------------------------*/
2005-10-10 02:41:57 +08:00
static void
Free_This_Type(void *argp)
1997-05-15 12:00:00 +08:00
{
2005-10-10 02:41:57 +08:00
if (argp)
1997-05-15 12:00:00 +08:00
free(argp);
}
/*---------------------------------------------------------------------------
2005-10-10 02:41:57 +08:00
| Facility : libnform
| Function : static bool Check_This_Character(
| int c,
1997-05-15 12:00:00 +08:00
| const void *argp)
|
2005-10-10 02:41:57 +08:00
| Description : Check a character for the alphanumeric type.
|
| Return Values : TRUE - character is valid
| FALSE - character is invalid
1997-05-15 12:00:00 +08:00
+--------------------------------------------------------------------------*/
2005-10-10 02:41:57 +08:00
static bool
Check_This_Character(int c, const void *argp GCC_UNUSED)
1997-05-15 12:00:00 +08:00
{
2005-10-10 02:41:57 +08:00
#if USE_WIDEC_SUPPORT
if (iswalnum((wint_t) c))
return TRUE;
#endif
return (isalnum(UChar(c)) ? TRUE : FALSE);
1997-05-15 12:00:00 +08:00
}
/*---------------------------------------------------------------------------
2005-10-10 02:41:57 +08:00
| Facility : libnform
| Function : static bool Check_This_Field(
| FIELD *field,
| const void *argp)
1997-05-15 12:00:00 +08:00
|
2005-10-10 02:41:57 +08:00
| Description : Validate buffer content to be a valid alphanumeric value
|
| Return Values : TRUE - field is valid
| FALSE - field is invalid
1997-05-15 12:00:00 +08:00
+--------------------------------------------------------------------------*/
2005-10-10 02:41:57 +08:00
static bool
Check_This_Field(FIELD *field, const void *argp)
1997-05-15 12:00:00 +08:00
{
2005-10-10 02:41:57 +08:00
int width = ((const thisARG *)argp)->width;
unsigned char *bp = (unsigned char *)field_buffer(field, 0);
bool result = (width < 0);
Check_CTYPE_Field(result, bp, width, Check_This_Character);
return (result);
1997-05-15 12:00:00 +08:00
}
2005-10-10 02:41:57 +08:00
static FIELDTYPE typeTHIS =
{
1997-05-15 12:00:00 +08:00
_HAS_ARGS | _RESIDENT,
2005-10-10 02:41:57 +08:00
1, /* this is mutable, so we can't be const */
1997-05-15 12:00:00 +08:00
(FIELDTYPE *)0,
(FIELDTYPE *)0,
2005-10-10 02:41:57 +08:00
Make_This_Type,
Copy_This_Type,
Free_This_Type,
Check_This_Field,
Check_This_Character,
1997-05-15 12:00:00 +08:00
NULL,
NULL
};
2005-10-10 02:41:57 +08:00
NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALNUM = &typeTHIS;
1997-05-15 12:00:00 +08:00
/* fty_alnum.c ends here */