xref: /illumos-gate/usr/src/lib/libeti/form/common/ty_alpha.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI" /* SVr4.0 1.1 */
32 
33 /*LINTLIBRARY*/
34 
35 #include <sys/types.h>
36 #include <stdlib.h>
37 #include "utility.h"
38 
39 /*
40  *	TYPE_ALPHA standard type
41  *
42  *	usage:
43  *		set_field_type(f, TYPE_ALPHA, width);
44  *
45  *		int width;	minimum token width
46  */
47 static char *make_alpha(va_list *);
48 static char *copy_alpha(char *);
49 static void free_alpha(char *);
50 static int fcheck_alpha(FIELD *, char *);
51 static int ccheck_alpha(int, char *);
52 
53 static FIELDTYPE typeALPHA =
54 {
55 				ARGS,			/* status	*/
56 				1,			/* ref		*/
57 				(FIELDTYPE *) 0,	/* left		*/
58 				(FIELDTYPE *) 0,	/* right	*/
59 				make_alpha,		/* makearg	*/
60 				copy_alpha,		/* copyarg	*/
61 				free_alpha,		/* freearg	*/
62 				fcheck_alpha,		/* fcheck	*/
63 				ccheck_alpha,		/* ccheck	*/
64 				(PTF_int) 0,		/* next		*/
65 				(PTF_int) 0,		/* prev		*/
66 };
67 
68 FIELDTYPE * TYPE_ALPHA = &typeALPHA;
69 
70 static char *
71 make_alpha(va_list *ap)
72 {
73 	int * width;
74 
75 	if (Alloc(width, int))
76 		*width = va_arg(*ap, int);
77 	return ((char *) width);
78 }
79 
80 static char *
81 copy_alpha(char *arg)
82 {
83 	int * width;
84 
85 	if (Alloc(width, int))
86 		*width = *((int *) arg);
87 	return ((char *) width);
88 }
89 
90 static void
91 free_alpha(char *arg)
92 {
93 	Free(arg);
94 }
95 
96 static int
97 fcheck_alpha(FIELD *f, char *arg)
98 {
99 	int	width	= *((int *) arg);
100 	int	n	= 0;
101 	char *	v	= field_buffer(f, 0);
102 
103 	while (*v && *v == ' ')
104 		++v;
105 	if (*v) {
106 		char * vbeg = v;
107 		while (*v && isalpha(*v))
108 			++v;
109 		n = v - vbeg;
110 		while (*v && *v == ' ')
111 			++v;
112 	}
113 	return (*v || n < width ? FALSE : TRUE);
114 }
115 
116 /*ARGSUSED*/
117 
118 static int
119 ccheck_alpha(int c, char *arg)
120 {
121 	return (isalpha(c));
122 }
123