source: trunk/essentials/sys-libs/ncurses/form/fty_alpha.c@ 3326

Last change on this file since 3326 was 2621, checked in by bird, 20 years ago

GNU ncurses 5.5

File size: 4.2 KB
Line 
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
15MODULE_ID("$Id: fty_alpha.c,v 1.20 2005/08/20 18:37:48 tom Exp $")
16
17#define thisARG alphaARG
18
19typedef struct
20 {
21 int width;
22 }
23thisARG;
24
25/*---------------------------------------------------------------------------
26| Facility : libnform
27| Function : static void *Make_This_Type(va_list *ap)
28|
29| Description : Allocate structure for alpha type argument.
30|
31| Return Values : Pointer to argument structure or NULL on error
32+--------------------------------------------------------------------------*/
33static void *
34Make_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_This_Type(const void * argp)
47|
48| Description : Copy structure for alpha type argument.
49|
50| Return Values : Pointer to argument structure or NULL on error.
51+--------------------------------------------------------------------------*/
52static void *
53Copy_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 alpha type argument.
69|
70| Return Values : -
71+--------------------------------------------------------------------------*/
72static void
73Free_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 alpha type.
86|
87| Return Values : TRUE - character is valid
88| FALSE - character is invalid
89+--------------------------------------------------------------------------*/
90static bool
91Check_This_Character(int c, const void *argp GCC_UNUSED)
92{
93#if USE_WIDEC_SUPPORT
94 if (iswalpha((wint_t) c))
95 return TRUE;
96#endif
97 return (isalpha(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 alpha value
107|
108| Return Values : TRUE - field is valid
109| FALSE - field is invalid
110+--------------------------------------------------------------------------*/
111static bool
112Check_This_Field(FIELD *field, const void *argp)