xref: /illumos-gate/usr/src/lib/libeti/form/common/ty_alpha.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  *      Copyright (c) 1997, by Sun Microsystems, Inc.
28  *      All rights reserved.
29  */
30 
31 /*LINTLIBRARY*/
32 
33 #include <sys/types.h>
34 #include <stdlib.h>
35 #include "utility.h"
36 
37 /*
38  *	TYPE_ALPHA standard type
39  *
40  *	usage:
41  *		set_field_type(f, TYPE_ALPHA, width);
42  *
43  *		int width;	minimum token width
44  */
45 static char *make_alpha(va_list *);
46 static char *copy_alpha(char *);
47 static void free_alpha(char *);
48 static int fcheck_alpha(FIELD *, char *);
49 static int ccheck_alpha(int, char *);
50 
51 static FIELDTYPE typeALPHA =
52 {
53 				ARGS,			/* status	*/
54 				1,			/* ref		*/
55 				(FIELDTYPE *) 0,	/* left		*/
56 				(FIELDTYPE *) 0,	/* right	*/
57 				make_alpha,		/* makearg	*/
58 				copy_alpha,		/* copyarg	*/
59 				free_alpha,		/* freearg	*/
60 				fcheck_alpha,		/* fcheck	*/
61 				ccheck_alpha,		/* ccheck	*/
62 				(PTF_int) 0,		/* next		*/
63 				(PTF_int) 0,		/* prev		*/
64 };
65 
66 FIELDTYPE * TYPE_ALPHA = &typeALPHA;
67 
68 static char *
make_alpha(va_list * ap)69 make_alpha(va_list *ap)
70 {
71 	int * width;
72 
73 	if (Alloc(width, int))
74 		*width = va_arg(*ap, int);
75 	return ((char *) width);
76 }
77 
78 static char *
copy_alpha(char * arg)79 copy_alpha(char *arg)
80 {
81 	int * width;
82 
83 	if (Alloc(width, int))
84 		*width = *((int *) arg);
85 	return ((char *) width);
86 }
87 
88 static void
free_alpha(char * arg)89 free_alpha(char *arg)
90 {
91 	Free(arg);
92 }
93 
94 static int
fcheck_alpha(FIELD * f,char * arg)95 fcheck_alpha(FIELD *f, char *arg)
96 {
97 	int	width	= *((int *) arg);
98 	int	n	= 0;
99 	char *	v	= field_buffer(f, 0);
100 
101 	while (*v && *v == ' ')
102 		++v;
103 	if (*v) {
104 		char * vbeg = v;
105 		while (*v && isalpha(*v))
106 			++v;
107 		n = v - vbeg;
108 		while (*v && *v == ' ')
109 			++v;
110 	}
111 	return (*v || n < width ? FALSE : TRUE);
112 }
113 
114 /*ARGSUSED*/
115 
116 static int
ccheck_alpha(int c,char * arg)117 ccheck_alpha(int c, char *arg)
118 {
119 	return (isalpha(c));
120 }
121