soc/intel/xeon_sp/util: Enhance lock_pam0123
[coreboot2.git] / payloads / libpayload / curses / form / fty_alpha.c
blob917a9e0ea0a402519df1693bf745338a971b176d
1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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 ****************************************************************************/
29 /***************************************************************************
30 * *
31 * Author : Juergen Pfeifer *
32 * *
33 ***************************************************************************/
35 #include "form.priv.h"
37 MODULE_ID("$Id: fty_alpha.c,v 1.26 2010/01/23 21:14:36 tom Exp $")
39 #define thisARG alphaARG
41 typedef struct
43 int width;
45 thisARG;
47 /*---------------------------------------------------------------------------
48 | Facility : libnform
49 | Function : static void *Generic_This_Type(va_list *ap)
51 | Description : Allocate structure for alpha type argument.
53 | Return Values : Pointer to argument structure or NULL on error
54 +--------------------------------------------------------------------------*/
55 static void *
56 Generic_This_Type(void *arg)
58 thisARG *argp = (thisARG *) 0;
60 if (arg)
62 argp = typeMalloc(thisARG, 1);
64 if (argp)
66 T((T_CREATE("thisARG %p"), (void *)argp));
67 argp->width = *((int *)arg);
70 return ((void *)argp);
73 /*---------------------------------------------------------------------------
74 | Facility : libnform
75 | Function : static void *Make_This_Type(va_list *ap)
77 | Description : Allocate structure for alpha type argument.
79 | Return Values : Pointer to argument structure or NULL on error
80 +--------------------------------------------------------------------------*/
81 static void *
82 Make_This_Type(va_list *ap)
84 int w = va_arg(*ap, int);
86 return Generic_This_Type((void *)&w);
89 /*---------------------------------------------------------------------------
90 | Facility : libnform
91 | Function : static void *Copy_This_Type(const void * argp)
93 | Description : Copy structure for alpha type argument.
95 | Return Values : Pointer to argument structure or NULL on error.
96 +--------------------------------------------------------------------------*/
97 static void *
98 Copy_This_Type(const void *argp)
100 const thisARG *ap = (const thisARG *)argp;
101 thisARG *result = typeMalloc(thisARG, 1);
103 if (result)
105 T((T_CREATE("thisARG %p"), (void *)result));
106 *result = *ap;
109 return ((void *)result);
112 /*---------------------------------------------------------------------------
113 | Facility : libnform
114 | Function : static void Free_This_Type(void *argp)
116 | Description : Free structure for alpha type argument.
118 | Return Values : -
119 +--------------------------------------------------------------------------*/
120 static void
121 Free_This_Type(void *argp)
123 if (argp)
124 free(argp);
127 /*---------------------------------------------------------------------------
128 | Facility : libnform
129 | Function : static bool Check_This_Character(
130 | int c,
131 | const void *argp)
133 | Description : Check a character for the alpha type.
135 | Return Values : TRUE - character is valid
136 | FALSE - character is invalid
137 +--------------------------------------------------------------------------*/
138 static bool
139 Check_This_Character(int c, const void *argp GCC_UNUSED)
141 #if USE_WIDEC_SUPPORT
142 if (iswalpha((wint_t) c))
143 return TRUE;
144 #endif
145 return (isalpha(UChar(c)) ? TRUE : FALSE);
148 /*---------------------------------------------------------------------------
149 | Facility : libnform
150 | Function : static bool Check_This_Field(
151 | FIELD *field,
152 | const void *argp)
154 | Description : Validate buffer content to be a valid alpha value
156 | Return Values : TRUE - field is valid
157 | FALSE - field is invalid
158 +--------------------------------------------------------------------------*/
159 static bool
160 Check_This_Field(FIELD *field, const void *argp)
162 int width = ((const thisARG *)argp)->width;
163 unsigned char *bp = (unsigned char *)field_buffer(field, 0);
164 bool result = (width < 0);
166 Check_CTYPE_Field(result, bp, width, Check_This_Character);
167 return (result);
170 static FIELDTYPE typeTHIS =
172 _HAS_ARGS | _RESIDENT,
173 1, /* this is mutable, so we can't be const */
174 (FIELDTYPE *)0,
175 (FIELDTYPE *)0,
176 Make_This_Type,
177 Copy_This_Type,
178 Free_This_Type,
179 INIT_FT_FUNC(Check_This_Field),
180 INIT_FT_FUNC(Check_This_Character),
181 INIT_FT_FUNC(NULL),
182 INIT_FT_FUNC(NULL),
183 #if NCURSES_INTEROP_FUNCS
184 Generic_This_Type
185 #endif
188 NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALPHA = &typeTHIS;
190 #if NCURSES_INTEROP_FUNCS
191 /* The next routines are to simplify the use of ncurses from
192 programming languages with restictions on interop with C level
193 constructs (e.g. variable access or va_list + ellipsis constructs)
195 NCURSES_EXPORT(FIELDTYPE *)
196 _nc_TYPE_ALPHA(void)
198 return TYPE_ALPHA;
200 #endif
202 /* fty_alpha.c ends here */